* Key binding problem
@ 2007-02-26 13:23 tubescreamer808
2007-02-26 13:33 ` weber
0 siblings, 1 reply; 10+ messages in thread
From: tubescreamer808 @ 2007-02-26 13:23 UTC (permalink / raw)
To: help-gnu-emacs
Hi all,
I'm trying to bind a few keys in c mode and so far, didn't have much
success with it. I have the following defined in my .emacs:
(defun my-c-mode-common-hook ()
(local-set-key [C-|] 'indent-region)
(local-set-key [C-%] 'query-replace-regexp)
(local-set-key (kbd "RET") 'newline-and-indent)
(local-set-key [C-/] 'comment-region)
(local-set-key [C-?] 'uncomment-region)
(c-subword-mode 1)
)
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
The only binding that works is the one for the newline-and-indent
command. For the other ones, emacs tells me that the key combination
is not defined. However, if I run local-set-key interactively once
emacs is done loading and after visiting a C++ file, it works. I tried
the same bindings in c++-mode-hook but, unsurprisingly, it made no
difference at all which.
What am I doing wrong?
Thanks in advance
Jean
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-26 13:23 Key binding problem tubescreamer808
@ 2007-02-26 13:33 ` weber
2007-02-26 14:19 ` tubescreamer808
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: weber @ 2007-02-26 13:33 UTC (permalink / raw)
To: help-gnu-emacs
On 26 fev, 10:23, "tubescreamer...@gmail.com"
<tubescreamer...@gmail.com> wrote:
> Hi all,
>
> I'm trying to bind a few keys in c mode and so far, didn't have much
> success with it. I have the following defined in my .emacs:
>
> (defun my-c-mode-common-hook ()
> (local-set-key [C-|] 'indent-region)
> (local-set-key [C-%] 'query-replace-regexp)
> (local-set-key (kbd "RET") 'newline-and-indent)
> (local-set-key [C-/] 'comment-region)
> (local-set-key [C-?] 'uncomment-region)
> (c-subword-mode 1)
> )
>
> (add-hook 'c-mode-common-hook 'my-c-mode-common-hook)
>
> The only binding that works is the one for the newline-and-indent
> command. For the other ones, emacs tells me that the key combination
> is not defined. However, if I run local-set-key interactively once
> emacs is done loading and after visiting a C++ file, it works. I tried
> the same bindings in c++-mode-hook but, unsurprisingly, it made no
> difference at all which.
>
> What am I doing wrong?
>
> Thanks in advance
> Jean
I don't know about this local-set-key command...
Could you try changing to something like these
(define-key c-mode-map "\C-%" 'query-replace-regexp)
instead?
Cheers,
weber
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-26 13:33 ` weber
@ 2007-02-26 14:19 ` tubescreamer808
2007-02-26 16:12 ` Lennart Borgman (gmail)
[not found] ` <mailman.118.1172506366.7795.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 10+ messages in thread
From: tubescreamer808 @ 2007-02-26 14:19 UTC (permalink / raw)
To: help-gnu-emacs
> I don't know about this local-set-key command...
>From emacs help:
local-set-key is an interactive compiled Lisp function in
`subr.el'.
(local-set-key KEY COMMAND)
Give KEY a local binding as COMMAND.
COMMAND is the command definition to use; usually it is
a symbol naming an interactively-callable function.
KEY is a key sequence; noninteractively, it is a string or vector
of characters or event types, and non-ASCII characters with codes
above 127 (such as ISO Latin-1) can be included if you use a
vector.
The binding goes in the current buffer's local map,
which in most cases is shared with all other buffers in the same
major mode.
>
> I don't know about this local-set-key command...
>
> Could you try changing to something like these
> (define-key c-mode-map "\C-%" 'query-replace-regexp)
> instead?
>
I tried that also and got the same result.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-26 13:33 ` weber
2007-02-26 14:19 ` tubescreamer808
@ 2007-02-26 16:12 ` Lennart Borgman (gmail)
[not found] ` <mailman.118.1172506366.7795.help-gnu-emacs@gnu.org>
2 siblings, 0 replies; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2007-02-26 16:12 UTC (permalink / raw)
To: weber; +Cc: help-gnu-emacs
weber wrote:
>> (local-set-key [C-|] 'indent-region)
Try
(local-set-key [(control ?|)] (lambda() (interactive) (message "Hi from
C-|")))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
[not found] ` <mailman.118.1172506366.7795.help-gnu-emacs@gnu.org>
@ 2007-02-26 16:54 ` tubescreamer808
2007-02-26 18:41 ` Xavier Maillard
0 siblings, 1 reply; 10+ messages in thread
From: tubescreamer808 @ 2007-02-26 16:54 UTC (permalink / raw)
To: help-gnu-emacs
Thank you very much weber, it works perfectly.
Alternatively, I have just discovered that using the kbd macro works
fine also e.g.
(local-set-key (kbd "C-|") 'indent-region)
Don't ask me why I never tried it before since I was already using it
for the newline-and-indent binding. I guess that sometimes things are
just too obvious or you're just too stupid...
Anyways, thanks again for your help!
Jean
On 26 fév, 17:12, "Lennart Borgman (gmail)"
<lennart.borg...@gmail.com> wrote:
> weber wrote:
> >> (local-set-key [C-|] 'indent-region)
>
> Try
>
> (local-set-key [(control ?|)] (lambda() (interactive) (message "Hi from
> C-|")))
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-26 16:54 ` tubescreamer808
@ 2007-02-26 18:41 ` Xavier Maillard
2007-02-26 19:15 ` Drew Adams
0 siblings, 1 reply; 10+ messages in thread
From: Xavier Maillard @ 2007-02-26 18:41 UTC (permalink / raw)
To: tubescreamer808@gmail.com; +Cc: help-gnu-emacs
tubescreamer808@gmail.com <tubescreamer808@gmail.com> wrote:
> Thank you very much weber, it works perfectly.
>
> Alternatively, I have just discovered that using the kbd macro works
> fine also e.g.
> (local-set-key (kbd "C-|") 'indent-region)
>
> Don't ask me why I never tried it before since I was already using it
> for the newline-and-indent binding. I guess that sometimes things are
> just too obvious or you're just too stupid...
You are not stupid at all. The two versions are perfectly right
kbd macro is just "the new syntax" to define key bindings. It has
been introduced into emacs 20.x as far as I remember.
[()} is called the XEmacs way and has been supported (and is
still supported) by older emacs.
There is also the string syntax but I do not use it.
Xavier
^ permalink raw reply [flat|nested] 10+ messages in thread
* RE: Key binding problem
2007-02-26 18:41 ` Xavier Maillard
@ 2007-02-26 19:15 ` Drew Adams
2007-02-26 20:28 ` Xavier Maillard
[not found] ` <mailman.136.1172521894.7795.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 10+ messages in thread
From: Drew Adams @ 2007-02-26 19:15 UTC (permalink / raw)
To: help-gnu-emacs
> kbd macro is just "the new syntax" to define key bindings. It has
> been introduced into emacs 20.x as far as I remember.
Not AFAIK. GNU Emacs 21 perhaps, but not GNU Emacs 20.
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-26 19:15 ` Drew Adams
@ 2007-02-26 20:28 ` Xavier Maillard
[not found] ` <mailman.136.1172521894.7795.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 10+ messages in thread
From: Xavier Maillard @ 2007-02-26 20:28 UTC (permalink / raw)
To: Drew Adams; +Cc: help-gnu-emacs
Drew Adams <drew.adams@oracle.com> wrote:
> > kbd macro is just "the new syntax" to define key bindings. It has
> > been introduced into emacs 20.x as far as I remember.
>
> Not AFAIK. GNU Emacs 21 perhaps, but not GNU Emacs 20.
Hum I am pretty sure I have seen it introduced in emacs 20.1 or
something like that.
I may be wrong, I will have to check this.
Xavier
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
[not found] ` <mailman.136.1172521894.7795.help-gnu-emacs@gnu.org>
@ 2007-02-27 8:50 ` tubescreamer808
2007-02-27 10:15 ` Lennart Borgman (gmail)
0 siblings, 1 reply; 10+ messages in thread
From: tubescreamer808 @ 2007-02-27 8:50 UTC (permalink / raw)
To: help-gnu-emacs
On 26 fév, 21:28, Xavier Maillard <z...@gnu.org> wrote:
> Drew Adams <drew.ad...@oracle.com> wrote:
> > > kbd macro is just "the new syntax" to define key bindings. It has
> > > been introduced into emacs 20.x as far as I remember.
>
> > Not AFAIK. GNU Emacs 21 perhaps, but not GNU Emacs 20.
>
> Hum I am pretty sure I have seen it introduced in emacs 20.1 or
> something like that.
>
> I may be wrong, I will have to check this.
>
> Xavier
Oops, I just noticed that I thanked weber for the solution but it was
in fact Lennart Borgman who came up with the answer. So, sorry about
that Lennart and thank you very much.
Jean
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: Key binding problem
2007-02-27 8:50 ` tubescreamer808
@ 2007-02-27 10:15 ` Lennart Borgman (gmail)
0 siblings, 0 replies; 10+ messages in thread
From: Lennart Borgman (gmail) @ 2007-02-27 10:15 UTC (permalink / raw)
To: tubescreamer808@gmail.com; +Cc: help-gnu-emacs
tubescreamer808@gmail.com wrote:
> Oops, I just noticed that I thanked weber for the solution but it was
> in fact Lennart Borgman who came up with the answer. So, sorry about
> that Lennart and thank you very much.
As always it is the intention that counts. I was fond to see you liked
it and did not care that you thought someone else did it.
If there were some salaries involved I might have thought differently,
but anyway in that case it is quite often so that no one cares about who
actually does the job ;-)
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2007-02-27 10:15 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-26 13:23 Key binding problem tubescreamer808
2007-02-26 13:33 ` weber
2007-02-26 14:19 ` tubescreamer808
2007-02-26 16:12 ` Lennart Borgman (gmail)
[not found] ` <mailman.118.1172506366.7795.help-gnu-emacs@gnu.org>
2007-02-26 16:54 ` tubescreamer808
2007-02-26 18:41 ` Xavier Maillard
2007-02-26 19:15 ` Drew Adams
2007-02-26 20:28 ` Xavier Maillard
[not found] ` <mailman.136.1172521894.7795.help-gnu-emacs@gnu.org>
2007-02-27 8:50 ` tubescreamer808
2007-02-27 10:15 ` Lennart Borgman (gmail)
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).