* Have `define-key` return the keymap
@ 2017-05-13 8:19 Tianxiang Xiong
2017-05-13 8:32 ` Andreas Schwab
2017-05-13 12:21 ` Michael Heerdegen
0 siblings, 2 replies; 7+ messages in thread
From: Tianxiang Xiong @ 2017-05-13 8:19 UTC (permalink / raw)
To: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 393 bytes --]
Would there be any issues with / objections to having `define-key` return
the keymap it adds a key to? It currently returns `nil`, making it a
statement (bleh!) rather than a function.
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))
```
[-- Attachment #2: Type: text/html, Size: 574 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Have `define-key` return the keymap
2017-05-13 8:19 Have `define-key` return the keymap Tianxiang Xiong
@ 2017-05-13 8:32 ` Andreas Schwab
2017-05-13 9:11 ` Tianxiang Xiong
2017-05-13 12:21 ` Michael Heerdegen
1 sibling, 1 reply; 7+ messages in thread
From: Andreas Schwab @ 2017-05-13 8:32 UTC (permalink / raw)
To: Tianxiang Xiong; +Cc: Emacs developers
On Mai 13 2017, Tianxiang Xiong <tianxiang.xiong@gmail.com> wrote:
> Would there be any issues with / objections to having `define-key` return
> the keymap it adds a key to? It currently returns `nil`, making it a
> statement (bleh!) rather than a function.
That would cause major inconvenience when define-key is evaluated with
M-: or ielm. A keymap is a big structure to print.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5
"And now for something completely different."
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Have `define-key` return the keymap
2017-05-13 8:19 Have `define-key` return the keymap Tianxiang Xiong
2017-05-13 8:32 ` Andreas Schwab
@ 2017-05-13 12:21 ` Michael Heerdegen
2017-05-13 14:58 ` Drew Adams
1 sibling, 1 reply; 7+ messages in thread
From: Michael Heerdegen @ 2017-05-13 12:21 UTC (permalink / raw)
To: Tianxiang Xiong; +Cc: Emacs developers
Tianxiang Xiong <tianxiang.xiong@gmail.com> 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.
^ permalink raw reply [flat|nested] 7+ messages in thread
* RE: Have `define-key` return the keymap
2017-05-13 12:21 ` Michael Heerdegen
@ 2017-05-13 14:58 ` Drew Adams
2017-05-13 15:12 ` Kaushal Modi
2017-05-13 15:13 ` Stefan Monnier
0 siblings, 2 replies; 7+ messages in thread
From: Drew Adams @ 2017-05-13 14:58 UTC (permalink / raw)
To: Michael Heerdegen, Tianxiang Xiong; +Cc: Emacs developers
> > 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:
>
> (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))
I'm probably missing something, but (to me, so far) all of this
has the scent of a solution looking for a problem to solve.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Have `define-key` return the keymap
2017-05-13 14:58 ` Drew Adams
@ 2017-05-13 15:12 ` Kaushal Modi
2017-05-13 15:13 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Kaushal Modi @ 2017-05-13 15:12 UTC (permalink / raw)
To: Drew Adams, Michael Heerdegen, Tianxiang Xiong; +Cc: Emacs developers
[-- Attachment #1: Type: text/plain, Size: 357 bytes --]
On Sat, May 13, 2017, 10:58 AM Drew Adams <drew.adams@oracle.com> wrote:
>
> I'm probably missing something, but (to me, so far) all of this
> has the scent of a solution looking for a problem to solve.
>
+1
bind-keys from use-package already allows for succinct key bindings to the
same or multiple key maps. Have you tried that OP?
> --
Kaushal Modi
[-- Attachment #2: Type: text/html, Size: 864 bytes --]
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: Have `define-key` return the keymap
2017-05-13 14:58 ` Drew Adams
2017-05-13 15:12 ` Kaushal Modi
@ 2017-05-13 15:13 ` Stefan Monnier
1 sibling, 0 replies; 7+ messages in thread
From: Stefan Monnier @ 2017-05-13 15:13 UTC (permalink / raw)
To: emacs-devel
> I'm probably missing something, but (to me, so far) all of this
> has the scent of a solution looking for a problem to solve.
Indeed. If we're concerned about the redundancy in the various
define-key calls for a keymap, then I'd rather we provide something like
(defvar toto-mode-map (fumble-map map '(("a" foo) ("B" bar))))
-- Stefan
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2017-05-13 15:13 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-13 8:19 Have `define-key` return the keymap Tianxiang Xiong
2017-05-13 8:32 ` Andreas Schwab
2017-05-13 9:11 ` Tianxiang Xiong
2017-05-13 12:21 ` Michael Heerdegen
2017-05-13 14:58 ` Drew Adams
2017-05-13 15:12 ` Kaushal Modi
2017-05-13 15:13 ` Stefan Monnier
Code repositories for project(s) associated with this public inbox
https://git.savannah.gnu.org/cgit/emacs.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).