all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Michal Nazarewicz <mina86@mina86.com>
To: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: 18729@debbugs.gnu.org
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	[thread overview]
Message-ID: <xa1tk340gpeb.fsf@mina86.com> (raw)
In-Reply-To: <jwvwq811l3c.fsf-monnier+emacsbugs@gnu.org>

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





  reply	other threads:[~2014-10-16 12:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-15  7:48 bug#18729: [PATCH] subr.el (set-key): New macro making creating new bindings more concise Michal Nazarewicz
2014-10-15 14:20 ` Stefan Monnier
2014-10-16 12:39   ` Michal Nazarewicz [this message]
2014-10-16 14:50     ` Stefan Monnier
2014-10-27 17:52       ` Michal Nazarewicz
2015-01-19 15:40 ` Michal Nazarewicz

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

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

  git send-email \
    --in-reply-to=xa1tk340gpeb.fsf@mina86.com \
    --to=mina86@mina86.com \
    --cc=18729@debbugs.gnu.org \
    --cc=monnier@iro.umontreal.ca \
    /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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.