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

前端 未结 2 807
囚心锁ツ
囚心锁ツ 2020-12-31 09:02

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 c

相关标签:
2条回答
  • 2020-12-31 09:15

    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)))
    
    0 讨论(0)
  • 2020-12-31 09:18

    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)
    
    0 讨论(0)
提交回复
热议问题