* progmodes/octave-mod.el (inferior-octave-send-list-and-digest):
[bpt/emacs.git] / lisp / vc-hooks.el
index 1029e74..80f12af 100644 (file)
@@ -12,7 +12,7 @@
 
 ;; GNU Emacs is free software; you can redistribute it and/or modify
 ;; it under the terms of the GNU General Public License as published by
-;; the Free Software Foundation; either version 2, or (at your option)
+;; the Free Software Foundation; either version 3, or (at your option)
 ;; any later version.
 
 ;; GNU Emacs is distributed in the hope that it will be useful,
@@ -62,9 +62,10 @@ interpreted as hostnames."
   :type 'regexp
   :group 'vc)
 
-(defcustom vc-handled-backends '(RCS CVS SVN SCCS BZR HG Arch MCVS)
-  ;; BZR, HG, Arch and MCVS come last because they are per-tree rather
-  ;; than per-dir.
+(defcustom vc-handled-backends '(RCS CVS SVN SCCS Bzr Git Hg Mtn Arch MCVS)
+  ;; RCS, CVS, SVN and SCCS come first because they are per-dir
+  ;; rather than per-tree.  RCS comes first because of the multibackend
+  ;; support intended to use RCS for local commits (with a remote CVS server).
   "List of version control backends for which VC will be used.
 Entries in this list will be tried in order to determine whether a
 file is under that sort of version control.
@@ -279,7 +280,10 @@ It is usually called via the `vc-call' macro."
      (t                (apply f args)))))
 
 (defmacro vc-call (fun file &rest args)
-  ;; BEWARE!! `file' is evaluated twice!!
+  "A convenience macro for calling VC backend functions.
+Functions called by this macro must accept FILE as the first argument.
+ARGS specifies any additional arguments. FUN should be unquoted.
+BEWARE!! `file' is evaluated twice!!"
   `(vc-call-backend (vc-backend ,file) ',fun ,file ,@args))
 \f
 (defsubst vc-parse-buffer (pattern i)
@@ -358,7 +362,8 @@ file was previously registered under a certain backend, then that
 backend is tried first."
   (let (handler)
     (cond
-     ((string-match vc-ignore-dir-regexp (file-name-directory file)) nil)
+     ((and (file-name-directory file) (string-match vc-ignore-dir-regexp (file-name-directory file)))
+      nil)
      ((and (boundp 'file-name-handler-alist)
           (setq handler (find-file-name-handler file 'vc-registered)))
       ;; handler should set vc-backend and return t if registered
@@ -368,7 +373,7 @@ backend is tried first."
       ;; Try vc-BACKEND-registered for each handled BACKEND.
       (catch 'found
        (let ((backend (vc-file-getprop file 'vc-backend)))
-         (mapcar
+         (mapc
           (lambda (b)
             (and (vc-call-backend b 'registered file)
                  (vc-file-setprop file 'vc-backend b)
@@ -488,7 +493,7 @@ For registered files, the value returned is one of:
                      prompt the user to do it)."
   ;; FIXME: New (sub)states needed (?):
   ;; - `added' (i.e. `edited' but with no base version yet,
-  ;;            typically represented by vc-workfile-version = "0")
+  ;;            typically represented by vc-working-revision = "0")
   ;; - `conflict' (i.e. `edited' with conflict markers)
   ;; - `removed'
   ;; - `copied' and `moved' (might be handled by `removed' and `added')
@@ -544,13 +549,20 @@ Return non-nil if FILE is unchanged."
                 (signal (car err) (cdr err))
               (vc-call diff (list file)))))))
 
-(defun vc-workfile-version (file)
+(defun vc-working-revision (file)
   "Return the repository version from which FILE was checked out.
 If FILE is not registered, this function always returns nil."
-  (or (vc-file-getprop file 'vc-workfile-version)
+  (or (vc-file-getprop file 'vc-working-revision)
       (if (vc-backend file)
-          (vc-file-setprop file 'vc-workfile-version
-                           (vc-call workfile-version file)))))
+          (vc-file-setprop file 'vc-working-revision
+                           (vc-call working-revision file)))))
+;; Backward compatibility.
+(define-obsolete-function-alias
+  'vc-workfile-version 'vc-working-revision "23.1")
+(defun vc-default-working-revision (backend file)
+  (message
+   "`working-revision' not found: using the old `workfile-version' instead")
+  (vc-call-backend backend 'workfile-version file))
 
 (defun vc-default-registered (backend file)
   "Check if FILE is registered in BACKEND using vc-BACKEND-master-templates."
@@ -651,14 +663,14 @@ a regexp for matching all such backup files, regardless of the version."
               "\\.~.+" (unless manual "\\.") "~")
     (expand-file-name (concat (file-name-nondirectory file)
                               ".~" (subst-char-in-string
-                                    ?/ ?_ (or rev (vc-workfile-version file)))
+                                    ?/ ?_ (or rev (vc-working-revision file)))
                               (unless manual ".") "~")
                       (file-name-directory file))))
 
 (defun vc-delete-automatic-version-backups (file)
   "Delete all existing automatic version backups for FILE."
   (condition-case nil
-      (mapcar
+      (mapc
        'delete-file
        (directory-files (or (file-name-directory file) default-directory) t
                        (vc-version-backup-file-name file nil nil t)))
@@ -693,6 +705,8 @@ Before doing that, check if there are any old backups and get rid of them."
         (vc-call make-version-backups-p file)
          (vc-make-version-backup file))))
 
+(declare-function vc-dired-resynch-file "vc" (file))
+
 (defun vc-after-save ()
   "Function to be called by `basic-save-buffer' (in files.el)."
   ;; If the file in the current buffer is under version control,
@@ -716,9 +730,19 @@ Before doing that, check if there are any old backups and get rid of them."
             ;; any VC Dired buffer to synchronize.
             (vc-dired-resynch-file file)))))
 
+(defvar vc-menu-entry
+  '(menu-item "Version Control" vc-menu-map
+    :filter vc-menu-map-filter))
+
+(when (boundp 'menu-bar-tools-menu)
+  ;; We do not need to worry here about the placement of this entry
+  ;; because menu-bar.el has already created the proper spot for us
+  ;; and this will simply use it.
+  (define-key menu-bar-tools-menu [vc] vc-menu-entry))
+
 (defconst vc-mode-line-map
   (let ((map (make-sparse-keymap)))
-    (define-key map [mode-line down-mouse-1] 'vc-menu-map)
+    (define-key map [mode-line down-mouse-1] vc-menu-entry)
     map))
 
 (defun vc-mode-line (file)
@@ -775,7 +799,7 @@ This function assumes that the file is registered."
   (setq backend (symbol-name backend))
   (let ((state   (vc-state file))
        (state-echo nil)
-       (rev     (vc-workfile-version file)))
+       (rev     (vc-working-revision file)))
     (propertize
      (cond ((or (eq state 'up-to-date)
                (eq state 'needs-patch))
@@ -873,13 +897,9 @@ Used in `find-file-not-found-functions'."
     (if backend (vc-call-backend backend 'find-file-not-found-hook))))
 
 (defun vc-default-find-file-not-found-hook (backend)
-  (if (yes-or-no-p
-       (format "File %s was lost; check out from version control? "
-              (file-name-nondirectory buffer-file-name)))
-      (save-excursion
-       (require 'vc)
-       (setq default-directory (file-name-directory buffer-file-name))
-       (not (vc-error-occurred (vc-checkout buffer-file-name))))))
+  ;; This used to do what vc-rcs-find-file-not-found-hook does, but it only
+  ;; really makes sense for RCS.  For other backends, better not do anything.
+  nil)
 
 (add-hook 'find-file-not-found-functions 'vc-file-not-found-hook)
 
@@ -914,41 +934,59 @@ Used in `find-file-not-found-functions'."
     (define-key map "v" 'vc-next-action)
     (define-key map "+" 'vc-update)
     (define-key map "=" 'vc-diff)
-    (define-key map "~" 'vc-version-other-window)
+    (define-key map "~" 'vc-revision-other-window)
     map))
 (fset 'vc-prefix-map vc-prefix-map)
 (define-key global-map "\C-xv" 'vc-prefix-map)
 
-(if (not (boundp 'vc-menu-map))
-    ;; Don't do the menu bindings if menu-bar.el wasn't loaded to defvar
-    ;; vc-menu-map.
-    ()
-  ;;(define-key vc-menu-map [show-files]
-  ;;  '("Show Files under VC" . (vc-directory t)))
-  (define-key vc-menu-map [vc-retrieve-snapshot]
-    '("Retrieve Snapshot" . vc-retrieve-snapshot))
-  (define-key vc-menu-map [vc-create-snapshot]
-    '("Create Snapshot" . vc-create-snapshot))
-  (define-key vc-menu-map [vc-directory] '("VC Directory Listing" . vc-directory))
-  (define-key vc-menu-map [separator1] '("----"))
-  (define-key vc-menu-map [vc-annotate] '("Annotate" . vc-annotate))
-  (define-key vc-menu-map [vc-rename-file] '("Rename File" . vc-rename-file))
-  (define-key vc-menu-map [vc-version-other-window]
-    '("Show Other Version" . vc-version-other-window))
-  (define-key vc-menu-map [vc-diff] '("Compare with Base Version" . vc-diff))
-  (define-key vc-menu-map [vc-update-change-log]
-    '("Update ChangeLog" . vc-update-change-log))
-  (define-key vc-menu-map [vc-print-log] '("Show History" . vc-print-log))
-  (define-key vc-menu-map [separator2] '("----"))
-  (define-key vc-menu-map [vc-insert-header]
-    '("Insert Header" . vc-insert-headers))
-  (define-key vc-menu-map [undo] '("Undo Last Check-In" . vc-rollback))
-  (define-key vc-menu-map [vc-revert]
-    '("Revert to Base Version" . vc-revert))
-  (define-key vc-menu-map [vc-update]
-    '("Update to Latest Version" . vc-update))
-  (define-key vc-menu-map [vc-next-action] '("Check In/Out" . vc-next-action))
-  (define-key vc-menu-map [vc-register] '("Register" . vc-register)))
+(defvar vc-menu-map
+  (let ((map (make-sparse-keymap "Version Control")))
+    ;;(define-key map [show-files]
+    ;;  '("Show Files under VC" . (vc-directory t)))
+    (define-key map [vc-retrieve-snapshot]
+      '("Retrieve Snapshot" . vc-retrieve-snapshot))
+    (define-key map [vc-create-snapshot]
+      '("Create Snapshot" . vc-create-snapshot))
+    (define-key map [vc-directory] '("VC Directory Listing" . vc-directory))
+    (define-key map [separator1] '("----"))
+    (define-key map [vc-annotate] '("Annotate" . vc-annotate))
+    (define-key map [vc-rename-file] '("Rename File" . vc-rename-file))
+    (define-key map [vc-revision-other-window]
+      '("Show Other Version" . vc-revision-other-window))
+    (define-key map [vc-diff] '("Compare with Base Version" . vc-diff))
+    (define-key map [vc-update-change-log]
+      '("Update ChangeLog" . vc-update-change-log))
+    (define-key map [vc-print-log] '("Show History" . vc-print-log))
+    (define-key map [separator2] '("----"))
+    (define-key map [vc-insert-header]
+      '("Insert Header" . vc-insert-headers))
+    (define-key map [undo] '("Undo Last Check-In" . vc-rollback))
+    (define-key map [vc-revert]
+      '("Revert to Base Version" . vc-revert))
+    (define-key map [vc-update]
+      '("Update to Latest Version" . vc-update))
+    (define-key map [vc-next-action] '("Check In/Out" . vc-next-action))
+    (define-key map [vc-register] '("Register" . vc-register))
+    map))
+
+(defalias 'vc-menu-map vc-menu-map)
+
+(defun vc-menu-map-filter (orig-binding)
+  (if (and (symbolp orig-binding) (fboundp orig-binding))
+      (setq orig-binding (indirect-function orig-binding)))
+  (let ((ext-binding
+         (if vc-mode (vc-call-backend (vc-backend buffer-file-name)
+                                      'extra-menu))))
+    ;; Give the VC backend a chance to add menu entries
+    ;; specific for that backend.
+    (if (null ext-binding)
+        orig-binding
+      (append orig-binding
+             '((ext-menu-separator "---"))
+              ext-binding))))
+
+(defun vc-default-extra-menu (backend)
+  nil)
 
 ;; These are not correct and it's not currently clear how doing it
 ;; better (with more complicated expressions) might slow things down
@@ -956,7 +994,7 @@ Used in `find-file-not-found-functions'."
 
 ;;(put 'vc-rename-file 'menu-enable 'vc-mode)
 ;;(put 'vc-annotate 'menu-enable '(eq (vc-buffer-backend) 'CVS))
-;;(put 'vc-version-other-window 'menu-enable 'vc-mode)
+;;(put 'vc-revision-other-window 'menu-enable 'vc-mode)
 ;;(put 'vc-diff 'menu-enable 'vc-mode)
 ;;(put 'vc-update-change-log 'menu-enable
 ;;     '(member (vc-buffer-backend) '(RCS CVS)))