annotate lisp/utils/shadowfile.el @ 0:376386a54a3c r19-14

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