如何禁用Emacs邪恶选择自动复制到剪贴板
关于这个问题: 这适用于鼠标如何禁用Emacs邪恶选择自动复制到剪贴板,emacs,clipboard,emacs24,evil-mode,Emacs,Clipboard,Emacs24,Evil Mode,关于这个问题: 这适用于鼠标 (setq mouse-drag-copy-region nil) 如何在emacs中对邪恶模式执行相同操作 我在Mac OS上运行Emacs 24.2.91。我将此发送到邪恶模式邮件列表: 剪贴板历史记录和选择的问题 x-select-enable-clipboard的当前实现调用x-select-text来执行所有光标的移动。这不是使用非邪恶模式时的行为。基本上,除非完成下面的补丁,否则emacs将接管我的剪贴板历史记录。我在Mac电脑上使用Alfred剪贴板
(setq mouse-drag-copy-region nil)
如何在emacs中对邪恶模式执行相同操作
我在Mac OS上运行Emacs 24.2.91。我将此发送到邪恶模式邮件列表: 剪贴板历史记录和选择的问题 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}粘贴板作为程序间{cut,paste}函数:
; 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)
"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))))))
(取消x-select-text(文本)
“根据窗口系统选择文本(字符串)。
在X上,如果“X-select-enable-clipboard”为非零,则将文本复制到
剪贴板。如果“x-select-enable-primary”为非零,则将文本放入
初选。
在MS Windows上,将文本设置为当前选择。如果
`x-select-enable-clipboard'为非零,请将文本复制到
还有剪贴板。
在下一步中,将文本放入粘贴板(`x-select-enable-clipboard'
未使用)。“
(cond((eq(framep(选定帧))'w32)
(如果x-选择-启用-剪贴板
(w32设置剪贴板数据文本)
(setq x-last-selected-text)
((功能);这是OS X
不要向粘贴板发送太多文本。
它变慢了,如果真的很大,就会引起错误。
(ns设置粘贴板文本)
(设置上次选择的文本))
(t
;对于多tty,可以从tty帧调用此函数。
(当(eq(framep(选定帧))'x)
(当x-选择-启用-主
(x-set-selection“主文本”)
(setq x-last-selected-text-primary text)
(x选择-启用-剪贴板时)
(x-set-selection“剪贴板文本”)
(setq x-last-selected-text-clipboard text(()()))
在谷歌搜索此问题的解决方案时遇到此问题。我所发现的工作是:
这个答案更好的原因是什么?它解决了所选文本被放在键盘上的问题,而不仅仅是因为邪恶。对我来说,那些ns set pasteboard,ns get pasteboard似乎不存在,所以我在剪切文本时出错(emacs mac)出于某种原因,
ns set粘贴板
不设置ns上次选定文本的值
。因此,ns get pasteboard
会立即覆盖emacs自己的选择,这会搞乱各种事情。您需要定义一个新函数,如(defun my ns set pasteboard(text)(ns set pasteboard text)(setq ns last selected text))
,并将其用于程序间剪切函数
插入。
(fset 'evil-visual-update-x-selection 'ignore)