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.
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.
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)
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))))))
ns-set-pasteboard
doesn't set the value of ns-last-selected-text
. As a result, ns-get-pasteboard
immediately overwrites emacs's own selection, which messes up various things. You need to define a new function like (defun my-ns-set-pasteboard (text) (ns-set-pasteboard text) (setq ns-last-selected-text text))
and use that for interprogram-cut-function
insetad. –
Refresh I sent this to the evil-mode mailing list:
Problems with Clipboard History and selections
The current implementation of x-select-enable-clipboard calls x-select-text for all cursor movement with a selection. This is not the behavior when using non-evil mode. Basically, emacs takes over my clipboard history unless the below patch is done. I'm on a Mac and use Alfred clipboard history.
My change below in bold seems to fix this issue.
Thanks,
Justin
(setq x-select-enable-clipboard nil)
(defun evil-visual-update-x-selection (&optional buffer)
"Update the X selection with the current visual region."
(let ((buf (or buffer (current-buffer))))
(when (buffer-live-p buf)
(with-current-buffer buf
(when (and (evil-visual-state-p)
(fboundp 'x-select-text)
(or (not (boundp 'ns-initialized))
(with-no-warnings ns-initialized))
(not (eq evil-visual-selection 'block)))
;; CHANGE
;; ONLY call x-select-text if x-select-enable-clipboard is true
(if x-select-enable-clipboard
(x-select-text (buffer-substring-no-properties
evil-visual-beginning
evil-visual-end))))))))
© 2022 - 2024 — McMap. All rights reserved.