Sublime Text 2 的 Emacs“Goto Anything”(或即时搜索)?

2024-01-20

我尝试过崇高文本2 http://www.sublimetext.com/2最近,我发现转到任何内容 https://www.youtube.com/watch?v=36NIIgcrYzE对于浏览源代码非常有用(Ctrl-P 文件@符号 https://www.youtube.com/watch?v=Q0OtfjgnoLA#t=1m00s似乎工作得很好)。 Emacs 有类似的东西吗?最好是能够正常工作的东西,而不需要大量的自定义 elisp。

到目前为止我尝试过的:

  1. 我见过Helm http://emacs-helm.github.com/helm/ and Anything http://www.emacswiki.org/Anything但据我了解,它们都无法进行实际的“即时”搜索(请参阅下面的编辑)。

  2. 我用过multi-occur-in-matching-buffers http://www.masteringemacs.org/articles/2011/07/20/searching-buffers-occur-mode/,但它似乎也无法满足“即时”标准。

  3. imenu http://emacswiki.org/emacs/ImenuMode / idomenu http://emacswiki.org/emacs/idomenu.el对于单个文件效果很好,但不适用于跨文件。

我目前将 #2 和 #3 一起使用,作为 Goto Anything 的糟糕替代品。

如果不是 Goto Anything 的精确克隆,那么我可以使用一个简单的即时搜索解决方案(在所有打开的缓冲区中搜索给定字符串并动态显示结果的解决方案)。所以这也是可以接受的。

我使用 Emacs 24.2,所以任何 v24-only elisp 也可以。

EDIT:我又给了 Helm 一次机会,在event_jr的建议 https://stackoverflow.com/questions/14726601/sublime-text-2s-goto-anything-or-instant-search-for-emacs#14731718,我发现它does支持在所有打开的缓冲区中进行即时搜索。helm-multi-occur + helm-follow-mode出奇地接近满足我的需求,唯一的小问题是(冒着听起来挑剔的风险):

  • 我还没有找到开启的方法helm-follow-mode 自动地当我跑步时helm-multi-occur。我必须手动调用它C-c C-f。有人愿意用 elisp 片段来尝试一下吗? (请参阅下面的编辑#2)

  • 它不像 ST2 的 Goto Anything 那样“智能”(即,它不像 Goto Anything 那样理解源代码中的“符号”)。

EDIT #2:现在我已经掌握了 Goto Anything 的大部分内容,感谢下面是 event_jr 的回答 https://stackoverflow.com/questions/14726601/sublime-text-2s-goto-anything-or-instant-search-for-emacs#14731718(当然,要感谢 Helm 的创造者,蒂埃里·沃尔皮亚托 https://github.com/thierryvolpiatto)。我衷心向任何正在寻找类似功能的人推荐它。下面是我目前使用的 elisp:

;; 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 ;)。

你应该向蒂埃里提交一个错误,以获得对新手更友好的东西 默认值。他对问题非常敏感。

helm-多次发生

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 缓冲区列表

通常您并不关心查询字符串的确切出现次数,而是想要一个 包含它的所有缓冲区的列表。

helm-buffers-list有一些技巧。第一个符号是你 指定是按major-mode过滤,可以使用“@”前缀来缩小范围 包含字符串的缓冲区列表。

也就是说,“ruby @prompt”将向您显示主要模式的缓冲区列表 包含“ruby”并且其内容包含“prompt”。或者您可以只使用“@prompt”来显示包含“prompt”的所有缓冲区。


一旦你习惯了它,它就会变得强大而舒适。


EDIT修改的my-helm-multi-all启用 helm-follow-mode。

EDIT 2 update helm-follow-mode反映 helm 变化的代码。

EDIT 3再次更新以反映掌舵变化 https://github.com/emacs-helm/helm/issues/623

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Sublime Text 2 的 Emacs“Goto Anything”(或即时搜索)? 的相关文章

随机推荐