Unsetting Key Bindings in emacs
I make use of emacs – my ability to customize the editor has made it easier for me to be productive. Switching between windows has always been a bit annoying in emacs. After reading Managing Emacs windows, I figured that I would give the
ace-window library a try to see if it could solve my problems.
ace-window and dropping the file in my
.emacs, I was ready to go. I’m lazy and a touch typist, so I set up
ace-window to run from the home row using:
(global-set-key (kbd "C-;") 'ace-window)
My initial experiments worked well and I was able to hop between buffers and frames quickly. Things came crashing to a halt when I hit a Markdown buffer. Markdown buffers fire up a spellchecker usingFlyspell and Flyspell maps
C-; to spellcheck previous word or some other moderately worthless command.
My first attempt at getting rid of this setting was to use
global-unset-key. This would work, but only if Flyspell immediately started with all emacs buffers and if the key bindings were set across all of emacs. This was a no-go, but I left it in my emacs customization just because I don’t want something else to steal this binding in the future.
My second attempt was to create a minor mode. If you’re interested in this approach, you can find instructions at Globally override key binding in Emacs. This approach didn’t work at all. I couldn’t determine why Flyspell mode was loading at a higher priority than my own minor mode. Another answer in that same question suggested adding “advice” to the load function. This approach was barely effective. After the buffer was initially populated, my key binding would not be in place; after some period of time, though, my binding would start working and I could use
C-: to navigate between windows. As near as I can tell, the problem is that the spell check process was still running in the buffer and that means that the mode hadn’t finished loading for the buffer.
I finally came across the question Set custom keybinding for specifics Emacs mode. After I added my custom keybinding to the mode, my earlier bindings worked beautifully. The full working set of shortcuts is:
(global-unset-key (kbd "C-;")) (global-set-key (kbd "C-;") 'ace-window) (eval-after-load "flyspell" '(define-key flyspell-mode-map (kbd "C-;") nil))
And now I’ve got a lovely set of key bindings that work like a charm, let me zip around files with ease, and don’t get in the way of each other… too much.
This is Jeremiah
I live in Portland, OR. I have two dogs.
I recently received a Master's of Science in Computer Science from Portland State University.
I'm was Microsoft MVP from 2009 - 2018 with a pile of certifications. Somewhere along the way, I wrote a database client for Riak and then handed it off to the community.