【发布时间】:2013-06-12 04:42:34
【问题描述】:
与本题相关:How to disable x paste in emacs
这适用于鼠标
(setq mouse-drag-copy-region nil)
如何在 emacs 中对 Evil 模式执行相同操作?
我在 Mac OS 上,运行 Emacs 24.2.91。
【问题讨论】:
标签: emacs clipboard emacs24 evil-mode
与本题相关:How to disable x paste in emacs
这适用于鼠标
(setq mouse-drag-copy-region nil)
如何在 emacs 中对 Evil 模式执行相同操作?
我在 Mac OS 上,运行 Emacs 24.2.91。
【问题讨论】:
标签: emacs clipboard emacs24 evil-mode
我把这个发到了邪恶模式的邮件列表:
剪贴板历史记录和选择问题
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))))))))
【讨论】:
在对同一个问题进行了一些研究之后,我认为问题实际上在于 Emacs 的 x-select-text 函数,它明确忽略了 NextStep 上的 x-select-enable-clipboard 的值(而 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的原始代码:
【讨论】:
ns-set-pasteboard 没有设置ns-last-selected-text 的值。结果,ns-get-pasteboard 立即覆盖了 emacs 自己的选择,从而搞砸了各种事情。您需要定义一个新函数,如 (defun my-ns-set-pasteboard (text) (ns-set-pasteboard text) (setq ns-last-selected-text text)) 并将其用于 interprogram-cut-function insetad。
在谷歌搜索此问题的解决方案时遇到了这个问题。我发现工作是Spacemacs FAQ 的一部分:
(fset 'evil-visual-update-x-selection 'ignore)
【讨论】: