all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* Novice question: my add-hook binding for c-mode doesnt work :(
@ 2005-12-01 11:08 Kpoxman (sent by Nabble.com)
  2005-12-02  6:52 ` Xavier Maillard
  0 siblings, 1 reply; 11+ messages in thread
From: Kpoxman (sent by Nabble.com) @ 2005-12-01 11:08 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 586 bytes --]


The code from .emacs:

(add-hook 'c-mode-common-hook
	  '(lambda () (define-key c-mode-map (kbd "M-o") 'kpox-switch-h-cpp))
	  )

After I open .CPP file kpox-switch-h-cpp appears in c-mode-map bindings (I checked c-mode-map variable). But pressing M-o doesnt call kpox-switch-h-cpp. An old function from global binding is called (set-face or something similar).

Please advise me what is the problem and how to solve it.
--
Sent from the Emacs - Help forum at Nabble.com:
http://www.nabble.com/Novice-question%3A-my-add-hook-binding-for-c-mode-doesnt-work-%3A%28-t651747.html#a1732372

[-- Attachment #1.2: Type: text/html, Size: 864 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
       [not found] <mailman.17480.1133437995.20277.help-gnu-emacs@gnu.org>
@ 2005-12-01 13:45 ` Anselm Helbig
  2005-12-01 16:18 ` Thien-Thi Nguyen
  2005-12-01 16:56 ` Johan Bockgård
  2 siblings, 0 replies; 11+ messages in thread
From: Anselm Helbig @ 2005-12-01 13:45 UTC (permalink / raw)


At Thu, 1 Dec 2005 03:08:14 -0800 (PST),
"Kpoxman (sent by Nabble.com)" <lists@nabble.com> wrote:
> The code from .emacs:
> 
> (add-hook 'c-mode-common-hook
>           '(lambda () (define-key c-mode-map (kbd "M-o") 'kpox-switch-h-cpp))
>           )

remove the quote before the lambda expression. you want the lambda
expression to be evaluated, because it returns an anonymous function. 

regards, 

anselm

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
       [not found] <mailman.17480.1133437995.20277.help-gnu-emacs@gnu.org>
  2005-12-01 13:45 ` Novice question: my add-hook binding for c-mode doesnt work :( Anselm Helbig
@ 2005-12-01 16:18 ` Thien-Thi Nguyen
  2005-12-01 16:56 ` Johan Bockgård
  2 siblings, 0 replies; 11+ messages in thread
From: Thien-Thi Nguyen @ 2005-12-01 16:18 UTC (permalink / raw)


"Kpoxman (sent by Nabble.com)" <lists@nabble.com> writes:

> Please advise me what is the problem and how to solve it.

the problem may be that:               (kbd "M-o")
does not return the "expected" value:  [239]

put the expression into *scratch* and type `C-j' after the close-paren
to see for yourself.  fwiw, on my computer i see [134217839].  you can
try "\M-o" instead of "M-o" (note backslash).

thi

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
       [not found] <mailman.17480.1133437995.20277.help-gnu-emacs@gnu.org>
  2005-12-01 13:45 ` Novice question: my add-hook binding for c-mode doesnt work :( Anselm Helbig
  2005-12-01 16:18 ` Thien-Thi Nguyen
@ 2005-12-01 16:56 ` Johan Bockgård
  2 siblings, 0 replies; 11+ messages in thread
From: Johan Bockgård @ 2005-12-01 16:56 UTC (permalink / raw)


"Kpoxman (sent by Nabble.com)" <lists@nabble.com> writes:

> The code from .emacs:
>
> (add-hook 'c-mode-common-hook
> 	  '(lambda () (define-key c-mode-map (kbd "M-o") 'kpox-switch-h-cpp))
> 	  )
>
> After I open .CPP file kpox-switch-h-cpp appears in c-mode-map
> bindings (I checked c-mode-map variable).

c-mode-base-map
  Variable: Keymap shared by all CC Mode related modes.

c++-mode-map
  Variable: Keymap used in c++-mode buffers.

c-mode-map
  Variable: Keymap used in c-mode buffers.

-- 
Johan Bockgård

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
  2005-12-01 11:08 Kpoxman (sent by Nabble.com)
@ 2005-12-02  6:52 ` Xavier Maillard
  2005-12-02  7:07   ` Henrik Enberg
  0 siblings, 1 reply; 11+ messages in thread
From: Xavier Maillard @ 2005-12-02  6:52 UTC (permalink / raw)
  Cc: Help-gnu-emacs

"Kpoxman (sent by Nabble.com)" <lists@nabble.com> writes:

> The code from .emacs:
>
> (add-hook 'c-mode-common-hook
> 	  '(lambda () (define-key c-mode-map (kbd "M-o") 'kpox-switch-h-cpp))
> 	  )

This form is useless. You don't need to bind this key definition to this hook.

Just use the (define-key ..) stuff and that *should* work.

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
  2005-12-02  6:52 ` Xavier Maillard
@ 2005-12-02  7:07   ` Henrik Enberg
  2005-12-02  9:10     ` Kpoxman (sent by Nabble.com)
       [not found]     ` <mailman.17607.1133515063.20277.help-gnu-emacs@gnu.org>
  0 siblings, 2 replies; 11+ messages in thread
From: Henrik Enberg @ 2005-12-02  7:07 UTC (permalink / raw)


> From: Xavier Maillard <zedek@gnu-rox.org>
> Date: Fri, 02 Dec 2005 07:52:03 +0100
> 
> "Kpoxman (sent by Nabble.com)" <lists@nabble.com> writes:
> 
> > The code from .emacs:
> >
> > (add-hook 'c-mode-common-hook
> > 	  '(lambda () (define-key c-mode-map (kbd "M-o") 'kpox-switch-h-cpp))
> > 	  )
> 
> This form is useless. You don't need to bind this key definition to this hook.
> 
> Just use the (define-key ..) stuff and that *should* work.

`c-mode-map' isn't defined until cc-mode is loaded, putting just the
define-key in .emacs will thow an error.

