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