emacs-devel
[Top][All Lists]
Advanced

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

Re: Get a command by its keybinding and also respecting key translation


From: Stefan Monnier
Subject: Re: Get a command by its keybinding and also respecting key translation
Date: Sat, 18 Dec 2010 11:16:17 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

>> > (define-context-key outline-minor-mode-map
>> >   (kbd "<tab>")
>> >   th-outline-context-p
>> >   org-cycle)
>> 
>> You can do it this way:
>> 
>> (define-key outline-minor-mode-map
>> (kdb "<tab>")
>> `(menu-item "dummy" org-cycle
>> :filter ,(lambda (cmd)
>> (if (th-outline-context-p) cmd))))

> Hm, just for educational purposes, could you please explain the
> backquoting and the comma-substitution of the lambda?  I mean, I know
> that `,' in a backquote triggers evaluation, but since a lambda evals to
> itself, what's the point in doing so?

Without backquote and comma, the whole menu-item is just a piece of data
which happens to contain something that looks like a function.
With the backquote and comma, it turns into something that contains
a function, so tools can handle this `lambda' knowing that it *is*
a function (e.g. it can be byte-compiled, can cause warnings if it uses
obsolete functions, can be macro-expanded, ...).

Try to byte-compile

   (equal '(lambda () (foo (bar a b c)))
          (lambda () (foo (bar a b c))))

to see what I mean.  In the presence of lexical-scoping the difference
will be present even without byte-compiling.


        Stefan



reply via email to

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