Find files in a project quickly, on any operating system.
This program provides a couple methods for quickly finding any file in a given project. It depends on GNU Find.
By default, it will automatically search file in directory managed by git/subversion/mercurial. But you can easily switch to other types of projects.
- Only dependency is GNU Find
- Works perfectly on any OS (Yes, including Windows)
- It’s quick. Tested with 50,000+ files with NO performance issue
- Furthing tweaking of GNU find through flag `ffip-find-options` is possible
- Versatile. You provide “helloWorld”, we search “HelloWorld.html” “hello-world.css”, “HelloWorld.js”
Please use melpa.
Ivy-mode is the dependency which is installed automatically if you use melpa.
Since v3.7, Emacs 24.3 is required.
Windows setup is as easy as install Cygwin at default directory of any driver. `GNU Find’ will be detected automatically. You don’t need tweak environment variable! For Linux and Mac, no setup is needed.
- `M-x find-file-in-project-by-selected` use the selected region as keyword to search. If no region selected, you need provide the keyword. Keyword could contain wildcard which passed to Find as value of `-name` option
- `M-x find-file-in-project` starts search immediately
- `M-x find-directory-in-project-by-selected` use the selected region as keyword to search. If no region selected, you need provide the keyword. Keyword could contain wildcard which passed to Find as value of `-iwholname` option
If parameter is passed to above commands, file or directory will be opened in new window.
Project root is automatically detected if you use Git/Mercurical/Subversion.
You can manually specify the root directory by set `ffip-project-root` any time to override the default root directory,
(setq ffip-project-root "~/projs/PROJECT_DIR")
Please note all tips are OPTIONAL. find-file-in-project works out of box in 99% cases.
You prefer ido-mode?
(ido-mode 1) (setq ffip-prefer-ido-mode t)
- “ffip-get-project-root-directory” return the full path of current project
Per-project setup using Emacs lisp
Here is complete setup you could insert into “~/.emacs.d/init.el”,
;; if the full path of current file is under SUBPROJECT1 or SUBPROJECT2 ;; OR if I'm reading my personal issue track document, (defun my-setup-develop-environment () (interactive) (when (ffip-current-full-filename-match-pattern-p "\\(/|/PROJECT_DIR\\|issue-track.org\\)") ;; Though PROJECT_DIR is team's project, I care only its sub-directory "subproj1"" (setq-local ffip-project-root "~/projs/PROJECT_DIR/subproj1") ;; well, I'm not interested in concatenated BIG js file or file in dist/ (setq-local ffip-find-options "-not -size +64k -not -iwholename '*/dist/*'") ;; for this project, I'm only interested certain types of files (setq-local ffip-patterns '("*.html" "*.js" "*.css" "*.java" "*.xml" "*.js")) ;; exclude below directories and files (setq-local ffip-prune-patterns '("*/.git/*" "*/node_modules/*" "*/index.js"))) ;; insert more WHEN statements below this line for other projects ) ;; most major modes inherit from prog-mode, so below line is enough (add-hook 'prog-mode-hook 'my-setup-develop-environment)
Per-directory setup with .dir-locals.el
All variables may be overridden on a per-directory basis in your .dir-locals.el. See (info “(Emacs) Directory Variables”) for details.
You only need place .dir-locals.el into your project root directory.
Here is a sample .dir-locals.el,
((nil . ((ffip-project-root . "~/projs/PROJECT_DIR") (ffip-find-options "-not -size +64k -not -iwholename '*/dist/*'") (ffip-patterns '("*.html" "*.js" "*.css" "*.java" "*.xml" "*.js")) (ffip-prune-patterns '("*/.git/*" "*/node_modules/*" "*/index.js")) )))
Please use either per-directory setup or per-project setup, NOT both.
Specify root directory on Windows
(if (eq system-type 'windows-nt) ;; Native Windows (setq ffip-project-root "C:/Users/myname/projs/myproj1") ;; Cygwin (setq ffip-project-root "~/projs/myprojs1"))
Search multiple file name patterns
The variable `ffip-filename-rules’ create some extra file names for search when calling `find-file-in-project-by-selected’. For example, When file basename `helloWorld’ provided, `HelloWorld’, `hello-world’ are added as the file name search patterns.
`C-h v ffip-filename-rules’ to see its default value.
As other variables, it could be customized per project,
(setq-local ffip-filename-rules '(ffip-filename-identity ffip-filename-dashes-to-camelcase ffip-filename-camelcase-to-dashes))
That’s especially useful when you are doing web frontend development.