Find alternative files in Emacs according to customizable rules.
Put the file in
load-pathand load it using
Bind keys to functions
(global-set-key (kbd "M-s a") 'alternative-files-find-file) (global-set-key (kbd "M-s A") 'alternative-files-create-file)
User rules can be setup using directory local variables, for example, create a file
.dir-locals.el, and following rules:
Every rule is a list. The first element (
car) is a regular expression. The rest elements (
cdr) are replacements. If a file path match the regular expression, all the replacements are used as alternative files. In following example,
spec/hello_spec.coffeehas alternative file
((nil (alternative-files-rules . (("spec/\\(.*\\)_spec.coffee" "assets/\\1.coffee") ("assets/\\(.*\\).coffee" "spec/\\1_spec.coffee")))))
M-x customize-group <RET> alternative-files <RET>
A list of functions to find alternative files. The function takes no argument and should return a list of alternative files as absolute path for current buffer. The functions can return directory name in list, then all files in that directory are used.
Completion function used to read user choice minibuffer
A function to return the root directory of current buffer. If alternative file is in this root directory, the relative file name is used. It can make completion list shorter and cleaner.