[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: remap C-c C-d in C file
From: |
Alan Mackenzie |
Subject: |
Re: remap C-c C-d in C file |
Date: |
Wed, 24 Apr 2013 22:13:14 +0000 (UTC) |
User-agent: |
tin/1.9.6-20101126 ("Burnside") (UNIX) (FreeBSD/8.4-PRERELEASE (amd64)) |
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).