+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
(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.
(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.
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.