2

我使用 emacs 24 (OSX) 并且在换档选择时遇到问题。如果我用鼠标选择一个区域,文本会突出显示并自动保存到杀伤环上(我可以立即拉出它)。使用 shift-selection,文本会突出显示,但我必须手动保存文本 ( M-w) 才能拉出它。有没有什么方法可以让 shift-selection 突出显示文本并将其保存到 kill ring 上?

4

2 回答 2

2

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

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

C-hig (emacs) Cut and Paste RET

有没有什么方法可以让 shift-selection 突出显示文本并将其保存到 kill ring 上?

我不确定是否有任何方法可以检测到您已停止选择内容,但您可能会建议handle-shift-selection设置一个临时post-command-hook运行自定义函数以将该区域放置在剪贴板中(并删除 post-command-hook) .

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

如果我在 Emacs 中移动选择一些文本,然后在任何应用程序中单击鼠标中键,我会粘贴所选文本。

运行时尝试测试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))
于 2012-06-11T02:12:27.653 回答
0

“从班次选择自动终止”的问题是确定班次选择何时结束(此时您最终可以执行终止)。

于 2012-06-11T14:19:16.390 回答