Following a link into a git-repo without lengthy dialog

。_饼干妹妹 提交于 2019-12-04 22:59:37

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!