Emacs递归项目搜索 [英] Emacs recursive project search

查看:321
本文介绍了Emacs递归项目搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从TextMate切换到Emacs。在Emacs中我真正想要的TextMate的一个功能是使用模糊匹配的在项目中查找搜索框。通过 ido 可以使用Emacs,但是ido不会通过子目录递归搜索。它只在一个目录中搜索。



有没有办法给ido一个根目录,并搜索其下的所有内容?



更新:



以下问题涉及MichałMarczyk的答案中的find-file-in-project.el。



如果此消息中的任何内容听起来很明显,那是因为我使用Emacs不到一周。 : - )



据了解,project-local-variables可以让我在我的项目根目录下的.emacs-project文件中定义一些东西。 >

如何将find-file-in-project指向我的项目根?



我不熟悉正则表达式语法在Emacs Lisp中ffip-regexp的默认值为:

 。* \\.\\(rb\\\ \\ | js\\ | css\\ | yml\\ | yaml\\ | rhtml\\ | erb\\ | html\\ | el\\) 

我假设我可以将扩展切换到适合我的项目的扩展。 >

你能解释一下ffip-find-options吗?从文件:



(defvar ffip-find-options

使用find-file时传递给find的额外选项-in-project。



使用它来排除项目​​的部分内容:\-not -regex \\。 > \\\)



这是什么意思,如何使用它排除文件/目录?



你可以分享一个例子.emacs-project文件吗?

解决方案

为了包含与RINARI发行版中的下面提到的find-file-in-project.el一起使用的实际设置指令,原始答案保持原样;新位在第二个水平规则之后。) TextMate页面的EmacsWiki。他们提到的最有希望的事情可能是这个Emacs Lisp脚本,它在一些变量指导的项目目录下提供递归搜索。这个文件从一个广泛的评论部分开始,描述如何使用它。



什么让它特别有希望的是以下几点:

  ;;如果启用了ido-mode,菜单将使用ido-completion-read
;;而不是完成阅读。

注意我没有使用它自己...虽然我可以很好地尝试一下我找到了! : - )



HTH。



(BTW,该脚本是其中的一部分 - GitHub - Rinari不是Rails IDE(它是Rails的Emacs小模式),如果您正在进行任何Rails开发,您可能需要查看整个事情。)






在进一步进行之前,请配置 ido .el 。认真地说,这是一个必须拥有的自己的,它将提高您的find-file-in-project的体验。请参阅Stuart Halloway的本屏幕截图(我已经在对此答案的评论中提到过)了解您需要的原因使用它。此外,Stu通过以自己的方式模拟TextMate的项目范围文件查找工具,演示了如何灵活的ido;如果他的功能符合您的需求,请不要再进一步阅读。



