Tibor's Musings

Quick Jumping Around Project Files in Emacs

Imagine you are hacking on a project, working on some file, and you would like to quickly open another file of the same project, located in a completely different and possibly nested subdirectory. How to do this efficiently in Emacs?

Usual solutions are not fast enough

There are several ways how to address the task of "jumping around files": (a) use find-file or eshell and type the desired file name by heart, using auto-complete of pathnames; (b) use dired and jump between directories via caret etc; (c) use cedet or similar project file browser to jump between files or functions via sidebar; (d) use tags to jump to wanted function definition location; etc. However, the listed techniques are either relatively slow or work only for tagged source code, while we'd like to jump to a random lambda file of the project.

find-file-in-repository meets ido-ubiquitous

The way I do this more efficiently is via find-file-in-repository combined with ido-ubiquitous fuzzy completion. (Together with ido-vertical-mode for extra eye candy.)

(Note that find-file-in-repository works with projects using git, mercurial, darcs, bazaar, monotone, or svn source code management system.)

Here is one possible configuration of these packages:

(require 'find-file-in-repository)
(require 'ido)
(require 'ido-ubiquitous)
(require 'ido-vertical-mode)
(global-set-key (kbd "C-x f") 'find-file-in-repository)
(ido-ubiquitous-mode 1)
(ido-vertical-mode)
(setq ido-vertical-define-keys 'C-n-C-p-up-down-left-right)

The quick opening of project files is hooked under C-x f keyboard shortcut to create an analogy with the usual C-x C-f file opening shortcut.

Example

Consider we are working on, say, fuzzy tokeniser in Invenio and we would like to quickly open, say, search engine API documentation. In other words, we are editing:

modules/bibindex/lib/tokenizers/BibIndexAuthorTokenizer.py

and we would like to jump to:

modules/websearch/doc/hacking/search-engine-api.webdoc

Here is the key sequence to achieve this:

C-x f s e a RET

It takes only five keystrokes, thanks to fuzzy ido mapping of s e a to mean search-engine-api.webdoc based on starting letters of the file name. Since there is no other file named like this, ido offers search engine API guide as the first auto-complete hit, so it is sufficient to press RET without further ado.

Live demo

Emacs find-file-in-repository

Learning from the past

Morever, ido learns from user's past actions and behaviour, so if you happen to edit more frequently websearch_templates.py rather than websubmit_templates.py, because you are working more with the Search component rather than the Submit component, then typing:

C-x f wstempl RET

will bring up the "correct" search file rather then the submit file. In other words, w s can stand either for websearch or websubmit, depending on your past behaviour. Neat, isn't it?

emacs git