unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Get a command by its keybinding and also respecting key translation
@ 2010-12-13 18:57 Tassilo Horn
  2010-12-14 19:50 ` Stefan Monnier
  0 siblings, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-13 18:57 UTC (permalink / raw)
  To: emacs-devel

Hi all,

is there a way to get a command by its keybinding that also respects key
translation?  Or more precise: Is there a way to get the binding of KEY,
and if there's none, get the binding of some other key that happens to
translate to KEY (and if there are more than one, then check them in the
order the that would be used when really looking up a key a user typed)?

The reason for that question is a home-brewn macro that enables me to
define a key for some keymap just like define-key, but with an
additional predicate that is tested before executing the given command.
If the predicate does not match, then the binding should execute the
command that would have been executed normally.

Now the problem is getting the command that would have been executed
before.  The problem with `lookup-key' and `key-binding' which I
currently use is that they don't handle key translation.

Here's an example:

(define-context-key outline-minor-mode-map
  (kbd "<tab>")
  th-outline-context-p
  org-cycle)

This will first use `lookup-key' to check if there's already a <tab>
binding in `outline-minor-mode-map', and if not, the expandsion will
let-bind the given map's mode variable (e.g. `outline-minor-mode') and
then check the `key-binding' of <tab> and execute that function.

Ok, now to the problem: I use `outline-minor-mode' in most programming
modes, and those usually define TAB to `indent-according-to-mode'.  But
since TAB is only translated to <tab>, (key-binding (kbd "<tab>")) will
return nil.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-13 18:57 Get a command by its keybinding and also respecting key translation Tassilo Horn
@ 2010-12-14 19:50 ` Stefan Monnier
  2010-12-14 22:51   ` Tassilo Horn
  2010-12-15  8:21   ` Tassilo Horn
  0 siblings, 2 replies; 19+ messages in thread
From: Stefan Monnier @ 2010-12-14 19:50 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

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


-- Stefan



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-14 19:50 ` Stefan Monnier
@ 2010-12-14 22:51   ` Tassilo Horn
  2010-12-18 16:16     ` Stefan Monnier
  2010-12-15  8:21   ` Tassilo Horn
  1 sibling, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-14 22:51 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