好的,所以这里是如何设置RINARI的 find-file-in-project.el


  1. 获取 find-file-in-project.el project-local-variables.el ,并放在Emacs可以找到它们的地方(这意味着在 load-path 变量的目录之一;你可以使用 c $(添加到列表'加载路径)/路径/到/ some /目录)添加新目录)


  2. (require'find-file-in-project)添加到您的 .emacs 文件。还要添加以下内容以使 Cx CMf 序列显示在项目中的find-file提示符:(global-set-key(kbd Cx CMf)'find-file-in-project)


  3. 创建一个名为的文件。 emacs-project 在您的项目根目录下。至少应该包含以下内容:(setl ffip-regexp。* \\\\(clj\\ | py\\)$)。这将使得只搜索名称和 clj py 的文件;请调整正则表达式以满足您的需求。 (请注意,这个正则表达式将传递给Unix find 实用程序,并应使用 find 的首选正则表达式语法您仍然必须按照Emacs中的常规方式将正则表达式中的每个反斜杠加倍;无论您还需要在括号/管道之前放置反斜杠( | )如果你想使用他们的魔术正则表达式取决于你的查找的期望。上面给出的例子适用于我在一个Ubuntu的框中查找关于正则表达式的附加信息如果有疑问。)(注意:本段已在上次修改中修改,以修正一些混淆wrt正则表达式语法。)


  4. Cx CMf away。


可能的定制;特别是,您可以使用(setl ffip-find-options...)将其他选项传递给Unix find 命令,这是什么 find-file-in-project.el 调用在引擎盖下。



如果事情似乎不起作用,请检查并仔细检查您的拼写 - 我做了一些类似(setl ffip-regex ...)一次(注意缺少最终的'p'在变量名称),最初很困惑,发现没有找到任何文件。


I am switching to Emacs from TextMate. One feature of TextMate that I would really like to have in Emacs is the "Find in Project" search box that uses fuzzy matching. Emacs sort of has this with ido, but ido does not search recursively through child directories. It searches only within one directory.

Is there a way to give ido a root directory and to search everything under it?

Update:

The questions below pertain to find-file-in-project.el from Michał Marczyk's answer.

If anything in this message sounds obvious it's because I have used Emacs for less than one week. :-)

As I understand it, project-local-variables lets me define things in a .emacs-project file that I keep in my project root.

How do I point find-file-in-project to my project root?

I am not familiar with regex syntax in Emacs Lisp. The default value for ffip-regexp is:

".*\\.\\(rb\\|js\\|css\\|yml\\|yaml\\|rhtml\\|erb\\|html\\|el\\)"

I presume that I can just switch the extensions to the ones appropriate for my project.

Could you explain the ffip-find-options? From the file:

(defvar ffip-find-options "" "Extra options to pass to `find' when using find-file-in-project.

Use this to exclude portions of your project: \"-not -regex \\".vendor.\\"\"")

What does this mean exactly and how do I use it to exclude files/directories?

Could you share an example .emacs-project file?

解决方案

(Updated primarily in order to include actual setup instructions for use with the below mentioned find-file-in-project.el from the RINARI distribution. Original answer left intact; the new bits come after the second horizontal rule.)


Have a look at the TextMate page of the EmacsWiki. The most promising thing they mention is probably this Emacs Lisp script, which provides recursive search under a "project directory" guided by some variables. That file begins with an extensive comments section describing how to use it.

What makes it particularly promising is the following bit:

;; If `ido-mode' is enabled, the menu will use `ido-completing-read'
;; instead of `completing-read'.

Note I haven't used it myself... Though I may very well give it a try now that I've found it! :-)

HTH.

(BTW, that script is part of -- to quote the description from GitHub -- "Rinari Is Not A Rails IDE (it is an Emacs minor mode for Rails)". If you're doing any Rails development, you might want to check out the whole thing.)


Before proceeding any further, configure ido.el. Seriously, it's a must-have on its own and it will improve your experience with find-file-in-project. See this screencast by Stuart Halloway (which I've already mentioned in a comment on this answer) to learn why you need to use it. Also, Stu demonstrates how flexible ido is by emulating TextMate's project-scoped file-finding facility in his own way; if his function suits your needs, read no further.

Ok, so here's how to set up RINARI's find-file-in-project.el:

  1. Obtain find-file-in-project.el and project-local-variables.el from the RINARI distribution and put someplace where Emacs can find them (which means in one of the directories in the load-path variable; you can use (add-to-list 'load-path "/path/to/some/directory") to add new directories to it).

  2. Add (require 'find-file-in-project) to your .emacs file. Also add the following to have the C-x C-M-f sequence bring up the find-file-in-project prompt: (global-set-key (kbd "C-x C-M-f") 'find-file-in-project).

  3. Create a file called .emacs-project in your projects root directory. At a minimum it should contain something like this: (setl ffip-regexp ".*\\.\\(clj\\|py\\)$"). This will make it so that only files whose names and in clj or py will be searched for; please adjust the regex to match your needs. (Note that this regular expression will be passed to the Unix find utility and should use find's preferred regular expression syntax. You still have to double every backslash in regexes as is usual in Emacs; whether you also have to put backslashes before parens / pipes (|) if you want to use their 'magic' regex meaning depends on your find's expectations. The example given above works for me on an Ubuntu box. Look up additional info on regexes in case of doubt.) (Note: this paragraph has been revised in the last edit to fix some confusion w.r.t. regular expression syntax.)

  4. C-x C-M-f away.

There's a number of possible customisations; in particular, you can use (setl ffip-find-options "...") to pass additional options to the Unix find command, which is what find-file-in-project.el calls out to under the hood.

If things appear not to work, please check and double check your spelling -- I did something like (setl ffip-regex ...) once (note the lack of the final 'p' in the variable name) and were initially quite puzzled to discover that no files were being found.

这篇关于Emacs递归项目搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