]> code.delx.au - gnu-emacs/blobdiff - lisp/vc-hooks.el
(tildify-ignored-environments-alist): Recognize \verb* right.
[gnu-emacs] / lisp / vc-hooks.el
index 8e662efefba1d8f91aab1f06b43515cf9b3cea38..4dfe4100bca62b3f0620d1fc857ff7ae984ce889 100644 (file)
@@ -5,7 +5,7 @@
 ;; Author:     FSF (see vc.el for full credits)
 ;; Maintainer: Andre Spiegel <spiegel@gnu.org>
 
-;; $Id: vc-hooks.el,v 1.121 2000/10/02 12:02:37 spiegel Exp $
+;; $Id: vc-hooks.el,v 1.130 2000/11/20 14:01:18 spiegel Exp $
 
 ;; This file is part of GNU Emacs.
 
@@ -33,8 +33,8 @@
 
 ;;; Code:
 
-;(eval-when-compile
-;  (require 'vc))
+(eval-when-compile
+  (require 'cl))
 
 ;; Customization Variables (the rest is in vc.el)
 
@@ -208,26 +208,21 @@ It is usually called via the `vc-call' macro."
 
 Optional argument LIMIT is a regexp.  If present, the file is inserted
 in chunks of size BLOCKSIZE (default 8 kByte), until the first
-occurrence of LIMIT is found.  The function returns nil if FILE doesn't
-exist."
+occurrence of LIMIT is found.  The function returns non-nil if FILE 
+exists and its contents were successfully inserted."
   (erase-buffer)
-  (cond ((file-exists-p file)
-        (cond (limit
-               (if (not blocksize) (setq blocksize 8192))
-               (let (found s)
-                 (while (not found)
-                   (setq s (buffer-size))
-                   (goto-char (1+ s))
-                   (setq found
-                         (or (zerop (cadr (insert-file-contents
-                                           file nil s (+ s blocksize))))
-                             (progn (beginning-of-line)
-                                    (re-search-forward limit nil t)))))))
-              (t (insert-file-contents file)))
-        (set-buffer-modified-p nil)
-        (auto-save-mode nil)
-        t)
-       (t nil)))
+  (when (file-exists-p file)
+    (if (not limit)
+        (insert-file-contents file)
+      (if (not blocksize) (setq blocksize 8192))
+      (let ((filepos 0))
+        (while
+           (and (< 0 (cadr (insert-file-contents
+                            file nil filepos (incf filepos blocksize))))
+                (progn (beginning-of-line)
+                       (not (re-search-forward limit nil 'move)))))))
+    (set-buffer-modified-p nil)
+    t))
 
 ;;; Access functions to file properties
 ;;; (Properties should be _set_ using vc-file-setprop, but
@@ -459,14 +454,40 @@ to do that, use this command a second time with no argument."
     (toggle-read-only)))
 (define-key global-map "\C-x\C-q" 'vc-toggle-read-only)
 
-(defun vc-default-make-version-backups (backend file)
+(defun vc-default-make-version-backups-p (backend file)
   "Return non-nil if unmodified repository versions should 
 be backed up locally.  The default is to switch off this feature."
   nil)
 
-(defun vc-version-backup-file-name (file &optional rev)
-  "Return a backup file name for REV or the current version of FILE."
-  (concat file ".~" (or rev (vc-workfile-version file)) "~"))
+(defun vc-version-backup-file-name (file &optional rev manual regexp)
+  "Return a backup file name for REV or the current version of FILE.
+If MANUAL is non-nil it means that a name for backups created by
+the user should be returned; if REGEXP is non-nil that means to return
+a regexp for matching all such backup files, regardless of the version."
+  (if regexp
+      (concat (regexp-quote (file-name-nondirectory file))
+              "\\.~[0-9.]+" (unless manual "\\.") "~")
+    (expand-file-name (concat (file-name-nondirectory file) 
+                              ".~" (or rev (vc-workfile-version file)) 
+                              (unless manual ".") "~")
+                      (file-name-directory file))))
+
+(defun vc-delete-automatic-version-backups (file)
+  "Delete all existing automatic version backups for FILE."
+  (mapcar
+   (lambda (f)
+     (delete-file f))
+   (directory-files (file-name-directory file) t
+                    (vc-version-backup-file-name file nil nil t))))
+
+(defun vc-make-version-backup (file)
+  "Make a backup copy of FILE, which is assumed in sync with the repository.
+Before doing that, check if there are any old backups and get rid of them."
+  (unless (and (fboundp 'msdos-long-file-names)
+               (not (msdos-long-file-names)))
+    (vc-delete-automatic-version-backups file)
+    (copy-file file (vc-version-backup-file-name file)
+               nil 'keep-date)))
 
 (defun vc-before-save ()
   "Function to be called by `basic-save-buffer' (in files.el)."
@@ -477,9 +498,8 @@ be backed up locally.  The default is to switch off this feature."
     (and (vc-backend file)
         (vc-up-to-date-p file)
         (eq (vc-checkout-model file) 'implicit)
-        (vc-call make-version-backups file)
-        (copy-file file (vc-version-backup-file-name file) 
-                   'ok-if-already-exists 'keep-date))))
+        (vc-call make-version-backups-p file)
+         (vc-make-version-backup file))))
 
 (defun vc-after-save ()
   "Function to be called by `basic-save-buffer' (in files.el)."
@@ -508,7 +528,7 @@ be backed up locally.  The default is to switch off this feature."
   "Set `vc-mode' to display type of version control for FILE.
 The value is set in the current buffer, which should be the buffer
 visiting FILE."
-  (interactive (list buffer-file-name nil))
+  (interactive (list buffer-file-name))
   (unless (not (vc-backend file))
     (setq vc-mode (concat " " (if vc-display-status
                                  (vc-call mode-line-string file)