* Key-binding without minor mode!
@ 2014-09-11 11:47 Phillip Lord
2014-09-11 12:19 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-11 11:47 UTC (permalink / raw)
To: help-gnu-emacs
I am trying to find what a keybinding would have been if a minor mode
had not been active, by switching the minor mode off with a let binding.
But I don't know how to find the keybinding. I have tried...
(key-binding (char-to-string last-command-event))
Works quite nicely keys such alphabetical keys, but fails for return
which return a symbol.
I've also tried
(key-binding (this-command-keys))
(key-binding (this-command-keys-vector))
and also sorts of other alternatives.
I'd appreciate any help!
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 11:47 Key-binding without minor mode! Phillip Lord
@ 2014-09-11 12:19 ` Stefan Monnier
2014-09-11 14:22 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-11 12:19 UTC (permalink / raw)
To: help-gnu-emacs
> (key-binding (this-command-keys-vector))
This should work.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 12:19 ` Stefan Monnier
@ 2014-09-11 14:22 ` Phillip Lord
2014-09-11 14:31 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-11 14:22 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> (key-binding (this-command-keys-vector))
>
> This should work.
Unfortunately, this fails for me.
This problem seems to be this. If I define keys as follows:
(define-key pabbrev-mode-map [tab] 'pabbrev-expand-maybe)
Then in lisp mode this looks up looks up the binding for
[tab] which returns nil, presumably because of this...
(define-key global-map "\t" 'indent-for-tab-command)
which binds "\t" and not [tab] even though the [tab] keybinding
overrides the "\t" one.
Previously I've dealt with this by checking for either, but this
hard codes [tab] as my keypress, so it can't be changed.
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 14:22 ` Phillip Lord
@ 2014-09-11 14:31 ` Stefan Monnier
2014-09-11 14:53 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-11 14:31 UTC (permalink / raw)
To: Phillip Lord; +Cc: help-gnu-emacs
> This problem seems to be this. If I define keys as follows:
> (define-key pabbrev-mode-map [tab] 'pabbrev-expand-maybe)
If you don't want to distinguish between [tab] and "\t", then use "\t",
which will cover both.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 14:31 ` Stefan Monnier
@ 2014-09-11 14:53 ` Phillip Lord
2014-09-11 18:46 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-11 14:53 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> This problem seems to be this. If I define keys as follows:
>> (define-key pabbrev-mode-map [tab] 'pabbrev-expand-maybe)
>
> If you don't want to distinguish between [tab] and "\t", then use "\t",
> which will cover both.
It's a nice idea, but it fails, unfortunate, because I am defining for a
minor mode. If the major mode uses `\t` then all is good. The minor-mode
will override the major. But if the major-mode defines binds to [tab]
then it will override the minor mode.
I think I have no choice but to handle tab explicitly. Is [tab] the only
key that works like this?
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 14:53 ` Phillip Lord
@ 2014-09-11 18:46 ` Stefan Monnier
2014-09-12 9:50 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-11 18:46 UTC (permalink / raw)
To: help-gnu-emacs
> But if the major-mode defines binds to [tab] then it will override the
> minor mode.
Indeed. It might be a bug in the major-mode, tho (which manifests
for example under ttys where the TAB key sends a \t rather than a `tab').
> I think I have no choice but to handle tab explicitly. Is [tab] the only
> key that works like this?
No. What you're trying to do is inherently tricky/fiddly/unreliable
because Emacs's key-binding infrastructure is not designed for that.
You might want to report a bug asking for some feature that lets you do
what you want (which I suspect is something like "let my command
delegate to the next command bound to this key").
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-11 18:46 ` Stefan Monnier
@ 2014-09-12 9:50 ` Phillip Lord
2014-09-12 11:51 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-12 9:50 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> But if the major-mode defines binds to [tab] then it will override the
>> minor mode.
>
> Indeed. It might be a bug in the major-mode, tho (which manifests
> for example under ttys where the TAB key sends a \t rather than a `tab').
Oh, dear, yes. So binding to [tab] in my minor mode is a mistake. I need
to bind to both \t and [tab]. If I bind to just \t then a major mode can
override this by binding [tab]. If I bind, though, to just [tab] then I
have no binding in tty.
>
>> I think I have no choice but to handle tab explicitly. Is [tab] the only
>> key that works like this?
>
> No. What you're trying to do is inherently tricky/fiddly/unreliable
> because Emacs's key-binding infrastructure is not designed for that.
>
Yep. I've ended up with this. I've had to do something similar for
return which does the same thing.
(defun pabbrev-get-previous-binding ()
"Show the binding of tab if pabbrev were not active.
The command `pabbrev-show-previous-binding' prints this out."
(let ((pabbrev-mode nil))
(let ((tckv
(if pabbrev-xemacs-p
(this-command-keys)
(this-command-keys-vector))))
(cond
((or (equal tckv [tab])
(equal tckv [9]))
(or (key-binding [tab]) (key-binding "\t")))
((or (equal tckv [return])
(equal tckv [32]))
(or (key-binding [return]) (key-binding "\n")))
(t
(key-binding tckv))))))
> You might want to report a bug asking for some feature that lets you do
> what you want (which I suspect is something like "let my command
> delegate to the next command bound to this key").
Will do!
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-12 9:50 ` Phillip Lord
@ 2014-09-12 11:51 ` Stefan Monnier
2014-09-12 15:24 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-12 11:51 UTC (permalink / raw)
To: help-gnu-emacs
> I need to bind to both \t and [tab].
Preferably no.
> If I bind to just \t then a major mode can override this by binding [tab].
That'd be a bug in the major mode, which would be better to fix there.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-12 11:51 ` Stefan Monnier
@ 2014-09-12 15:24 ` Phillip Lord
2014-09-12 16:56 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-12 15:24 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I need to bind to both \t and [tab].
>
> Preferably no.
>
>> If I bind to just \t then a major mode can override this by binding [tab].
>
> That'd be a bug in the major mode, which would be better to fix there.
I am confused then. Should the major mode be binding to \t always then,
and never [tab]? In which case, what is the point of being able to bind
to [tab]?
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-12 15:24 ` Phillip Lord
@ 2014-09-12 16:56 ` Stefan Monnier
2014-09-15 12:48 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-12 16:56 UTC (permalink / raw)
To: Phillip Lord; +Cc: help-gnu-emacs
> I am confused then. Should the major mode be binding to \t always then,
> and never [tab]? In which case, what is the point of being able to bind
> to [tab]?
The major mode should only bind to [tab] if it wants to behave
differently under a GUI than under a tty (which seems highly unlikely),
or if it does not care to work under a tty and wants to distinguish the
TAB key from the C-i key.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-12 16:56 ` Stefan Monnier
@ 2014-09-15 12:48 ` Phillip Lord
2014-09-15 14:19 ` Stefan Monnier
0 siblings, 1 reply; 13+ messages in thread
From: Phillip Lord @ 2014-09-15 12:48 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> I am confused then. Should the major mode be binding to \t always then,
>> and never [tab]? In which case, what is the point of being able to bind
>> to [tab]?
>
> The major mode should only bind to [tab] if it wants to behave
> differently under a GUI than under a tty (which seems highly unlikely),
> or if it does not care to work under a tty and wants to distinguish the
> TAB key from the C-i key.
org does I think -- it binds tab, and C-i but not "\t".
(org-defkey org-mode-map "\C-i" 'org-cycle)
(org-defkey org-mode-map [(tab)] 'org-cycle)
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-15 12:48 ` Phillip Lord
@ 2014-09-15 14:19 ` Stefan Monnier
2014-09-15 15:58 ` Phillip Lord
0 siblings, 1 reply; 13+ messages in thread
From: Stefan Monnier @ 2014-09-15 14:19 UTC (permalink / raw)
To: Phillip Lord; +Cc: help-gnu-emacs
> org does I think -- it binds tab, and C-i but not "\t".
\C-i is another way to write \t
> (org-defkey org-mode-map "\C-i" 'org-cycle)
> (org-defkey org-mode-map [(tab)] 'org-cycle)
The second binding looks like a misfeature to me. You might want to
report it as a bug.
Stefan
^ permalink raw reply [flat|nested] 13+ messages in thread
* Re: Key-binding without minor mode!
2014-09-15 14:19 ` Stefan Monnier
@ 2014-09-15 15:58 ` Phillip Lord
0 siblings, 0 replies; 13+ messages in thread
From: Phillip Lord @ 2014-09-15 15:58 UTC (permalink / raw)
To: Stefan Monnier; +Cc: help-gnu-emacs
Stefan Monnier <monnier@iro.umontreal.ca> writes:
>> org does I think -- it binds tab, and C-i but not "\t".
>
> \C-i is another way to write \t
>
>> (org-defkey org-mode-map "\C-i" 'org-cycle)
>> (org-defkey org-mode-map [(tab)] 'org-cycle)
>
> The second binding looks like a misfeature to me. You might want to
> report it as a bug.
I'll find out why. They are obviously aware of it, as it breaks
yasnippet at least according to their faq. Although yasnippet binds:
(define-key map [(tab)] 'yas-expand)
(define-key map (kbd "TAB") 'yas-expand)
I'm really glad that it wasn't just me that was confused!
Phil
^ permalink raw reply [flat|nested] 13+ messages in thread
end of thread, other threads:[~2014-09-15 15:58 UTC | newest]
Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-11 11:47 Key-binding without minor mode! Phillip Lord
2014-09-11 12:19 ` Stefan Monnier
2014-09-11 14:22 ` Phillip Lord
2014-09-11 14:31 ` Stefan Monnier
2014-09-11 14:53 ` Phillip Lord
2014-09-11 18:46 ` Stefan Monnier
2014-09-12 9:50 ` Phillip Lord
2014-09-12 11:51 ` Stefan Monnier
2014-09-12 15:24 ` Phillip Lord
2014-09-12 16:56 ` Stefan Monnier
2014-09-15 12:48 ` Phillip Lord
2014-09-15 14:19 ` Stefan Monnier
2014-09-15 15:58 ` Phillip Lord
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).