[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
bug#18729: [PATCH] subr.el (set-key): New macro making creating new bind
From: |
Michal Nazarewicz |
Subject: |
bug#18729: [PATCH] subr.el (set-key): New macro making creating new bindings more concise. |
Date: |
Thu, 16 Oct 2014 14:39:08 +0200 |
User-agent: |
Notmuch/0.17+15~gb65ca8e (http://notmuchmail.org) Emacs/25.0.50.1 (x86_64-unknown-linux-gnu) |
On Wed, Oct 15 2014, Stefan Monnier <monnier@iro.umontreal.ca> wrote:
>> +(defmacro set-key (keymap key &rest def)
> I'm not convinced the added complexity is worth the trouble, I'm afraid.
> I don't see a real benefit in
>
> (set-key :global KEY CMD)
You wouldn't normally put “:global” here…
> (set-key :local KEY CMD)
> (set-key MAP KEY CMD)
>
> over
>
> (global-set-key KEY CMD)
> (local-set-key KEY CMD)
> (define-key MAP KEY CMD)
[…]
…but I can see your point and it's true that for those cases, the saving
is not that big.
> I also don't see the benefit of (:args ARGS INTERACTIVE . BODY)
> over (lambda ARGS (interactive INTERACTIVE) . BODY).
>
> The only thing I think is really valuable is things like
>
> (set-key ... KEY (dired "foo"))
Indeed, this is the main reason I've created the macro (I would still
argue :args syntax is also convenient though).
> For which there is also a precedent in easy-define-menu (where the CMD
> can be either a symbol or an expression, in which case that expression
> gets wrapped in (lambda () (interactive) ...)).
>
> Maybe we could simply extend define-key to accept
>
> (define-key MAP KEY '(dired "foo"))
So are you think about something like:
diff --git a/src/keymap.c b/src/keymap.c
index c7c7d19..4b8251b 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -786,6 +786,9 @@ store_in_keymap (Lisp_Object keymap, register Lisp_Object
idx, Lisp_Object def)
&& (EQ (XCAR (def), Qmenu_item) || STRINGP (XCAR (def))))
def = Fcons (XCAR (def), XCDR (def));
+ if (CONSP (def) && !EQ (XCAR (quoted), Qlambda) && !EQ (XCAR (quoted),
Qclosure))
+ def = Fcons (Qlambda, Fcons (Qnil, Fcons (Fcons (Qinteractive, Qnil),
def)));
+
if (!CONSP (keymap) || !EQ (XCAR (keymap), Qkeymap))
error ("attempt to define a key in a non-keymap");
? Or am I looking at completely wrong place.
Thing I'm worried about here is that the function will not get
byte-compiled, whereas with set-key macro it will. Also, I'm not
entirely sure whether the function should use lexical-binding.
--
Best regards, _ _
.o. | Liege of Serenely Enlightened Majesty of o' \,=./ `o
..o | Computer Science, Michał “mina86” Nazarewicz (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--