Get the VC root in Emacs Lisp

[亡魂溺海] 提交于 2019-12-22 07:01:21

问题


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

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