annotate lisp/shadowfile.el @ 98561:bac33d669abf

ibuffer: Fix issue with ERC scroll-to-bottom (Bug #858).
author Michael Olson <mwolson@gnu.org>
date Wed, 08 Oct 2008 05:02:09 +0000
parents c3512b2085a0
children 6e47884b9b26
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
1 ;;; shadowfile.el --- automatic file copying
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
64762
41bb365f41c4 Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents: 64091
diff changeset
3 ;; Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
79721
73661ddc7ac7 Add 2008 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 79278
diff changeset
4 ;; 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
5
25278
cbe304a26771 Fix maintainer address.
Karl Heuer <kwzh@gnu.org>
parents: 24294
diff changeset
6 ;; Author: Boris Goldowsky <boris@gnu.org>
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
7 ;; Keywords: comm files
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
8
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
9 ;; This file is part of GNU Emacs.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
12 ;; it under the terms of the GNU General Public License as published by
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
13 ;; the Free Software Foundation, either version 3 of the License, or
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
14 ;; (at your option) any later version.
13337
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
15
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
16 ;; 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
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
19 ;; GNU General Public License for more details.
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
20
84acc3adcd63 Comment change.
Richard M. Stallman <rms@gnu.org>
parents: 13336
diff changeset
21 ;; You should have received a copy of the GNU General Public License
94678
ee5932bf781d Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents: 93975
diff changeset
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
23
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
24 ;;; Commentary:
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
25
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
26 ;; This package helps you to keep identical copies of files in more than one
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
27 ;; place - possibly on different machines. When you save a file, it checks
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
28 ;; whether it is on the list of files with "shadows", and if so, it tries to
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
29 ;; copy it when you exit Emacs (or use the shadow-copy-files command).
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
31 ;; Installation & Use:
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
32
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
33 ;; Add clusters (if necessary) and file groups with shadow-define-cluster,
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
34 ;; shadow-define-literal-group, and shadow-define-regexp-group (see the
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
35 ;; documentation for these functions for information on how and when to use
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
36 ;; them). After doing this once, everything should be automatic.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
37
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
38 ;; The lists of clusters and shadows are saved in a file called .shadows,
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
39 ;; so that they can be remembered from one Emacs session to another, even
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
40 ;; (as much as possible) if the Emacs session terminates abnormally. The
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
41 ;; files needing to be copied are stored in .shadow_todo; if a file cannot
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
42 ;; be copied for any reason, it will stay on the list to be tried again
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
43 ;; next time. The .shadows file should itself have shadows on all your
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
44 ;; accounts so that the information in it is consistent everywhere, but
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
45 ;; .shadow_todo is local information and should have no shadows.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
46
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
47 ;; If you do not want to copy a particular file, you can answer "no" and
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
48 ;; be asked again next time you hit C-x 4 s or exit Emacs. If you do not
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
49 ;; want to be asked again, use shadow-cancel, and you will not be asked
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
50 ;; until you change the file and save it again. If you do not want to
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
51 ;; shadow that file ever again, you can edit it out of the .shadows
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
52 ;; buffer. Anytime you edit the .shadows buffer, you must type M-x
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
53 ;; shadow-read-files to load in the new information, or your changes will
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
54 ;; be overwritten!
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
55
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
56 ;; Bugs & Warnings:
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
57 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
58 ;; - It is bad to have two emacses both running shadowfile at the same
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
59 ;; time. It tries to detect this condition, but is not always successful.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
60 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
61 ;; - You have to be careful not to edit a file in two locations
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
62 ;; before shadowfile has had a chance to copy it; otherwise
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
63 ;; "updating shadows" will overwrite one of the changed versions.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
64 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
65 ;; - It ought to check modification times of both files to make sure
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
66 ;; it is doing the right thing. This will have to wait until
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
67 ;; file-newer-than-file-p works between machines.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
68 ;;
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
69 ;; - It will not make directories for you, it just fails to copy files
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
70 ;; that belong in non-existent directories.
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
71 ;;
25278
cbe304a26771 Fix maintainer address.
Karl Heuer <kwzh@gnu.org>
parents: 24294
diff changeset
72 ;; Please report any bugs to me (boris@gnu.org). Also let me know
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 13337
diff changeset
73 ;; if you have suggestions or would like to be informed of updates.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
75
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76 ;;; Code:
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 (require 'ange-ftp)
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
81 ;;; Variables
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
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
84 (defgroup shadow nil
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
85 "Automatic file copying when saving a file."
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
86 :prefix "shadow-"
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
87 :link '(emacs-commentary-link "shadowfile")
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
88 :group 'files)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
89
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
90 (defcustom shadow-noquery nil
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
91 "*If t, always copy shadow files without asking.
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
92 If nil \(the default), always ask. If not nil and not t, ask only if there
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
93 is no buffer currently visiting the file."
22598
dcb17af08ae0 (shadow-noquery): Use `other' widget type.
Andreas Schwab <schwab@suse.de>
parents: 21408
diff changeset
94 :type '(choice (const t) (const nil) (other :tag "Ask if no buffer" maybe))
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
95 :group 'shadow)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
96
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
97 (defcustom shadow-inhibit-message nil
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
98 "*If non-nil, do not display a message when a file needs copying."
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
99 :type 'boolean
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
100 :group 'shadow)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
101
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
102 (defcustom shadow-inhibit-overload nil
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
103 "If non-nil, shadowfile won't redefine \\[save-buffers-kill-emacs].
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
104 Normally it overloads the function `save-buffers-kill-emacs' to check for
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
105 files that have been changed and need to be copied to other systems."
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
106 :type 'boolean
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
107 :group 'shadow)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
108
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
109 (defcustom shadow-info-file nil
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
110 "File to keep shadow information in.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
111 The `shadow-info-file' should be shadowed to all your accounts to
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
112 ensure consistency. Default: ~/.shadows"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
113 :type '(choice (const nil) file)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
114 :group 'shadow)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
115
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
116 (defcustom shadow-todo-file nil
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
117 "File to store the list of uncopied shadows in.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
118 This means that if a remote system is down, or for any reason you cannot or
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
119 decide not to copy your shadow files at the end of one Emacs session, it will
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
120 remember and ask you again in your next Emacs session.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
121 This file must NOT be shadowed to any other system, it is host-specific.
21088
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
122 Default: ~/.shadow_todo"
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
123 :type '(choice (const nil) file)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
124 :group 'shadow)
ac1673121774 Customized.
Stephen Eglen <stephen@gnu.org>
parents: 18402
diff changeset
125
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
126
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
127 ;;; The following two variables should in most cases initialize themselves
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
128 ;;; correctly. They are provided as variables in case the defaults are wrong
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
129 ;;; on your machine \(and for efficiency).
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
130
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
131 (defvar shadow-system-name (system-name)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
132 "The complete hostname of this machine.")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
133
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
134 (defvar shadow-homedir nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
135 "Your home directory on this machine.")
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 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138 ;;; Internal variables whose values are stored in the info and todo files:
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139 ;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 (defvar shadow-clusters nil
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
142 "List of host clusters \(see `shadow-define-cluster').")
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 (defvar shadow-literal-groups nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145 "List of files that are shared between hosts.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 This list contains shadow structures with literal filenames, created by
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
147 `shadow-define-literal-group'.")
5119
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-regexp-groups nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 "List of file types that are shared between hosts.
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
151 This list contains shadow structures with regexps matching filenames,
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
152 created by `shadow-define-regexp-group'.")
5119
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 ;;; Other internal variables:
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 (defvar shadow-files-to-copy nil) ; List of files that need to
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 ; be copied to remote hosts.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 (defvar shadow-hashtable nil) ; for speed
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 (defvar shadow-info-buffer nil) ; buf visiting shadow-info-file
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164 (defvar shadow-todo-buffer nil) ; buf visiting shadow-todo-file
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
165
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
166 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
167 ;;; Syntactic sugar; General list and string manipulation
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
168 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
169
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
170 (defun shadow-union (a b)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
171 "Add members of list A to list B if not equal to items already in B."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 (if (null a)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 b
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174 (if (member (car a) b)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175 (shadow-union (cdr a) b)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
176 (shadow-union (cdr a) (cons (car a) b)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178 (defun shadow-find (func list)
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
179 "If FUNC applied to some element of LIST is non-nil, return first such element."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 (while (and list (not (funcall func (car list))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181 (setq list (cdr list)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (car list))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184 (defun shadow-remove-if (func list)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 "Remove elements satisfying FUNC from LIST.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 Nondestructive; actually returns a copy of the list with the elements removed."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187 (if list
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (if (funcall func (car list))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 (shadow-remove-if func (cdr list))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190 (cons (car list) (shadow-remove-if func (cdr list))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 (defun shadow-regexp-superquote (string)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
194 "Like `regexp-quote', but includes the ^ and $.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
195 This makes sure regexp matches nothing but STRING."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 (concat "^" (regexp-quote string) "$"))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198 (defun shadow-suffix (prefix string)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
199 "If PREFIX begins STRING, return the rest.
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
200 Return value is non-nil if PREFIX and STRING are `string=' up to the length of
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 PREFIX."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 (let ((lp (length prefix))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (ls (length string)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 (if (and (>= ls lp)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (string= prefix (substring string 0 lp)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (substring string lp))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207
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 ;;; Clusters and sites
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
210 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
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 ;;; 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
213 ;;; cluster or a literal hostname. All user-level commands should accept
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 ;;; either.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (defun shadow-make-cluster (name primary regexp)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
217 "Create a shadow cluster.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
218 It is called NAME, uses the PRIMARY hostname and REGEXP matching all
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
219 hosts in the cluster. The variable `shadow-clusters' associates the
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
220 names of clusters to these structures. This function is for program
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
221 use: to create clusters interactively, use `shadow-define-cluster'
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
222 instead."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 (list name primary regexp))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 (defmacro shadow-cluster-name (cluster)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 "Return the name of the CLUSTER."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 (list 'elt cluster 0))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 (defmacro shadow-cluster-primary (cluster)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 "Return the primary hostname of a CLUSTER."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 (list 'elt cluster 1))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 (defmacro shadow-cluster-regexp (cluster)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 "Return the regexp matching hosts in a CLUSTER."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 (list 'elt cluster 2))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 (defun shadow-set-cluster (name primary regexp)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
238 "Put cluster NAME on the list of clusters.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
239 Replace old definition, if any. PRIMARY and REGEXP are the
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 information defining the cluster. For interactive use, call
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
241 `shadow-define-cluster' instead."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242 (let ((rest (shadow-remove-if
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 (function (lambda (x) (equal name (car x))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 shadow-clusters)))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
245 (setq shadow-clusters
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246 (cons (shadow-make-cluster name primary regexp)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 rest))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (defmacro shadow-get-cluster (name)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 "Return cluster named NAME, or nil."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 (list 'assoc name 'shadow-clusters))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
253 (defun shadow-site-primary (site)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 "If SITE is a cluster, return primary host, otherwise return SITE."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 (let ((c (shadow-get-cluster site)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 (if c
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (shadow-cluster-primary c)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 site)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 ;;; SITES
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262 (defun shadow-site-cluster (site)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
263 "Given a SITE \(hostname or cluster name), return cluster it is in, or nil."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (or (assoc site shadow-clusters)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (shadow-find
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 (function (lambda (x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267 (string-match (shadow-cluster-regexp x)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 site)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 shadow-clusters)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 (defun shadow-read-site ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 "Read a cluster name or hostname from the minibuffer."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 (let ((ans (completing-read "Host or cluster name [RET when done]: "
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 shadow-clusters)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 (if (equal "" ans)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 nil
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ans)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (defun shadow-site-match (site1 site2)
78492
7c8949dbfa0d Replace `iff' in doc-strings and comments.
Glenn Morris <rgm@gnu.org>
parents: 78236
diff changeset
280 "Non-nil if SITE1 is or includes SITE2.
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
281 Each may be a host or cluster name; if they are clusters, regexp of SITE1 will
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
282 be matched against the primary of SITE2."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
283 (or (string-equal site1 site2) ; quick check
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (let* ((cluster1 (shadow-get-cluster site1))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 (primary2 (shadow-site-primary site2)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 (if cluster1
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (string-match (shadow-cluster-regexp cluster1) primary2)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (string-equal site1 primary2)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290 (defun shadow-get-user (site)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
291 "Return the default username for a SITE."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
292 (ange-ftp-get-user (shadow-site-primary site)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
293
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
294 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
295 ;;; Filename manipulation
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
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
298 (defun shadow-parse-fullname (fullname)
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
299 "Parse FULLNAME into \(site user path) list.
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
300 Leave it alone if it already is one. Return nil if the argument is
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
301 not a full ange-ftp pathname."
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
302 (if (listp fullname)
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
303 fullname
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
304 (ange-ftp-ftp-name fullname)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
305
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
306 (defun shadow-parse-name (name)
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
307 "Parse any NAME into \(site user name) list.
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
308 Argument can be a simple name, full ange-ftp name, or already a hup list."
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
309 (or (shadow-parse-fullname name)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (list shadow-system-name
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (user-login-name)
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
312 name)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
314 (defsubst shadow-make-fullname (host user name)
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
315 "Make an ange-ftp style fullname out of HOST, USER (optional), and NAME.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 This is probably not as general as it ought to be."
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
317 (concat "/"
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318 (if user (concat user "@"))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319 host ":"
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
320 name))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
322 (defun shadow-replace-name-component (fullname newname)
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
323 "Return FULLNAME with the name component changed to NEWNAME."
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
324 (let ((hup (shadow-parse-fullname fullname)))
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
325 (shadow-make-fullname (nth 0 hup) (nth 1 hup) newname)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (defun shadow-local-file (file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
328 "If FILE is at this site, remove /user@host part.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
329 If refers to a different system or a different user on this system,
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
330 return nil."
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
331 (let ((hup (shadow-parse-fullname file)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 (cond ((null hup) file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 ((and (shadow-site-match (nth 0 hup) shadow-system-name)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (string-equal (nth 1 hup) (user-login-name)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (nth 2 hup))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (t nil))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun shadow-expand-cluster-in-file-name (file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
339 "If hostname part of FILE is a cluster, expand it to cluster's primary hostname.
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
340 Will return the name bare if it is a local file."
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
341 (let ((hup (shadow-parse-name file))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342 cluster)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (cond ((null hup) file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 ((shadow-local-file hup))
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
345 ((shadow-make-fullname (shadow-site-primary (nth 0 hup))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 (nth 1 hup)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 (nth 2 hup))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 (defun shadow-expand-file-name (file &optional default)
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
350 "Expand file name and get FILE's true name."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (file-truename (expand-file-name file default)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353 (defun shadow-contract-file-name (file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
354 "Simplify FILE.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
355 Do so by replacing (when possible) home directory with ~, and hostname
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
356 with cluster name that includes it. Filename should be absolute and
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
357 true."
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
358 (let* ((hup (shadow-parse-name file))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 (homedir (if (shadow-local-file hup)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360 shadow-homedir
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361 (file-name-as-directory
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
362 (nth 2 (shadow-parse-fullname
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 (expand-file-name
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
364 (shadow-make-fullname
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 (nth 0 hup) (nth 1 hup) "~")))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (suffix (shadow-suffix homedir (nth 2 hup)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (cluster (shadow-site-cluster (nth 0 hup))))
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
368 (shadow-make-fullname
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (if cluster
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 (shadow-cluster-name cluster)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 (nth 0 hup))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 (nth 1 hup)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
373 (if suffix
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (concat "~/" suffix)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (nth 2 hup)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 (defun shadow-same-site (pattern file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 "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
379 If usernames are supplied, they must also match exactly. PATTERN and FILE may
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
380 be lists of host, user, name, or ange-ftp file names. FILE may also be just a
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 local filename."
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
382 (let ((pattern-sup (shadow-parse-fullname pattern))
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
383 (file-sup (shadow-parse-name file)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 (and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 (shadow-site-match (nth 0 pattern-sup) (nth 0 file-sup))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (or (null (nth 1 pattern-sup))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (string-equal (nth 1 pattern-sup) (nth 1 file-sup))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (defun shadow-file-match (pattern file &optional regexp)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
390 "Return t if PATTERN matches FILE.
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
391 If REGEXP is supplied and non-nil, the file part of the pattern is a regular
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 expression, otherwise it must match exactly. The sites and usernames must
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
393 match---see `shadow-same-site'. The pattern must be in full ange-ftp format,
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
394 but the file can be any valid filename. This function does not do any
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
395 filename expansion or contraction, you must do that yourself first."
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
396 (let* ((pattern-sup (shadow-parse-fullname pattern))
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
397 (file-sup (shadow-parse-name file)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (and (shadow-same-site pattern-sup file-sup)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
399 (if regexp
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (string-match (nth 2 pattern-sup) (nth 2 file-sup))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 (string-equal (nth 2 pattern-sup) (nth 2 file-sup))))))
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 43971
diff changeset
402
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 ;;; User-level Commands
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
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
407 ;;;###autoload
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 (defun shadow-define-cluster (name)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
409 "Edit \(or create) the definition of a cluster NAME.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410 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
411 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
412 defined by a name, the network address of a primary host \(the one we copy
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
413 files to), and a regular expression that matches the hostnames of all the
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
414 sites in the cluster."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (interactive (list (completing-read "Cluster name: " shadow-clusters () ())))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416 (let* ((old (shadow-get-cluster name))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (primary (read-string "Primary host: "
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
418 (if old (shadow-cluster-primary old)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 name)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420 (regexp (let (try-regexp)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (while (not
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
422 (string-match
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (setq try-regexp
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
424 (read-string
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 "Regexp matching all host names: "
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 (if old (shadow-cluster-regexp old)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (shadow-regexp-superquote primary))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428 primary))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
429 (message "Regexp doesn't include the primary host!")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
430 (sit-for 2))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
431 try-regexp))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
432 ; (username (read-no-blanks-input
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
433 ; (format "Username (default %s): "
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
434 ; (shadow-get-user primary))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
435 ; (if old (or (shadow-cluster-username old) "")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
436 ; (user-login-name))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
437 )
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
438 ; (if (string-equal "" username) (setq username nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
439 (shadow-set-cluster name primary regexp)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
440
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
441 ;;;###autoload
5119
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
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
446 specific hostnames, or names of clusters \(see `shadow-define-cluster')."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 (interactive)
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
448 (let* ((hup (shadow-parse-fullname
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 (shadow-contract-file-name (buffer-file-name))))
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
450 (name (nth 2 hup))
5119
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))
65680
ed770a0a7846 2005-09-24 Emilio C. Lopes <eclig@gmx.net>
Romain Francoise <romain@orebokech.com>
parents: 64762
diff changeset
453 (setq user (read-string (format "Username (default %s): "
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 (shadow-get-user site)))
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
455 name (read-string "Filename: " name))
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
456 (setq group (cons (shadow-make-fullname site
5119
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)
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
460 name)
5119
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
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
465 ;;;###autoload
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
466 (defun shadow-define-regexp-group ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
467 "Make each of a group of files be shared between hosts.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
468 Prompts for regular expression; files matching this are shared between a list
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
469 of sites, which are also prompted for. The filenames must be identical on all
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
470 hosts \(if they aren't, use `shadow-define-literal-group' instead of this
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
471 function). Each site can be either a hostname or the name of a cluster \(see
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
472 `shadow-define-cluster')."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
473 (interactive)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
474 (let ((regexp (read-string
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
475 "Filename regexp: "
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (if (buffer-file-name)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 (shadow-regexp-superquote
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 (nth 2
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
479 (shadow-parse-name
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 (shadow-contract-file-name
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (buffer-file-name))))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 site sites usernames)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (while (setq site (shadow-read-site))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (setq sites (cons site sites))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
485 (setq usernames
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (cons (read-string (format "Username for %s: " site)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 (shadow-get-user site))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 usernames)))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
489 (setq shadow-regexp-groups
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (cons (shadow-make-group regexp sites usernames)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 shadow-regexp-groups))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (shadow-write-info-file)))
49597
e88404e8f2cf Trailing whitespace deleted.
Juanma Barranquero <lekktu@gmail.com>
parents: 43971
diff changeset
493
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (defun shadow-shadows ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 ;; Mostly for debugging.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 "Interactive function to display shadows of a buffer."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (interactive)
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
498 (let ((msg (mapconcat #'cdr (shadow-shadows-of (buffer-file-name)) " ")))
14349
96692e2ba103 (shadow-shadows, shadow-add-to-todo): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
499 (message "%s"
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
500 (if (zerop (length msg))
5119
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.
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
507 Pending copies are stored in variable `shadow-files-to-copy', and in
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
508 `shadow-todo-file' if necessary. This function is invoked by
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
509 `shadow-save-buffers-kill-emacs', so it is not usually necessary to
5119
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")
57748
a5bb249b0f3b (shadow-copy-files): Use interactive-p
Richard M. Stallman <rms@gnu.org>
parents: 57544
diff changeset
512 (if (not shadow-files-to-copy)
a5bb249b0f3b (shadow-copy-files): Use interactive-p
Richard M. Stallman <rms@gnu.org>
parents: 57544
diff changeset
513 (if (interactive-p)
a5bb249b0f3b (shadow-copy-files): Use interactive-p
Richard M. Stallman <rms@gnu.org>
parents: 57544
diff changeset
514 (message "No files need to be shadowed."))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 (save-excursion
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (map-y-or-n-p (function
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (lambda (pair)
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
518 (or arg shadow-noquery
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (format "Copy shadow file %s? " (cdr pair)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (function shadow-copy-file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 shadow-files-to-copy
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 '("shadow" "shadows" "copy"))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (shadow-write-todo-file t))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (defun shadow-cancel ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 "Cancel the instruction to copy some files.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 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
528 them again, unless you make more changes to the files. To cancel a shadow
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
529 permanently, remove the group from `shadow-literal-groups' or
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
530 `shadow-regexp-groups'."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 (interactive)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 (map-y-or-n-p (function (lambda (pair)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
533 (format "Cancel copying %s to %s? "
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (car pair) (cdr pair))))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
535 (function (lambda (pair)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 (shadow-remove-from-todo pair)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 shadow-files-to-copy
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 '("shadow" "shadows" "cancel copy"))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
539 (message "There are %d shadows to be updated."
14349
96692e2ba103 (shadow-shadows, shadow-add-to-todo): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
540 (length shadow-files-to-copy))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (shadow-write-todo-file))
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 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 ;;; Internal functions
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
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
547 (defun shadow-make-group (regexp sites usernames)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
548 "Make a description of a file group---
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 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
550 be shadowed), list of SITES, and corresponding list of USERNAMES for each
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 site."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (if sites
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
553 (cons (shadow-make-fullname (car sites) (car usernames) regexp)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (shadow-make-group regexp (cdr sites) (cdr usernames)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 nil))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
556
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
557 (defun shadow-copy-file (s)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 "Copy one shadow file."
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
559 (let* ((buffer
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
560 (cond ((get-file-buffer
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
561 (abbreviate-file-name (shadow-expand-file-name (car s)))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
562 ((not (file-readable-p (car s)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 (if (y-or-n-p
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
564 (format "Cannot find file %s--cancel copy request? "
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
565 (car s)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
566 (shadow-remove-from-todo s))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
567 nil)
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
568 ((or (eq t shadow-noquery)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
569 (y-or-n-p
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
570 (format "No buffer for %s -- update shadow anyway? "
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
571 (car s))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
572 (find-file-noselect (car s)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
573 (to (shadow-expand-cluster-in-file-name (cdr s))))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
574 (when buffer
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
575 (set-buffer buffer)
95366
52e3cee99f90 * progmodes/flymake.el (flymake-save-buffer-in-file):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94678
diff changeset
576 (condition-case i
52e3cee99f90 * progmodes/flymake.el (flymake-save-buffer-in-file):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94678
diff changeset
577 (progn
52e3cee99f90 * progmodes/flymake.el (flymake-save-buffer-in-file):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94678
diff changeset
578 (write-region nil nil to)
52e3cee99f90 * progmodes/flymake.el (flymake-save-buffer-in-file):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94678
diff changeset
579 (shadow-remove-from-todo s))
52e3cee99f90 * progmodes/flymake.el (flymake-save-buffer-in-file):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 94678
diff changeset
580 (error (message "Shadow %s not updated!" (cdr s)))))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
581
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
582 (defun shadow-shadows-of (file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
583 "Return copy operations needed to update FILE.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
584 Filename should have clusters expanded, but otherwise can have any format.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
585 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
586 and to are absolute file names."
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
587 (or (symbol-value (intern-soft file shadow-hashtable))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
588 (let* ((absolute-file (shadow-expand-file-name
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
589 (or (shadow-local-file file) file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
590 shadow-homedir))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
591 (canonical-file (shadow-contract-file-name absolute-file))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
592 (shadows
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
593 (mapcar (function (lambda (shadow)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
594 (cons absolute-file shadow)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
595 (append
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
596 (shadow-shadows-of-1
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
597 canonical-file shadow-literal-groups nil)
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-regexp-groups t)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
600 (set (intern file shadow-hashtable) shadows))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
601
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
602 (defun shadow-shadows-of-1 (file groups regexp)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
603 "Return list of FILE's shadows in GROUPS.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
604 Consider them as regular expressions if third arg REGEXP is true."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
605 (if groups
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
606 (let ((nonmatching
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
607 (shadow-remove-if
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
608 (function (lambda (x) (shadow-file-match x file regexp)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
609 (car groups))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
610 (append (cond ((equal nonmatching (car groups)) nil)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
611 (regexp
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
612 (let ((realname (nth 2 (shadow-parse-fullname file))))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
613 (mapcar
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
614 (function
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
615 (lambda (x)
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
616 (shadow-replace-name-component x realname)))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
617 nonmatching)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
618 (t nonmatching))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
619 (shadow-shadows-of-1 file (cdr groups) regexp)))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
620
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
621 (defun shadow-add-to-todo ()
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
622 "If current buffer has shadows, add them to the list needing to be copied."
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
623 (let ((shadows (shadow-shadows-of
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
624 (shadow-expand-file-name
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
625 (buffer-file-name (current-buffer))))))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
626 (when shadows
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
627 (setq shadow-files-to-copy
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
628 (shadow-union shadows shadow-files-to-copy))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
629 (when (not shadow-inhibit-message)
14349
96692e2ba103 (shadow-shadows, shadow-add-to-todo): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
630 (message "%s" (substitute-command-keys
96692e2ba103 (shadow-shadows, shadow-add-to-todo): Pass proper format string to message.
Karl Heuer <kwzh@gnu.org>
parents: 14169
diff changeset
631 "Use \\[shadow-copy-files] to update shadows."))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
632 (sit-for 1))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
633 (shadow-write-todo-file)))
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
634 nil) ; Return nil for write-file-functions
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
635
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
636 (defun shadow-remove-from-todo (pair)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
637 "Remove PAIR from `shadow-files-to-copy'.
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
638 PAIR must be `eq' to one of the elements of that list."
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
639 (setq shadow-files-to-copy
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
640 (shadow-remove-if (function (lambda (s) (eq s pair)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
641 shadow-files-to-copy)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
642
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
643 (defun shadow-read-files ()
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
644 "Visit and load `shadow-info-file' and `shadow-todo-file'.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
645 Thus restores shadowfile's state from your last Emacs session.
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
646 Return t unless files were locked; then return nil."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
647 (interactive)
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
648 (if (and (fboundp 'file-locked-p)
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
649 (or (stringp (file-locked-p shadow-info-file))
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
650 (stringp (file-locked-p shadow-todo-file))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
651 (progn
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
652 (message "Shadowfile is running in another Emacs; can't have two.")
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
653 (beep)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
654 (sit-for 3)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
655 nil)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
656 (save-excursion
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
657 (when shadow-info-file
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
658 (set-buffer (setq shadow-info-buffer
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
659 (find-file-noselect shadow-info-file)))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
660 (when (and (not (buffer-modified-p))
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
661 (file-newer-than-file-p (make-auto-save-file-name)
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
662 shadow-info-file))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
663 (erase-buffer)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
664 (message "Data recovered from %s."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
665 (car (insert-file-contents (make-auto-save-file-name))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
666 (sit-for 1))
62459
b89461946700 Replace `eval-current-buffer' by `eval-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 57748
diff changeset
667 (eval-buffer))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
668 (when shadow-todo-file
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
669 (set-buffer (setq shadow-todo-buffer
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
670 (find-file-noselect shadow-todo-file)))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
671 (when (and (not (buffer-modified-p))
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
672 (file-newer-than-file-p (make-auto-save-file-name)
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
673 shadow-todo-file))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
674 (erase-buffer)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
675 (message "Data recovered from %s."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
676 (car (insert-file-contents (make-auto-save-file-name))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
677 (sit-for 1))
62459
b89461946700 Replace `eval-current-buffer' by `eval-buffer'.
Juanma Barranquero <lekktu@gmail.com>
parents: 57748
diff changeset
678 (eval-buffer nil))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
679 (shadow-invalidate-hashtable))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
680 t))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
681
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
682 (defun shadow-write-info-file ()
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
683 "Write out information to `shadow-info-file'.
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
684 Also clear `shadow-hashtable', since when there are new shadows
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
685 defined, the old hashtable info is invalid."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
686 (shadow-invalidate-hashtable)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
687 (if shadow-info-file
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
688 (save-excursion
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
689 (if (not shadow-info-buffer)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
690 (setq shadow-info-buffer (find-file-noselect shadow-info-file)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
691 (set-buffer shadow-info-buffer)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
692 (delete-region (point-min) (point-max))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
693 (shadow-insert-var 'shadow-clusters)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
694 (shadow-insert-var 'shadow-literal-groups)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
695 (shadow-insert-var 'shadow-regexp-groups))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
696
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
697 (defun shadow-write-todo-file (&optional save)
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
698 "Write out information to `shadow-todo-file'.
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
699 With non-nil argument also saves the buffer."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
700 (save-excursion
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
701 (if (not shadow-todo-buffer)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
702 (setq shadow-todo-buffer (find-file-noselect shadow-todo-file)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
703 (set-buffer shadow-todo-buffer)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
704 (delete-region (point-min) (point-max))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
705 (shadow-insert-var 'shadow-files-to-copy)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
706 (if save (shadow-save-todo-file))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
707
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
708 (defun shadow-save-todo-file ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
709 (if (and shadow-todo-buffer (buffer-modified-p shadow-todo-buffer))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
710 (save-excursion
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
711 (set-buffer shadow-todo-buffer)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
712 (condition-case nil ; have to continue even in case of
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
713 (basic-save-buffer) ; error, otherwise kill-emacs might
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
714 (error ; not work!
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
715 (message "WARNING: Can't save shadow todo file; it is locked!")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
716 (sit-for 1))))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
717
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
718 (defun shadow-invalidate-hashtable ()
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
719 (setq shadow-hashtable (make-vector 37 0)))
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-insert-var (variable)
79278
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
722 "Build a `setq' to restore VARIABLE.
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
723 Prettily insert a `setq' command which, when later evaluated,
15ad52029dc2 (shadow-inhibit-overload, shadow-remove-from-todo, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
724 will restore VARIABLE to its current setting.
73749
0ccca06d2010 (shadow-define-regexp-group, shadow-literal-groups, shadow-insert-var):
Juanma Barranquero <lekktu@gmail.com>
parents: 68651
diff changeset
725 VARIABLE must be the name of a variable whose value is a list."
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
726 (let ((standard-output (current-buffer)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
727 (insert (format "(setq %s" variable))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
728 (cond ((consp (eval variable))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
729 (insert "\n '(")
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
730 (prin1 (car (eval variable)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
731 (let ((rest (cdr (eval variable))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
732 (while rest
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
733 (insert "\n ")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
734 (prin1 (car rest))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
735 (setq rest (cdr rest)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
736 (insert "))\n\n")))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
737 (t (insert " ")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
738 (prin1 (eval variable))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
739 (insert ")\n\n")))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
740
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
741 (defun shadow-save-buffers-kill-emacs (&optional arg)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
742 "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
743 With prefix arg, silently save all file-visiting buffers, then kill.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
744
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
745 Extended by shadowfile to automatically save `shadow-todo-file' and
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
746 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
747 ;; This function is necessary because we need to get control and save
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
748 ;; the todo file /after/ saving other files, but /before/ the warning
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
749 ;; message about unsaved buffers (because it can get modified by the
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
750 ;; action of saving other buffers). `kill-emacs-hook' is no good
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
751 ;; 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
752 ;; called when the terminal is disconnected and we cannot ask whether
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
753 ;; to copy files.
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
754 (interactive "P")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
755 (shadow-save-todo-file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
756 (save-some-buffers arg t)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
757 (shadow-copy-files)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
758 (shadow-save-todo-file)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
759 (and (or (not (memq t (mapcar (function
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
760 (lambda (buf) (and (buffer-file-name buf)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
761 (buffer-modified-p buf))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
762 (buffer-list))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
763 (yes-or-no-p "Modified buffers exist; exit anyway? "))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
764 (or (not (fboundp 'process-list))
97142
c3512b2085a0 * bitmaps/README:
Dan Nicolaescu <dann@ics.uci.edu>
parents: 95366
diff changeset
765 ;; process-list is not defined on MSDOS.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
766 (let ((processes (process-list))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
767 active)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
768 (while processes
43971
92d4c0ba3ff9 Update copyright.
Kim F. Storm <storm@cua.dk>
parents: 38436
diff changeset
769 (and (memq (process-status (car processes)) '(run stop open listen))
92d4c0ba3ff9 Update copyright.
Kim F. Storm <storm@cua.dk>
parents: 38436
diff changeset
770 (process-query-on-exit-flag (car processes))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
771 (setq active t))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
772 (setq processes (cdr processes)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
773 (or (not active)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
774 (yes-or-no-p "Active processes exist; kill them and exit anyway? "))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
775 (kill-emacs)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
776
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
777 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
778 ;;; Lucid Emacs compatibility
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
779 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
780
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
781 ;; 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
782 ;; map-ynp for Lucid Emacs.
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
783
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
784 ;(when (string-match "Lucid" emacs-version)
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
785 ; (require 'symlink-fix)
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
786 ; (require 'ange-ftp)
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
787 ; (require 'map-ynp)
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
788 ; (if (not (fboundp 'file-truename))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
789 ; (fset 'shadow-expand-file-name
5288
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
790 ; (symbol-function 'symlink-expand-file-name)))
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
791 ; (if (not (fboundp 'ange-ftp-ftp-name))
c32c5d1aa89d (shadow-noquery): Use it.
Richard M. Stallman <rms@gnu.org>
parents: 5119
diff changeset
792 ; (fset 'ange-ftp-ftp-name
50426
23d82f089582 (shadow-parse-fullname): Renamed from shadow-parse-fullpath.
Richard M. Stallman <rms@gnu.org>
parents: 49597
diff changeset
793 ; (symbol-function 'ange-ftp-ftp-name))))
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
794
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
795 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
796 ;;; Hook us up
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
797 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
798
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
799 ;;;###autoload
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
800 (defun shadow-initialize ()
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
801 "Set up file shadowing."
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
802 (interactive)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
803 (if (null shadow-homedir)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
804 (setq shadow-homedir
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
805 (file-name-as-directory (shadow-expand-file-name "~"))))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
806 (if (null shadow-info-file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
807 (setq shadow-info-file
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
808 (shadow-expand-file-name "~/.shadows")))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
809 (if (null shadow-todo-file)
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
810 (setq shadow-todo-file
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
811 (shadow-expand-file-name "~/.shadow_todo")))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
812 (if (not (shadow-read-files))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
813 (progn
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
814 (message "Shadowfile information files not found - aborting")
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
815 (beep)
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
816 (sit-for 3))
27685
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
817 (when (and (not shadow-inhibit-overload)
15ad3fb709f8 (shadow-when): Removed.
Gerd Moellmann <gerd@gnu.org>
parents: 25278
diff changeset
818 (not (fboundp 'shadow-orig-save-buffers-kill-emacs)))
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
819 (defalias 'shadow-orig-save-buffers-kill-emacs
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
820 (symbol-function 'save-buffers-kill-emacs))
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
821 (defalias 'save-buffers-kill-emacs 'shadow-save-buffers-kill-emacs))
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
822 (add-hook 'write-file-functions 'shadow-add-to-todo)
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
823 (define-key ctl-x-4-map "s" 'shadow-copy-files)))
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
824
85828
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
825 (defun shadowfile-unload-function ()
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
826 (substitute-key-definition 'shadow-copy-files nil ctl-x-4-map)
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
827 (when (fboundp 'shadow-orig-save-buffers-kill-emacs)
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
828 (fset 'save-buffers-kill-emacs
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
829 (symbol-function 'shadow-orig-save-buffers-kill-emacs)))
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
830 ;; continue standard unloading
04fb80d58b60 (shadow-join): Remove.
Juanma Barranquero <lekktu@gmail.com>
parents: 78492
diff changeset
831 nil)
57544
9eb4eed0a14c (shadowfile-unload-hook): Set as variable w/ add-hook.
Richard M. Stallman <rms@gnu.org>
parents: 52401
diff changeset
832
36041
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
833 (provide 'shadowfile)
8606adf5daf6 Doc fixes.
Dave Love <fx@gnu.org>
parents: 27685
diff changeset
834
93975
1e3a407766b9 Fix up comment convention on the arch-tag lines.
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 87649
diff changeset
835 ;; arch-tag: e2f4cdd7-2bab-4def-9130-9e69b412b79e
5119
bf9e7676a73e Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
836 ;;; shadowfile.el ends here