防止Emacs修改OS X剪贴板? [英] Prevent Emacs from modifying the OS X clipboard?

查看:151
本文介绍了防止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。 >

我还应该尝试什么?

解决方案

在做同样的挖掘之后问题,我相信这个问题其实在于Emacs x-select-text 函数,它明确地忽略了 x-select-enable-我在NextStep(和OS X是NextStep)上的剪贴板



我已经通过替换 x-select-text 与no-op函数,然后显式地使用ns- {get,set}用于interprogram {cut,paste}功能的粘贴板:

 ;覆盖默认的x-select-text函数,因为它不是
;在OS X上尊重x-select-enable-clipboard。
(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)
根据窗口系统选择TEXT,一个字符串

在X上,如果x-select-enable-clipboard不为零,则将TEXT复制到
剪贴板。如果x-select-enable-primary不为零,则将TEXT放在
中作为主要选择。

在MS-Windows上,使TEXT成为当前选择,如果
`x-select-enable-clipboard'是非零的,将文本复制到
剪贴板

在Nextstep上,将TEXT放在贴板(`x-选择启用剪贴板'
未使用)

(cond((eq (框架(选择框))'w32)
(如果x-select-enable-clipboard
(w32-set-clipboard-data text))
(setq x最后选择-text text))
((featurep'ns);这是OS X
;;不要发送贴纸太多的文字。
;;它变得缓慢,如果真的很大,会导致错误。
(ns-set-pasteboard text)
(setq ns-last-selected-text text))

(t
;;使用多个tty,函数可以从tty框架调用
(when(eq(framep(selected-frame)))x)
(当x-select-enable-primary
(x-set-选择'PRIMARY文本'
(setq x-last-selected-text-primary text))
(当x-select-enable-clipboard
(x-set-selection'CLIPBOARD文本)
(setq x-last-selected-text-clipboard text))))))


How can I prevent Emacs from ever modifying the OS X clipboard unless I explicitly ask it to?

I've tried all of:

(setq x-select-enable-clipboard nil)
(setq interprogram-cut-function nil)
(setq x-select-enable-primary nil)
(setq mouse-drag-copy-region nil)

Which does prevent kill/yank from modifying the clipboard, but selected text is still put on the clipboard.

This is GNU Emacs.app on OS X.

What else should I try?

解决方案

After doing some digging into the same issue, I believe that the issue actually lies in the Emacs x-select-text function, which explicitly ignores the value of x-select-enable-clipboard on NextStep (and OS X is a NextStep).

I've "solved" this problem by replacing x-select-text with a no-op function, then explicitly using 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)

Here is the original x-select-text code:

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

这篇关于防止Emacs修改OS X剪贴板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