views:

70

answers:

2

I would like the "delete to end of word" command to delete the word, regardless of cursor position.

+4  A: 
(defun my-kill-word ()
  (interactive)
  (backward-word)
  (kill-word 1))

(global-set-key (kbd "M-d") 'my-kill-word)
Matthew Flaschen
But what if you're at the beginning of the word? Then it will delete the previous word, won't it?
Thomas Kappler
+1  A: 

A better code could be:

(defun my-kill-word ()
   (interactive)
   (unless (looking-at "\\<")
     (backward-word))
   (kill-word 1))

(global-set-key (kbd "M-d") 'my-kill-word)

So we move backward only if we are not at the beginning of the word yet.

Rémi
Thank you for this one. I've switched over to it. I'm enjoying my conversion to Emacs, but elisp is still gibberish.
Fletcher Moore