Emacs takes care that symlinked files are resolved before visiting a version controlled file. This behavior is set by vc-follow-symlinks, which is by default "ask". One can set it to nil, but even then Emacs will issue a warning when visiting the symlink, instead of the "file-truename".

I'd like to do the same thing to some specific files (not all) which are not under version control, due to a particular use case of mine (Org files with external links to relative paths, which I'd like to keep consistent).

I've found what seems to be the more general equivalent of vc-follow-symlinks: find-file-visit-truename. Indeed, the docstring of find-file-visit-truename says:

Non-nil means visiting a file uses its truename as the visited-file name. That is, the buffer visiting the file has the truename as the value of ‘buffer-file-name’. The truename of a file is found by chasing all links both at the file level and at the levels of the containing directories.

If I customize it and set it to true (equivalent of (setq-default find-file-visit-truename t)), indeed Emacs will resolve symlinks of any file I happen to visit.

The help for this variable also informs us that:

This variable is safe as a file local variable if its value satisfies the predicate ‘booleanp’.

So, I assumed I could set this for individual files (which is what I want) by setting find-file-visit-truename as a local variable. Unfortunately, this doesn't seem to work, either as a regular local variable, as prop line local variable, or as dir-local variable.

I don't know enough of the workings of local variables to assess if this is expected behavior or not. My hunch about it says local variables are set after the file is visited, so too late for this particular case.

That given, my question is: is there a way to instruct Emacs to resolve symlinks when visiting an individual specific file, visiting its "truename" instead, for files not under version control? (preferably by some sort of local variable setting, but any working solution is welcome).

Your Answer

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

Browse other questions tagged or ask your own question.