On Tuesday 14 December 2010 20:50:43 Stefan Monnier wrote:
> > (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?

Thanks!
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-14 19:50 ` Stefan Monnier
  2010-12-14 22:51   ` Tassilo Horn
@ 2010-12-15  8:21   ` Tassilo Horn
  2010-12-15 15:27     ` Tassilo Horn
  2010-12-18 16:23     ` Get a command by its keybinding and also respecting key translation Stefan Monnier
  1 sibling, 2 replies; 19+ messages in thread
From: Tassilo Horn @ 2010-12-15  8:21 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

On Tuesday 14 December 2010 20:50:43 Stefan Monnier wrote:
> > (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))))

This is cool, but sadly not equivalent, because I cannot add multiple
binding for one key in the same keymap.  That was the whole intention of
my macro: I hit TAB (or whatever), and it'll execute some command
depending on the context.

In my approach with multiple TAB bindings in one keymap, the last one
defined was the real binding, but if its predicate didn't match, it
delegated to the former binding of TAB (which it had stolen), and if all
predicates of all context keys failed, it would call the original
command.

So do I go to implement that behavior in a more standard way?

The docs state, that the :filter may also switch the REAL-BINDING to
some other command, so I could write a macro that expands according to
your definition with a (cond ((PRED1) (CMD1)) ((PRED2) (CMD2))) instead
of the if.

And is this approach not pretty slow?  I mean, my approach did the
predicate checks only when that key was typed, but I think that your
approach does the checks on any redisplay, right?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-15  8:21   ` Tassilo Horn
@ 2010-12-15 15:27     ` Tassilo Horn
  2010-12-15 15:30       ` Davis Herring
  2010-12-15 22:03       ` Get a command by its keybinding and also respecting keytranslation Drew Adams
  2010-12-18 16:23     ` Get a command by its keybinding and also respecting key translation Stefan Monnier
  1 sibling, 2 replies; 19+ messages in thread
From: Tassilo Horn @ 2010-12-15 15:27 UTC (permalink / raw)
  To: emacs-devel; +Cc: Stefan Monnier

On Wednesday 15 December 2010 09:21:21 Tassilo Horn wrote:

Hi again!

> This is cool, but sadly not equivalent, because I cannot add multiple
> binding for one key in the same keymap.  That was the whole intention
>
> In my approach with multiple TAB bindings in one keymap, the last one
> defined was the real binding, but if its predicate didn't match, it
> delegated to the former binding of TAB (which it had stolen), and if
> all predicates of all context keys failed, it would call the original
> command.
> 
> So do I go to implement that behavior in a more standard way?

Ok, now I've revamped my macro according to your example with some
changes.  A dispatching form has to be provided that returns the
function to use, or nil if the original binding should be triggered.
Additionally, I let-bind a variable default-command to that original
binding in order to make it possible to trigger context sensitive
behavior only after hitting a key twice.

What do you think of that?

--8<---------------cut here---------------start------------->8---
(defmacro define-context-key (keymap key dispatch)
  "Define KEY in KEYMAP to execute according to DISPATCH.

DISPATCH is a form that is evaluated and should return the
command to be executed.

If DISPATCH returns nil, then the command normally bound to KEY
will be executed.

DISPATCH can access a dynamically set variable `default-command',
which contains the command that would be executed, if DISPATCH
returns nil.  This makes it possible to make DISPATCH return some
command only if a user wants to trigger it twice in a row.

Example:

  (define-context-key hs-minor-mode-map
     (kbd \"TAB\")
     (cond
      ((and (not (hs-already-hidden-p))
            (eq last-command default-command))
       'hs-hide-block)
      ((hs-already-hidden-p)
       'hs-show-block)))

This will make TAB show a hidden block.  If the block is shown,
then the first TAB will act as usual (e.g. indent the code), but
the second TAB will hide the block."
  `(define-key ,keymap ,key
     (quote
      (menu-item "context-key" ignore
                 :filter (lambda (&optional ignored)
                           (let ((default-command (key-binding ,key t)))
                             ,dispatch))))))
--8<---------------cut here---------------end--------------->8---

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key  translation
  2010-12-15 15:27     ` Tassilo Horn
@ 2010-12-15 15:30       ` Davis Herring
  2010-12-15 21:20         ` Tassilo Horn
  2010-12-15 22:03       ` Get a command by its keybinding and also respecting keytranslation Drew Adams
  1 sibling, 1 reply; 19+ messages in thread
From: Davis Herring @ 2010-12-15 15:30 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Stefan Monnier, emacs-devel

>                            (let ((default-command (key-binding ,key t)))

Wasn't it key-binding's insufficiency that provoked the original question?

Davis

-- 
This product is sold by volume, not by mass.  If it appears too dense or
too sparse, it is because mass-energy conversion has occurred during
shipping.



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-15 15:30       ` Davis Herring
@ 2010-12-15 21:20         ` Tassilo Horn
  0 siblings, 0 replies; 19+ messages in thread
From: Tassilo Horn @ 2010-12-15 21:20 UTC (permalink / raw)
  To: emacs-devel, herring; +Cc: Stefan Monnier

On Wednesday 15 December 2010 16:30:47 Davis Herring wrote:

Hi Davis,

> >                            (let ((default-command (key-binding ,key t)))
> 
> Wasn't it key-binding's insufficiency that provoked the original
> question?

Good catch!  But the situation has still improved in this use case.
Formerly, if no context key predicate triggered and no default command
could be found (due to TAB vs. <tab> or other translations), you ended
up with a possibly important command missing, like indenting according
to mode.  The only use case for default-command I can see is triggering
a context key only when the user types a key repeatedly.  And if then
the original command after translation and the guessed default-command
don't match or the latter is nil, you could still look it up manually
and encode it in your predicate.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: Get a command by its keybinding and also respecting keytranslation
  2010-12-15 15:27     ` Tassilo Horn
  2010-12-15 15:30       ` Davis Herring
@ 2010-12-15 22:03       ` Drew Adams
  2010-12-15 22:17         ` Tassilo Horn
  1 sibling, 1 reply; 19+ messages in thread
From: Drew Adams @ 2010-12-15 22:03 UTC (permalink / raw)
  To: 'Tassilo Horn', emacs-devel; +Cc: 'Stefan Monnier'

I think I see what you want, but I'm not getting part of the why (use case).
Can you describe a bit what the advantage is in doing this at a key-binding
level rather than at a command level?

IOW, I imagine that this must save you some trouble but I'm not sure what that
savings is.  What is the advantage over defining a dispatching command and
binding that to the key? E.g.,

(defun my-dispatch-cmd ()
  "..."
  (interactive)
  (cond (blah (foo))
        (toto (call-interactively #'fee))
        (titi (call-interactively #'bar))
        (tata (booph))
        (t (call-interactively default-command))))

Stefan's suggestion was at the key-binding level, like yours, but I think its
effect is pretty much the same as binding a command that tests the conditions
(?).

You contrasted your proposal with Stefan's suggestion, saying that yours allowed
for multiple bindings of the same key, applying whichever binding was
appropriate in context (using a priority order and conditions IIUC).

But I don't get that point.  What is the advantage of having multiple bindings
for the same key (in the same map) and picking which is used according to a
condition?  Why not just bind the key to a command that tests those same
conditions?  What am I missing?




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting keytranslation
  2010-12-15 22:03       ` Get a command by its keybinding and also respecting keytranslation Drew Adams
@ 2010-12-15 22:17         ` Tassilo Horn
  2010-12-15 22:39           ` Drew Adams
  2010-12-18 16:27           ` Stefan Monnier
  0 siblings, 2 replies; 19+ messages in thread
From: Tassilo Horn @ 2010-12-15 22:17 UTC (permalink / raw)
  To: Drew Adams; +Cc: 'Stefan Monnier', emacs-devel

"Drew Adams" <drew.adams@oracle.com> writes:

Hi Drew,

> What is the advantage of having multiple bindings for the same key (in
> the same map) and picking which is used according to a condition?  Why
> not just bind the key to a command that tests those same conditions?

Basically, it's pretty much equivalent, except that the key binding
approach seems a bit more general in that the original command that
would normally have been triggered by KEY is executed automatically if
no predicate matches.  With a DWIM wrapper command, you have to look
that up first and put it in the command as fallback.  And you'd probably
have to manually set this-command/last-command in order to keep the
wrapper out but only the "real" commands which you have to call
interactively...

Another really cool feature with Stefan's approach is that `C-h k' in
some special context matched by one of the predicates will show the docs
of the command in that context.  With a wrapper, you have to write your
own docstring explaining all possible contexts and actions.

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* RE: Get a command by its keybinding and also respecting keytranslation
  2010-12-15 22:17         ` Tassilo Horn
@ 2010-12-15 22:39           ` Drew Adams
  2010-12-18 16:27           ` Stefan Monnier
  1 sibling, 0 replies; 19+ messages in thread
From: Drew Adams @ 2010-12-15 22:39 UTC (permalink / raw)
  To: 'Tassilo Horn'; +Cc: 'Stefan Monnier', emacs-devel

Thanks for the clarification.




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-14 22:51   ` Tassilo Horn
@ 2010-12-18 16:16     ` Stefan Monnier
  2010-12-20  8:19       ` Tassilo Horn
  0 siblings, 1 reply; 19+ messages in thread
From: Stefan Monnier @ 2010-12-18 16:16 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

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



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-15  8:21   ` Tassilo Horn
  2010-12-15 15:27     ` Tassilo Horn
@ 2010-12-18 16:23     ` Stefan Monnier
  1 sibling, 0 replies; 19+ messages in thread
From: Stefan Monnier @ 2010-12-18 16:23 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: emacs-devel

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

> This is cool, but sadly not equivalent, because I cannot add multiple
> binding for one key in the same keymap.

Very good point.  I bumped into the same problem a while ago for the
case where the "key" is the default [t] binding (where I wanted to have
a single binding cover a whole bunch of keys at a time).

You can hack around this limitation by using

  (setcdr outline-minor-mode-map
          (cons (cons 'tab `(menu-item "dummy" org-cycle
                             :filter ,(lambda (cmd)
                                        (if (th-outline-context-p) cmd))))
                (cdr outline-minor-mode-map)))

which might work.  But that's *really* ugly, and I wouldn't be surprised
if it didn't work right in some cases.

> So do I go to implement that behavior in a more standard way?

> The docs state, that the :filter may also switch the REAL-BINDING to
> some other command, so I could write a macro that expands according to
> your definition with a (cond ((PRED1) (CMD1)) ((PRED2) (CMD2))) instead
> of the if.

Yes, of course, that will work just fine.  The disadvantage being of
course that you lose modularity: you can't add PRED1/CMD1 and
PRED2/CMD2 separately.

> And is this approach not pretty slow?  I mean, my approach did the
> predicate checks only when that key was typed, but I think that your
> approach does the checks on any redisplay, right?

No, it'll do the check only when the key is pressed and will definitely
not interact with redisplay.


        Stefan



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting keytranslation
  2010-12-15 22:17         ` Tassilo Horn
  2010-12-15 22:39           ` Drew Adams
@ 2010-12-18 16:27           ` Stefan Monnier
  1 sibling, 0 replies; 19+ messages in thread
From: Stefan Monnier @ 2010-12-18 16:27 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Drew Adams, emacs-devel

> Another really cool feature with Stefan's approach is that `C-h k' in
> some special context matched by one of the predicates will show the docs
> of the command in that context.  With a wrapper, you have to write your
> own docstring explaining all possible contexts and actions.

It's an OK feature, but it has the disadvantage that it doesn't tell you
that the binding you see might be different in a different context.  in
many cases you'd rather have a docstring that tells you "in this context
does foo, elsewhere does bar", or at least "here does foo because it's
in a context that happens to have such and such property".


        Stefan



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-18 16:16     ` Stefan Monnier
@ 2010-12-20  8:19       ` Tassilo Horn
  2010-12-20 10:09         ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-20  8:19 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

Stefan Monnier <monnier@iro.umontreal.ca> writes:

Hi Stefan,

>>> (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, ...).

Thanks!  So now the next question, how can I write a macro whose
expansion contains backticks and commas, and I'm still able to
comma-expand in the "inner" backquoted parts?

Or with an example:

(defmacro define-context-key (keymap key dispatch)
  `(define-key ,keymap ,key
     (backquote
      (menu-item "context-key" ignore
                 :filter (lambda (&optional ignored)
                           ,dispatch)))))

How do I smuggle a `,' before the lambda?

Bye,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-20  8:19       ` Tassilo Horn
@ 2010-12-20 10:09         ` Andreas Schwab
  2010-12-20 10:19           ` Tassilo Horn
  0 siblings, 1 reply; 19+ messages in thread
From: Andreas Schwab @ 2010-12-20 10:09 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: Stefan Monnier, emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> Or with an example:
>
> (defmacro define-context-key (keymap key dispatch)
>   `(define-key ,keymap ,key
>      (backquote
>       (menu-item "context-key" ignore
>                  :filter (lambda (&optional ignored)
>                            ,dispatch)))))
>
> How do I smuggle a `,' before the lambda?

First, backquote != `.  Then just put it there.

(defmacro define-context-key (keymap key dispatch)
  `(define-key ,keymap ,key
     `(menu-item "context-key" ignore
                 :filter ,(lambda (&optional ignored)
                           ,dispatch))))

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-20 10:09         ` Andreas Schwab
@ 2010-12-20 10:19           ` Tassilo Horn
  2010-12-20 10:35             ` David Kastrup
  0 siblings, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-20 10:19 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Stefan Monnier, emacs-devel

Andreas Schwab <schwab@linux-m68k.org> writes:

Hi Andreas,

>> Or with an example:
>>
>> (defmacro define-context-key (keymap key dispatch)
>>   `(define-key ,keymap ,key
>>      (backquote
>>       (menu-item "context-key" ignore
>>                  :filter (lambda (&optional ignored)
>>                            ,dispatch)))))
>>
>> How do I smuggle a `,' before the lambda?
>
> First, backquote != `.

It is not?  From backquote.el:

  (defalias '\` (symbol-function 'backquote))

And describe-function returns the same (except the name) for both ``'
and `backquote'.

> Then just put it there.
>
> (defmacro define-context-key (keymap key dispatch)
>   `(define-key ,keymap ,key
>      `(menu-item "context-key" ignore
>                  :filter ,(lambda (&optional ignored)
>                            ,dispatch))))

Oh, that does work.  I just didn't grasp that I can use `,' to evaluate
inside forms that are already evaluated as a whole.

Thanks,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-20 10:19           ` Tassilo Horn
@ 2010-12-20 10:35             ` David Kastrup
  2010-12-20 11:10               ` Tassilo Horn
  0 siblings, 1 reply; 19+ messages in thread
From: David Kastrup @ 2010-12-20 10:35 UTC (permalink / raw)
  To: emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> Andreas Schwab <schwab@linux-m68k.org> writes:
>
> Hi Andreas,
>
>>> Or with an example:
>>>
>>> (defmacro define-context-key (keymap key dispatch)
>>>   `(define-key ,keymap ,key
>>>      (backquote
>>>       (menu-item "context-key" ignore
>>>                  :filter (lambda (&optional ignored)
>>>                            ,dispatch)))))
>>>
>>> How do I smuggle a `,' before the lambda?
>>
>> First, backquote != `.
>
> It is not?  From backquote.el:
>
>   (defalias '\` (symbol-function 'backquote))
>
> And describe-function returns the same (except the name) for both ``'
> and `backquote'.

You are confusing \` with `.  ` is (obviously) treated specially by the
Lisp reader and converted into a form involving the macro \`.  At some
point in the past, this rather used the macro backquote instead.  If
this were still so, you probably would be less confused.  The connection
between ` and \` is arbitrary, and established by the Lisp reader.

M-: '`(+ 4 ,soup)

