Emacs: how to delete text without kill ring?

后端 未结 15 1102
旧巷少年郎
旧巷少年郎 2020-12-04 14:00

I\'d like to just delete some text so I can yank some other text instead of it. How can I do that? C-w cuts the selected text to kill ring and I end up with

15条回答
  •  悲哀的现实
    2020-12-04 14:43

    Most kill functions use kill-region to do the actual work of killing text. I use a lisp macro to create delete functions from kill functions.

    (defmacro jpk/delete-instead-of-kill (&rest body)
      "Replaces `kill-region' with `delete-region' in BODY."
      `(cl-letf (((symbol-function 'kill-region)
                  (lambda (beg end &optional yank-handler)
                    (delete-region beg end))))
         ,@body))
    
    (defun jpk/delete-word (arg)
      "Like `kill-word', but does not save to the `kill-ring'."
      (interactive "*p")
      (jpk/delete-instead-of-kill (kill-word arg)))
    

提交回复
热议问题