(vc-cvs-checkout): Fix bug that broke C-x v ~-style checkouts.
[bpt/emacs.git] / lisp / shadowfile.el
index 315cf2a..1cc3436 100644 (file)
-;;; shadowfile.el -- automatic file copying for Emacs 19
-
-;;; Author: Boris Goldowsky <boris@cs.rochester.edu>
-;;; Keywords: comm
-
-;;; Copyright (c) 1993, 1994 Free Software Foundation
-;;;
-;;; This program 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)
-;;; any later version.
-;;;
-;;; This program is distributed in the hope that it will be useful,
-;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
-;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-;;; GNU General Public License for more details.
-;;;
-;;; A copy of the GNU General Public License can be obtained from this
-;;; program's author or from the Free Software Foundation, Inc., 675
-;;; Mass Ave, Cambridge, MA 02139, USA.
-
-;;; LCD Archive Entry:
-;;; shadowfile|Boris Goldowsky|boris@cs.rochester.edu|
-;;; Helps you keep identical copies of files in multiple places.|
-;;; $Date: 1993/12/23 03:45:09 $ |$Revision: 1.2 $|~/misc/shadowfile.el.Z|
-
-;;; Commentary:
-;;;
-;;;  This package helps you to keep identical copies of files in more than one
-;;;  place - possibly on different machines.  When you save a file, it checks
-;;;  whether it is on the list of files with "shadows", and if so, it tries to
-;;;  copy it when you exit emacs (or use the shadow-copy-files command).
-
-;;; Installation & Use:
-;;;
-;;;      Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
-;;;  and file groups with shadow-define-cluster, shadow-define-literal-group,
-;;;  and shadow-define-regexp-group (see the documentation for these functions
-;;;  for information on how and when to use them).  After doing this once,
-;;;  everything should be automatic.
-;;;      The lists of clusters and shadows are saved in a file called
-;;;  .shadows, so that they can be remembered from one emacs session to
-;;;  another, even (as much as possible) if the emacs session terminates
-;;;  abnormally.  The files needing to be copied are stored in .shadow_todo; if
-;;;  a file cannot be copied for any reason, it will stay on the list to be
-;;;  tried again next time.  The .shadows file should itself have shadows on
-;;;  all your accounts so that the information in it is consistent everywhere,
-;;;  but .shadow_todo is local information and should have no shadows.
-;;;     If you do not want to copy a particular file, you can answer "no"
-;;;  and be asked again next time you hit C-x 4 s or exit emacs.  If you do not
-;;;  want to be asked again, use shadow-cancel, and you will not be asked until
-;;;  you change the file and save it again.  If you do not want to shadow
-;;;  that file ever again, you can edit it out of the .shadows buffer.
-;;;  Anytime you edit the .shadows buffer, you must type M-x shadow-read-files
-;;;  to load in the new information, or your changes will be overwritten!
-
-;;; Bugs & Warnings:
-;;;
-;;;  - It is bad to have two emacses both running shadowfile at the same
-;;;  time.  It tries to detect this condition, but is not always successful.
-;;;
-;;;  - You have to be careful not to edit a file in two locations
-;;;  before shadowfile has had a chance to copy it; otherwise
-;;;  "updating shadows" will overwrite one of the changed versions.
-;;;
-;;;  - It ought to check modification times of both files to make sure
-;;;  it is doing the right thing.  This will have to wait until
-;;;  file-newer-than-file-p works between machines.
-;;;
-;;;  - It will not make directories for you, it just fails to copy files
-;;;  that belong in non-existent directories.
-;;;
-;;;  Please report any bugs to me (boris@cs.rochester.edu).  Also let me know
-;;;  if you have suggestions or would like to be informed of updates.
+;;; shadowfile.el --- automatic file copying for Emacs 19
+
+;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
+
+;; Author: Boris Goldowsky <boris@gnu.org>
+;; Keywords: comm
+
+;; This file is part of GNU Emacs.
+
+;; 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)
+;; any later version.
+
+;; GNU Emacs is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with GNU Emacs; see the file COPYING.  If not, write to the
+;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+;; Boston, MA 02111-1307, USA.
+
+;; Commentary:
+
+;;  This package helps you to keep identical copies of files in more than one
+;;  place - possibly on different machines.  When you save a file, it checks
+;;  whether it is on the list of files with "shadows", and if so, it tries to
+;;  copy it when you exit emacs (or use the shadow-copy-files command).
+
+;; Installation & Use:
+
+;;  Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
+;;  and file groups with shadow-define-cluster,
+;;  shadow-define-literal-group, and shadow-define-regexp-group (see the
+;;  documentation for these functions for information on how and when to
+;;  use them).  After doing this once, everything should be automatic.
+
+;;  The lists of clusters and shadows are saved in a file called .shadows,
+;;  so that they can be remembered from one emacs session to another, even
+;;  (as much as possible) if the emacs session terminates abnormally.  The
+;;  files needing to be copied are stored in .shadow_todo; if a file cannot
+;;  be copied for any reason, it will stay on the list to be tried again
+;;  next time.  The .shadows file should itself have shadows on all your
+;;  accounts so that the information in it is consistent everywhere, but
+;;  .shadow_todo is local information and should have no shadows.
+
+;;  If you do not want to copy a particular file, you can answer "no" and
+;;  be asked again next time you hit C-x 4 s or exit emacs.  If you do not
+;;  want to be asked again, use shadow-cancel, and you will not be asked
+;;  until you change the file and save it again.  If you do not want to
+;;  shadow that file ever again, you can edit it out of the .shadows
+;;  buffer.  Anytime you edit the .shadows buffer, you must type M-x
+;;  shadow-read-files to load in the new information, or your changes will
+;;  be overwritten!
+
+;; Bugs & Warnings:
+;;
+;;  - It is bad to have two emacses both running shadowfile at the same
+;;  time.  It tries to detect this condition, but is not always successful.
+;;
+;;  - You have to be careful not to edit a file in two locations
+;;  before shadowfile has had a chance to copy it; otherwise
+;;  "updating shadows" will overwrite one of the changed versions.
+;;
+;;  - It ought to check modification times of both files to make sure
+;;  it is doing the right thing.  This will have to wait until
+;;  file-newer-than-file-p works between machines.
+;;
+;;  - It will not make directories for you, it just fails to copy files
+;;  that belong in non-existent directories.
+;;
+;;  Please report any bugs to me (boris@gnu.org).  Also let me know
+;;  if you have suggestions or would like to be informed of updates.
 
 ;;; Code:
 
 (provide 'shadowfile)
 (require 'ange-ftp)
 
-(setq find-file-visit-truename t)      ; makes life easier with symbolic links
-
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;;; Variables
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defvar shadow-noquery nil
+(defgroup shadow nil
+  "Automatic file copying when saving a file."
+  :prefix "shadow-"
+  :group 'files)
+
+(defcustom shadow-noquery nil
   "*If t, always copy shadow files without asking.
 If nil \(the default), always ask.  If not nil and not t, ask only if there
-is no buffer currently visiting the file.")
+is no buffer currently visiting the file."
+  :type '(choice (const t) (const nil) (other :tag "Ask if no buffer" maybe))
+  :group 'shadow)
 
-(defvar shadow-inhibit-message nil
-  "*If nonnil, do not display a message when a file needs copying.")
+(defcustom shadow-inhibit-message nil
+  "*If nonnil, do not display a message when a file needs copying."
+  :type 'boolean
+  :group 'shadow)
 
-(defvar shadow-inhibit-overload nil
+(defcustom shadow-inhibit-overload nil
   "If nonnil, shadowfile won't redefine C-x C-c.
 Normally it overloads the function `save-buffers-kill-emacs' to check
-for files have been changed and need to be copied to other systems.")
+for files have been changed and need to be copied to other systems."
+  :type 'boolean
+  :group 'shadow)
 
-(defvar shadow-info-file nil
+(defcustom shadow-info-file nil
   "File to keep shadow information in.  
 The shadow-info-file should be shadowed to all your accounts to
-ensure consistency.  Default: ~/.shadows")
+ensure consistency.  Default: ~/.shadows"
+  :type '(choice (const nil) file)
+  :group 'shadow)
 
-(defvar shadow-todo-file nil
+(defcustom shadow-todo-file nil
   "File to store the list of uncopied shadows in.
 This means that if a remote system is down, or for any reason you cannot or
 decide not to copy your shadow files at the end of one emacs session, it will
 remember and ask you again in your next emacs session.
 This file must NOT be shadowed to any other system, it is host-specific.
-Default: ~/.shadow_todo")
+Default: ~/.shadow_todo"
+  :type '(choice (const nil) file)
+  :group 'shadow)
+
 
 ;;; The following two variables should in most cases initialize themselves
 ;;; correctly.  They are provided as variables in case the defaults are wrong
@@ -153,11 +168,6 @@ created by shadow-define-regexp-group.")
 ;;; Syntactic sugar; General list and string manipulation
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 
-(defmacro shadow-when (condition &rest body)
-  ;; From cl.el
-  "(shadow-when CONDITION . BODY) => evaluate BODY if CONDITION is true."
-  (` (if (not (, condition))  ()  (,@ body))))
-  
 (defun shadow-union (a b)
   "Add members of list A to list B
 if they are not equal to items already in B."
@@ -495,7 +505,8 @@ shadow-define-cluster)."
   (let ((msg (shadow-join (mapcar (function cdr)
                                  (shadow-shadows-of (buffer-file-name)))
                          " ")))
-    (message (if (zerop (length msg)) 
+    (message "%s"
+            (if (zerop (length msg)) 
                 "No shadows."
               msg))))
 
@@ -533,8 +544,8 @@ shadow-regexp-groups."
                            (shadow-remove-from-todo pair)))
                shadow-files-to-copy
                '("shadow" "shadows" "cancel copy"))
-  (message (format "There are %d shadows to be updated." 
-                  (length shadow-files-to-copy)))
+  (message "There are %d shadows to be updated." 
+          (length shadow-files-to-copy))
   (shadow-write-todo-file))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@@ -568,7 +579,7 @@ site."
                              (car s))))
                 (find-file-noselect (car s)))))
         (to (shadow-expand-cluster-in-file-name (cdr s))))
