Emacs:组合iseach前进和最上层 [英] Emacs: Combine iseach-forward and recenter-top-bottom
问题描述
非常感谢您的帮助。
在Emacs中,我喜欢使用iseach-forward(Cs),但是如果突出显示的浮动字将集中在屏幕中间而不是底部。
In Emacs, I like to use iseach-forward (C-s) but I'd like it ever more if the highlighted fount words would be centered in the middle of the screen instead of at the very bottom.
我发现自己在不断地这样做:
I find myself doing this continuously:
Cs foo
Cs Cs Cs ...
哦!这是我正在寻找的'foo'!
Cl
C-s foo C-s C-s C-s... oh! that's the 'foo' I was looking for! C-l
有没有办法将屏幕中央的搜索结果居中?
Is there a way to center the search results in the middle of the screen?
cheers
推荐答案
最佳方法可能是添加以下钩子:
Best approach would probably be to add the following hook:
(add-hook 'isearch-mode-end-hook 'recenter-top-bottom)
在每次成功的增量搜索完成后,将执行 recenter-top-bottom
命令。
This will execute the recenter-top-bottom
command at the completion of every successful incremental search.
编辑:我已经调查了一点,并且重复搜索相同字符串执行的功能(即连续输入 Cs
或 Cr
在活动搜索期间)似乎是 isearch-repeat-forward
和/或 ISEARCH重复向后
。因此,如果您希望在每次重复的同时,您还需要建议所述功能,除了定义上述钩子,如下所示:
I've investigated a bit, and the functions that are executed on repeated searches for the same string (i.e., with successive input of C-s
or C-r
during an active search) appear to be isearch-repeat-forward
and/or isearch-repeat-backward
. Hence, if you wish to recenter on every repeat as well, you need to advise said functions in addition to defining the above hook, like so:
(defadvice
isearch-repeat-forward
(after isearch-repeat-forward-recenter activate)
(recenter-top-bottom))
(defadvice
isearch-repeat-backward
(after isearch-repeat-backward-recenter activate)
(recenter-top-bottom))
(ad-activate 'isearch-repeat-forward)
(ad-activate 'isearch-repeat-backward)
isearch-mode-end-hook 中使用 recenter-top-bottom
并使用 recenter
单独对重复
函数的建议将不那么讨厌。
Personally, I find the resulting behavior to be extremely annoying and disorienting, but de gustibus non est disputandum. Perhaps reserving recenter-top-bottom
for use in the initial isearch-mode-end-hook
and using recenter
alone in the advice to the repeat
functions would be less obnoxious.
建议 isearch-forward
本身等同于添加我以前建议的钩子,似乎对重复搜索没有影响。添加钩子比较简单,我认为更惯用,所以应该比建议这个功能更好。
Advising isearch-forward
by itself is equivalent to adding the hook I originally suggested above and seemingly has no effect on repeat searches. Adding the hook is simpler and I think more idiomatic, so it should probably be preferred over advising the function.
这篇关于Emacs:组合iseach前进和最上层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!