The problem is as someone pointed out that he should use
`c-mode-base-map' instead of `c-mode-map'.

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
  2005-12-02  7:07   ` Henrik Enberg
@ 2005-12-02  9:10     ` Kpoxman (sent by Nabble.com)
       [not found]     ` <mailman.17607.1133515063.20277.help-gnu-emacs@gnu.org>
  1 sibling, 0 replies; 11+ messages in thread
From: Kpoxman (sent by Nabble.com) @ 2005-12-02  9:10 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 346 bytes --]


Thank you guys!
So, the correct code is (I've tested and it works):

(add-hook 'c-mode-common-hook
	  '(lambda () (define-key c-mode-base-map (kbd "M-o") 'kpox-switch-h-cpp))
	  )

--
Sent from the Emacs - Help forum at Nabble.com:
http://www.nabble.com/Novice-question%3A-my-add-hook-binding-for-c-mode-doesnt-work-%3A%28-t651747.html#a1749159

[-- Attachment #1.2: Type: text/html, Size: 620 bytes --]

[-- Attachment #2: Type: text/plain, Size: 152 bytes --]

_______________________________________________
Help-gnu-emacs mailing list
Help-gnu-emacs@gnu.org
http://lists.gnu.org/mailman/listinfo/help-gnu-emacs

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
       [not found]     ` <mailman.17607.1133515063.20277.help-gnu-emacs@gnu.org>
@ 2005-12-03  2:07       ` Stefan Monnier
  2005-12-03 21:15       ` Alan Mackenzie
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2005-12-03  2:07 UTC (permalink / raw)


> (add-hook 'c-mode-common-hook
> 	  '(lambda () (define-key c-mode-base-map (kbd "M-o") 'kpox-switch-h-cpp))
         ^^
Removing this quote will improve your karma, will save 1 byte, and won't
hurt anything else.


        Stefan

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
       [not found]     ` <mailman.17607.1133515063.20277.help-gnu-emacs@gnu.org>
  2005-12-03  2:07       ` Stefan Monnier
@ 2005-12-03 21:15       ` Alan Mackenzie
  2005-12-04 15:48         ` Stefan Monnier
  2005-12-04 16:05         ` Matthieu Moy
  1 sibling, 2 replies; 11+ messages in thread
From: Alan Mackenzie @ 2005-12-03 21:15 UTC (permalink / raw)


"Kpoxman (sent by Nabble.com)" <lists@nabble.com> wrote on Fri, 2 Dec
2005 01:10:36 -0800 (PST):

> Thank you guys!
> So, the correct code is (I've tested and it works):

> (add-hook 'c-mode-common-hook
> 	  '(lambda () (define-key c-mode-base-map (kbd "M-o") 'kpox-switch-h-cpp))
> 	  )

Just one small point:  The above code "adds" the binding to the key map
every time you open a CC Mode buffer.  You really only need to add the
key binding once: use CC Mode's initialization hook instead:

(add-hook 'c-initialization-hook
        '(lambda () (define-key c-mode-base-map (kbd "M-o") 'kpox-switch-h-cpp)))

-- 
Alan Mackenzie (Munich, Germany)
Email: aacm@muuc.dee; to decode, wherever there is a repeated letter
(like "aa"), remove half of them (leaving, say, "a").

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
  2005-12-03 21:15       ` Alan Mackenzie
@ 2005-12-04 15:48         ` Stefan Monnier
  2005-12-04 16:05         ` Matthieu Moy
  1 sibling, 0 replies; 11+ messages in thread
From: Stefan Monnier @ 2005-12-04 15:48 UTC (permalink / raw)


> (add-hook 'c-initialization-hook
>         '(lambda () (define-key c-mode-base-map (kbd "M-o") 'kpox-switch-h-cpp)))
         ^^

Same problem of bad karma.


        Stefan

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

* Re: Novice question: my add-hook binding for c-mode doesnt work :(
  2005-12-03 21:15       ` Alan Mackenzie
  2005-12-04 15:48         ` Stefan Monnier
@ 2005-12-04 16:05         ` Matthieu Moy
  1 sibling, 0 replies; 11+ messages in thread
From: Matthieu Moy @ 2005-12-04 16:05 UTC (permalink / raw)


Alan Mackenzie <acm@muc.de> writes:

> Just one small point:  The above code "adds" the binding to the key map
> every time you open a CC Mode buffer.  You really only need to add the
> key binding once: use CC Mode's initialization hook instead:

See also `eval-after-load'.

-- 
Matthieu

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

end of thread, other threads:[~2005-12-04 16:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.17480.1133437995.20277.help-gnu-emacs@gnu.org>
2005-12-01 13:45 ` Novice question: my add-hook binding for c-mode doesnt work :( Anselm Helbig
2005-12-01 16:18 ` Thien-Thi Nguyen
2005-12-01 16:56 ` Johan Bockgård
2005-12-01 11:08 Kpoxman (sent by Nabble.com)
2005-12-02  6:52 ` Xavier Maillard
2005-12-02  7:07   ` Henrik Enberg
2005-12-02  9:10     ` Kpoxman (sent by Nabble.com)
     [not found]     ` <mailman.17607.1133515063.20277.help-gnu-emacs@gnu.org>
2005-12-03  2:07       ` Stefan Monnier
2005-12-03 21:15       ` Alan Mackenzie
2005-12-04 15:48         ` Stefan Monnier
2005-12-04 16:05         ` Matthieu Moy

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.