Emacs recursive project search

2020-02-16 09:05发布

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?

8条回答
▲ chillily
2楼-- · 2020-02-16 09:24

eproject has eproject-grep, which does exactly what you want.

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; this dependency will be eliminated soon.

查看更多
Juvenile、少年°
3楼-- · 2020-02-16 09:24

You can get the effect you want by using GNU Global or IDUtils. They are not Emacs specific, but they has Emacs scripts that integrate that effect. (I don't know too much about them myself.)

You could also opt to use CEDET and the EDE project system. EDE is probably a bit heavy weight, but it has a way to just mark the top of a project. 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. CEDET is at http://cedet.sf.net

查看更多
女痞
4楼-- · 2020-02-16 09:35

Surprised nobody mentioned https://github.com/defunkt/textmate.el (now gotta make it work on Windows...)

查看更多
聊天终结者
5楼-- · 2020-02-16 09:35

FileCache may also be an option. However you would need to add your project directory manually with file-cache-add-directory-recursively.

查看更多
别忘想泡老子
6楼-- · 2020-02-16 09:36

See these links for info about how Icicles can help here:

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

查看更多
The star\"
7楼-- · 2020-02-16 09:44

I use M-x rgrep for this. It automatically skips a lot of things you don't want, like .svn directories.

查看更多
登录 后发表回答