In a directory I have symbolic links into a git-administered directory (all under Linux). Every time I want to e-dit such a link I get a dialog question:
Symbolic link to Git-controlled source file; follow link? (yes or no)
And I have to type y e s ⏎ to get to the file. Is there a somewhat simpler way?
Ideally, something like declaring that a directory needs no dialog.
Git can track symlinks as well as any other text files. After all, as the documentation says, a symbolic link is nothing but a file with special mode containing the path to the referenced file.
You can use hard links instead of symlinks (a.k.a., soft links). Git will handle a hard link like a copy of the file, except that the contents of the linked files change at the same time. Git may see changes in both files if both the original file and the hard link are in the same repository.
Set vc-follow-symlinks
. You probably want it to be nil
(open link), but be sure to read the docs because t
(open target) is also sensible.
(setq vc-follow-symlinks nil)
You can make this a dir local variable if you don't want it set globally.
An interesting question. I store all my dotfiles in the repository and have a bunch of symlinks scattered all over the filesystem so this is a known problem to me.
First, a half-solution:
(defalias 'yes-or-no-p 'y-or-n-p)
Now instead of typing a full yes
+ Enter you can just
type a single y or n letter in all situations
where yes-or-no
is asked in Emacs
.
Now, a real solution:
(defun vc-mode-hook ()
(message buffer-file-name)
(when
(and
(file-exists-p (buffer-file-name))
(stringp buffer-file-name)
(or (string-equal "/home/ja/.fluxbox/keys" buffer-file-name)
(string-equal "<PATH_TO_ANOTHER_FILE>" buffer-file-name))
(setq-local vc-follow-symlinks t)
)))
(add-hook 'find-file-hook 'vc-mode-hook)
Here we create a new hook that is called every time find-file
is
called, for example with C-x
C-f or e in Dired
. It first checks
if a visited file really exists on the filesystem using
file-exists-p
because it doesn't make sense to run it on files that
haven't been created yet. Next it checks if a file name is known using
stringp
- it will return t
when a regular file is opened but nil
in a Dired
buffer for example. And finally it checks if the file
name is equal to one of strings provided using string-equal
. If it
is, it locally sets vc-follow-symlinks
to t
. You can add as many
string-equal
lines as you wish. In the example above I added
/home/ja/.fluxbox/keys
and an placeholder for an another file name
in the next line.
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