]> git.eshelyaron.com Git - emacs.git/commitdiff
Provide function for asking vc about project root
authorDaniel Colascione <dancol@dancol.org>
Sun, 20 Apr 2014 23:24:04 +0000 (16:24 -0700)
committerDaniel Colascione <dancol@dancol.org>
Sun, 20 Apr 2014 23:24:04 +0000 (16:24 -0700)
lisp/ChangeLog
lisp/vc/vc-hooks.el
lisp/vc/vc.el

index a1da41a569568dd44154ce673455b7b962c3f844..28b9c79079ed93dc395a2f80c3bf66eccf8e1769 100644 (file)
@@ -1,3 +1,11 @@
+2014-04-20  Daniel Colascione  <dancol@dancol.org>
+
+       * 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  <dancol@dancol.org>
 
        * emacs-lisp/cl-macs.el (cl-the): Make `cl-the' assert its type
index 1cd297ae43ae48f89db7bb85ad37126565ad7e67..ce7f2c8f4ed754e0c1e5baec224c0b50ba7a4b24 100644 (file)
@@ -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.
index 305cc6b561e911f7f7779f7bad7d529e0c25c399..5491d67e700fb9db61fdf174e3a1dfbff06d5747 100644 (file)
@@ -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.