[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Have `define-key` return the keymap

From: Drew Adams
Subject: RE: Have `define-key` return the keymap
Date: Sat, 13 May 2017 07:58:04 -0700 (PDT)

> > 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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]