gives

(\` (+ 4 (\, soup)))

-- 
David Kastrup




^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-20 10:35             ` David Kastrup
@ 2010-12-20 11:10               ` Tassilo Horn
  2010-12-20 11:30                 ` Andreas Schwab
  0 siblings, 1 reply; 19+ messages in thread
From: Tassilo Horn @ 2010-12-20 11:10 UTC (permalink / raw)
  To: David Kastrup; +Cc: emacs-devel

David Kastrup <dak@gnu.org> writes:

Hi David,

>>> First, backquote != `.
>>
>> It is not?  From backquote.el:
>>
>>   (defalias '\` (symbol-function 'backquote))
>>
>> And describe-function returns the same (except the name) for both ``'
>> and `backquote'.
>
> You are confusing \` with `.  ` is (obviously) treated specially by
> the Lisp reader and converted into a form involving the macro \`.

Oh, even this sencence was hard to parse.  What does \` have to do with
a dot followed by two spaces!?!  After increasing my lookahead, I
managed to grasp it. :-)

> At some point in the past, this rather used the macro backquote
> instead.  If this were still so, you probably would be less confused.

Yes.

> The connection between ` and \` is arbitrary, and established by the
> Lisp reader.
>
> M-: '`(+ 4 ,soup)
>
> gives
>
> (\` (+ 4 (\, soup)))

Yes, I thought the expansion would have been either `(+ 4 (\, soup)) or
(backquote (+ 4 (\, soup))).  The comment

  ;; GNU Emacs has no reader macros

before the defalias doesn't make it clearer, though.

Thanks for your clarification,
Tassilo



^ permalink raw reply	[flat|nested] 19+ messages in thread

* Re: Get a command by its keybinding and also respecting key translation
  2010-12-20 11:10               ` Tassilo Horn
@ 2010-12-20 11:30                 ` Andreas Schwab
  0 siblings, 0 replies; 19+ messages in thread
From: Andreas Schwab @ 2010-12-20 11:30 UTC (permalink / raw)
  To: Tassilo Horn; +Cc: David Kastrup, emacs-devel

Tassilo Horn <tassilo@member.fsf.org> writes:

> Yes, I thought the expansion would have been either `(+ 4 (\, soup)) or
> (backquote (+ 4 (\, soup))).  The comment
>
>   ;; GNU Emacs has no reader macros
>
> before the defalias doesn't make it clearer, though.

In the Emacs Lisp reader the special behaviour of ` is hard coded.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."



^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2010-12-20 11:30 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-12-13 18:57 Get a command by its keybinding and also respecting key translation Tassilo Horn
2010-12-14 19:50 ` Stefan Monnier
2010-12-14 22:51   ` Tassilo Horn
2010-12-18 16:16     ` Stefan Monnier
2010-12-20  8:19       ` Tassilo Horn
2010-12-20 10:09         ` Andreas Schwab
2010-12-20 10:19           ` Tassilo Horn
2010-12-20 10:35             ` David Kastrup
2010-12-20 11:10               ` Tassilo Horn
2010-12-20 11:30                 ` Andreas Schwab
2010-12-15  8:21   ` Tassilo Horn
2010-12-15 15:27     ` Tassilo Horn
2010-12-15 15:30       ` Davis Herring
2010-12-15 21:20         ` Tassilo Horn
2010-12-15 22:03       ` Get a command by its keybinding and also respecting keytranslation Drew Adams
2010-12-15 22:17         ` Tassilo Horn
2010-12-15 22:39           ` Drew Adams
2010-12-18 16:27           ` Stefan Monnier
2010-12-18 16:23     ` Get a command by its keybinding and also respecting key translation Stefan Monnier

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