除非我明确要求,否则如何防止Emacs修改OS X剪贴板?
我已经尝试了所有:
(setq x-select-enable-clipboard nil)
(setq interprogram-cut-function nil)
(setq x-select-enable-primary nil)
(setq mouse-drag-copy-region nil)
这可以防止kill / yank修改剪贴板,但所选文本仍然放在剪贴板上。
这是OS X上的GNU Emacs.app。
我还应该尝试什么?
答案 0 :(得分:4)
在深入研究同一问题后,我认为问题实际上在于Emacs x-select-text
函数,该函数明确忽略了NextStep上x-select-enable-clipboard
的值(OS X是NextStep)
我已经解决了#34;这个问题是用无操作函数替换x-select-text
,然后明确地使用ns- {get,set}粘贴板进行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) "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))))))