annotate lisp/utils/shadowfile.el @ 8:4b173ad71786 r19-15b5

Import from CVS: tag r19-15b5
author cvs
date Mon, 13 Aug 2007 08:47:35 +0200
parents ac2d302a0011
children 4103f0995bd7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; shadowfile.el --- automatic file copying for Emacs 19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1993, 1994 Free Software Foundation, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Author: Boris Goldowsky <boris@gnu.ai.mit.edu>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: comm
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
8 ;; This file is part of XEmacs.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
11 ;; under the terms of the GNU General Public License as published by
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
18 ;; General Public License for more details.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
25 ;; LCD Archive Entry:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
26 ;; shadowfile|Boris Goldowsky|boris@gnu.ai.mit.edu|
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
27 ;; Helps you keep identical copies of files in multiple places.|
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
28 ;; $Date: 1996/12/18 03:45:48 $ |$Revision: 1.1.1.2 $|~/misc/shadowfile.el.Z|
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;;; Synched up with: FSF 19.30.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
32 ;; Commentary:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
33
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
34 ;; This package helps you to keep identical copies of files in more than one
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
35 ;; place - possibly on different machines. When you save a file, it checks
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
36 ;; whether it is on the list of files with "shadows", and if so, it tries to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
37 ;; copy it when you exit emacs (or use the shadow-copy-files command).
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
38
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
39 ;; Installation & Use:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
40
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
41 ;; Put (require 'shadowfile) in your .emacs; add clusters (if necessary)
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
42 ;; and file groups with shadow-define-cluster,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
43 ;; shadow-define-literal-group, and shadow-define-regexp-group (see the
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
44 ;; documentation for these functions for information on how and when to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
45 ;; use them). After doing this once, everything should be automatic.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
46
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
47 ;; The lists of clusters and shadows are saved in a file called .shadows,
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
48 ;; so that they can be remembered from one emacs session to another, even
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
49 ;; (as much as possible) if the emacs session terminates abnormally. The
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
50 ;; files needing to be copied are stored in .shadow_todo; if a file cannot
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
51 ;; be copied for any reason, it will stay on the list to be tried again
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
52 ;; next time. The .shadows file should itself have shadows on all your
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
53 ;; accounts so that the information in it is consistent everywhere, but
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
54 ;; .shadow_todo is local information and should have no shadows.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
56 ;; If you do not want to copy a particular file, you can answer "no" and
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
57 ;; be asked again next time you hit C-x 4 s or exit emacs. If you do not
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
58 ;; want to be asked again, use shadow-cancel, and you will not be asked
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
59 ;; until you change the file and save it again. If you do not want to
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
60 ;; shadow that file ever again, you can edit it out of the .shadows
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
61 ;; buffer. Anytime you edit the .shadows buffer, you must type M-x
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
62 ;; shadow-read-files to load in the new information, or your changes will
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
63 ;; be overwritten!
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
65 ;; Bugs & Warnings:
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
66 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
67 ;; - It is bad to have two emacses both running shadowfile at the same
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
68 ;; time. It tries to detect this condition, but is not always successful.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
69 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
70 ;; - You have to be careful not to edit a file in two locations
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
71 ;; before shadowfile has had a chance to copy it; otherwise
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
72 ;; "updating shadows" will overwrite one of the changed versions.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
73 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
74 ;; - It ought to check modification times of both files to make sure
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
75 ;; it is doing the right thing. This will have to wait until
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
76 ;; file-newer-than-file-p works between machines.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
77 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
78 ;; - It will not make directories for you, it just fails to copy files
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
79 ;; that belong in non-existent directories.
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
80 ;;
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
81 ;; Please report any bugs to me (boris@gnu.ai.mit.edu). Also let me know
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
82 ;; if you have suggestions or would like to be informed of updates.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (provide 'shadowfile)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (require 'ange-ftp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (setq find-file-visit-truename t) ; makes life easier with symbolic links
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 ;;; Variables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (defvar shadow-noquery nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 "*If t, always copy shadow files without asking.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 If nil \(the default), always ask. If not nil and not t, ask only if there
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 is no buffer currently visiting the file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 (defvar shadow-inhibit-message nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 "*If nonnil, do not display a message when a file needs copying.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 (defvar shadow-inhibit-overload nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 "If nonnil, shadowfile won't redefine C-x C-c.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 Normally it overloads the function `save-buffers-kill-emacs' to check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 for files have been changed and need to be copied to other systems.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 (defvar shadow-info-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 "File to keep shadow information in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110 The shadow-info-file should be shadowed to all your accounts to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 ensure consistency. Default: ~/.shadows")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (defvar shadow-todo-file nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 "File to store the list of uncopied shadows in.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 This means that if a remote system is down, or for any reason you cannot or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 decide not to copy your shadow files at the end of one emacs session, it will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 remember and ask you again in your next emacs session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 This file must NOT be shadowed to any other system, it is host-specific.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 Default: ~/.shadow_todo")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 ;;; The following two variables should in most cases initialize themselves
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 ;;; correctly. They are provided as variables in case the defaults are wrong
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 ;;; on your machine \(and for efficiency).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125 (defvar shadow-system-name (system-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 "The complete hostname of this machine.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (defvar shadow-homedir nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 "Your home directory on this machine.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 ;;; Internal variables whose values are stored in the info and todo files:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (defvar shadow-clusters nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 "List of host clusters \(see shadow-define-cluster).")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (defvar shadow-literal-groups nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 "List of files that are shared between hosts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 This list contains shadow structures with literal filenames, created by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 shadow-define-group.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 (defvar shadow-regexp-groups nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 "List of file types that are shared between hosts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 This list contains shadow structures with regexps matching filenames,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 created by shadow-define-regexp-group.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 ;;; Other internal variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 ;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (defvar shadow-files-to-copy nil) ; List of files that need to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ; be copied to remote hosts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 (defvar shadow-hashtable nil) ; for speed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 (defvar shadow-info-buffer nil) ; buf visiting shadow-info-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 (defvar shadow-todo-buffer nil) ; buf visiting shadow-todo-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 ;;; Syntactic sugar; General list and string manipulation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (defmacro shadow-when (condition &rest body)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 ;; From cl.el
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 "(shadow-when CONDITION . BODY) => evaluate BODY if CONDITION is true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (` (if (not (, condition)) () (,@ body))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169 (defun shadow-union (a b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 "Add members of list A to list B
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 if they are not equal to items already in B."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 (if (null a)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 b
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 (if (member (car a) b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 (shadow-union (cdr a) b)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 (shadow-union (cdr a) (cons (car a) b)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (defun shadow-find (func list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 "If FUNC applied to some element of LIST is nonnil,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 return the first such element."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (while (and list (not (funcall func (car list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (setq list (cdr list)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 (defun shadow-remove-if (func list)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 "Remove elements satisfying FUNC from LIST.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 Nondestructive; actually returns a copy of the list with the elements removed."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 (if list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (if (funcall func (car list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (shadow-remove-if func (cdr list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (cons (car list) (shadow-remove-if func (cdr list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (defun shadow-join (strings sep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 "Concatenate elements of the list of STRINGS with SEP between each."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (cond ((null strings) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 ((null (cdr strings)) (car strings))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 ((concat (car strings) " " (shadow-join (cdr strings) sep)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 (defun shadow-regexp-superquote (string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 "Like regexp-quote, but includes the ^ and $
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 to make sure regexp matches nothing but STRING."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 (concat "^" (regexp-quote string) "$"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 (defun shadow-suffix (prefix string)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 "If PREFIX begins STRING, return the rest.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 Return value is nonnil if PREFIX and STRING are string= up to the length of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 PREFIX."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 (let ((lp (length prefix))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (ls (length string)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (and (>= ls lp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (string= prefix (substring string 0 lp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (substring string lp))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 ;;; Clusters and sites
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 ;;; I use the term `site' to refer to a string which may be the name of a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 ;;; cluster or a literal hostname. All user-level commands should accept
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 ;;; either.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 (defun shadow-make-cluster (name primary regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224 "Creates a shadow cluster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 called NAME, using the PRIMARY hostname, REGEXP matching all hosts in the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 cluster. The variable shadow-clusters associates the names of clusters to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 these structures.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 This function is for program use: to create clusters interactively, use
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 shadow-define-cluster instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (list name primary regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (defmacro shadow-cluster-name (cluster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 "Return the name of the CLUSTER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 (list 'elt cluster 0))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 (defmacro shadow-cluster-primary (cluster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
237 "Return the primary hostname of a CLUSTER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
238 (list 'elt cluster 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 (defmacro shadow-cluster-regexp (cluster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 "Return the regexp matching hosts in a CLUSTER."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242 (list 'elt cluster 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 (defun shadow-set-cluster (name primary regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 "Put cluster NAME on the list of clusters,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 replacing old definition if any. PRIMARY and REGEXP are the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 information defining the cluster. For interactive use, call
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 shadow-define-cluster instead."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249 (let ((rest (shadow-remove-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
250 (function (lambda (x) (equal name (car x))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 shadow-clusters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 (setq shadow-clusters
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
253 (cons (shadow-make-cluster name primary regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
254 rest))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 (defmacro shadow-get-cluster (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 "Return cluster named NAME, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258 (list 'assoc name 'shadow-clusters))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 (defun shadow-site-primary (site)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 "If SITE is a cluster, return primary host, otherwise return SITE."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 (let ((c (shadow-get-cluster site)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 (if c
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264 (shadow-cluster-primary c)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 site)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 ;;; SITES
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 (defun shadow-site-cluster (site)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270 "Given a SITE \(hostname or cluster name), return the cluster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
271 that it is in, or nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 (or (assoc site shadow-clusters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 (shadow-find
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
274 (function (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
275 (string-match (shadow-cluster-regexp x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 site)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 shadow-clusters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279 (defun shadow-read-site ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 "Read a cluster name or hostname from the minibuffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 (let ((ans (completing-read "Host or cluster name [RET when done]: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282 shadow-clusters)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 (if (equal "" ans)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285 ans)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 (defun shadow-site-match (site1 site2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 "Nonnil iff SITE1 is or includes SITE2.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289 Each may be a host or cluster name; if they are clusters, regexp of site1 will
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 be matched against the primary of site2."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 (or (string-equal site1 site2) ; quick check
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 (let* ((cluster1 (shadow-get-cluster site1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 (primary2 (shadow-site-primary site2)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 (if cluster1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 (string-match (shadow-cluster-regexp cluster1) primary2)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 (string-equal site1 primary2)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 (defun shadow-get-user (site)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 "Returns the default username for a site."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 (ange-ftp-get-user (shadow-site-primary site)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 ;;; Filename manipulation
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 (defun shadow-parse-fullpath (fullpath)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 "Parse PATH into \(site user path) list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 or leave it alone if it already is one. Returns nil if the argument is not a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 full ange-ftp pathname."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 (if (listp fullpath)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 fullpath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 (ange-ftp-ftp-name fullpath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 (defun shadow-parse-path (path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 "Parse any PATH into \(site user path) list.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 Argument can be a simple path, full ange-ftp path, or already a hup list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 (or (shadow-parse-fullpath path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 (list shadow-system-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 (user-login-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 path)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 (defsubst shadow-make-fullpath (host user path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 "Make an ange-ftp style fullpath out of HOST, USER (optional), and PATH.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324 This is probably not as general as it ought to be."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 (concat "/"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 (if user (concat user "@"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 host ":"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 (defun shadow-replace-path-component (fullpath newpath)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331 "Return FULLPATH with the pathname component changed to NEWPATH."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 (let ((hup (shadow-parse-fullpath fullpath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 (shadow-make-fullpath (nth 0 hup) (nth 1 hup) newpath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 (defun shadow-local-file (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 "If FILENAME is at this site,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 remove /user@host part. If refers to a different system or a different user on
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 this system, return nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339 (let ((hup (shadow-parse-fullpath file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 (cond ((null hup) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 ((and (shadow-site-match (nth 0 hup) shadow-system-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 (string-equal (nth 1 hup) (user-login-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 (nth 2 hup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 (t nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 (defun shadow-expand-cluster-in-file-name (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 "If hostname part of FILE is a cluster, expand it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 into the cluster's primary hostname. Will return the pathname bare if it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349 a local file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 (let ((hup (shadow-parse-path file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 cluster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352 (cond ((null hup) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 ((shadow-local-file hup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 ((shadow-make-fullpath (shadow-site-primary (nth 0 hup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 (nth 1 hup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 (nth 2 hup))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 (defun shadow-expand-file-name (file &optional default)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 "Expand file name and get file's true name."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 (file-truename (expand-file-name file default)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 (defun shadow-contract-file-name (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 "Simplify FILENAME
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364 by replacing (when possible) home directory with ~, and hostname with cluster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 name that includes it. Filename should be absolute and true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 (let* ((hup (shadow-parse-path file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 (homedir (if (shadow-local-file hup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368 shadow-homedir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 (file-name-as-directory
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370 (nth 2 (shadow-parse-fullpath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 (expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 (shadow-make-fullpath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373 (nth 0 hup) (nth 1 hup) "~")))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 (suffix (shadow-suffix homedir (nth 2 hup)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 (cluster (shadow-site-cluster (nth 0 hup))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376 (shadow-make-fullpath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 (if cluster
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 (shadow-cluster-name cluster)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 (nth 0 hup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380 (nth 1 hup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 (if suffix
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 (concat "~/" suffix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383 (nth 2 hup)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 (defun shadow-same-site (pattern file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386 "True if the site of PATTERN and of FILE are on the same site.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 If usernames are supplied, they must also match exactly. PATTERN and FILE may
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 be lists of host, user, path, or ange-ftp pathnames. FILE may also be just a
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 local filename."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 (let ((pattern-sup (shadow-parse-fullpath pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 (file-sup (shadow-parse-path file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 (and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 (shadow-site-match (nth 0 pattern-sup) (nth 0 file-sup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 (or (null (nth 1 pattern-sup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 (string-equal (nth 1 pattern-sup) (nth 1 file-sup))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 (defun shadow-file-match (pattern file &optional regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 "Returns t if PATTERN matches FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 If REGEXP is supplied and nonnil, the pathname part of the pattern is a regular
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 expression, otherwise it must match exactly. The sites and usernames must
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401 match---see shadow-same-site. The pattern must be in full ange-ftp format, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 the file can be any valid filename. This function does not do any filename
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 expansion or contraction, you must do that yourself first."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 (let* ((pattern-sup (shadow-parse-fullpath pattern))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 (file-sup (shadow-parse-path file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 (and (shadow-same-site pattern-sup file-sup)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 (if regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 (string-match (nth 2 pattern-sup) (nth 2 file-sup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 (string-equal (nth 2 pattern-sup) (nth 2 file-sup))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 ;;; User-level Commands
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
414
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 (defun shadow-define-cluster (name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
416 "Edit \(or create) the definition of a cluster.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
417 This is a group of hosts that share directories, so that copying to or from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 one of them is sufficient to update the file on all of them. Clusters are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 defined by a name, the network address of a primary host \(the one we copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420 files to), and a regular expression that matches the hostnames of all the sites
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 in the cluster."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 (interactive (list (completing-read "Cluster name: " shadow-clusters () ())))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 (let* ((old (shadow-get-cluster name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 (primary (read-string "Primary host: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 (if old (shadow-cluster-primary old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 (regexp (let (try-regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428 (while (not
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 (string-match
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 (setq try-regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 "Regexp matching all host names: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433 (if old (shadow-cluster-regexp old)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
434 (shadow-regexp-superquote primary))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 primary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
436 (message "Regexp doesn't include the primary host!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
437 (sit-for 2))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 try-regexp))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 ; (username (read-no-blanks-input
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 ; (format "Username [default: %s]: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441 ; (shadow-get-user primary))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
442 ; (if old (or (shadow-cluster-username old) "")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 ; (user-login-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
444 )
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
445 ; (if (string-equal "" username) (setq username nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 (shadow-set-cluster name primary regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 (defun shadow-define-literal-group ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 "Declare a single file to be shared between sites.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 It may have different filenames on each site. When this file is edited, the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451 new version will be copied to each of the other locations. Sites can be
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
452 specific hostnames, or names of clusters \(see shadow-define-cluster)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 (let* ((hup (shadow-parse-fullpath
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
455 (shadow-contract-file-name (buffer-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
456 (path (nth 2 hup))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 user site group)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 (while (setq site (shadow-read-site))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 (setq user (read-string (format "Username [default %s]: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 (shadow-get-user site)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461 path (read-string "Filename: " path))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462 (setq group (cons (shadow-make-fullpath site
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 (if (string-equal "" user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 (shadow-get-user site)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 user)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466 path)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 group)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 (setq shadow-literal-groups (cons group shadow-literal-groups)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 (shadow-write-info-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 (defun shadow-define-regexp-group ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472 "Make each of a group of files be shared between hosts.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 Prompts for regular expression; files matching this are shared between a list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 of sites, which are also prompted for. The filenames must be identical on all
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 hosts \(if they aren't, use shadow-define-group instead of this function).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Each site can be either a hostname or the name of a cluster \(see
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 shadow-define-cluster)."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 (let ((regexp (read-string
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 "Filename regexp: "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 (if (buffer-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 (shadow-regexp-superquote
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 (nth 2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 (shadow-parse-path
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 (shadow-contract-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 (buffer-file-name))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487 site sites usernames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 (while (setq site (shadow-read-site))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 (setq sites (cons site sites))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490 (setq usernames
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 (cons (read-string (format "Username for %s: " site)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 (shadow-get-user site))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 usernames)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 (setq shadow-regexp-groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495 (cons (shadow-make-group regexp sites usernames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 shadow-regexp-groups))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 (shadow-write-info-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 (defun shadow-shadows ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 ;; Mostly for debugging.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 "Interactive function to display shadows of a buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503 (let ((msg (shadow-join (mapcar (function cdr)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 (shadow-shadows-of (buffer-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 " ")))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
506 (message "%s"
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
507 (if (zerop (length msg))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 "No shadows."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 msg))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 (defun shadow-copy-files (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512 "Copy all pending shadow files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 With prefix argument, copy all pending files without query.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 Pending copies are stored in variable shadow-files-to-copy, and in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515 shadow-todo-file if necessary. This function is invoked by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516 shadow-save-buffers-kill-emacs, so it is not usually necessary to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 call it manually."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 (if (and (not shadow-files-to-copy) (interactive-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520 (message "No files need to be shadowed.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 (map-y-or-n-p (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 (lambda (pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 (or arg shadow-noquery
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 (format "Copy shadow file %s? " (cdr pair)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526 (function shadow-copy-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 shadow-files-to-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 '("shadow" "shadows" "copy"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (shadow-write-todo-file t))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 (defun shadow-cancel ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 "Cancel the instruction to copy some files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 Prompts for which copy operations to cancel. You will not be asked to copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 them again, unless you make more changes to the files. To cancel a shadow
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535 permanently, remove the group from shadow-literal-groups or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 shadow-regexp-groups."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 (map-y-or-n-p (function (lambda (pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 (format "Cancel copying %s to %s? "
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 (car pair) (cdr pair))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541 (function (lambda (pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 (shadow-remove-from-todo pair)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543 shadow-files-to-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 '("shadow" "shadows" "cancel copy"))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
545 (message "There are %d shadows to be updated."
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
546 (length shadow-files-to-copy))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547 (shadow-write-todo-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550 ;;; Internal functions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 (defun shadow-make-group (regexp sites usernames)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 "Makes a description of a file group---
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 actually a list of regexp ange-ftp file names---from REGEXP \(name of file to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556 be shadowed), list of SITES, and corresponding list of USERNAMES for each
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 site."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 (if sites
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559 (cons (shadow-make-fullpath (car sites) (car usernames) regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 (shadow-make-group regexp (cdr sites) (cdr usernames)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561 nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563 (defun shadow-copy-file (s)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 "Copy one shadow file."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 (let* ((buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 (cond ((get-file-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 (abbreviate-file-name (shadow-expand-file-name (car s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 ((not (file-readable-p (car s)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 (if (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 (format "Cannot find file %s--cancel copy request?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 (car s)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 (shadow-remove-from-todo s))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 ((or (eq t shadow-noquery)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 (y-or-n-p
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576 (format "No buffer for %s -- update shadow anyway?"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 (car s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 (find-file-noselect (car s)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 (to (shadow-expand-cluster-in-file-name (cdr s))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 (shadow-when buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 (set-buffer buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582 (save-restriction
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 (widen)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584 (condition-case i
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 (write-region (point-min) (point-max) to)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 (shadow-remove-from-todo s))
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
588 (error (message "Shadow %s not updated!" (cdr s))))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 (defun shadow-shadows-of (file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 "Returns copy operations needed to update FILE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 Filename should have clusters expanded, but otherwise can have any format.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 Return value is a list of dotted pairs like \(from . to), where from
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 and to are absolute file names."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 (or (symbol-value (intern-soft file shadow-hashtable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 (let* ((absolute-file (shadow-expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597 (or (shadow-local-file file) file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 shadow-homedir))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 (canonical-file (shadow-contract-file-name absolute-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 (shadows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601 (mapcar (function (lambda (shadow)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 (cons absolute-file shadow)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 (append
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 (shadow-shadows-of-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 canonical-file shadow-literal-groups nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 (shadow-shadows-of-1
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 canonical-file shadow-regexp-groups t)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 (set (intern file shadow-hashtable) shadows))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 (defun shadow-shadows-of-1 (file groups regexp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 "Return list of FILE's shadows in GROUPS,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612 which are considered as regular expressions if third arg REGEXP is true."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 (if groups
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 (let ((nonmatching
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 (shadow-remove-if
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 (function (lambda (x) (shadow-file-match x file regexp)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 (car groups))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 (append (cond ((equal nonmatching (car groups)) nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 (regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 (let ((realpath (nth 2 (shadow-parse-fullpath file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 (mapcar
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 (lambda (x)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624 (shadow-replace-path-component x realpath)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 nonmatching)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626 (t nonmatching))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 (shadow-shadows-of-1 file (cdr groups) regexp)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 (defun shadow-add-to-todo ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 "If current buffer has shadows, add them to the list
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 of files needing to be copied."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 (let ((shadows (shadow-shadows-of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 (shadow-expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634 (buffer-file-name (current-buffer))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 (shadow-when shadows
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 (setq shadow-files-to-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 (shadow-union shadows shadow-files-to-copy))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 (shadow-when (not shadow-inhibit-message)
2
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
639 (message "%s" (substitute-command-keys
ac2d302a0011 Import from CVS: tag r19-15b2
cvs
parents: 0
diff changeset
640 "Use \\[shadow-copy-files] to update shadows."))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 (sit-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 (shadow-write-todo-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 nil) ; Return nil for write-file-hooks
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 (defun shadow-remove-from-todo (pair)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 "Remove PAIR from shadow-files-to-copy.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 PAIR must be (eq to) one of the elements of that list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 (setq shadow-files-to-copy
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 (shadow-remove-if (function (lambda (s) (eq s pair)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 shadow-files-to-copy)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 (defun shadow-read-files ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 "Visits and loads shadow-info-file and shadow-todo-file,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 thus restoring shadowfile's state from your last emacs session.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 Returns t unless files were locked; then returns nil."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656 (interactive)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 (if (and (fboundp 'file-locked-p)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658 (or (stringp (file-locked-p shadow-info-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 (stringp (file-locked-p shadow-todo-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 (message "Shadowfile is running in another emacs; can't have two.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 (sit-for 3)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 (shadow-when shadow-info-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 (set-buffer (setq shadow-info-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 (find-file-noselect shadow-info-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669 (shadow-when (and (not (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 (file-newer-than-file-p (make-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 shadow-info-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 (message "Data recovered from %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674 (car (insert-file-contents (make-auto-save-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 (sit-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 (eval-current-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 (shadow-when shadow-todo-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 (set-buffer (setq shadow-todo-buffer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 (find-file-noselect shadow-todo-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680 (shadow-when (and (not (buffer-modified-p))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 (file-newer-than-file-p (make-auto-save-file-name)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 shadow-todo-file))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 (erase-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 (message "Data recovered from %s."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 (car (insert-file-contents (make-auto-save-file-name))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686 (sit-for 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 (eval-current-buffer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 (shadow-invalidate-hashtable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 (defun shadow-write-info-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 "Write out information to shadow-info-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 Also clears shadow-hashtable, since when there are new shadows defined, the old
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 hashtable info is invalid."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 (shadow-invalidate-hashtable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696 (if shadow-info-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 (if (not shadow-info-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 (setq shadow-info-buffer (find-file-noselect shadow-info-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700 (set-buffer shadow-info-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 (shadow-insert-var 'shadow-clusters)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 (shadow-insert-var 'shadow-literal-groups)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 (shadow-insert-var 'shadow-regexp-groups))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 (defun shadow-write-todo-file (&optional save)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707 "Write out information to shadow-todo-file.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708 With nonnil argument also saves the buffer."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 (if (not shadow-todo-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 (setq shadow-todo-buffer (find-file-noselect shadow-todo-file)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712 (set-buffer shadow-todo-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 (delete-region (point-min) (point-max))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 (shadow-insert-var 'shadow-files-to-copy)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 (if save (shadow-save-todo-file))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 (defun shadow-save-todo-file ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718 (if (and shadow-todo-buffer (buffer-modified-p shadow-todo-buffer))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
719 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
720 (set-buffer shadow-todo-buffer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
721 (condition-case nil ; have to continue even in case of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
722 (basic-save-buffer) ; error, otherwise kill-emacs might
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
723 (error ; not work!
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
724 (message "WARNING: Can't save shadow todo file; it is locked!")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
725 (sit-for 1))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
726
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 (defun shadow-invalidate-hashtable ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728 (setq shadow-hashtable (make-vector 37 0)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 (defun shadow-insert-var (variable)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 "Prettily insert a setq command for VARIABLE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 which, when later evaluated, will restore it to its current setting.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733 SYMBOL must be the name of a variable whose value is a list."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 (let ((standard-output (current-buffer)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735 (insert (format "(setq %s" variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 (cond ((consp (eval variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 (insert "\n '(")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
738 (prin1 (car (eval variable)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
739 (let ((rest (cdr (eval variable))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
740 (while rest
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
741 (insert "\n ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
742 (prin1 (car rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
743 (setq rest (cdr rest)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
744 (insert "))\n\n")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
745 (t (insert " ")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
746 (prin1 (eval variable))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
747 (insert ")\n\n")))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
748
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
749 (defun shadow-save-buffers-kill-emacs (&optional arg)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
750 "Offer to save each buffer and copy shadows, then kill this Emacs process.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
751 With prefix arg, silently save all file-visiting buffers, then kill.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
752
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
753 Extended by shadowfile to automatically save `shadow-todo-file' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
754 look for files that have been changed and need to be copied to other systems."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
755 ;; This function is necessary because we need to get control and save
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
756 ;; the todo file /after/ saving other files, but /before/ the warning
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
757 ;; message about unsaved buffers (because it can get modified by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
758 ;; action of saving other buffers). `kill-emacs-hook' is no good
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
759 ;; because it is not called at the correct time, and also because it is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
760 ;; called when the terminal is disconnected and we cannot ask whether
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
761 ;; to copy files.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
762 (interactive "P")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
763 (shadow-save-todo-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
764 (save-some-buffers arg t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
765 (shadow-copy-files)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
766 (shadow-save-todo-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
767 (and (or (not (memq t (mapcar (function
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
768 (lambda (buf) (and (buffer-file-name buf)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
769 (buffer-modified-p buf))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
770 (buffer-list))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
771 (yes-or-no-p "Modified buffers exist; exit anyway? "))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
772 (or (not (fboundp 'process-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
773 ;; process-list is not defined on VMS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
774 (let ((processes (process-list))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
775 active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
776 (while processes
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
777 (and (memq (process-status (car processes)) '(run stop open))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
778 (let ((val (process-kill-without-query (car processes))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
779 (process-kill-without-query (car processes) val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
780 val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
781 (setq active t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
782 (setq processes (cdr processes)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
783 (or (not active)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
784 (yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
785 (kill-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
786
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
787 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
788 ;;; Lucid Emacs compatibility
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
789 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
790
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
791 ;; This is on hold until someone tells me about a working version of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
792 ;; map-ynp for Lucid Emacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
793
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
794 ;(shadow-when (string-match "Lucid" emacs-version)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
795 ; (require 'symlink-fix)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
796 ; (require 'ange-ftp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
797 ; (require 'map-ynp)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
798 ; (if (not (fboundp 'file-truename))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
799 ; (fset 'shadow-expand-file-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
800 ; (symbol-function 'symlink-expand-file-name)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
801 ; (if (not (fboundp 'ange-ftp-ftp-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
802 ; (fset 'ange-ftp-ftp-name
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
803 ; (symbol-function 'ange-ftp-ftp-path))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
804
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
805 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
806 ;;; Hook us up
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
807 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
808
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
809 ;;; File shadowing is activated at load time, unless this this file is
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
810 ;;; being preloaded, in which case it is added to after-init-hook.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
811 ;;; Thanks to Richard Caley for this scheme.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
812
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
813 (defun shadow-initialize ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
814 (if (null shadow-homedir)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
815 (setq shadow-homedir
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
816 (file-name-as-directory (shadow-expand-file-name "~"))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
817 (if (null shadow-info-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
818 (setq shadow-info-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
819 (shadow-expand-file-name "~/.shadows")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
820 (if (null shadow-todo-file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
821 (setq shadow-todo-file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
822 (shadow-expand-file-name "~/.shadow_todo")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
823 (if (not (shadow-read-files))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
824 (progn
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
825 (message "Shadowfile information files not found - aborting")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
826 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
827 (sit-for 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
828 (shadow-when (and (not shadow-inhibit-overload)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
829 (not (fboundp 'shadow-orig-save-buffers-kill-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
830 (fset 'shadow-orig-save-buffers-kill-emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
831 (symbol-function 'save-buffers-kill-emacs))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
832 (fset 'save-buffers-kill-emacs
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
833 (symbol-function 'shadow-save-buffers-kill-emacs)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
834 (add-hook 'write-file-hooks 'shadow-add-to-todo)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
835 (define-key ctl-x-4-map "s" 'shadow-copy-files)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
836
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
837 (if noninteractive
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
838 (add-hook 'after-init-hook 'shadow-initialize)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
839 (shadow-initialize))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
840
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
841 ;;;Local Variables:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
842 ;;;eval:(put 'shadow-when 'lisp-indent-hook 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
843 ;;;End:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
844
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
845 ;;; shadowfile.el ends here