How and where to change mouse button behaviour in a special mode - emacs

In Markdown mode with flyspell enabled, mouse-2 bound to mouse-yank-primary is also bound to flyspell-correct-word, the flyspell function that displays in a menu correction propositions. If the buffer is empty, the menu is displayed, if not, its content is yanked. Grrr.
I spent some time trying to find where to change this second binding but as I'm not an emacs guru, I just got lost. I tried (global-set-key "S-mouse-2" #'flyspell-correct-word) in ~/.emacs.d/init.el but I didn't manage to get anything working properly.
So the question is how and where to bind say S-mouse-2 to that function. A better solution would be to keep both bindings but to prioritize the menu over yanking when the mouse is over a word that needs correction.

On my GNU Emacs 25.2.2 the command (executed from the *scratch* buffer)
(global-set-key "S-mouse-2" #'flyspell-correct-word)
pops up the debugger. However,
(global-set-key [S-mouse-2] #'flyspell-correct-word)
works, as also
(global-set-key [S-mouse-2] 'flyspell-correct-word)
You can check the effect with:
(global-key-binding [S-mouse-2])

Related

Emacs auto-complete.el switch tab to spacebar

I've used auto-complete.el in Emacs for ages. I'm using Emacs a bit more these days and my left pinky is starting to get RSI from hitting TAB and ctrl all the time. I've done some keyboard remapping to alleviate the situation but every few characters I'm generally pressing tab to complete a word. Is there any way to switch auto-complete.el from using TAB for completion to spacebar with my less used and stronger thumbs?
Edit2: I was using a really old version of auto-complete.el which meant that #hd1 suggestion didn't work for me immediately.
Going to the source and scrolling down to line 235 shows that if you set the variable ac-trigger-key you can change the key that's used to trigger completion. You should set this variable in your custom-set-variables block in your .emacs file.
I think ac-complete-mode-map is a keymap used when the auto-complete
menu is shown. How about trying something like this instead (this is
my setting):
(define-key evil-insert-state-map (kbd "C-SPC") 'auto-complete)
If you don't use evil, you need to find another keymap. Perhaps a
mode-specific map, or even global-map will work.

How to scroll up in Emacs ansi-term

I've been Googling around and looking at Emacs built-in help but I have yet to determine how to scroll up (or down) in Emacs ansi-term.
I'm using Emacs 23.3.1, OS X, in iTerm2. Thanks!
Edit: I've noticed most the advice people give me doesn't work in ansi-term but does work in eshell. I have since moved to eshell.
In general, if you don't need full screen terminal emulation, shell or eshell are better choices.
However, if you decide to stick with ansi-term, press C-c C-j to go into line mode. Then you can move around normally with the usual cursor movement keys. Press C-c C-k to get back into char mode to interact with the terminal.
Alternatively, you can scroll backwards a screen at a time with C-c C-v and just enter text to scroll back to the terminal input point.
Take a look at the Emacs documentation on term-mode (most of which applies equally to ansi-term) for more information.
Shift-page up/down (in Emacs-speak, S-prior/S-next) will work using the default bindings.
(While the normal C-h m/C-h b don't work to see mode information and bindings in this mode, you can still use C-c M-x describe-mode/describe-bindings, or depending on your setup, use F1 or the help key instead of C-h.)
install evil-mode at first, press C-z to switch to vim key binding.
You can use C-f, C-b to scroll up and down
you can use 20% to jump to to the top 20% of the buffer
you can use /, ?, #, * to search the text in the buffer.
all the grep/filter commands now usable (occur, swiper, helm-swoop, .... just name a few)
you can narrow/widen the buffer
you can yank text
Have you tried: Page up, up arrow, Ctrl-V,Alt-V
For ansi-term, I have this in my .emacs:
(add-hook 'term-mode-hook
(function
(lambda ()
(define-key term-raw-map [?\C-c prior] 'scroll-down)
(define-key term-raw-map [?\C-c next] 'scroll-up))))
Then I can use C-c pgup and C-c pgdn to scroll.
I was having the same issue but with multi-term (zsh), and after reading the response from #muffinista (the C-v did not work for me) but the Alt-v worked to go 1 page, after that you can use the normal C-p and C-n to scroll up and down.
This worked for me, but it depends a lot on which term you are using and key bindings you might have.
Up and down are Ctrl-P and Ctrl-V. There's a whole long list here

Is there any way to get Ediff to not open its navigation interface in an external window?

Not being using Emacs all that long (v23, windows) and just discovered M-x ediff. Fantastic.
Although I'm not to keen on the fact it opens its help/navigation in a separate frame/window, meaning that if I lose focus to that window, the single key shortcuts don't work.
For example as soon as I press ? to expand the window, it shifts over top of my current window, so I have to pick up my mouse and move it to another screen. Then if I lose focus to that window and press p / n / j or any other key to work with the diff, it inserts it into my document. So i have to undo, grab mouse, focus to other window, and repeat.
Is there any way to configure these options to show in a split instead?
I didn't know how to do it but it is usually easy to learn with Emacs. First I asked about ediff customizations:
M-x customize-apropos
ediff
I saw there is something called Ediff Window Setup Function which takes the values Multi Frame, Single Frame, or Other Function. Mine was set to Multi Frame and changed it to Single Frame and saved it for future sessions. And Voila! as they say somewhere.
Simply:
(setq ediff-window-setup-function 'ediff-setup-windows-plain)
M-x describe-variable ediff-window-setup-function will enlighten you
further.
For reference my ediff customisation is fairly simple:
(if (locate-library "ediff")
(progn
(autoload 'ediff-files "ediff")
(autoload 'ediff-buffers "ediff")
(eval-after-load "ediff" '(progn
(message "doing ediff customisation")
(setq diff-switches "-u"
ediff-custom-diff-options "-U3"
ediff-split-window-function 'split-window-horizontally
ediff-window-setup-function 'ediff-setup-windows-plain)
(add-hook 'ediff-startup-hook 'ediff-toggle-wide-display)
(add-hook 'ediff-cleanup-hook 'ediff-toggle-wide-display)
(add-hook 'ediff-suspend-hook 'ediff-toggle-wide-display)))))
From chapter Window and Frame Configuration in Ediff User's Manual:
The following variable controls how
windows are set up:
ediff-window-setup-function
The multiframe setup is done by the ediff-setup-windows-multiframe
function, which is the default on
windowing displays. The plain setup,
one where all windows are always in
one frame, is done by
ediff-setup-windows-plain, which is
the default on a non-windowing display
(or in an xterm window). In fact,
under Emacs, you can switch freely
between these two setups by executing
the command ediff-toggle-multiframe
using the Minibuffer of the Menubar.
(custom-set-variables
...
'(ediff-window-setup-function (quote ediff-setup-windows-plain))
...)
Not that you would set the variable this way, but it allows you to know these things:
The variable you are interested in is ediff-window-setup-function
The value it needs to be set to is ediff-setup-windows-plain
You can configure the variable from customize: M-x customize-group RET ediff-window
Ediff Window Setup Function: Menu Single Frame
Note: you can avoid using the mouse to go back to the ediff control window by using M-x other-frame. Also found on C-x 5 o.
This no longer works in 2017 gnu emacs (24.5, 25.2, 2017) on windows
(setq ediff-window-setup-function 'ediff-setup-windows-plain) ; stopped working
Even
ediff-toggle-multiframe ; no longer has any effect now.
It works in emacs22.3 on windows, so I have use older emacs from 2008!

emacs list-buffers behavior

In GNU emacs, every time I hit Ctrl-x Ctrl-b to see all of my buffers, the window is split to show the buffer list, or if I have my window already split in 2 (for instance, I will have a shell running in the lower window), the buffer list appears in the other window.
My desired behavior is for the buffer list to appear in my active window so that I can select the buffer I want and continue to working in the same window, rather than having to Ctrl-x Ctrl-o to the other buffer, selecting the buffer (with enter) and editing that buffer in the other window... I've googled for it but it doesn't seem to be a common desire? I wonder if anyone has an elispy (or other) solution?
You might want to rebind C-x C-b to invoke buffer-menu rather than list-buffers:
(global-set-key "\C-x\C-b" 'buffer-menu)
Just customize the variable same-window-regexps. display-buffer will display any buffer whose name matches a regexp there in the currently-selected window.
(You will want to add "[*]Buffer List".)
not exactly a solution, but ido-mode provides a different and powerful way to interact with buffers. C-x b will then show a list of all the open buffers, and the one you select will open in the current window.
Strangely, there isn't an answer here about ibuffer.
I would recommend this as a standard change for the majority of Emacs users:
(global-set-key (kbd "C-x C-b") 'ibuffer)
ibuffer is a very advanced replacement for the default buffer listing, and not only features the exact behaviour requested, but provides a wealth of other functionality.
I listed a few ibuffer filtering and grouping basics in
Emacs: help me understand file/buffer management, but be sure to read the documentation for details.
Try to add
(ido-mode 1)
to your .emacs, and enjoy the result :)
If you like the original buffer list (as opposed to the 'buffer-menu solution proposed by others), you can use this:
(global-set-key (kbd "C-x C-b") 'my-list-buffers)
(defun my-list-buffers (&optional files-only)
"Display a list of names of existing buffers.
The list is displayed in a buffer named `*Buffer List*'.
Note that buffers with names starting with spaces are omitted.
Non-null optional arg FILES-ONLY means mention only file buffers.
For more information, see the function `buffer-menu'."
(interactive "P")
(switch-to-buffer (list-buffers-noselect files-only)))
Which is the same function as before, only in the current window.
I highly recommend bs.el from http://www.geekware.de/software/emacs/ Install it and:
(require 'bs)
(add-hook 'bs-mode-hook 'turn-on-font-lock)
(global-set-key "\C-x\C-b" 'bs-show)
It manages buffers and window configuration in the right way, so everything requires minimum number of keystrokes.
Not sure where I got this but:
;;; Faster buffer switching
(global-set-key [(C tab)] 'buffer-menu)
This makes Ctrl-Tab display all buffers in the current window. You can then navigate to a buffer and hit Enter to visit it.
Another not-what-you-asked-for solution: don't select the desired buffer with the mouse, rather finish typing its name (use tab-completion to reduce keystrokes and increase accuracy), then hit return. The buffer list will disappear, and the new file will be open in the previously active window.

How do I close an automatically opened window in Emacs?

This is probably a very naive Emacs question - I'm new to it.
When I'm evaluating a lisp expression, if there's an error the debugger automatically comes up in another window. If I have *scratch* and *info* open (the former for trying out lisp and the latter for reading about it), then the debugger opens up in the window that *info* was in. At the moment, I have to switch to that window, then change it back to *info*, before returning to *scratch*. (The same thing happens if I do C-x C-b for a list of buffers.) I'm guessing there has to be a way to just close that window without this long sequence of commands. Can anyone enlighten me?
At least here on my emacs (22.3), when the debugger pops up, its window becomes the active one. There, pressing q just quits the debugger, if that's what you want. At that point, it also gets out of recursive editing.
From what I understand, you want to close the buffer in the other window without moving your cursor from the current window.
I don't any existing function does that, so I rolled my own.
(defun other-window-kill-buffer ()
"Kill the buffer in the other window"
(interactive)
;; Window selection is used because point goes to a different window
;; if more than 2 windows are present
(let ((win-curr (selected-window))
(win-other (next-window)))
(select-window win-other)
(kill-this-buffer)
(select-window win-curr)))
You can bind it to something like "C-x K" or some other somewhat difficult-to-press key so you won't press it by mistake.
(global-set-key (kbd "C-x K") 'other-window-kill-buffer)
I use this a LOT! (for Help buffers, Compilation buffers, Grep buffers, and just plain old buffers I want to close now, without moving the point)
I'm usually using the delete-other-windows command. C-x 1.
It's so regullar, that I rebinded to F4.
Official docs: https://www.gnu.org/software/emacs/manual/html_node/emacs/Change-Window.html#Change-Window
HTH
Using winner mode, you can use the keybinding C-C left arrow to return to the previous window configuration. Of course, this doesn't actually kill the new buffer, but it does hide it.
I think you're looking for C-x 4 C-o, which displays a buffer in the "other" window without switching to it.
As mentioned above, in the case of the backtrace buffer you probably want to exit from it with q, to get out of the recursive edit.
Try to use popwin-mode. It is really good about closing windows automatically.
I want to describe how mechanism work|
You open undo-tree-visualize than you find your correct branch, after that when you change your active window which has cursor via switch-window undo-tree related buffer will close other window automatically.
One possible solution is to use a window management package. Store your "preferred" window arrangement, and after the debugger/buffer window pops up and you're done with it, revert to your preferred arrangement.
There are a bunch of packages to choose from, see: switching window configurations on the wiki.
Additionally, you might want to figure out the actions you commonly do that trigger the extra (unwanted) window popping up, and use that to trigger saving your window configuration just before the window pops up.
If you want to roll your own (it's pretty easy), you can just save off the window configuration, and restore it like so:
(setq the-window-configuration-i-want (current-window-configuration))
(global-set-key (kbd "<f7>")
(lambda () (interactive)
(set-window-configuration the-window-configuration-i-want)))
The trick is figuring out where to put the setting of the-window-configuration-i-want.
Thanks go to #spk for a nice function. I merely modified it to also close the window too and bound it to the already nice set of window control functions found in evil-windows (via "C-w"):
(use-package evil
:bind (:map evil-window-map ("O" . delete-most-recent-window))
:preface
(defun delete-most-recent-window ()
"Kill the buffer in the most recent window."
(interactive)
;; Window selection is used because point goes to a different window
;; if more than 2 windows are present
(let ((win-curr (selected-window))
(win-other (next-window)))
(select-window win-other)
(kill-this-buffer)
(delete-window) ; <-- Added this
(select-window win-curr))))