Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete a word without adding it to the kill-ring in Emacs

When switching files using the minibuffer (C-x C-f), I often use M-Backspace to delete words in the path. Emacs automatically places what I delete into the kill ring. This can be annoying, as sometime I am moving to another file to paste something, and I end up pasting part of the file path. I know there are workarounds, and the other code is still in the kill ring, etc, but I would just like to disable this functionality.

like image 849
drewrobb Avatar asked May 26 '11 04:05

drewrobb


1 Answers

Emacs doesn't have a backward-delete-word function, but it's easy enough to define one:

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

Then you can bind M-Backspace to backward-delete-word in minibuffer-local-map:

(define-key minibuffer-local-map [M-backspace] 'backward-delete-word)
like image 78
cjm Avatar answered Oct 14 '22 22:10

cjm