emacs - how to make find-file search in subdirectories
Asked Answered
E

4

9

I'd like to implement something like Resharper's "Go To File" feature for Emacs. When one presses mentioned shortcut, Resharper pops a text box that accepts a wildcard string and displays an autocompletion menu that lists all files in a project that match that wildcard:

"Go To File" dialog
(source: jetbrains.com)

For now, I know a crude way to achieve something more or less equivalent. It involves running dired with -lR and then invoking dired-isearch-filenames - that will start incremental search over the entire hierarchy of files inside certain root directory.

upd. I'm also aware about the option of opening loads of buffers, keeping them all in memory and using switch-to-buffer. This solution works nicely with ido, though it isn't 100% bullet-proof (what if some files get added or deleted?). It also doesn't play well with tabbar, since tabs will display all the files that are included in the project, but not a subset of the project that represents my current context.

However, this shows lots of unnecessary information and lacks autocompletion. I've taken a look at ido and icicles, but they seem to work shallowly, only within current directory. Is there a Emacs plugin that will help me to achieve my goal?

Eloquence answered 9/8, 2011 at 11:17 Comment(0)
C
5

Although you might not want to keep lots of buffers open, you can hook IDO into recentf, which tracks recently-opened files:

(recentf-mode 1)
(setq recentf-max-saved-items 300)

(defun ido-choose-from-recentf ()
  "Use ido to select a recently opened file from the `recentf-list'"
  (interactive)
  (find-file (ido-completing-read "Open file: " recentf-list nil t)))

(global-set-key [(meta f11)] 'ido-choose-from-recentf)

I've been using this trick for years, and it's 99% of all the file-switching I need.

Beyond that, I use M-x rgrep, and you might also like to look at M-x find-dired and M-x find-grep-dired.

For more options still, check out the answers to this similar question.

Controversy answered 9/8, 2011 at 12:4 Comment(1)
My project has not so much files, that's why I went for a dumb, but practical solution. I just invoke "find path1 path2 .. pathN -print0", split the result by "\0"-s and feed them to ido-completing-read. Thanks for an über-idea!Eloquence
E
4

Have you tried helm yet? You can easily choose to search files, buffers, commands, and a lot of other things.

Exieexigency answered 9/8, 2011 at 17:40 Comment(0)
C
4

Projectile has a function named projectile-jump-to-project-file that does more or less what you want. There is also find-file-in-project - a simpler utility, but dependent on the presence of GNU find.

Cand answered 9/8, 2011 at 20:25 Comment(0)
L
2

You mentioned Icicles, but you mistakenly thought that it "works shallowly". It works any way you want it to work. You can search for any file on your system, if you want, matching any part of the file name and path. And you can define a project of particular files and/or directories, save its definition, and later search only among those files/dirs. (Emacs filesets are a strict subset of this feature, but you can use filesets directly the same way.)

This should help (see also the links at the end of that page):

http://www.emacswiki.org/emacs/Icicles_-_File-Name_Input

Lily answered 19/8, 2011 at 18:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.