BackwardDeleteWord

Last edit

Summary: fixed grammar

Changed:

< I think M-backspace should delete, rather than kill. Here code for .emacs to accomplish that.

to

> I think M-backspace should delete, rather than kill. Here is some code for .emacs to accomplish that.


I think M-backspace should delete, rather than kill. Here is some code for .emacs to accomplish that.

(defun delete-word (arg)
  "Delete characters forward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-region (point) (progn (forward-word arg) (point))))

(defun backward-delete-word (arg)
  "Delete characters backward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-word (- arg)))

(global-set-key (read-kbd-macro "<M-DEL>") 'backward-delete-word)

If you use CUA mode, you might want to register these functions as movements, so that shift-<key> works properly:

(dolist (cmd '(delete-word backward-delete-word))
  (put cmd 'CUA 'move))