【问题标题】:How to disable Emacs Evil selection auto-copies to clipboard如何禁用 Emacs Evil 选择自动复制到剪贴板
【发布时间】: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


    【解决方案1】:

    我把这个发到了邪恶模式的邮件列表:

    剪贴板历史记录和选择问题

    x-select-enable-clipboard 的当前实现调用 x-select-text 来处理所有带有选择的光标移动。这不是使用非邪恶模式时的行为。基本上,除非完成以下补丁,否则 emacs 会接管我的剪贴板历史记录。我在 Mac 上使用 Alfred 剪贴板历史记录。

    我在下面的粗体更改似乎解决了这个问题。

    1. 这是正确的做法吗?
    2. 是否有一个贡献信息页面来解释如何为这个项目做贡献。我熟悉 github 分叉和拉取请求。

    谢谢,

    贾斯汀

    (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))))))))
    

    【讨论】:

      【解决方案2】:

      在对同一个问题进行了一些研究之后,我认为问题实际上在于 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的原始代码:

      (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' 为非零,将文本复制到 剪贴板也是如此。 在下一步中,将 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 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))))))

      【讨论】:

      • 这个答案有什么更好的理由吗?
      • 它修复了所选文本被放置在键盘上的问题,而不仅仅是来自 Evil。
      • 对我来说,那些 ns-set-pasteboard、ns-get-pasteboard 似乎不存在,所以我在剪切文本等时出错。(emacs-mac)
      • 由于某种原因,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。
      【解决方案3】:

      在谷歌搜索此问题的解决方案时遇到了这个问题。我发现工作是Spacemacs FAQ 的一部分:

      (fset 'evil-visual-update-x-selection 'ignore)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-02-14
        • 1970-01-01
        • 2010-10-15
        • 1970-01-01
        • 2012-07-15
        • 1970-01-01
        • 2016-01-18
        相关资源
        最近更新 更多