unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Michael Heerdegen <michael_heerdegen@web.de>
To: Tianxiang Xiong <tianxiang.xiong@gmail.com>
Cc: Emacs developers <emacs-devel@gnu.org>
Subject: Re: Have `define-key` return the keymap
Date: Sat, 13 May 2017 14:21:53 +0200	[thread overview]
Message-ID: <87d1bd7xr2.fsf@drachen> (raw)
In-Reply-To: <CACMkxixPJZmoKb0zSWJ5oAC4LaEZbJJJmePC-XMZ1XPbOmxSwg@mail.gmail.com> (Tianxiang Xiong's message of "Sat, 13 May 2017 01:19:17 -0700")

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.



  parent reply	other threads:[~2017-05-13 12:21 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2017-05-13 14:58   ` Drew Adams
2017-05-13 15:12     ` Kaushal Modi
2017-05-13 15:13     ` Stefan Monnier

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87d1bd7xr2.fsf@drachen \
    --to=michael_heerdegen@web.de \
    --cc=emacs-devel@gnu.org \
    --cc=tianxiang.xiong@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).