macos - Shift-选择和 emacs 24

标签 macos emacs dot-emacs emacs24

我使用 emacs 24 (OSX),并且在类次选择方面遇到问题。 如果我用鼠标选择一个区域,文本就会突出显示并自动保存到杀戮环中(我可以立即将其拉出)。 通过shift-选择,文本会突出显示,但我必须手动保存文本(M-w)才能将其拉出。 有没有什么方法可以让移位选择突出显示文本并将其保存到杀戮环上?

最佳答案

默认情况下,使用鼠标选择文本不会将任何内容放置到终止环上(它将其复制到 X 剪贴板)。

您可以通过多种方式自定义 Emacs 与剪贴板的交互方式。请参阅:

C-hig (emacs) 剪切和粘贴 RET

Is there any way that shift-selection hightlights the text AND saves it onto the kill ring ?

我不确定是否有任何方法可以检测到您已停止选择内容,但您也许可以建议handle-shift-selection设置一个临时post-command- Hook 来运行自定义函数以将该区域放入剪贴板(并删除后命令 Hook )。

编辑:等等,你所描述的正是我在 Ubuntu 上的 Emacs 24.1 中发生的情况。

如果我在 Emacs 中按住 Shift 键选择某些文本,然后在任何应用程序中单击鼠标中键,则会粘贴所选文本。

尝试在运行 emacs -Q 时进行测试

编辑2:啊,但你指的不是鼠标,是吗?

这个怎么样?

(defvar my-shift-selection-in-progress nil)
(make-variable-buffer-local 'my-shift-selection-in-progress)

(defadvice handle-shift-selection
  (before my-shift-selection-to-kill-ring-advice)
  "Automatically copy shift-selected text to the kill ring.

If `interprogram-cut-function' is non-nil, also save the text for a window
system cut and paste.

See `my-shift-selection-to-kill-ring'."
  (when (and shift-select-mode
             this-command-keys-shift-translated
             (not my-shift-selection-in-progress))
    (add-hook 'post-command-hook 'my-shift-selection-to-kill-ring nil t)))

(ad-activate 'handle-shift-selection)

(defun my-shift-selection-to-kill-ring ()
  "Post-command callback for my-shift-selection-to-kill-ring-advice."
  (if this-command-keys-shift-translated
      (kill-new (filter-buffer-substring (region-beginning) (region-end))
                my-shift-selection-in-progress)
    (remove-hook 'post-command-hook 'my-shift-selection-to-kill-ring t))
  (setq my-shift-selection-in-progress this-command-keys-shift-translated))

关于macos - Shift-选择和 emacs 24,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10972215/

相关文章:

emacs - 防止SLIME切换到repl缓冲区

emacs - 在每个文件(不是文件类型)的基础上禁用自动填充模式

java - 为了 Macify 一个 Java 应用程序,捕捉关于事件,我必须实现一个菜单吗?

emacs - 从 Racket REPL 更改输出打印样式

c++ - 如何在 Clions 外部工具中使用 Emacs

emacs - 如何在emacs中的缓冲区上获得焦点跟随鼠标?

macos - otool 错误 : is not an object file

cocoa - 使用 Cocoa (OS X) 进行内存中 mime 类型检测?

macos - 如何更改 javapackager 用于 .pkg 安装程序的图标?

emacs 24 主题和继承属性