* Comment/Uncomment in C files?
@ 2008-04-19 9:06 saneman
2008-04-19 9:48 ` Lennart Borgman (gmail)
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: saneman @ 2008-04-19 9:06 UTC (permalink / raw)
To: help-gnu-emacs
I use emacs22 and have enabled CUA mode. I have assigned
Comment/Uncomment to:
;; Toogle comment/uncomment
(global-set-key "\C-d" 'comment-dwim)
But nothing happens when I press C-d. Does emacs C-mode use some other
config files?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-19 9:06 Comment/Uncomment in C files? saneman
@ 2008-04-19 9:48 ` Lennart Borgman (gmail)
2008-04-19 10:25 ` Alan Mackenzie
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Lennart Borgman (gmail) @ 2008-04-19 9:48 UTC (permalink / raw)
To: saneman; +Cc: help-gnu-emacs
saneman wrote:
> I use emacs22 and have enabled CUA mode. I have assigned
> Comment/Uncomment to:
>
>
> ;; Toogle comment/uncomment
> (global-set-key "\C-d" 'comment-dwim)
>
> But nothing happens when I press C-d. Does emacs C-mode use some other
> config files?
You can use C-h k or C-h c to find out what a key actually is bound to.
Maybe that can help you find out what is happening.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-19 9:06 Comment/Uncomment in C files? saneman
2008-04-19 9:48 ` Lennart Borgman (gmail)
@ 2008-04-19 10:25 ` Alan Mackenzie
[not found] ` <mailman.10571.1208599695.18990.help-gnu-emacs@gnu.org>
2008-04-19 17:10 ` David Hansen
3 siblings, 0 replies; 9+ messages in thread
From: Alan Mackenzie @ 2008-04-19 10:25 UTC (permalink / raw)
To: saneman; +Cc: help-gnu-emacs
On Sat, Apr 19, 2008 at 11:06:38AM +0200, saneman wrote:
> I use emacs22 and have enabled CUA mode. I have assigned
> Comment/Uncomment to:
> ;; Toogle comment/uncomment
> (global-set-key "\C-d" 'comment-dwim)
Quick question: why do you want to do this? comment-dwim has M-; as a
standard key binding, which is surely just as easy to type, and just as
(un)intuitive ;-).
However, if you just want to do this for no particular reason, .....
> But nothing happens when I press C-d. Does emacs C-mode use some other
> config files?
C Mode itself binds C-d to c-electric-delete-forward. More to the point,
it binds it in the keymap c-mode-base-map, and this keymap takes
precedence over the global keymap. So, if you want your global key
binding to be seen, you'll have to suppress the local keybinding.
Something like this (untested) should work:
(define-key c-mode-base-map "\C-d" nil)
That is, if you _really_ want to do it.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
[not found] ` <mailman.10571.1208599695.18990.help-gnu-emacs@gnu.org>
@ 2008-04-19 10:49 ` saneman
2008-04-19 11:02 ` saneman
0 siblings, 1 reply; 9+ messages in thread
From: saneman @ 2008-04-19 10:49 UTC (permalink / raw)
To: help-gnu-emacs
> (define-key c-mode-base-map "\C-d" nil)
Above gives an error:
An error has occurred while loading `/home/mm/.emacs':
Symbol's value as variable is void: c-mode-base-map
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-19 10:49 ` saneman
@ 2008-04-19 11:02 ` saneman
2008-04-20 11:40 ` Alan Mackenzie
[not found] ` <mailman.10603.1208690550.18990.help-gnu-emacs@gnu.org>
0 siblings, 2 replies; 9+ messages in thread
From: saneman @ 2008-04-19 11:02 UTC (permalink / raw)
To: help-gnu-emacs
saneman wrote:
>
>> (define-key c-mode-base-map "\C-d" nil)
>
> Above gives an error:
>
>
>
> An error has occurred while loading `/home/mm/.emacs':
>
> Symbol's value as variable is void: c-mode-base-map
This did the trick:
(define-key c-mode-base-map "\C-d" 'comment-dwim)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-19 9:06 Comment/Uncomment in C files? saneman
` (2 preceding siblings ...)
[not found] ` <mailman.10571.1208599695.18990.help-gnu-emacs@gnu.org>
@ 2008-04-19 17:10 ` David Hansen
3 siblings, 0 replies; 9+ messages in thread
From: David Hansen @ 2008-04-19 17:10 UTC (permalink / raw)
To: help-gnu-emacs
On Sat, 19 Apr 2008 11:06:38 +0200 saneman wrote:
> I use emacs22 and have enabled CUA mode. I have assigned
> Comment/Uncomment to:
>
>
> ;; Toogle comment/uncomment
> (global-set-key "\C-d" 'comment-dwim)
>
> But nothing happens when I press C-d. Does emacs C-mode use some other
> config files?
What's wrong with the standard M-;? Overwriting an essential command
like `delete-char' doesn't seem wise to me.
David
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-19 11:02 ` saneman
@ 2008-04-20 11:40 ` Alan Mackenzie
[not found] ` <mailman.10603.1208690550.18990.help-gnu-emacs@gnu.org>
1 sibling, 0 replies; 9+ messages in thread
From: Alan Mackenzie @ 2008-04-20 11:40 UTC (permalink / raw)
To: saneman; +Cc: help-gnu-emacs
Hi, Saneman!
On Sat, Apr 19, 2008 at 01:02:07PM +0200, saneman wrote:
> saneman wrote:
> >>(define-key c-mode-base-map "\C-d" nil)
> >Above gives an error:
> >An error has occurred while loading `/home/mm/.emacs':
> >Symbol's value as variable is void: c-mode-base-map
Whoops, sorry! What happened there was that CC Mode hadn't been loaded
when you tried to execute the `define-key'.
> This did the trick:
> (define-key c-mode-base-map "\C-d" 'comment-dwim)
That will suffer exactly the same problem. What you need is
(defun sm-C-d ()
(define-key c-mode-base-map "\C-d" 'comment-dwim)) ; or nil
(add-hook 'c-initialization-hook 'sm-C-d)
, fairly early on in your .emacs. That will cause the key to rebound
when CC Mode later gets loaded.
--
Alan Mackenzie (Nuremberg, Germany).
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
[not found] ` <mailman.10603.1208690550.18990.help-gnu-emacs@gnu.org>
@ 2008-04-20 11:48 ` Joost Kremers
2008-04-20 12:58 ` David Hansen
0 siblings, 1 reply; 9+ messages in thread
From: Joost Kremers @ 2008-04-20 11:48 UTC (permalink / raw)
To: help-gnu-emacs
Alan Mackenzie wrote:
> (defun sm-C-d ()
> (define-key c-mode-base-map "\C-d" 'comment-dwim)) ; or nil
> (add-hook 'c-initialization-hook 'sm-C-d)
no need to use a defun for that:
(add-hook 'c-initialization-hook #'(lambda ()
(define-key c-mode-base-map "\C-d" 'comment-dwim)
works just as well.
--
Joost Kremers joostkremers@yahoo.com
Selbst in die Unterwelt dringt durch Spalten Licht
EN:SiS(9)
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Comment/Uncomment in C files?
2008-04-20 11:48 ` Joost Kremers
@ 2008-04-20 12:58 ` David Hansen
0 siblings, 0 replies; 9+ messages in thread
From: David Hansen @ 2008-04-20 12:58 UTC (permalink / raw)
To: help-gnu-emacs
On 20 Apr 2008 11:48:13 GMT Joost Kremers wrote:
> Alan Mackenzie wrote:
>> (defun sm-C-d ()
>> (define-key c-mode-base-map "\C-d" 'comment-dwim)) ; or nil
>> (add-hook 'c-initialization-hook 'sm-C-d)
>
> no need to use a defun for that:
>
> (add-hook 'c-initialization-hook #'(lambda ()
> (define-key c-mode-base-map "\C-d" 'comment-dwim)
>
> works just as well.
But it's way more complicated to `remove-hook' it now.
David
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2008-04-20 12:58 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-04-19 9:06 Comment/Uncomment in C files? saneman
2008-04-19 9:48 ` Lennart Borgman (gmail)
2008-04-19 10:25 ` Alan Mackenzie
[not found] ` <mailman.10571.1208599695.18990.help-gnu-emacs@gnu.org>
2008-04-19 10:49 ` saneman
2008-04-19 11:02 ` saneman
2008-04-20 11:40 ` Alan Mackenzie
[not found] ` <mailman.10603.1208690550.18990.help-gnu-emacs@gnu.org>
2008-04-20 11:48 ` Joost Kremers
2008-04-20 12:58 ` David Hansen
2008-04-19 17:10 ` David Hansen
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).