与此问题相关:如何在 emacs 中禁用 x 粘贴
这适用于鼠标
(setq mouse-drag-copy-region nil)
如何在 emacs 中对 Evil 模式执行相同操作?
我在 Mac OS 上,运行 Emacs 24.2.91。
与此问题相关:如何在 emacs 中禁用 x 粘贴
这适用于鼠标
(setq mouse-drag-copy-region nil)
如何在 emacs 中对 Evil 模式执行相同操作?
我在 Mac OS 上,运行 Emacs 24.2.91。
在谷歌搜索这个问题的解决方案时遇到了这个问题。我发现工作是Spacemacs FAQ的一部分:
(fset 'evil-visual-update-x-selection 'ignore)
在对同一个问题进行了一些研究之后,我认为问题实际上在于 Emacsx-select-text
函数,它明确忽略了x-select-enable-clipboard
on NextStep 的值(而 OS X 是 NextStep)。
我已经通过替换x-select-text
为无操作函数“解决”了这个问题,然后显式使用 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)
这是原始x-select-text
代码:
(defun x-select-text (文本) "根据窗口系统选择TEXT,一个字符串。 在 X 上,如果 `x-select-enable-clipboard' 不为 nil,则将 TEXT 复制到 剪贴板。如果 `x-select-enable-primary' 不为 nil,则将 TEXT 放入 主要选择。 在 MS-Windows 上,使 TEXT 成为当前选择。如果 `x-select-enable-clipboard' 为非零,将文本复制到 剪贴板也是如此。 在 Nextstep 中,将 TEXT 放入粘贴板(`x-select-enable-clipboard' 未使用)。" (cond ((eq (framep (selected-frame)) 'w32) (如果 x-select-enable-clipboard (w32-set-clipboard-data 文本)) (setq x-last-selected-text 文本)) ((featurep 'ns) ; 这是 OS X ;; 不要向粘贴板发送太多文本。 ;; 它变得很慢,如果真的很大,它会导致错误。 (ns-set-pasteboard 文本) (setq ns-last-selected-text 文本)) (吨 ;; 使用多 tty,可以从 tty 框架调用此函数。 (当 (eq (framep (selected-frame)) 'x) (当 x-select-enable-primary (x-set-selection '主要文本) (setq x-last-selected-text-primary text)) (当 x-select-enable-clipboard (x-set-selection '剪贴板文本) (setq x-last-selected-text-clipboard text))))))
我将其发送到邪恶模式邮件列表:
剪贴板历史记录和选择问题
x-select-enable-clipboard 的当前实现为所有光标移动调用 x-select-text 选择。这不是使用非邪恶模式时的行为。基本上,除非完成以下补丁,否则 emacs 会接管我的剪贴板历史记录。我在 Mac 上使用 Alfred 剪贴板历史记录。
我在下面的粗体更改似乎解决了这个问题。
谢谢,
贾斯汀
(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))))))))