单击 emacs 会取消 x 选择

发布于 2024-11-20 00:29:23 字数 383 浏览 5 评论 0原文

很多时候,当我使用鼠标单击 emacs 窗口时,我希望粘贴到缓冲区中的 x 选择会被吹走。这似乎是由于我单击左键时手的轻微移动导致了无意的“拖动复制”。我不相信我能够改掉这个特殊的习惯。

我发现防止这种情况发生的一个解决方案是设置:

(setq mouse-drag-copy-region nil)

然而,这有一个不幸的副作用,即阻止我在 emacs 中使用鼠标拖动功能。有没有办法控制鼠标拖动行为,以便忽略单击,除非它跨越缓冲区内的两个或多个字符?

我正在 Centos 5.x + GNOME 2 上使用 GNU emacs 23.3.1 进行编码,以防有所不同。

这似乎是 GTK/X 问题;我可以用其他应用程序产生类似的行为。

Much of the time when I use the mouse to click on an emacs window, the x selection which I hope to paste into the buffer is blown away. This seems to be caused by the slight shift of the hand as I apply the left click causing an inadvertant "drag copy." I do not believe I will be able to break this particular habit.

One solution I have found to prevent this is to set:

(setq mouse-drag-copy-region nil)

however this has the unfortunate side effect of preventing me from using the mouse drag functionality at all in emacs. Is there a way to control mouse drag behavior so that a click is ignored unless it spands two or more characters within the buffer?

I am coding on Centos 5.x + GNOME 2 with GNU emacs 23.3.1 in case it makes a difference.

This appears to be a GTK/X issue; I can produce similar behavior with other apps.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毁我热情 2024-11-27 00:29:23

最简单的解决方案是修改函数mouse-drag-track,该函数可以在mouse.el中找到。要查找函数定义,请Mx find-function mouse-drag-track RET

将其复制到您的 .emacs 文件中并进行一点小小的更改。找到如下所示的 and 语句:

(and mouse-drag-copy-region
     do-mouse-drag-region-post-process
     (let (deactivate-mark)
       (copy-region-as-kill region-commencement
                            region-termination)))

并将其修改为进行检查以确保该区域至少为 2 个字符。为了更容易测试,我将此检查设置为 10 个字符:

(and mouse-drag-copy-region
     (>= (abs (- region-commencement region-termination)) 10) ;; THIS IS NEW
     do-mouse-drag-region-post-process
     (let (deactivate-mark)
       (copy-region-as-kill region-commencement
                            region-termination)))

我没有看到通过建议、挂钩或变量设置来执行此操作的干净方法。
请确保在定义 mouse-drag-track 之前有一个 (require 'mouse),以确保您覆盖内置定义,而不是它覆盖您的定义。您可能还想在重新定义上方的 .emacs 中添加一个检查,以提醒您检查要覆盖的库/函数的新版本:

(unless (eq emacs-major-version 23)
  (error "check for new mouse-drag-track"))

The easiest solution to this is to modify the function mouse-drag-track, which can be found in mouse.el. To find the function definition, M-x find-function mouse-drag-track RET.

Copy that into your .emacs file and make one small change. Find the and statement that looks like:

(and mouse-drag-copy-region
     do-mouse-drag-region-post-process
     (let (deactivate-mark)
       (copy-region-as-kill region-commencement
                            region-termination)))

And modify it to have the check to ensure the region is at least 2 characters. I've made this check to be 10 characters for easier testing:

(and mouse-drag-copy-region
     (>= (abs (- region-commencement region-termination)) 10) ;; THIS IS NEW
     do-mouse-drag-region-post-process
     (let (deactivate-mark)
       (copy-region-as-kill region-commencement
                            region-termination)))

I don't see a clean way to do this via advice or hooks or variable settings.
Be sure to have a (require 'mouse) before your definition of mouse-drag-track to ensure you override the built-in definition, as opposed to it overriding yours. You also might want to add a check to your .emacs right above the re-definition to remind you to check for new versions of the library/function you're overwriting:

(unless (eq emacs-major-version 23)
  (error "check for new mouse-drag-track"))
酒浓于脸红 2024-11-27 00:29:23

这是 emacs 中的一个错误,于 2001 年被引入到源代码历史中。我已经发布了一个可以应用于本地安装的补丁。希望 emacs 维护者能够进一步调查。

这是我的补丁和讨论:

http://lists. gnu.org/archive/html/emacs-devel/2011-08/msg00818.html

This is a bug in emacs that was introduced into the source code history in 2001. I have posted a patch that can be applied to local installations. Hopefully the emacs maintainers will investigate further.

Here is my patch and discussion:

http://lists.gnu.org/archive/html/emacs-devel/2011-08/msg00818.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文