annotate lisp/shadowfile.el @ 13396:b44cc5a62941

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