emacs

Emacs and symbolic links


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?


Solution

  • 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)