【发布时间】:2012-06-11 22:19:16
【问题描述】:
我使用 emacs 24 (OSX) 并且在换档选择方面遇到问题。
如果我用鼠标选择一个区域,文本会突出显示并自动保存到杀伤环上(我可以立即拉出它)。
使用移位选择,文本会突出显示,但我必须手动保存文本 (M-w) 才能拉出它。
有没有什么方法可以让 shift-selection 突出显示文本并将其保存到 kill ring 上?
【问题讨论】:
标签: macos emacs dot-emacs emacs24
我使用 emacs 24 (OSX) 并且在换档选择方面遇到问题。
如果我用鼠标选择一个区域,文本会突出显示并自动保存到杀伤环上(我可以立即拉出它)。
使用移位选择,文本会突出显示,但我必须手动保存文本 (M-w) 才能拉出它。
有没有什么方法可以让 shift-selection 突出显示文本并将其保存到 kill ring 上?
【问题讨论】:
标签: macos emacs dot-emacs emacs24
默认情况下,用鼠标选择文本不会在杀伤环上放置任何东西(它会将其复制到 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))
【讨论】:
kill-new 不会用字符串填充 kill-ring 吗?
my-shift-selection-in-progress。
shift-select-mode)。
“从班次选择自动终止”的问题是确定班次选择何时结束(此时您最终可以执行终止)。
【讨论】: