views:

47

answers:

2

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.

+5  A: 

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.

Kilian Foth
`kill-whole-line` seems to be the function I'm looking for. I replaced my original verbose function with the single line: `(global-set-key [(control d)] 'kill-whole-line)` It works, but it still remaps my DEL key.
Fletcher Moore
In that case, whatever you use as the terminal substrate below emacs fails to distinguish properly between DEL and C-d, and you can only solve the problem on a lower level.
Kilian Foth
It's an Emacs thing, actually. Here's the explanation I found. http://www.gnu.org/software/emacs/manual/html_node/emacs/Named-ASCII-Chars.html#Named-ASCII-Chars Thanks for your help, though.
Fletcher Moore
Fletcher: According to that link it is actually a terminal thing: "With an ordinary ASCII terminal, there is no way to distinguish between <TAB> and C-i (and likewise for other such pairs), because the terminal sends the same character in both cases." That article also suggests that if you want to have different functions for different keys you have to actively bind both of them. So if you don't do two (global-set-key)'s emacs will think that you're trying treat the two kinds of inputs the same.
quodlibetor
+1  A: 

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)
Fletcher Moore