3

I would like to use normal modes commands like d c x etc without the content being copied to clipboard.

I want to make emacs so that only y command will write anything to the clipboard. Other commands like d should only delete the content without writing anything to the clipboard.

meain
  • 833
  • 9
  • 28

3 Answers3

3

As suggested by Gordon Gustafson use arround advice. evil-delete is what used by emacs for all kinds of delete, so making that to delete to a blackhole register fixed the issue. Just add the following to your .emacs

(defun bb/evil-delete (orig-fn beg end &optional type _ &rest args)
    (apply orig-fn beg end type ?_ args))
(advice-add 'evil-delete :around 'bb/evil-delete)
meain
  • 833
  • 9
  • 28
2

This is a step in the right direction:

(evil-define-operator evil-change-into-null-register (beg end type register yank-handler)
  "Change text from BEG to END with TYPE. Do not save it in any register."
  (interactive "<R><x><y>")
  (evil-change beg end type ?_ yank-handler))

(evil-define-operator evil-delete-into-null-register (beg end type register yank-handler)
  "Delete text from BEG to END with TYPE. Do not save it in any register."
  (interactive "<R><x><y>")
  (evil-delete beg end type ?_ yank-handler))

(define-key evil-normal-state-map "c" 'evil-change-into-null-register)
(define-key evil-normal-state-map "d" 'evil-delete-into-null-register)

However, C, D, s, S, x, X, and potentially several others would also need to be rebound, and this doesn't seem to work properly for x (it still expects a motion):

(evil-define-operator evil-delete-char-into-null-register (beg end type register yank-handler)
  "Delete text from BEG to END with TYPE. Do not save it in any register."
  (interactive "<R><x>")
  (evil-delete-char beg end type ?_ yank-handler))

(define-key evil-normal-state-map "x" 'evil-delete-char-into-null-register)

Your best bet is add around advice around evil-delete and always pass it the ?_ register (sorry, I don't have time to do that now, but I thought I'd post what I had).

Gordon Gustafson
  • 40,133
  • 25
  • 115
  • 157
0

This is not easily possible because the delete operator calls the yank operator. However, you could redefine evil-delete and simply remove the call to evil-yank.

fifr
  • 138
  • 5