简体   繁体   English

Emacs递归项目搜索

[英]Emacs recursive project search

I am switching to Emacs from TextMate. 我正在从TextMate切换到Emacs。 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中使用的TextMate的一个功能是使用模糊匹配的“在项目中查找”搜索框。 Emacs sort of has this with ido , but ido does not search recursively through child directories. Emacs有这个与ido ,但ido不会通过子目录递归搜索。 It searches only within one directory. 它只在一个目录中搜索。

Is there a way to give ido a root directory and to search everything under it? 有没有办法给ido一个根目录并搜索它下的所有内容?

Update: 更新:

The questions below pertain to find-file-in-project.el from Michał Marczyk's answer. 以下问题与MichałMarczyk的答案中的find-file-in-project.el有关。

If anything in this message sounds obvious it's because I have used Emacs for less than one week. 如果此消息中的任何内容听起来很明显,那是因为我使用Emacs的时间不到一周。 :-) :-)

As I understand it, project-local-variables lets me define things in a .emacs-project file that I keep in my project root. 据我所知,项目本地变量允许我在.emacs-project文件中定义我保留在项目根目录中的东西。

How do I point find-file-in-project to my project root? 如何将find-file-in-project指向我的项目根目录?

I am not familiar with regex syntax in Emacs Lisp. 我不熟悉Emacs Lisp中的正则表达式语法。 The default value for ffip-regexp is: ffip-regexp的默认值为:

".*\\.\\(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? 你能解释一下ffip-find-options吗? From the file: 从文件:

(defvar ffip-find-options "" "Extra options to pass to `find' when using find-file-in-project. (defvar ffip-find-options“”“使用项目中的find-file时传递给`find'的额外选项。

Use this to exclude portions of your project: \\"-not -regex \\\\". 使用它来排除项目​​的部分:\\“ - 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? 你能分享一个例子.emacs-project文件吗?

I use Mx rgrep for this. 我使用Mx rgrep。 It automatically skips a lot of things you don't want, like .svn directories. 它会自动跳过很多你不想要的东西,比如.svn目录。

(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.) (更新主要是为了包括与RINARI发行版中下面提到的find-file-in-project.el一起使用的实际设置说明。原始答案保持不变;新位在第二个水平规则之后。)


Have a look at the TextMate page of the EmacsWiki. 看看EmacsWiki的TextMate页面 The most promising thing they mention is probably this Emacs Lisp script , which provides recursive search under a "project directory" guided by some variables. 他们提到的最有希望的东西可能是这个Emacs Lisp脚本 ,它在一些变量引导的“项目目录”下提供递归搜索。 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. 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.) (顺便说一句,该脚本是其中的一部分 - 引用GitHub中的描述 - “Rinari不是Rails IDE(它是Rails的Emacs次要模式)”。如果你正在进行任何Rails开发,你可能想要检查整个事情。)


Before proceeding any further, configure ido.el . 在继续之前,请配置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. 请参阅Stuart Halloway的这个截屏视频 (我已经在这个答案的评论中提到过)来了解你需要使用它的原因。 Also, Stu demonstrates how flexible ido is by emulating TextMate's project-scoped file-finding facility in his own way; 此外,Stu通过以自己的方式模拟TextMate的项目范围的文件查找工具来演示如何灵活的ido; if his function suits your needs, read no further. 如果他的功能符合您的需求,请不要再读了。

