unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* Looking for the "best" notation for key-binding
@ 2012-09-20 23:11 Chap Harrison
  2012-09-21  0:30 ` John Wiegley
                   ` (4 more replies)
  0 siblings, 5 replies; 11+ messages in thread
From: Chap Harrison @ 2012-09-20 23:11 UTC (permalink / raw)
  To: help-gnu-emacs

[-- Attachment #1: Type: text/plain, Size: 830 bytes --]

Here are examples of key bindings culled from the Emacs FAQ and 
emacswiki.  Each one seems to use a slightly different notation to 
identify the keystroke.


(global-set-key     (quote [f1])   (quote help-for-help))
(global-unset-key   [?\e?{]        )
(global-set-key     [f10] [?\C-x?\e?\e?\C-a?\C-k?\C-g])
(global-unset-key   "\e["          )
(global-set-key     "\C-h" 'delete-backward-char)
(keyboard-translate ?\C-h          ?\C-?)
(global-set-key     (kbd "C-V")    'somefunction)
(global-set-key     (kbd "<f3>")   'comment-dwim)

It's maddening.  I've so far been unsuccessful in getting this binding 
to work:

(global-set-key (kbd "C-;") 'comment-indent)

It seems to bind the command to the *unmodified* ';'.

Isn't there a single, simple, consistent way to create key bindings that 
will always work?

Thanks,
Chap


[-- Attachment #2: Type: text/html, Size: 1943 bytes --]

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

* Re: Looking for the "best" notation for key-binding
  2012-09-20 23:11 Looking for the "best" notation for key-binding Chap Harrison
@ 2012-09-21  0:30 ` John Wiegley
       [not found] ` <mailman.9409.1348187445.855.help-gnu-emacs@gnu.org>
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 11+ messages in thread
From: John Wiegley @ 2012-09-21  0:30 UTC (permalink / raw)
  To: help-gnu-emacs

>>>>> Chap Harrison <chap.harrison@me.com> writes:

> Isn't there a single, simple, consistent way to create key bindings that
> will always work?

I use this:

    http://github.com/jwiegley/bind-key

Not only is it completely consistent, but it lets you M-x
describe-personal-keybindings and see what you've changed in your Emacs
environment.

John



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

* Re: Looking for the "best" notation for key-binding
       [not found] ` <mailman.9409.1348187445.855.help-gnu-emacs@gnu.org>
@ 2012-09-21  0:45   ` B. T. Raven
  0 siblings, 0 replies; 11+ messages in thread
From: B. T. Raven @ 2012-09-21  0:45 UTC (permalink / raw)
  To: help-gnu-emacs

Die Thu Sep 20 2012 19:30:39 GMT-0500 (Central Daylight Time) John
Wiegley <johnw@newartisans.com> scripsit:

>>>>>> Chap Harrison <chap.harrison@me.com> writes:
> 
>> Isn't there a single, simple, consistent way to create key bindings that
>> will always work?
> 
> I use this:
> 
>     http://github.com/jwiegley/bind-key
> 
> Not only is it completely consistent, but it lets you M-x
> describe-personal-keybindings and see what you've changed in your Emacs
> environment.
> 
> John
> 

Try:

(global-set-key [(control \;)] 'comment-indent)


Sorry, John. I first sent this only to you. Something new going on with
Mozilla Tbird.

Ed




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

* Re: Looking for the "best" notation for key-binding
  2012-09-20 23:11 Looking for the "best" notation for key-binding Chap Harrison
  2012-09-21  0:30 ` John Wiegley
       [not found] ` <mailman.9409.1348187445.855.help-gnu-emacs@gnu.org>
@ 2012-09-21  9:24 ` Peter Dyballa
  2012-09-21 15:27   ` Chap Harrison
       [not found] ` <mailman.9433.1348219496.855.help-gnu-emacs@gnu.org>
  2012-10-01 14:31 ` Jambunathan K
  4 siblings, 1 reply; 11+ messages in thread
From: Peter Dyballa @ 2012-09-21  9:24 UTC (permalink / raw)
  To: clh; +Cc: help-gnu-emacs


Am 21.09.2012 um 01:11 schrieb Chap Harrison:

> Isn't there a single, simple, consistent way to create key bindings that will always work?

I think the vector notation is a good choice:

	(global-set-key [C-∫]		'backward-sexp)	; A-C-b
	(global-set-key [M-S-return]	'other-window)
	(global-set-key [f1 f5]		'apropos-variable)
	(global-set-key [f3]	 	'compare-windows)
	(global-set-key [A-f1]	 	'replace-string)

The commands you bind in your examples the keys are some macros (for f10 for example) or different syntax:

	(quote help-for-help) = 'quote help-for-help
	(quote [f1]) = [f1]

Entries in this syntax are usually created when using global-set-key interactively and saving the resulting bind commands.

Trying to bind the Lisp comment character ";" to anything can become tricky… In my Emacsen (23.4, 24.2.50) this works:

	(global-set-key [67108923] 'comment-indent)

The number value can be found by typing, for example in *scratch* buffer, C-q C-;. This produces a record in the *Messages* buffer you can use.

--
Greetings

  Pete

There's no sense in being precise when you don't even know what you're talking about.
				– John von Neumann




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

* Re: Looking for the "best" notation for key-binding
       [not found] ` <mailman.9433.1348219496.855.help-gnu-emacs@gnu.org>
@ 2012-09-21 13:29   ` Stefan Monnier
  2012-09-21 14:59     ` Peter Dyballa
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2012-09-21 13:29 UTC (permalink / raw)
  To: help-gnu-emacs

> I think the vector notation is a good choice:
> 	(global-set-key [C-∫]		'backward-sexp)	; A-C-b

This likely won't work.  You need

    (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b

instead.  Yes, it's an annoyance.  You have to understand the
distinction between keys that emit characters and other keys (that emit
symbols).

> 	(global-set-key [M-S-return]	'other-window)
> 	(global-set-key [f1 f5]		'apropos-variable)
> 	(global-set-key [f3]	 	'compare-windows)
> 	(global-set-key [A-f1]	 	'replace-string)

These look just fine, yes.

> Trying to bind the Lisp comment character ";" to anything can become tricky…
> In my Emacsen (23.4, 24.2.50) this works:
> 	(global-set-key [67108923] 'comment-indent)

Now that's very intuitive.  A better choice (maybe still not totally
obvious to come across, but at least a bit more obvious to understand
when you read it):

    (global-set-key [?\C-\;] 'comment-indent)
        
> The number value can be found by typing, for example in *scratch* buffer,
> C-q C-;. This produces a record in the *Messages* buffer you can use.

If you type C-x C-e twice in a row, with point right after the magical
number, you'll see alternative ways to write this number, one of them
being the one I used above.


        Stefan


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

* Re: Looking for the "best" notation for key-binding
  2012-09-21 13:29   ` Stefan Monnier
@ 2012-09-21 14:59     ` Peter Dyballa
  2012-09-21 16:29       ` Stefan Monnier
  0 siblings, 1 reply; 11+ messages in thread
From: Peter Dyballa @ 2012-09-21 14:59 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


Am 21.09.2012 um 15:29 schrieb Stefan Monnier:

>> I think the vector notation is a good choice:
>> 	(global-set-key [C-∫]		'backward-sexp)	; A-C-b
> 
> This likely won't work.  You need
> 
>    (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b
> 
> instead.  Yes, it's an annoyance.  You have to understand the
> distinction between keys that emit characters and other keys (that emit
> symbols).

Yes, it stopped working. A-b produces on my (Mac) keyboard ∫. So ∫ is a symbol just as © or Ω? What makes the distinction? Unicode character classes?

--
Greetings

  Pete

When you meet a master swordsman,
show him your sword.
When you meet a man who is not a poet,
do not show him your poem.
			– Rinzai, ninth century Zen master




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

* Re: Looking for the "best" notation for key-binding
  2012-09-21  9:24 ` Peter Dyballa
@ 2012-09-21 15:27   ` Chap Harrison
  2012-10-19  3:39     ` Kevin Rodgers
  0 siblings, 1 reply; 11+ messages in thread
From: Chap Harrison @ 2012-09-21 15:27 UTC (permalink / raw)
  To: Peter Dyballa, help-gnu-emacs

On 09/21/2012 03:24 AM, Peter Dyballa wrote:
> Am 21.09.2012 um 01:11 schrieb Chap Harrison:
>
>> Isn't there a single, simple, consistent way to create key bindings that will always work?
> I think the vector notation is a good choice:
>
> 	(global-set-key [C-∫]		'backward-sexp)	; A-C-b
> 	(global-set-key [M-S-return]	'other-window)
> 	(global-set-key [f1 f5]		'apropos-variable)
> 	(global-set-key [f3]	 	'compare-windows)
> 	(global-set-key [A-f1]	 	'replace-string)

That looks and sounds straightforward enough.

I don't know elisp.  Is there an exhaustive list of how to express all 
of the key chords using vector notation?  For instance, I wouldn't have 
guessed that the 'return' key was denoted by 'return' - I usually see it 
written RET.

As to my problem with C-; I strongly suspect my binding is getting 
stomped by C++ mode.  So I'd also appreciate some guidelines on what 
keys to use or avoid.

Chap






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

* Re: Looking for the "best" notation for key-binding
  2012-09-21 14:59     ` Peter Dyballa
@ 2012-09-21 16:29       ` Stefan Monnier
  2012-09-21 20:37         ` Peter Dyballa
  0 siblings, 1 reply; 11+ messages in thread
From: Stefan Monnier @ 2012-09-21 16:29 UTC (permalink / raw)
  To: Peter Dyballa; +Cc: help-gnu-emacs

>>> I think the vector notation is a good choice:
>>> (global-set-key [C-∫]		'backward-sexp)	; A-C-b
>> This likely won't work.  You need
>> (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b
>> instead.  Yes, it's an annoyance.  You have to understand the
>> distinction between keys that emit characters and other keys (that emit
>> symbols).
> Yes, it stopped working.

When did it work?

> So ∫ is a symbol just as © or Ω?

AFAIK they're all characters (my use of `symbol' was in the Lisp sense
of symbol as opposed to integer, string, cons, float, ...).

> What makes the distinction?

The code that turns GUI events into Lisp events, mostly.  The general
rule is that keys which should self-insert get turned into
character-events, while other (special) keys get turned into symbol-events.

> Unicode character classes?

Unicode has nothing to do with it, no.


        Stefan



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

* Re: Looking for the "best" notation for key-binding
  2012-09-21 16:29       ` Stefan Monnier
@ 2012-09-21 20:37         ` Peter Dyballa
  0 siblings, 0 replies; 11+ messages in thread
From: Peter Dyballa @ 2012-09-21 20:37 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: help-gnu-emacs


Am 21.09.2012 um 18:29 schrieb Stefan Monnier:

>>>> I think the vector notation is a good choice:
>>>> (global-set-key [C-∫]		'backward-sexp)	; A-C-b
>>> This likely won't work.  You need
>>> (global-set-key [?\C-∫] 'backward-sexp) ; A-C-b
>>> instead.  Yes, it's an annoyance.  You have to understand the
>>> distinction between keys that emit characters and other keys (that emit
>>> symbols).
>> Yes, it stopped working.
> 
> When did it work?

I think it was in GNU Emacs 22 based "Carbon Emacs".

> 
>> So ∫ is a symbol just as © or Ω?
> 
> AFAIK they're all characters (my use of `symbol' was in the Lisp sense
> of symbol as opposed to integer, string, cons, float, ...).
> 
>> What makes the distinction?
> 
> The code that turns GUI events into Lisp events, mostly.  The general
> rule is that keys which should self-insert get turned into
> character-events, while other (special) keys get turned into symbol-events.

∫ is a self-insert command:

	∫ runs the command self-insert-command, which is an interactive
	built-in function in `C source code'.
	
	It is bound to many ordinary text characters.

--
Greetings

  Pete

The wise man said: "Never argue with an idiot. They bring you down to their level and beat you with experience."







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

* Re: Looking for the "best" notation for key-binding
  2012-09-20 23:11 Looking for the "best" notation for key-binding Chap Harrison
                   ` (3 preceding siblings ...)
       [not found] ` <mailman.9433.1348219496.855.help-gnu-emacs@gnu.org>
@ 2012-10-01 14:31 ` Jambunathan K
  4 siblings, 0 replies; 11+ messages in thread
From: Jambunathan K @ 2012-10-01 14:31 UTC (permalink / raw)
  To: clh; +Cc: help-gnu-emacs

Chap Harrison <chap.harrison@me.com> writes:

> Here are examples of key bindings culled from the Emacs FAQ and
> emacswiki. Each one seems to use a slightly different notation to
> identify the keystroke.
>
> (global-set-key (quote [f1]) (quote help-for-help))
> (global-unset-key [?\e?{] )
> (global-set-key [f10] [?\C-x?\e?\e?\C-a?\C-k?\C-g])
> (global-unset-key "\e[" )
> (global-set-key "\C-h" 'delete-backward-char)
> (keyboard-translate ?\C-h ?\C-?)
> (global-set-key (kbd "C-V") 'somefunction)
> (global-set-key (kbd "<f3>") 'comment-dwim)
>
> It's maddening. I've so far been unsuccessful in getting this binding
> to work:
>
> (global-set-key (kbd "C-;") 'comment-indent)
>
> It seems to bind the command to the *unmodified* ';'.
>
> Isn't there a single, simple, consistent way to create key bindings
> that will always work?
>

Use M-x global-set-key RET (or M-x local-set-key RET) and follow the
prompt.

Then M-x list-command-history.  You will see the required elisp.

Here is what I get:

,----
| (global-set-key [67108923] (quote comment-indent))
`----

Will above representation work across different platforms or different
invocations of Emacs (terminal/gui/remote).  I don't know and I would
like to know.

I can assure you that it will get the job done.

Likewise for local-set-key.

That said, in the long-run, it is better to not meddle with
Emacs-provided bindings.

> Thanks,
> Chap
>
>

-- 



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

* Re: Looking for the "best" notation for key-binding
  2012-09-21 15:27   ` Chap Harrison
@ 2012-10-19  3:39     ` Kevin Rodgers
  0 siblings, 0 replies; 11+ messages in thread
From: Kevin Rodgers @ 2012-10-19  3:39 UTC (permalink / raw)
  To: help-gnu-emacs

On 9/21/12 9:27 AM, Chap Harrison wrote:
> I don't know elisp. Is there an exhaustive list of how to express all of the key
> chords using vector notation? For instance, I wouldn't have guessed that the
> 'return' key was denoted by 'return' - I usually see it written RET.

They are different, see the "(emacs)Named ASCII Chars" info node.

> As to my problem with C-; I strongly suspect my binding is getting stomped by
> C++ mode. So I'd also appreciate some guidelines on what keys to use or avoid.

See the "(elisp)Key Binding Conventions" info node.

-- 
Kevin Rodgers
Denver, Colorado, USA




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

end of thread, other threads:[~2012-10-19  3:39 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-20 23:11 Looking for the "best" notation for key-binding Chap Harrison
2012-09-21  0:30 ` John Wiegley
     [not found] ` <mailman.9409.1348187445.855.help-gnu-emacs@gnu.org>
2012-09-21  0:45   ` B. T. Raven
2012-09-21  9:24 ` Peter Dyballa
2012-09-21 15:27   ` Chap Harrison
2012-10-19  3:39     ` Kevin Rodgers
     [not found] ` <mailman.9433.1348219496.855.help-gnu-emacs@gnu.org>
2012-09-21 13:29   ` Stefan Monnier
2012-09-21 14:59     ` Peter Dyballa
2012-09-21 16:29       ` Stefan Monnier
2012-09-21 20:37         ` Peter Dyballa
2012-10-01 14:31 ` Jambunathan K

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