How can I tweak this elisp function to distinguish between C-d & DEL?
Here's my current function (blindly copy-pasted from a website)
(defun tweakemacs-delete-one-line ()
"Delete current line."
(interactive)
(beginning-of-line)
(kill-line)
(kill-line))
(global-set-key (kbd "C-d") 'tweakemacs-delete-one-l开发者_运维问答ine)
There are two quirks here that I want to get rid of. 1) This actually rebinds DEL to the same function. I want my DEL to remain "delete one character". 2) There needs to be a condition where it will not double-kill if the line is only a newline character.
To distinguish those two, use the preferred vector syntax for keys:
(global-set-key [delete] 'foo)
(global-set-key [(control d)] 'bar)
As for the second thing, it sounds as if you either want
(setq kill-whole-line t)
or just want to use the function kill-entire-line
instead.
I read part of the manual on keybindings, and it said that C-d
and <DEL>
, like other special keys, are bound. To unbind them you have to explicitly set both of them.
Ultimately, I used this solution:
(global-set-key (kbd "<delete>") 'delete-char)
(global-set-key ([control d]) 'kill-whole-word)
精彩评论