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

那年仲夏 提交于 2019-12-18 13:01:44

问题


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.


回答1:


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)



回答2:


See a discussion of this topic at help-gnu-emacs@gnu.org: http://lists.gnu.org/archive/html/help-gnu-emacs/2011-10/msg00277.html

The discussion boils down to this short solution:

(add-hook 'minibuffer-setup-hook'
          (lambda ()
            (make-local-variable 'kill-ring)))


来源:https://stackoverflow.com/questions/6133799/delete-a-word-without-adding-it-to-the-kill-ring-in-emacs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!