Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable Emacs Evil selection auto-copies to clipboard

Related to this question: How to disable x paste in emacs

This works for the mouse

(setq mouse-drag-copy-region nil)

How do I do the same for Evil mode in emacs?

I'm on Mac OS, running Emacs 24.2.91.

like image 218
justingordon Avatar asked Jun 15 '13 19:06

justingordon


2 Answers

Came across this while Googling for a solution to this problem. What I found to work is part of the Spacemacs FAQ:

(fset 'evil-visual-update-x-selection 'ignore)
like image 78
Kai von Fintel Avatar answered Nov 01 '22 08:11

Kai von Fintel


After doing some digging into the same issue, I believe that the issue actually lies in the Emacs x-select-text function, which explicitly ignores the value of x-select-enable-clipboard on NextStep (and OS X is a NextStep).

I've "solved" this problem by replacing x-select-text with a no-op function, then explicitly using ns-{get,set}pasteboard for interprogram{cut,paste}-function:

; Override the default x-select-text function because it doesn't
; respect x-select-enable-clipboard on OS X.
(defun x-select-text (text))
(setq x-select-enable-clipboard nil)
(setq x-select-enable-primary nil)
(setq mouse-drag-copy-region nil)

(setq interprogram-cut-function 'ns-set-pasteboard)
(setq interprogram-paste-function 'ns-get-pasteboard)

Here is the original x-select-text code:

(defun x-select-text (text)
  "Select TEXT, a string, according to the window system.

On X, if `x-select-enable-clipboard' is non-nil, copy TEXT to the
clipboard.  If `x-select-enable-primary' is non-nil, put TEXT in
the primary selection.

On MS-Windows, make TEXT the current selection.  If
`x-select-enable-clipboard' is non-nil, copy the text to the
clipboard as well.

On Nextstep, put TEXT in the pasteboard (`x-select-enable-clipboard'
is not used)."
  (cond ((eq (framep (selected-frame)) 'w32)
         (if x-select-enable-clipboard
             (w32-set-clipboard-data text))
         (setq x-last-selected-text text))
        ((featurep 'ns) ; This is OS X
         ;; Don't send the pasteboard too much text.
         ;; It becomes slow, and if really big it causes errors.
         (ns-set-pasteboard text)
         (setq ns-last-selected-text text))
        (t
         ;; With multi-tty, this function may be called from a tty frame.
         (when (eq (framep (selected-frame)) 'x)
           (when x-select-enable-primary
             (x-set-selection 'PRIMARY text)
             (setq x-last-selected-text-primary text))
           (when x-select-enable-clipboard
             (x-set-selection 'CLIPBOARD text)
             (setq x-last-selected-text-clipboard text))))))
like image 45
David Wolever Avatar answered Nov 01 '22 09:11

David Wolever