From: Daniel Colascione Date: Sun, 20 Apr 2014 23:24:04 +0000 (-0700) Subject: Provide function for asking vc about project root X-Git-Tag: emacs-25.0.90~2640^2~208 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=e8a77f2423f5e66e040a40a1d57aec640cc08dcf;p=emacs.git Provide function for asking vc about project root --- diff --git a/lisp/ChangeLog b/lisp/ChangeLog index a1da41a5695..28b9c79079e 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,11 @@ +2014-04-20 Daniel Colascione + + * vc/vc.el (vc-root-dir): New public autoloaded function for + generically finding the current VC root. + * vc/vc-hooks.el (vc-not-supported): New error. + (vc-call-backend): Signal `vc-not-supported' instead of generic + error. + 2014-04-20 Daniel Colascione * emacs-lisp/cl-macs.el (cl-the): Make `cl-the' assert its type diff --git a/lisp/vc/vc-hooks.el b/lisp/vc/vc-hooks.el index 1cd297ae43a..ce7f2c8f4ed 100644 --- a/lisp/vc/vc-hooks.el +++ b/lisp/vc/vc-hooks.el @@ -190,6 +190,11 @@ individually should stay local." (make-variable-buffer-local 'vc-mode) (put 'vc-mode 'permanent-local t) +;;; We signal this error when we try to do something a VC backend +;;; doesn't support. Two arguments: the method that's not supported +;;; and the backend +(define-error 'vc-not-supported "VC method not implemented for backend") + (defun vc-mode (&optional _arg) ;; Dummy function for C-h m "Version Control minor mode. @@ -268,10 +273,10 @@ It is usually called via the `vc-call' macro." (setq f (vc-find-backend-function backend function-name)) (push (cons function-name f) (get backend 'vc-functions))) (cond - ((null f) - (error "Sorry, %s is not implemented for %s" function-name backend)) - ((consp f) (apply (car f) (cdr f) args)) - (t (apply f args))))) + ((null f) + (signal 'vc-not-supported (list function-name backend))) + ((consp f) (apply (car f) (cdr f) args)) + (t (apply f args))))) (defmacro vc-call (fun file &rest args) "A convenience macro for calling VC backend functions. diff --git a/lisp/vc/vc.el b/lisp/vc/vc.el index 305cc6b561e..5491d67e700 100644 --- a/lisp/vc/vc.el +++ b/lisp/vc/vc.el @@ -1878,6 +1878,19 @@ saving the buffer." t (list backend (list rootdir) working-revision) nil nil (called-interactively-p 'interactive)))))) +;;;###autoload +(defun vc-root-dir () + "Return the root directory for the current VC tree. +Return nil if the root directory cannot be identified." + (let ((backend (vc-deduce-backend))) + (if backend + (condition-case err + (vc-call-backend backend 'root default-directory) + (vc-not-supported + (unless (eq (cadr err) 'root) + (signal (car err) (cdr err))) + nil))))) + ;;;###autoload (defun vc-revision-other-window (rev) "Visit revision REV of the current file in another window.