-    (shadow-when buffer
+    (when buffer
       (set-buffer buffer)
       (save-restriction
        (widen)
@@ -576,8 +587,7 @@ site."
            (progn
              (write-region (point-min) (point-max) to)
              (shadow-remove-from-todo s))
-         (error (message (format "Shadow %s not updated!" 
-                                 (cdr s)))))))))
+         (error (message "Shadow %s not updated!" (cdr s))))))))
 
 (defun shadow-shadows-of (file)
   "Returns copy operations needed to update FILE.
@@ -624,12 +634,12 @@ of files needing to be copied."
   (let ((shadows (shadow-shadows-of 
                  (shadow-expand-file-name 
                   (buffer-file-name (current-buffer))))))
-    (shadow-when shadows
+    (when shadows
       (setq shadow-files-to-copy
            (shadow-union shadows shadow-files-to-copy))
-      (shadow-when (not shadow-inhibit-message)
-       (message (substitute-command-keys
-                 "Use \\[shadow-copy-files] to update shadows."))
+      (when (not shadow-inhibit-message)
+       (message "%s" (substitute-command-keys
+                      "Use \\[shadow-copy-files] to update shadows."))
        (sit-for 1))
       (shadow-write-todo-file)))
   nil)     ; Return nil for write-file-hooks
@@ -655,23 +665,23 @@ Returns t unless files were locked; then returns nil."
        (sit-for 3)
        nil)
     (save-excursion
-      (shadow-when shadow-info-file
+      (when shadow-info-file
        (set-buffer (setq shadow-info-buffer
                          (find-file-noselect shadow-info-file)))
-       (shadow-when (and (not (buffer-modified-p))
-                         (file-newer-than-file-p (make-auto-save-file-name)
-                                                 shadow-info-file))
+       (when (and (not (buffer-modified-p))
+                  (file-newer-than-file-p (make-auto-save-file-name)
+                                          shadow-info-file))
          (erase-buffer)
          (message "Data recovered from %s." 
                   (car (insert-file-contents (make-auto-save-file-name))))
          (sit-for 1))
        (eval-current-buffer))
-      (shadow-when shadow-todo-file
+      (when shadow-todo-file
        (set-buffer (setq shadow-todo-buffer 
                          (find-file-noselect shadow-todo-file)))
-       (shadow-when (and (not (buffer-modified-p))
-                         (file-newer-than-file-p (make-auto-save-file-name)
-                                                 shadow-todo-file))
+       (when (and (not (buffer-modified-p))
+                  (file-newer-than-file-p (make-auto-save-file-name)
+                                          shadow-todo-file))
          (erase-buffer)
          (message "Data recovered from %s." 
                   (car (insert-file-contents (make-auto-save-file-name))))
@@ -783,7 +793,7 @@ look for files that have been changed and need to be copied to other systems."
 ;; This is on hold until someone tells me about a working version of
 ;; map-ynp for Lucid Emacs.
 
-;(shadow-when (string-match "Lucid" emacs-version)
+;(when (string-match "Lucid" emacs-version)
 ;  (require 'symlink-fix)
 ;  (require 'ange-ftp)
 ;  (require 'map-ynp)
@@ -817,8 +827,8 @@ look for files that have been changed and need to be copied to other systems."
        (message "Shadowfile information files not found - aborting")
        (beep)
        (sit-for 3))
-    (shadow-when (and (not shadow-inhibit-overload)
-                     (not (fboundp 'shadow-orig-save-buffers-kill-emacs)))
+    (when (and (not shadow-inhibit-overload)
+              (not (fboundp 'shadow-orig-save-buffers-kill-emacs)))
       (fset 'shadow-orig-save-buffers-kill-emacs 
            (symbol-function 'save-buffers-kill-emacs))
       (fset 'save-buffers-kill-emacs
@@ -826,12 +836,4 @@ look for files that have been changed and need to be copied to other systems."
     (add-hook 'write-file-hooks 'shadow-add-to-todo)
     (define-key ctl-x-4-map "s" 'shadow-copy-files)))
 
-(if noninteractive
-    (add-hook 'after-init-hook 'shadow-initialize)
-  (shadow-initialize))
-
-;;;Local Variables:
-;;;eval:(put 'shadow-when 'lisp-indent-hook 1)
-;;;End:
-
 ;;; shadowfile.el ends here