Ok, so here's how to set up RINARI's find-file-in-project.el : 好的,这里是如何设置RINARI的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). 从RINARI发行版中获取find-file-in-project.elproject-local-variables.el并将其放置在Emacs可以找到它们的位置(这意味着在load-path变量的一个目录中;您可以使用(add-to-list 'load-path "/path/to/some/directory")向其添加新目录)。

  2. Add (require 'find-file-in-project) to your .emacs file. (require 'find-file-in-project)您的.emacs文件中添加(require 'find-file-in-project) Also add the following to have the Cx CMf sequence bring up the find-file-in-project prompt: (global-set-key (kbd "Cx CMf") 'find-file-in-project) . 还添加以下内容以使Cx CMf序列显示项目中的find-file提示: (global-set-key (kbd "Cx CMf") 'find-file-in-project)

  3. Create a file called .emacs-project in your projects root directory. 在项目根目录中创建名为.emacs-project的文件。 At a minimum it should contain something like this: (setl ffip-regexp ".*\\\\.\\\\(clj\\\\|py\\\\)$") . 它至少应包含以下内容: (setl ffip-regexp ".*\\\\.\\\\(clj\\\\|py\\\\)$") This will make it so that only files whose names and in clj or py will be searched for; 这样就可以只搜索其名称和cljpy文件; 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 wrt regular expression syntax.) (请注意,这个正则表达式将被传递给Unix find实用程序,并且应该使用find的首选正则表达式语法。你仍然必须像正常情况一样在正则表达式中加倍每个反斜杠 ;你是否还需要在parens之前放入反斜杠/管道( | )如果你想使用他们的'魔术'正则表达式意思取决于你的find的期望。上面给出的例子对我来说在Ubuntu盒子上工作。如果有疑问, 查看有关正则表达式的其他信息。) (注意:在最后一次编辑中修改了这一段,修复了正则表达式语法的一些混淆。)

  4. Cx CMf away. Cx CMf走了。

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. 特别是,您可以使用(setl ffip-find-options "...")将其他选项传递给Unix find命令,这就是find-file-in-project.el的内容。

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. 如果事情看起来不起作用,请检查并仔细检查你的拼写 - 我做了一次( (setl ffip-regex ...)一次(注意变量名中缺少最后的'p')并且最初很困惑发现没有找到任何文件。

惊讶没人提到https://github.com/defunkt/textmate.el (现在要让它在Windows上工作......)

eproject has eproject-grep , which does exactly what you want. eprojecteproject-grep ,它完全符合你的要求。

With the right project definition, it will only search project files; 使用正确的项目定义,它只会搜索项目文件; it will ignore version control, build artifacts, generated files, whatever. 它将忽略版本控制,构建工件,生成的文件等等。 The only downside is that it requires a grep command on your system; 唯一的缺点是它需要在你的系统上使用grep命令; this dependency will be eliminated soon. 这种依赖将很快消除。

For pure, unadulterated speed, I highly recommend a combination of the command-line tool The Silver Searcher (aka 'ag') with ag.el . 对于纯粹,纯粹的速度,我强烈建议将命令行工具The Silver Searcher (又名'ag')与ag.el结合使用 The ag-project interactive function will make an educated guess of your project root if you are using git, hg or svn and search the entire project. 如果您使用git,hg或svn并搜索整个项目,那么ag-project交互功能将对您的项目根进行有根据的猜测。

You can get the effect you want by using GNU Global or IDUtils. 您可以使用GNU Global或IDUtils获得所需的效果。 They are not Emacs specific, but they has Emacs scripts that integrate that effect. 它们不是特定于Emacs的,但它们具有集成该效果的Emacs脚本。 (I don't know too much about them myself.) (我自己也不太了解他们。)

You could also opt to use CEDET and the EDE project system. 您也可以选择使用CEDET和EDE项目系统。 EDE is probably a bit heavy weight, but it has a way to just mark the top of a project. EDE可能有点重,但它有一种方法可以标记项目的顶部。 If you also keep GNU Global or IDUtils index files with your project, EDE can use it to find a file by name anywhere, or you can use `semantic-symref' to find references to symbols in your source files. 如果您还将GNU Global或IDUtils索引文件保存在您的项目中,EDE可以使用它在任何地方按名称查找文件,或者您可以使用`semantic-symref'查找源文件中符号的引用。 CEDET is at http://cedet.sf.net CEDET位于http://cedet.sf.net

FileCache may also be an option. FileCache也可以是一个选项。 However you would need to add your project directory manually with file-cache-add-directory-recursively . 但是,您需要使用file-cache-add-directory-recursively手动添加项目目录。

See these links for info about how Icicles can help here: 有关Icicles如何在此处提供帮助的信息,请参阅以下链接:

Icicles completion matching can be substring, regexp, fuzzy (various kinds), or combinations of these. 冰柱完成匹配可以是子串,正则表达式,模糊(各种)或这些的组合。 You can also combine simple patterns, intersecting the matches or complementing (subtracting) a subset of them 您还可以组合简单模式,交叉匹配或补充(减去)它们的子集

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM