1

How can I tell Emacs than whenever it tries to open file /a/b/c/foo.txt, it should instead open /d/e/f/foo.txt?

I have a few projects and libraries which are accessible via multiple paths on the filesystem. This is mostly done by symlinks, but not only - sometimes I use bind mounts (some software, e.g. git, treats symlinks differently), and sometimes the files will simply always be identical copies of some other files.

Although when manually opening files, I always open them at their canonical location, following error messages and using "go-to-definition" actions will often open files under aliased paths, and I will end up with multiple buffers pointing to the same file. As such, I'd like to define a rule set of how to rewrite paths of all files it attempts to open. What would be the way to do this?

1

Try using Emacs file-name aliases. See the Emacs manual, node File Aliases. See, in particular, option directory-abbrev-alist.

0

I don't know off-hand of a better way to do it, but you might use defadvice on the find-file function. Your advice could rewrite the file path as needed before passing it in to find-file.

  • (Oops. I accidentally edited this answer instead of mine. Rolled it back to what it was.) – Drew Apr 23 '16 at 16:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.