崇高的文本2的“Goto Anything” (或即时搜索)Emacs? [英] Sublime Text 2's "Goto Anything" (or instant search) for Emacs?
问题描述
我最近尝试了崇高的文字2 ,我发现 Goto Anything 对导航源代码非常有用( Ctrl-P文件@符号似乎工作得很好)。 Emacs有什么类似的东西吗?最好的东西,只是工作,没有一吨的自定义elisp。
I tried out Sublime Text 2 recently, and I found Goto Anything superbly useful for navigating source code (Ctrl-P file@symbol seems to work really well). Is there something similar for Emacs? Preferably something that just works, without a ton of custom elisp.
我到目前为止尝试过:
I've seen Helm and Anything,
but as far as I understand neither of them is capable of actual "instant" search(see edit below).
我已经使用了 多重匹配缓冲区
,但它似乎也无法满足即时标准。
I've used multi-occur-in-matching-buffers
, but it too seems unable to satisfy the "instant" criterion.
imenu
/ idomenu
适用于单个文件,但不能跨文件运行。
imenu
/ idomenu
works well for single files, but doesn't work across files.
我目前使用#2和#3,作为Goto Anything的一个糟糕的替代品。
I currently use #2 and #3 together, as a poor substitute for Goto Anything.
如果不是一个确切的克隆Goto Anything,那么我可以做一个天真的即时搜索解决方案(一个在所有打开的缓冲区中搜索给定的字符串并动态显示结果)。所以这也是可以接受的。
If not an exact clone of Goto Anything, then I could make do with a naive instant search solution (one that searches for a given string across all open buffers and displays results dynamically). So that's acceptable too.
我使用Emacs 24.2,所以任何v24-only elisp也是可以的。
I use Emacs 24.2, so any v24-only elisp is also fine.
编辑:我给了Helm另一个镜头,在 event_jr的建议,我发现它 支持在所有打开的缓冲区中即时搜索。 helm-multi-occur
+ helm-follow-mode
令人惊讶地接近满足我的需求,唯一的小问题是(有风险的挑剔):
EDIT: I gave Helm another shot, at event_jr's suggestion, and I found that it does support instant searching across all open buffers. helm-multi-occur
+ helm-follow-mode
comes surprisingly close to meeting my needs, the only minor issues being (at the risk of sounding nit-picky):
-
我还没有找到打开方式code> helm-follow-mode 自动当我运行(见下面的编辑#2)helm-multi-occur
。我必须用C-c C-f
手动调用它。任何人都可以用一个elisp的片段来拍摄它?
I haven't found a way to turn on(see edit #2 below)helm-follow-mode
automatically when I runhelm-multi-occur
. I have to invoke it manually withC-c C-f
. Anyone care to take a shot at this with a snippet of elisp?
它不是聪明像ST2的Goto Anything(即它不明白源代码中的符号,如Goto Anything)。
it isn't "intelligent" like ST2's Goto Anything (i.e., it doesn't understand "symbols" in source code, like Goto Anything does).
编辑#2 :现在我有大部分Goto Anything,感谢 event_jr的下面的答案(当然,感谢Helm的创建者, Thierry Volpiatto )。我衷心地向任何寻找类似功能的人推荐。以下是我目前使用的elisp:
EDIT #2: Now I've got most of Goto Anything, thanks to event_jr's answer below (and of course, thanks to Helm's creator, Thierry Volpiatto). I recommend it heartily to anyone looking for a similar feature. Below is the elisp I'm currently using:
;; instant recursive grep on a directory with helm
(defun instant-rgrep-using-helm ()
"Recursive grep in a directory."
(interactive)
(let ((helm-after-initialize-hook #'helm-follow-mode))
(helm-do-grep)))
;; instant search across all buffers with helm
(defun instant-search-using-helm ()
"Multi-occur in all buffers backed by files."
(interactive)
(let ((helm-after-initialize-hook #'helm-follow-mode))
(helm-multi-occur
(delq nil
(mapcar (lambda (b)
(when (buffer-file-name b) (buffer-name b)))
(buffer-list))))))
;; set keybindings
(global-set-key (kbd "C-M-s") 'instant-search-using-helm)
(global-set-key (kbd "C-M-S-s") 'helm-resume)
(global-set-key (kbd "C-M-g") 'instant-rgrep-using-helm)
推荐答案
只需使用掌舵。
它可能比您要求的更多配置,但一旦得到
配置你喜欢什么,应该很舒服。非常喜欢Emacs
;)。
Just use helm.
It is perhaps more configuration than you asked for, but once you get it configured how you like, it should be quite comfortable. Very much like Emacs ;).
你应该向Thierry提交一个bug,以获得更多新手的
默认值。他的问题相当敏感。
And you should file a bug with Thierry for getting some more newbie friendly defaults. He is quite responsive with issues.
主要是多缓冲区互动发生通过
helm-multi-occur
提供。如果您执行该命令,您会注意到您有
首先选择一些缓冲区(使用 C-SPC 从列表中选择
M-SPC 选择全部)。然后,您可以在下一个
提示符下输入查询。很容易使自己的版本跳过缓冲区选择
,如下所示:
Primarily multi-buffer interactive "occur" is provided through
helm-multi-occur
. If you execute the command, you'll notice that you have
to pick some buffers first (use C-SPC to select from the list,
M-SPC to select all). Then you can enter your query at the next
prompt. It's easy to make your own version that skips the buffer selection
like so:
(eval-after-load "helm-regexp"
'(setq helm-source-moccur
(helm-make-source "Moccur"
'helm-source-multi-occur :follow 1)))
(defun my-helm-multi-all ()
"multi-occur in all buffers backed by files."
(interactive)
(helm-multi-occur
(delq nil
(mapcar (lambda (b)
(when (buffer-file-name b) (buffer-name b)))
(buffer-list)))))
helm-buffers-list
通常,您不关心查询字符串的确切事件,但需要包含所有缓冲区的
列表。
helm-buffers-list
Often you don't care about the exact occurrences of the query string, but want a list of all buffers that contain it.
helm-buffers-list
有一些技巧。
指定的第一个符号是按主要模式进行过滤,您可以使用@前缀将
的列表缩小到包含字符串的缓冲区。
helm-buffers-list
has some tricks up its sleeve. The first symbol you
specify is filtering by major-mode, and you can use the "@" prefix to narrow
the list to buffers that contain a string.
为了方便起见,ruby @prompt将显示一个缓冲区的列表,其主要模式
包含ruby,其内容包含prompt。或者您可以使用@prompt显示包含提示的所有缓冲区。
To wit, "ruby @prompt" will show you a list of buffers whose major-mode contains "ruby" and whose contents contains "prompt". Or you can just use "@prompt" to show all buffers that contain "prompt".
编辑修改 my-helm-多个全部
启用舵手跟随模式。
EDIT modified my-helm-multi-all
to enable helm-follow-mode.
编辑2 更新
编辑3 再次更新以反映掌舵更改
这篇关于崇高的文本2的“Goto Anything” (或即时搜索)Emacs?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!