unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* remap C-c C-d in C file
@ 2013-04-24 19:34 Rami A
  2013-04-24 22:13 ` Alan Mackenzie
  0 siblings, 1 reply; 3+ messages in thread
From: Rami A @ 2013-04-24 19:34 UTC (permalink / raw)
  To: help-gnu-emacs

Greetings,
I have these functions defined in my dotemacs file:

;; Duplicate entire line
(defun paste-line ()
  "Go to beginning of next line, then yank.(eam)"
  "Note: this yanks whatever was last killed, whether it was a line,"
  "      multiple lines, or part of a line."
  (interactive)
  (forward-line 1)
  (yank))
(defun duplicate-entire-line ()
  "Copy the whole line that point is on.(eam)"
  (interactive)
  (forward-line 1) 
  (let ((end (point))) 
  (forward-line -1) 
  (copy-region-as-kill (point) end)
  (paste-line)))
(global-set-key "\C-c\C-d"       'duplicate-entire-line)

So pressing C-c C-d works in assembly files and it duplicates the current line.
However, in C files it just proceeds to delete a character.
How to remap these keys combinations to "duplicate-entire-line"?
Thanks.


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

* Re: remap C-c C-d in C file
  2013-04-24 19:34 remap C-c C-d in C file Rami A
@ 2013-04-24 22:13 ` Alan Mackenzie
  2013-04-24 22:52   ` Rami A
  0 siblings, 1 reply; 3+ messages in thread
From: Alan Mackenzie @ 2013-04-24 22:13 UTC (permalink / raw)
  To: help-gnu-emacs

Rami A <rami.ammari@gmail.com> wrote:
> Greetings,
> I have these functions defined in my dotemacs file:

> ;; Duplicate entire line
> (defun paste-line ()
>  "Go to beginning of next line, then yank.(eam)"
>  "Note: this yanks whatever was last killed, whether it was a line,"
>  "      multiple lines, or part of a line."
>  (interactive)
>  (forward-line 1)
>  (yank))
> (defun duplicate-entire-line ()
>  "Copy the whole line that point is on.(eam)"
>  (interactive)
>  (forward-line 1) 
>  (let ((end (point))) 
>  (forward-line -1) 
>  (copy-region-as-kill (point) end)
>  (paste-line)))
> (global-set-key "\C-c\C-d"       'duplicate-entire-line)

> So pressing C-c C-d works in assembly files and it duplicates the current line.
> However, in C files it just proceeds to delete a character.

Actually, it does c-hungry-delete-forward, which deletes all contiguous white
space characters after point, but that's by the way.

Why are you using C-c C-d here?  As an Emacs convention, C-c C-<letter>
combinations are reserved for the use of major modes, so C Mode is behaving
quite correctly here.  I would recommend you instead to use something like
C-c d - C-c <letter> combinations are reserved for the use of users.  This
convention is documented in the Emacs Lisp manual on page "Key Binding
Conventions".

> How to remap these keys combinations to "duplicate-entire-line"?

If you really insist on this, you have to unbind C-c C-d in the C Mode
key map, since major mode key maps take priority over the global key map.
Something like this (untested) should do it:

(define-key c-mode-base-map "\C-c\C-d" nil)

> Thanks.

-- 
Alan Mackenzie (Nuremberg, Germany).



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

* Re: remap C-c C-d in C file
  2013-04-24 22:13 ` Alan Mackenzie
@ 2013-04-24 22:52   ` Rami A
  0 siblings, 0 replies; 3+ messages in thread
From: Rami A @ 2013-04-24 22:52 UTC (permalink / raw)
  To: help-gnu-emacs

Thank you so much Alan.
This did actually work:

(defun my-c-mode-common-hook ()
  (define-key c-mode-base-map "\C-c\C-d" nil)    ; unbind c-hungry-delete-forward 
  )
(add-hook 'c-mode-common-hook 'my-c-mode-common-hook)


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

end of thread, other threads:[~2013-04-24 22:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-04-24 19:34 remap C-c C-d in C file Rami A
2013-04-24 22:13 ` Alan Mackenzie
2013-04-24 22:52   ` Rami A

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