annotate lisp/utils/shadowfile.el @ 209:41ff10fd062f r20-4b3

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