Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

emacs - how to make find-file search in subdirectories

Tags:

emacs

icicles

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?

like image 624
Eugene Burmako Avatar asked Aug 09 '11 11:08

Eugene Burmako


People also ask

How do I search for files in a folder recursively?

Using Find You can also use the find command followed by the target directory and the file you wish to locate. The command will start in the root directory and recursively search all the subdirectories and locate any file with the specified name.

How do I search for a file in Emacs?

To find a file in Emacs, you use the C-x C-f ( find-file ) command.

What is a recursive directory search?

If you are searching recursively, it means that you search the current directory /home/user1 , and any subdirectories (like /home/user1/documents ), and any subdirectories of subdirectories (like /home/user1/documents/tests ), etc.


2 Answers

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.

like image 123
sanityinc Avatar answered Sep 20 '22 05:09

sanityinc


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.

like image 40
Bozhidar Batsov Avatar answered Sep 22 '22 05:09

Bozhidar Batsov