help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: F2


From: Tim X
Subject: Re: F2
Date: Tue, 01 Mar 2011 18:14:42 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

PJ Weisberg <pj@irregularexpressions.net> writes:

> On 2/28/11, TheFlyingDutchman <zzbbaadd@aol.com> wrote:
>> I was using
>> (global-set-key (kbd "<f2>") 'my-elisp-command)
>>
>> I don't know if that works differently than define-key.
>
> For the record,
>
> (global-set-key (kbd "<f2>") (lambda() (interactive) (message "Hello, 
> world!")))
>
> works perfectly well over here (Emacs 23.2.1 via Debian).
>

Note that you can see if a key is 'free' by using C-h b to list all
current key bindings. 

,----[ C-h k  control h b  ]
|  control h b runs the command describe-bindings, which is an interactive
|  compiled Lisp function in `help.el'.
| 
| It is bound to control h b , <f1> b , <help> b , <menu-bar> <help-menu>
| <describe> <list-keybindings> .
| 
| (describe-bindings &optional PREFIX BUFFER)
| 
| Show a list of all defined keys, and their definitions.
| We put that list in a buffer, and display the buffer.
| 
| The optional argument PREFIX, if non-nil, should be a key sequence;
| then we display only bindings that start with that prefix.
| The optional argument BUFFER specifies which buffer's bindings
| to display (default, the current buffer).  BUFFER can be a buffer
| or a buffer name.
| 
| [back]
`----

If I do this in now, on my system I see 

<f1>            help-command
<f10>           menu-bar-open
<f13>           kmacro-start-macro-or-insert-counter
<f14>           kmacro-end-or-call-macro
<f16>           clipboard-kill-ring-save
<f18>           clipboard-yank
<f2>            2C-command
<f20>           clipboard-kill-region
<f3>            kmacro-start-macro-or-insert-counter
<f4>            kmacro-end-or-call-macro
<f5>            tempo-template-generic-header

If you find, after defining a key using either define-key global-map or
global-set-key, that the key doesn't seem to work, it is likely that
your global key binding is being over shadowed by a local key binding.
Using C-h b can help to show what maybe going on.  It is important to
remember that key maps work in aa sort of hierarchy and that global
definitions can be overridden (including cleared) by local key maps. 

This could also explain why the definition works for some and not
others. Unless everyone is defining and testing the binding from wihtin
the same mode, with the same global and local key maps, you may see what
appears to be inconsistent results. It can also explain what is going on
if you define a global key definition, test it and find it works and
then later, try to use it while in a different mode and find it doesn'
work. 

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

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