How do I stop emacs from highlighting the line under the mouse in shell - shell

In emacs shell, invoked using M-x shell, input lines under the cursor are highlighted, so you can then "mouse 2: insert after prompt as new input" to repeat the command. I'd prefer not to have this activated and just select text under the mouse as I do in a regular terminal and middle click to insert (I know I can do this in emacs but I don't get any visual feedback until I stop the mouse selection).
Is there any way to do this? I've done quite a bit of searching and can't find anything.

That message comes from this function in comint.el.
Setting comint-use-prompt-regexp to a non-nil value should do what you want.
A good solution would probably be something like this (put the following somewhere in your initialization; regexp taken from comint-prompt-regexp docstring):
(add-hook 'shell-mode-hook
(lambda ()
(set (make-local-variable 'comint-use-prompt-regexp) t)
(set (make-local-variable 'comint-prompt-regexp) "^[^#$%>\n]*[#$%>] *")))

You do not specify the version of Emacs and I do not see that behaviour in my Emacs why I type M-x shell. However, a little googling turned up this:
(setq comint-highlight-input nil)
which is something that you can set in ~/.emacs.
This variable does not exist in GNU Emacs 25, even though there is a reference to a specific face (highlighting) to use in that case. Either that is a mere reminisence from when the feature was available or it is something that is actually enabled with another package. You can test by starting emacs with the "-Q" option and start shell as the first thing, if the behaviour does not appear, it is something that is related to your startup configuration or something you do before starting the shell.
The post in which the above variable was mentioned can be seen here:
https://stat.ethz.ch/pipermail/ess-help/2002-August/001134.html

Related

emacsclient, restore all windows in a frame in terminal

The object: In terminal, on start, in one frame, restore emacs workspace. i.e. restore all "windows", to the state before C-x C-c.
Descriptions: The window restoration could be simply done in emacs GUI, by adding (desktop-save-mode 1) to the init.el file.
However, when running emacs as a Daemon, emacsclient does not perform the same way. With the same setup, it still remember the major mode of the file, as well as other buffers before exiting, but the window layout will not be restored. Only 1 major window is displayed depend on the default settings.
I did some research, poked into some functions/variables using the elisp build-in documentation. I checked (desktop-save-buffer 1), framset-save, framset-restore and none of them seems to work. Also I checked similar questions posted before, and I found someone's answer using the following script:
(setq desktop-restore-forces-onscreen nil)
(add-hook 'desktop-after-read-hook
(lambda ()
(frameset-restore
desktop-saved-frameset
:reuse-frames (eq desktop-restore-reuses-frames t)
:cleanup-frames (not (eq desktop-restore-reuses-frames 'keep))
:force-display desktop-restore-in-current-display
:force-onscreen desktop-restore-forces-onscreen)))
However this script is buggy, it opens a "GUI" frame, and could not be closed properly(reopen automatically whenever closed, and if possible, I prefer to open the frame in terminal, so that a terminal 'texteditor' setting is possibe, with some other minor merits).
Sorry for the tedious question, any help would be appreciated.
I don't really know the right way to do this, but I was able to restore a frameset created in a GUI frame into a terminal frame. The new frame must be big enough or it will throw an error. I did (setq foo (frameset-save (frame-list))) and (pp foo (get-buffer "*scratch*")) to dump a readable representation of the frameset to the *scratch* buffer. Then I edited it by hand to get rid of (display . ":0.0"). That seemed to be enough to get it to not force a GUI frame. Then I did (frameset-restore [frameset ...]) on the edited frameset.
If you look at frameset.el, there are filtering functions to edit a frameset programmatically. Also, if you look at the comments, the display parameter is treated specially. You should look at the details there.

How to disable vim pasting to/from system clipboard?

Basically, I need advice on how to do the opposite of what is described here:
How to make vim paste from (and copy to) system's clipboard?
I do not want vim to overwrite system clipboard when I delete something within the editor. The usual workflow for me is to select a piece of code (let us call it piece #1) with a mouse, then go to another piece of code (let us call it piece #2), select piece #2 in visual mode in vim, delete it using "c", and paste piece #1 using mouse middle button. With the new behavior, instead of pasting piece #1 I paste back piece #2.
In vim 7.2 I can do that, but in vim 7.4 I can not. I want to use 7.4 due to proper C++11 syntax highlighting but this changed default behavior is killing me.
I think, it has something to do with the "+xterm_clipboard" and/or "+clipboard" features of vim (vim --version), and I need to change them somehow to "-xterm_clipboard" and/or "-clipboard". I tried to recompile vim 7.4 with the option "--with-x=no" but somehow it did not help.
Please, help me to disable copying/pasting in vim to system clipboard by default.
Thank you!
Well, to answer the question in your title, you can just do
:set clipboard=
Which will make vim use it's internal register instead of the system one.
But really, this behavior has nothing to do with the system clipboard. It's more just a general misunderstanding of vim registers.
Vim by default "cuts" rather than "deletes". This means that every delete command (c and d) yanks to the unnamed register at the same time. To get around this, just use the black hole register, e.g. use "_c or "_d instead of just doing c or d.
9. Black hole register "_ *quote_*
When writing to this register, nothing happens. This can be used to delete
text without affecting the normal registers. When reading from this register,
nothing is returned. {not in Vi}
To make this the default behavior for your specific case, you can do
xnoremap c "_d
The 'x' in 'xnoremap' means this mapping applies to visual mode (with v) and select mode (with the mouse)
Related SO link.
check
:h clipboard-unnamed
This extension may be also of use to you http://vimawesome.com/plugin/easyclip

Why does shell mode display some rubbish code?

When I use bower in M-x shell, as you can see in the picture, some rubbish code is displayed.
However M-x ansi-term works well
What could be the problem ? Is it possible to make shell mode display properly ?
Those symbols are ANSI escape sequences that the terminal emulator uses for visual effects like changing the color of text. shell-mode apparently doesn't know how to display these codes by default. What you want may be Term Mode:
Some programs (such as Emacs itself) need to control the appearance of the terminal screen in detail. They do this by emitting special control codes. Term mode recognizes and handles ANSI-standard VT100-style escape sequences, which are accepted by most modern terminals, including xterm. (Hence, you can actually run Emacs inside an Emacs Term window.)
Try the solution given in Cucumber's ANSI colors messing up emacs compilation buffer:
(require 'ansi-color)
(defun colorize-compilation-buffer ()
(toggle-read-only)
(ansi-color-apply-on-region (point-min) (point-max))
(toggle-read-only))
(add-hook 'compilation-filter-hook 'colorize-compilation-buffer)
that works beautifuly for me on emacs24.
ps: to colorize even more the shell output I like to play with
M-x highlight-regexp RET a regexp, i.e. \[OK\] RET a color (make use of TAB to see choices)
or
(add-hook 'shell-mode-hook (lambda () (highlight-regexp "\\[OK\\]" "hi-green-b")))
and (add-hook 'shell-mode-hook (lambda () (goto-address-mode ))) to make URLs clikable. Looking for the same stuff for file paths.
edit: making file paths clickable is as easy as using compilation-shell-minor-mode :)
edit2: my sources: http://wikemacs.org/index.php/Shell
WRT to bash, sometimes setting $PAGER helps here, i.e.
PAGER=cat

term inside emacs:: how to turn "word wrap" off

In setting up my personal Linux command line development environment, I want to use term inside emacs b/c then I can switch to 'line mode' and copy/paste the output into any other buffer.
However, when I run mysql inside term inside emacs, the pretty sql tables still word wrap according to the width of that emacs window :(. I was hoping that emacs would truncate the bash output.
Is there a way to do this?
EDIT:
toggle-truncate-lines is on, so "word wrap" is off, but the problem is that before emacs even does anything with the text, the underlying bash process itself manually adds newlines to wrap text according to the width it's told it's using. That's at least how it acts. toggling truncate lines on/off doesn't change anything for me in the term buffer
I think what you probably want is "M-x toggle-truncate-lines". That toggles between wrapping or requiring you to scroll right and left to see the entire line.
You probably want to add something to the sql hook to turn off the wrapping:
(add-hook 'sql-interactive-mode-hook '(lambda () (toggle-truncate-lines 1))
I think Emacs might be setting the COLUMNS environment variable to indicate when the shell should wrap lines. Try setting it to a very large value and see if that helps.
I have no idea what other things this will break though.
Meta-X auto-fill-mode
This will toggle auto-fill mode and stop the line wrap.
The function term--unwrap-visible-long-lines is called by term-reset-size whenever the window is resized and appears to be responsible for the unwanted wrapping, and is not configurable. I hack this by advising the function to fix the wrapped width to a large value.
(defun my-prevent-term-unwrap (original-function height width)
(apply original-function (list height 10000)))
(advice-add 'term-reset-size :around 'my-prevent-term-unwrap)

Emacs M-x commands for invoking "GUI-style" menus

Question: How could I find out the M-x equivalent commands for doing GUI-based operations in Emacs, in those cases where my Emacs-variant uses OS-specific desktop functionality?
Background: Conventional understanding states that everything in Emacs is a command, and that commands can be invoked via M-x, as long as you know the name of the command. Assuming this statement is correct, what is the way to find the name of the commands used to trigger the "GUI-style" menus in a "desktop" based Emacs variant?
For example, if I were to mouse-select the File menu to open a file, the OS-specific "GUI" style file-open dialog pops up, waiting for my input.
How could I find out the M-x equivalent command for doing the exact same thing?
I thought that describe-key would tell me what I needed to know, but it's indication to use:
M-x menu-find-file-existing
doesn't invoke the "GUI" style file-open dialog. Instead, it uses the Emacs internal non-GUI-OS-neutral variant.
You need to trick Emacs into thinking that the keyboard was not being used, which is not as intuitive as tricking it into thinking that the mouse was used. :)
(defadvice find-file-read-args (around find-file-read-args-always-use-dialog-box act)
"Simulate invoking menu item as if by the mouse; see `use-dialog-box'."
(let ((last-nonmenu-event nil))
ad-do-it))
Tested on Emacs 22.2.1 on WinXP. I believe the paradigm has been around for a while, though, so it should work on older Emacs. No clue if XEmacs works similarly or not.
Wow, I'm glad you asked that. I've been meaning for a while to look it up myself.
C-h k followed by the menu choice will tell you this. Here, for example, is what you get from choosing menu/edit/paste:
<menu-bar> <edit> <paste> runs the command clipboard-yank
which is an interactive compiled Lisp function in `menu-bar.el'.
It is bound to <paste>, <f18>, <menu-bar> <edit> <paste>.
(clipboard-yank)
Insert the clipboard contents, or the last stretch of killed text.
If you want the details, follow the link for menu-bar-el to the LISP source:
(defun menu-find-file-existing ()
"Edit the existing file FILENAME."
(interactive)
(let* ((mustmatch (not (and (fboundp 'x-uses-old-gtk-dialog)
(x-uses-old-gtk-dialog))))
(filename (car (find-file-read-args "Find file: " mustmatch))))
(if mustmatch
(find-file-existing filename)
(find-file filename))))

Resources