Say I have a symbolic link at /home/.bashrc
that points to an actual .bashrc file somewhere else: /some/other/path/.bashrc
that is under a git repository.
If I open /home/.bashrc
in Emacs, it prompts me with:
Symbolic link to Git-controlled source file; follow link? (y or n)
I usually type y
, since I want to edit the actual file. However, later on, if I do buffer-file-name
Emacs returns /some/other/path/.bashrc
, and not /home/.bashrc
).
I would like Emacs to remember that the way I accessed this file was through a symbolic link.
In other words, I would like my symbolic links to be transparent to Emacs. Part of the reason is because I have several Emacs macros that depend on the path of the current file, and these macros think that I am working with a file located in /some/other/path
and not in /home/
.
How can I do this?
When it prompts with
Symbolic link to Git-controlled source file; follow link? (y or n)
type n
. Instead of following the symlink and directly opening the file that the symlink points to, emacs will use the symlink itself, as you desire.
A warning: doing this prevents emacs' version control features from detecting and interacting with the repository at the destination, if there is one.
If you'd like to change the default behaviour, check out the documentation of the vc-follow-symlinks
customization variable. (C-h v vc-follow-symlinks
)
Just for completeness, for someone who has a question about
Symbolic link to Git-controlled source file; follow link? (y or n)
but doesn't necessarily want what the OP wants, this is the documentation from C-h v vc-follow-symlinks
(as of my Emacs version — look up your own Emacs for details):
vc-follow-symlinks
is a variable defined invc-hooks.el
. Its value is askDocumentation: What to do if visiting a symbolic link to a file under version control. Editing such a file through the link bypasses the version control system, which is dangerous and probably not what you want.
If this variable is t, VC follows the link and visits the real file, telling you about it in the echo area. If it is `ask', VC asks for confirmation whether it should follow the link. If nil, the link is visited and a warning displayed.
You can customize this variable.
The upshot is that to avoid being prompted each time, you can in your .emacs
set either
(setq vc-follow-symlinks t)
to always follow the symlink (and edit the "actual" file directly), or
(setq vc-follow-symlinks nil)
to always edit the file as if it's at the symlink itself (this seems to work ok — it won't delete the symlink or anything — but it won't let you use version-control related stuff on the file). I prefer the former (unlike the OP).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With