Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Looking for the "best" notation for key-binding
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  11 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Chap Harrison  
View profile  
 More options Sep 20 2012, 7:11 pm
Newsgroups: gnu.emacs.help
From: Chap Harrison <chap.harri...@me.com>
Date: Thu, 20 Sep 2012 17:11:48 -0600
Local: Thurs, Sep 20 2012 7:11 pm
Subject: Looking for the "best" notation for key-binding

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
John Wiegley  
View profile  
 More options Sep 20 2012, 8:30 pm
Newsgroups: gnu.emacs.help
From: "John Wiegley" <jo...@newartisans.com>
Date: Thu, 20 Sep 2012 19:30:39 -0500
Local: Thurs, Sep 20 2012 8:30 pm
Subject: Re: Looking for the "best" notation for key-binding

>>>>> Chap Harrison <chap.harri...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
B. T. Raven  
View profile  
 More options Sep 20 2012, 8:46 pm
Newsgroups: gnu.emacs.help
From: "B. T. Raven" <btra...@nihilo.net>
Date: Thu, 20 Sep 2012 19:45:41 -0500
Local: Thurs, Sep 20 2012 8:45 pm
Subject: Re: Looking for the "best" notation for key-binding
Die Thu Sep 20 2012 19:30:39 GMT-0500 (Central Daylight Time) John
Wiegley <jo...@newartisans.com> scripsit:

>>>>>> Chap Harrison <chap.harri...@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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Dyballa  
View profile  
 More options Sep 21 2012, 5:24 am
Newsgroups: gnu.emacs.help
From: Peter Dyballa <Peter_Dyba...@Web.DE>
Date: Fri, 21 Sep 2012 11:24:35 +0200
Local: Fri, Sep 21 2012 5:24 am
Subject: Re: Looking for the "best" notation for key-binding

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Monnier  
View profile  
 More options Sep 21 2012, 9:29 am
Newsgroups: gnu.emacs.help
From: Stefan Monnier <monn...@iro.umontreal.ca>
Date: Fri, 21 Sep 2012 09:29:21 -0400
Local: Fri, Sep 21 2012 9:29 am
Subject: Re: Looking for the "best" notation for key-binding

> 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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Dyballa  
View profile  
 More options Sep 21 2012, 11:00 am
Newsgroups: gnu.emacs.help
From: Peter Dyballa <Peter_Dyba...@Web.DE>
Date: Fri, 21 Sep 2012 16:59:54 +0200
Local: Fri, Sep 21 2012 10:59 am
Subject: Re: Looking for the "best" notation for key-binding

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Chap Harrison  
View profile  
 More options Sep 21 2012, 11:28 am
Newsgroups: gnu.emacs.help
From: Chap Harrison <chap.harri...@me.com>
Date: Fri, 21 Sep 2012 09:27:37 -0600
Local: Fri, Sep 21 2012 11:27 am
Subject: Re: Looking for the "best" notation for key-binding
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Stefan Monnier  
View profile  
 More options Sep 21 2012, 12:29 pm
Newsgroups: gnu.emacs.help
From: Stefan Monnier <monn...@IRO.UMontreal.CA>
Date: Fri, 21 Sep 2012 12:29:06 -0400
Local: Fri, Sep 21 2012 12:29 pm
Subject: Re: Looking for the "best" notation for key-binding

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter Dyballa  
View profile  
 More options Sep 21 2012, 4:37 pm
Newsgroups: gnu.emacs.help
From: Peter Dyballa <Peter_Dyba...@Web.DE>
Date: Fri, 21 Sep 2012 22:37:40 +0200
Local: Fri, Sep 21 2012 4:37 pm
Subject: Re: Looking for the "best" notation for key-binding

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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jambunathan K  
View profile  
 More options Oct 1 2012, 10:30 am
Newsgroups: gnu.emacs.help
From: Jambunathan K <kjambunat...@gmail.com>
Date: Mon, 01 Oct 2012 20:01:49 +0530
Local: Mon, Oct 1 2012 10:31 am
Subject: Re: Looking for the "best" notation for key-binding

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

--

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Kevin Rodgers  
View profile  
 More options Oct 18 2012, 11:39 pm
Newsgroups: gnu.emacs.help
From: Kevin Rodgers <kevin.d.rodg...@gmail.com>
Date: Thu, 18 Oct 2012 21:39:56 -0600
Local: Thurs, Oct 18 2012 11:39 pm
Subject: Re: Looking for the "best" notation for key-binding
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


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »