comparison lisp/utils/shadowfile.el @ 2:ac2d302a0011 r19-15b2

Import from CVS: tag r19-15b2
author cvs
date Mon, 13 Aug 2007 08:46:35 +0200
parents 376386a54a3c
children 4103f0995bd7
comparison
equal deleted inserted replaced
1:c0c6a60d29db 2:ac2d302a0011
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc. 3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
4 4
5 ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu> 5 ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
6 ;; Keywords: comm 6 ;; Keywords: comm
7 7
8 ;; This file is part of GNU Emacs. 8 ;; This file is part of XEmacs.
9 9
10 ;; GNU Emacs is free software; you can redistribute it and/or modify 10 ;; XEmacs is free software; you can redistribute it and/or modify it
11 ;; it under the terms of the GNU General Public License as published by 11 ;; under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option) 12 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; any later version. 13 ;; any later version.
14 14
15 ;; GNU Emacs is distributed in the hope that it will be useful, 15 ;; XEmacs is distributed in the hope that it will be useful, but
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ;; GNU General Public License for more details. 18 ;; General Public License for more details.
19 19
20 ;; You should have received a copy of the GNU General Public License 20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to 21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
22 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 23 ;; 02111-1307, USA.
24 ;;; LCD Archive Entry: 24
25 ;;; shadowfile|Boris Goldowsky|boris@gnu.ai.mit.edu| 25 ;; LCD Archive Entry:
26 ;;; Helps you keep identical copies of files in multiple places.| 26 ;; shadowfile|Boris Goldowsky|boris@gnu.ai.mit.edu|
27 ;;; $Date: 1996/12/18 03:32:59 $ |$Revision: 1.1.1.1 $|~/misc/shadowfile.el.Z| 27 ;; Helps you keep identical copies of files in multiple places.|
28 ;; $Date: 1996/12/18 03:45:48 $ |$Revision: 1.1.1.2 $|~/misc/shadowfile.el.Z|
28 29
29 ;;; Synched up with: FSF 19.30. 30 ;;; Synched up with: FSF 19.30.
30 31
31 ;;; Commentary: 32 ;; Commentary:
32 ;;; 33
33 ;;; This package helps you to keep identical copies of files in more than one 34 ;; This package helps you to keep identical copies of files in more than one
34 ;;; place - possibly on different machines. When you save a file, it checks 35 ;; place - possibly on different machines. When you save a file, it checks
35 ;;; whether it is on the list of files with "shadows", and if so, it tries to 36 ;; whether it is on the list of files with "shadows", and if so, it tries to
36 ;;; copy it when you exit emacs (or use the shadow-copy-files command). 37 ;; copy it when you exit emacs (or use the shadow-copy-files command).
37 38
38 ;;; Installation & Use: 39 ;; Installation & Use:
39 ;;; 40
40 ;;; Put (require 'shadowfile) in your .emacs; add clusters (if necessary) 41 ;; Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
41 ;;; and file groups with shadow-define-cluster, shadow-define-literal-group, 42 ;; and file groups with shadow-define-cluster,
42 ;;; and shadow-define-regexp-group (see the documentation for these functions 43 ;; shadow-define-literal-group, and shadow-define-regexp-group (see the
43 ;;; for information on how and when to use them). After doing this once, 44 ;; documentation for these functions for information on how and when to
44 ;;; everything should be automatic. 45 ;; use them). After doing this once, everything should be automatic.
45 ;;; The lists of clusters and shadows are saved in a file called 46
46 ;;; .shadows, so that they can be remembered from one emacs session to 47 ;; The lists of clusters and shadows are saved in a file called .shadows,
47 ;;; another, even (as much as possible) if the emacs session terminates 48 ;; so that they can be remembered from one emacs session to another, even
48 ;;; abnormally. The files needing to be copied are stored in .shadow_todo; if 49 ;; (as much as possible) if the emacs session terminates abnormally. The
49 ;;; a file cannot be copied for any reason, it will stay on the list to be 50 ;; files needing to be copied are stored in .shadow_todo; if a file cannot
50 ;;; tried again next time. The .shadows file should itself have shadows on 51 ;; be copied for any reason, it will stay on the list to be tried again
51 ;;; all your accounts so that the information in it is consistent everywhere, 52 ;; next time. The .shadows file should itself have shadows on all your
52 ;;; but .shadow_todo is local information and should have no shadows. 53 ;; accounts so that the information in it is consistent everywhere, but
53 ;;; If you do not want to copy a particular file, you can answer "no" 54 ;; .shadow_todo is local information and should have no shadows.
54 ;;; and be asked again next time you hit C-x 4 s or exit emacs. If you do not 55
55 ;;; want to be asked again, use shadow-cancel, and you will not be asked until 56 ;; If you do not want to copy a particular file, you can answer "no" and
56 ;;; you change the file and save it again. If you do not want to shadow 57 ;; be asked again next time you hit C-x 4 s or exit emacs. If you do not
57 ;;; that file ever again, you can edit it out of the .shadows buffer. 58 ;; want to be asked again, use shadow-cancel, and you will not be asked
58 ;;; Anytime you edit the .shadows buffer, you must type M-x shadow-read-files 59 ;; until you change the file and save it again. If you do not want to
59 ;;; to load in the new information, or your changes will be overwritten! 60 ;; shadow that file ever again, you can edit it out of the .shadows
60 61 ;; buffer. Anytime you edit the .shadows buffer, you must type M-x
61 ;;; Bugs & Warnings: 62 ;; shadow-read-files to load in the new information, or your changes will
62 ;;; 63 ;; be overwritten!
63 ;;; - It is bad to have two emacses both running shadowfile at the same 64
64 ;;; time. It tries to detect this condition, but is not always successful. 65 ;; Bugs & Warnings:
65 ;;; 66 ;;
66 ;;; - You have to be careful not to edit a file in two locations 67 ;; - It is bad to have two emacses both running shadowfile at the same
67 ;;; before shadowfile has had a chance to copy it; otherwise 68 ;; time. It tries to detect this condition, but is not always successful.
68 ;;; "updating shadows" will overwrite one of the changed versions. 69 ;;
69 ;;; 70 ;; - You have to be careful not to edit a file in two locations
70 ;;; - It ought to check modification times of both files to make sure 71 ;; before shadowfile has had a chance to copy it; otherwise
71 ;;; it is doing the right thing. This will have to wait until 72 ;; "updating shadows" will overwrite one of the changed versions.
72 ;;; file-newer-than-file-p works between machines. 73 ;;
73 ;;; 74 ;; - It ought to check modification times of both files to make sure
74 ;;; - It will not make directories for you, it just fails to copy files 75 ;; it is doing the right thing. This will have to wait until
75 ;;; that belong in non-existent directories. 76 ;; file-newer-than-file-p works between machines.
76 ;;; 77 ;;
77 ;;; Please report any bugs to me (boris@gnu.ai.mit.edu). Also let me know 78 ;; - It will not make directories for you, it just fails to copy files
78 ;;; if you have suggestions or would like to be informed of updates. 79 ;; that belong in non-existent directories.
80 ;;
81 ;; Please report any bugs to me (boris@gnu.ai.mit.edu). Also let me know
82 ;; if you have suggestions or would like to be informed of updates.
79 83
80 ;;; Code: 84 ;;; Code:
81 85
82 (provide 'shadowfile) 86 (provide 'shadowfile)
83 (require 'ange-ftp) 87 (require 'ange-ftp)
497 "Interactive function to display shadows of a buffer." 501 "Interactive function to display shadows of a buffer."
498 (interactive) 502 (interactive)
499 (let ((msg (shadow-join (mapcar (function cdr) 503 (let ((msg (shadow-join (mapcar (function cdr)
500 (shadow-shadows-of (buffer-file-name))) 504 (shadow-shadows-of (buffer-file-name)))
501 " "))) 505 " ")))
502 (message (if (zerop (length msg)) 506 (message "%s"
507 (if (zerop (length msg))
503 "No shadows." 508 "No shadows."
504 msg)))) 509 msg))))
505 510
506 (defun shadow-copy-files (&optional arg) 511 (defun shadow-copy-files (&optional arg)
507 "Copy all pending shadow files. 512 "Copy all pending shadow files.
535 (car pair) (cdr pair)))) 540 (car pair) (cdr pair))))
536 (function (lambda (pair) 541 (function (lambda (pair)
537 (shadow-remove-from-todo pair))) 542 (shadow-remove-from-todo pair)))
538 shadow-files-to-copy 543 shadow-files-to-copy
539 '("shadow" "shadows" "cancel copy")) 544 '("shadow" "shadows" "cancel copy"))
540 (message (format "There are %d shadows to be updated." 545 (message "There are %d shadows to be updated."
541 (length shadow-files-to-copy))) 546 (length shadow-files-to-copy))
542 (shadow-write-todo-file)) 547 (shadow-write-todo-file))
543 548
544 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
545 ;;; Internal functions 550 ;;; Internal functions
546 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
578 (widen) 583 (widen)
579 (condition-case i 584 (condition-case i
580 (progn 585 (progn
581 (write-region (point-min) (point-max) to) 586 (write-region (point-min) (point-max) to)
582 (shadow-remove-from-todo s)) 587 (shadow-remove-from-todo s))
583 (error (message (format "Shadow %s not updated!" 588 (error (message "Shadow %s not updated!" (cdr s))))))))
584 (cdr s)))))))))
585 589
586 (defun shadow-shadows-of (file) 590 (defun shadow-shadows-of (file)
587 "Returns copy operations needed to update FILE. 591 "Returns copy operations needed to update FILE.
588 Filename should have clusters expanded, but otherwise can have any format. 592 Filename should have clusters expanded, but otherwise can have any format.
589 Return value is a list of dotted pairs like \(from . to), where from 593 Return value is a list of dotted pairs like \(from . to), where from
630 (buffer-file-name (current-buffer)))))) 634 (buffer-file-name (current-buffer))))))
631 (shadow-when shadows 635 (shadow-when shadows
632 (setq shadow-files-to-copy 636 (setq shadow-files-to-copy
633 (shadow-union shadows shadow-files-to-copy)) 637 (shadow-union shadows shadow-files-to-copy))
634 (shadow-when (not shadow-inhibit-message) 638 (shadow-when (not shadow-inhibit-message)
635 (message (substitute-command-keys 639 (message "%s" (substitute-command-keys
636 "Use \\[shadow-copy-files] to update shadows.")) 640 "Use \\[shadow-copy-files] to update shadows."))
637 (sit-for 1)) 641 (sit-for 1))
638 (shadow-write-todo-file))) 642 (shadow-write-todo-file)))
639 nil) ; Return nil for write-file-hooks 643 nil) ; Return nil for write-file-hooks
640 644
641 (defun shadow-remove-from-todo (pair) 645 (defun shadow-remove-from-todo (pair)