I have an ErgoEmacs minor mode turned on globally, which defines many custom keyboard shortcuts for basic editing. However when I open any lisp file, slime-mode turns on automatically and overrides M-p and M-n with its own commands. However I want M-p and M-n to be always defined by ergoemacs-mode. How do I set up order in which minor modes load and define keybindings? Or how do I raise ergoemacs-mode keybindings priority?
Asked
Active
Viewed 534 times
2 Answers
3
How do I set up order in which minor modes load and define keybindings? Or how do I raise ergoemacs-mode keybindings priority?
I think you need to ensure that ErgoEmacs appears before slime-mode in the variable minor-mode-map-alist
. There's probably a much better way, but the code below should achieve this. Let me know if it does what you want.
(require 'cl) (add-hook 'slime-mode-hook (lambda () (let ((elem (first (remove-if-not (lambda (item) (equal 'ergoemacs-mode (car item))) minor-mode-map-alist)))) (setq minor-mode-map-alist (remove elem minor-mode-map-alist)) (add-to-list 'minor-mode-map-alist elem))))

Stefan
- 27,908
- 4
- 53
- 82

Luke Girvin
- 13,221
- 9
- 64
- 84
-
It worked, thanks! The solution is still kinda hacky. How it is determined in what order minor modes are loaded? Maybe understanding of this mechanism could produce a more elegant solution. – Mirzhan Irkegulov Mar 10 '12 at 18:52
-
Most libraries are loaded on demand via the `autoload` mechanism, or explicitly via `require`, and you should generally treat the load order as being entirely arbitrary, although you may well be able to control it for things which are explicitly loaded via your init file, simply be re-ordering the contents of that file. You may find the following useful: http://stackoverflow.com/questions/683425/globally-override-key-binding-in-emacs/5340797#5340797 – phils Mar 11 '12 at 10:30
-
The let binding is equivalent to the more concise/clear `(assoc 'ergomacs-mode minor-mode-map-alist)`, though in this case you can use `assq` instead of `assoc` – Felipe Oct 31 '16 at 10:21
2
Maybe a simpler solution is to remove Slime's bindings:
(add-hook 'slime-mode-hook
(lambda ()
(define-key slime-mode-map [?\M-p] nil)
(define-key slime-mode-map [?\M-n] nil)))
Beware: guarantedd 100% untested, the variable's name might be different from slime-mode-map (and it probably will only exist after loading slime-mode).

Stefan
- 27,908
- 4
- 53
- 82