Skip to content
Quick access to project files in Emacs
Emacs Lisp Shell
Find file
Latest commit 908cc56 @redguardtoo redguardtoo bug/doc/command v4.5
- less ivy-mode API used, so single file can be opened without
  confirmation
- could create default .dir-locals.el
- doc fixed
Failed to load latest commit information.
.gitignore bug/doc/command v4.5
README.org bug/doc/command v4.5
find-file-in-project.el bug/doc/command v4.5
pkg.sh bug/doc/command v4.5

README.org

find-file-in-project (v4.5)

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.

Features:

  • 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”

Install

Please use melpa.

Ivy-mode is the dependency which is installed automatically if you use melpa.

Since v3.7, Emacs 24.3 is required.

Setup

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.

Usage

Project root is automatically detected if Git/Mercurical/Subversion used.

You can override the default root directory by set the variable `ffip-project-root`,

(setq ffip-project-root "~/projs/PROJECT_DIR")

`M-x find-file-in-project-by-selected`

Use the selected region as keyword to search file. If no region selected, you need provide the keyword. Keyword could contain wildcard which passed to Find as value of `-name` option

If parameter is passed , file will be opened in new window.

`M-x find-directory-in-project-by-selected`

Use the selected region as keyword to find directory. 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 , directory will be opened in new window.

`M-x find-file-in-project`

Starts search immediately

`M-x ffip-create-project-file`

Create .dir-locals.el which ”defines the same set of local variables to all the files in a certain directory and its subdirector”.

You can use it to setup find-file-in-project variable like “ffip-project-root”.

See Emacs manual for technical details.

Tips

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)

APIs

  • “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.

Search files in a directory

You could `(setq ffip-match-path-instead-of-filename t)` before `M-x find-file-in-project-by-selected`.

For example, if you want to search files belonging to directory “elpa” or the file name containing “elpa”, you can `M-x find-file-in-project-by-selected ENTER elpa`.

More keybinding tips

`C-h i g (ivy) Enter’ for more key-binding tips.

Development

Please note only `ivy-read` from ivy-mode is used. DO NOT use other APIs from ivy-mode. The less APIs used, the more stable this package will be.

Bug Report

Check https://github.com/technomancy/find-file-in-project

Something went wrong with that request. Please try again.