declare smobs in alloc.c
[bpt/emacs.git] / lisp / vc / vc-hooks.el
index 40a1f3d..ce7f2c8 100644 (file)
@@ -1,6 +1,6 @@
 ;;; vc-hooks.el --- resident support for version-control
 
-;; Copyright (C) 1992-1996, 1998-201 Free Software Foundation, Inc.
+;; Copyright (C) 1992-1996, 1998-2014 Free Software Foundation, Inc.
 
 ;; Author:     FSF (see vc.el for full credits)
 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
@@ -128,7 +128,7 @@ See also variable `vc-consult-headers'."
 This avoids slow queries over the network and instead uses heuristics
 and past information to determine the current status of a file.
 
-If value is the symbol `only-file' `vc-dir' will connect to the
+If value is the symbol `only-file', `vc-dir' will connect to the
 server, but heuristics will be used to determine the status for
 all other VC operations.
 
@@ -190,7 +190,12 @@ individually should stay local."
 (make-variable-buffer-local 'vc-mode)
 (put 'vc-mode 'permanent-local t)
 
-(defun vc-mode (&optional arg)
+;;; 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.
 This minor mode is automatically activated whenever you visit a file under
@@ -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.
@@ -438,8 +443,8 @@ For registered files, the possible values are:
 (defun vc-state (file &optional backend)
   "Return the version control state of FILE.
 
-If FILE is not registered, this function always returns nil.
-For registered files, the value returned is one of:
+A return of nil from this function means we have no information on the
+status of this file.  Otherwise, the value returned is one of:
 
   'up-to-date        The working file is unmodified with respect to the
                      latest version on the current branch, and not locked.
@@ -491,10 +496,8 @@ For registered files, the value returned is one of:
                      that any file with vc-state nil might be ignorable
                      without VC knowing it.
 
-  'unregistered      The file is not under version control.
+  'unregistered      The file is not under version control."
 
-A return of nil from this function means we have no information on the
-status of this file."
   ;; Note: in Emacs 22 and older, return of nil meant the file was
   ;; unregistered.  This is potentially a source of
   ;; backward-compatibility bugs.
@@ -633,7 +636,7 @@ this function."
 (define-obsolete-function-alias
   'vc-toggle-read-only 'toggle-read-only "24.1")
 
-(defun vc-default-make-version-backups-p (backend file)
+(defun vc-default-make-version-backups-p (_backend _file)
   "Return non-nil if unmodified versions should be backed up locally.
 The default is to switch off this feature."
   nil)
@@ -705,19 +708,21 @@ Before doing that, check if there are any old backups and get rid of them."
   ;; the state to 'edited and redisplay the mode line.
   (let* ((file buffer-file-name)
          (backend (vc-backend file)))
-    (and backend
-        (or (and (equal (vc-file-getprop file 'vc-checkout-time)
-                        (nth 5 (file-attributes file)))
-                 ;; File has been saved in the same second in which
-                 ;; it was checked out.  Clear the checkout-time
-                 ;; to avoid confusion.
-                 (vc-file-setprop file 'vc-checkout-time nil))
-            t)
-         (eq (vc-checkout-model backend (list file)) 'implicit)
-         (vc-state-refresh file backend)
-        (vc-mode-line file backend))
-    ;; Try to avoid unnecessary work, a *vc-dir* buffer is
-    ;; present if this is true.
+    (cond
+     ((null backend))
+     ((eq (vc-checkout-model backend (list file)) 'implicit)
+      ;; If the file was saved in the same second in which it was
+      ;; checked out, clear the checkout-time to avoid confusion.
+      (if (equal (vc-file-getprop file 'vc-checkout-time)
+                (nth 5 (file-attributes file)))
+         (vc-file-setprop file 'vc-checkout-time nil))
+      (if (vc-state-refresh file backend)
+         (vc-mode-line file backend)))
+     ;; If we saved an unlocked file on a locking based VCS, that
+     ;; file is not longer up-to-date.
+     ((eq (vc-file-getprop file 'vc-state) 'up-to-date)
+      (vc-file-setprop file 'vc-state nil)))
+    ;; Resynch *vc-dir* buffers, if any are present.
     (when vc-dir-buffers
       (vc-dir-resynch-file file))))
 
@@ -834,7 +839,7 @@ current, and kill the buffer that visits the link."
       (set-buffer true-buffer)
       (kill-buffer this-buffer))))
 
-(defun vc-default-find-file-hook (backend)
+(defun vc-default-find-file-hook (_backend)
   nil)
 
 (defun vc-find-file-hook ()
@@ -858,14 +863,23 @@ current, and kill the buffer that visits the link."
          (set (make-local-variable 'backup-inhibited) t))
        ;; Let the backend setup any buffer-local things he needs.
        (vc-call-backend backend 'find-file-hook))
-       ((let* ((truename (expand-file-name buffer-file-truename))
-              (link-type (and (not (equal buffer-file-name truename))
+       ((let* ((truename (and buffer-file-truename
+                             (expand-file-name buffer-file-truename)))
+              (link-type (and truename
+                              (not (equal buffer-file-name truename))
                               (vc-backend truename))))
          (cond ((not link-type) nil)   ;Nothing to do.
                ((eq vc-follow-symlinks nil)
                 (message
                  "Warning: symbolic link to %s-controlled source file" link-type))
                ((or (not (eq vc-follow-symlinks 'ask))
+                    ;; Assume we cannot ask, default to yes.
+                    noninteractive
+                    ;; Copied from server-start.  Seems like there should
+                    ;; be a better way to ask "can we get user input?"...
+                    (and (daemonp)
+                         (null (cdr (frame-list)))
+                         (eq (selected-frame) terminal-frame))
                     ;; If we already visited this file by following
                     ;; the link, don't ask again if we try to visit
                     ;; it again.  GUD does that, and repeated questions
@@ -909,6 +923,7 @@ current, and kill the buffer that visits the link."
     (define-key map "c" 'vc-rollback)
     (define-key map "d" 'vc-dir)
     (define-key map "g" 'vc-annotate)
+    (define-key map "G" 'vc-ignore)
     (define-key map "h" 'vc-insert-headers)
     (define-key map "i" 'vc-register)
     (define-key map "l" 'vc-print-log)
@@ -976,6 +991,10 @@ current, and kill the buffer that visits the link."
 "))
     (bindings--define-key map [undo]
       '(menu-item "Undo Last Check-In" vc-rollback
+                  :enable (let ((backend (if buffer-file-name
+                                             (vc-backend buffer-file-name))))
+                            (or (not backend)
+                                (vc-find-backend-function backend 'rollback)))
                  :help "Remove the most recent changeset committed to the repository"))
     (bindings--define-key map [vc-revert]
       '(menu-item "Revert to Base Version" vc-revert
@@ -989,6 +1008,9 @@ current, and kill the buffer that visits the link."
     (bindings--define-key map [vc-register]
       '(menu-item "Register" vc-register
                  :help "Register file set into a version control system"))
+    (bindings--define-key map [vc-ignore]
+      '(menu-item "Ignore File..." vc-ignore
+                 :help "Ignore a file under current version control system"))
     (bindings--define-key map [vc-dir]
       '(menu-item "VC Dir"  vc-dir
                  :help "Show the VC status of files in a directory"))
@@ -1016,7 +1038,7 @@ current, and kill the buffer that visits the link."
              '((ext-menu-separator "--"))
               ext-binding))))
 
-(defun vc-default-extra-menu (backend)
+(defun vc-default-extra-menu (_backend)
   nil)
 
 (provide 'vc-hooks)