[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Have `define-key` return the keymap
From: |
Michael Heerdegen |
Subject: |
Re: Have `define-key` return the keymap |
Date: |
Sat, 13 May 2017 14:21:53 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.0.50 (gnu/linux) |
Tianxiang Xiong <address@hidden> writes:
> If `define-key` returned the keymap, calls to it could be chained together in
> convenient ways, e.g.
>
> ```
> (thread-first (make-sparse-keymap)
> (define-key (kbd "a") #'foo)
> (define-key (kbd "b") #'bar))
> ```
A different solution would be to define something analog to
`thread-first' that substitutes always the first value as first argument
instead of the subsequent return values (in this case, this is always
the same object).
A variant of this approach that works without such a new macro:
#+begin_src emacs-lisp
(defun my-keybinder (map)
(apply-partially #'define-key map))
(let ((map (make-sparse-keymap)))
(cl-flet ((define-key (my-keybinder map)))
(define-key (kbd "a") #'foo)
(define-key (kbd "b") #'bar)
map))
#+end_src
Michael.