问题
In an Emacs Lisp function, I want to know the VC root of an arbitrary folder (if under source control), the same as something like vc-print-root-log does it. I'm trying to do it from outside the VC file/folder (though creating a temporary buffer to do this would be fine). I currently have a git-only solution through magit - (magit-get-top-dir dir-name)
.
I tried using (vc-deduce-backend)
and the 'root command, but the variables that vc-deduce-backend checks seems to only be set in existing vc mode (e.g. log-view-mode) buffers.
Is there a simple way to get this out of VC?
回答1:
Looking at your own example of vc-print-root-log
, the following seems to be what you're after:
(require 'vc)
(let ((path "~/.emacs.d/el-get/"))
(vc-call-backend (vc-responsible-backend path) 'root path))
来源:https://stackoverflow.com/questions/16125637/get-the-vc-root-in-emacs-lisp