Define keys more easily?
Hi, my key definitions come in packs, so instead of #+begin_src emacs-lisp (eval-after-load 'speedbar '(progn (evil-make-overriding-map speedbar-key-map) (evil-make-overriding-map speedbar-file-key-map) (evil-make-overriding-map speedbar-buffers-key-map) (evil-define-key 'motion speedbar-key-map "h" 'backward-char) (evil-define-key 'motion speedbar-key-map "j" 'speedbar-next) (evil-define-key 'motion speedbar-key-map "k" 'speedbar-prev) (evil-define-key 'motion speedbar-key-map "l" 'forward-char) (evil-define-key 'motion speedbar-key-map "i" 'speedbar-item-info) (evil-define-key 'motion speedbar-key-map "r" 'speedbar-refresh) (evil-define-key 'motion speedbar-key-map "u" 'speedbar-up-directory) (evil-define-key 'motion speedbar-key-map "o" 'speedbar-toggle-line-expansion) (evil-define-key 'motion speedbar-key-map (kbd "RET") 'speedbar-edit-line))) #+end_src emacs-lisp I like it #+begin_src emacs-lisp (eval-after-load 'speedbar '(progn (evil-make-overriding-map speedbar-key-map) (evil-make-overriding-map speedbar-file-key-map) (evil-make-overriding-map speedbar-buffers-key-map) (evil-define-keys 'motion speedbar-key-map "h" 'backward-char "j" 'speedbar-next "k" 'speedbar-prev "l" 'forward-char "i" 'speedbar-item-info "r" 'speedbar-refresh "u" 'speedbar-up-directory "o" 'speedbar-toggle-line-expansion (kbd "RET") 'speedbar-edit-line))) #+end_src emacs-lisp Easier to type and easier to read and understand, right? Is it worth to include it? And if, is it worth to keep the single key functions? The code is in my keys branch[1]. I did not open a merge request because I don't want it included half finished (the rest of the key functions). Michael Footnotes: [1] https://gitorious.org/~cofi/evil/cofis-evil/commits/keys
On 2011-08-20 00:26 +0200, Michael Markert wrote:
(evil-define-keys 'motion speedbar-key-map "h" 'backward-char "j" 'speedbar-next "k" 'speedbar-prev "l" 'forward-char ...)
Is it worth to include it? And if, is it worth to keep the single key functions?
I would just add a &rest parameter to the current function, `evil-define-key'. That makes it similar to `setq': you can specify multiple sets of arguments if you want to, or you can just use it in the same way as the standard function `define-key'. Note that Emacs won't indent the code like above. You have to break it up before the first of the bindings in order for them to line up: (evil-define-keys 'motion speedbar-key-map "h" 'backward-char "j" 'speedbar-next "k" 'speedbar-prev "l" 'forward-char ...) -- Vegard
On 20 Aug 2011, Vegard Øye wrote:
On 2011-08-20 00:26 +0200, Michael Markert wrote:
(evil-define-keys 'motion speedbar-key-map "h" 'backward-char "j" 'speedbar-next "k" 'speedbar-prev "l" 'forward-char ...)
Is it worth to include it? And if, is it worth to keep the single key functions?
I would just add a &rest parameter to the current function, `evil-define-key'. That makes it similar to `setq': you can specify multiple sets of arguments if you want to, or you can just use it in the same way as the standard function `define-key'.
Thought about it but didn't like the thought of using the singular to define many things. But it has the great advantage to keep backwards compatibility without cluttering the code. I'll do it that way!
Note that Emacs won't indent the code like above. You have to break it up before the first of the bindings in order for them to line up:
(evil-define-keys 'motion speedbar-key-map "h" 'backward-char "j" 'speedbar-next "k" 'speedbar-prev "l" 'forward-char ...)
Yeah of course, it was just an example how it would look (at least the big picture of it ;)) Michael
participants (2)
-
Michael Markert -
Vegard Øye