annotate lisp/prim/userlock.el @ 64:a01e7a40045c r19-16-pre7

Import from CVS: tag r19-16-pre7
author cvs
date Mon, 13 Aug 2007 08:59:30 +0200
parents b82b59fe008d
children 131b0175ea99
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 ;;; userlock.el --- handle file access contention between multiple users
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 ;; Copyright (C) 1985, 1986, 1993 Free Software Foundation, inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 ;; Maintainer: FSF
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6 ;; Keywords: internal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 ;; This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 ;; XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11 ;; under the terms of the GNU General Public License as published by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 ;; the Free Software Foundation; either version 2, or (at your option)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ;; any later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 ;; XEmacs is distributed in the hope that it will be useful, but
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 ;; General Public License for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21 ;; along with XEmacs; see the file COPYING. If not, write to the Free
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
22 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
23 ;; 02111-1307, USA.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
25 ;;; Synched up with: FSF 19.34.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 ;;; Commentary:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 ;; This file is autoloaded to handle certain conditions
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 ;; detected by the file-locking code within XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 ;; The two entry points are `ask-user-about-lock' and
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 ;; `ask-user-about-supersession-threat'.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 ;;; Code:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
36 (define-error 'file-locked "File is locked" 'file-error) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 (defun ask-user-about-lock-minibuf (fn opponent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40 (let (answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 (while (null answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 (message "%s is locking %s: action (s, q, p, ?)? " opponent fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 (let ((tem (let ((inhibit-quit t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 (cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 (prog1 (downcase (read-char))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46 (setq quit-flag nil)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 (if (= tem help-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 (ask-user-about-lock-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 (setq answer (assoc tem '((?s . t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 (?q . yield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 (?\C-g . yield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 (?p . nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 (?? . help))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54 (cond ((null answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 (message "Please type q, s, or p; or ? for help")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57 (sit-for 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58 ((eq (cdr answer) 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 (ask-user-about-lock-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 (setq answer nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 ((eq (cdr answer) 'yield)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
62 (signal 'file-locked (list "File is locked" fn opponent)))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 (cdr answer))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 (defun ask-user-about-lock-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67 (princ "It has been detected that you want to modify a file that someone else has
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 already started modifying in EMACS.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 You can <s>teal the file; The other user becomes the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 intruder if (s)he ever unmodifies the file and then changes it again.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 You can <p>roceed; you edit at your own (and the other user's) risk.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 You can <q>uit; don't modify this file.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76 (help-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
78 (define-error 'file-supersession "File changed on disk" 'file-error) ; XEmacs
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 (defun ask-user-about-supersession-threat-minibuf (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 (save-window-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82 (let (answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 (while (null answer)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
84 (message "%s changed on disk; really edit the buffer? (y, n, r or C-h) "
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 (file-name-nondirectory fn))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 (let ((tem (downcase (let ((cursor-in-echo-area t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87 (read-char)))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 (setq answer
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 (if (= tem help-char)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 'help
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 (cdr (assoc tem '((?n . yield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 (?\C-g . yield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 (?y . proceed)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
94 (?r . revert)
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 (?? . help))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 (cond ((null answer)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 (beep)
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
98 (message "Please type y, n or r; or ? for help")
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 (sit-for 3))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 ((eq answer 'help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 (ask-user-about-supersession-help)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 (setq answer nil))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
103 ((eq answer 'revert)
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
104 (revert-buffer nil (not (buffer-modified-p)))
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
105 ; ask confirmation iff buffer modified
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
106 (signal 'file-supersession
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
107 (list "File reverted" fn)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 ((eq answer 'yield)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 (signal 'file-supersession
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
110 (list "File changed on disk" fn))))))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 (message
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 "File on disk now will become a backup file if you save these changes.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 (setq buffer-backed-up nil))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 (defun ask-user-about-supersession-help ()
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 (with-output-to-temp-buffer "*Help*"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117 (princ "You want to modify a buffer whose disk file has changed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 since you last read it in or saved it with this buffer.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120 If you say `y' to go ahead and modify this buffer,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 you risk ruining the work of whoever rewrote the file.
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
122 If you say `r' to revert, the contents of the buffer are refreshed
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
123 from the file on disk.
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 If you say `n', the change you started to make will be aborted.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 Usually, you should type `n' and then `M-x revert-buffer',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 to get the latest version of the file, then make the change again.")
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 (save-excursion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 (set-buffer standard-output)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 (help-mode))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
132 ;;; dialog-box versions [XEmacs]
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134 (defun ask-user-about-lock-dbox (fn opponent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 (let ((echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 (dbox
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 (format "%s is locking %s\n
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 It has been detected that you want to modify a file that
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140 someone else has already started modifying in XEmacs."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 opponent fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 '(["Steal Lock\n\nThe other user will\nbecome the intruder" steal t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 ["Proceed\n\nEdit file at your own\n\(and the other user's) risk"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 proceed t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 ["Abort\n\nDon't modify the buffer\n" yield t]))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 (popup-dialog-box dbox)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148 (catch 'aual-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 (let ((event (next-command-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 (cond ((and (misc-user-event-p event) (eq (event-object event) 'proceed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 (throw 'aual-done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 ((and (misc-user-event-p event) (eq (event-object event) 'steal))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 (throw 'aual-done t))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 ((and (misc-user-event-p event) (eq (event-object event) 'yield))
4
b82b59fe008d Import from CVS: tag r19-15b3
cvs
parents: 0
diff changeset
156 (signal 'file-locked (list "File is locked" fn opponent)))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 ((button-release-event-p event) ;; don't beep twice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 (message "please answer the dialog box"))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 (defun ask-user-about-supersession-threat-dbox (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 (let ((echo-keystrokes 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 (dbox
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166 (cons
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 (format "File %s has changed on disk
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 since its buffer was last read in or saved.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170 Do you really want to edit the buffer? " fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 '(["Yes\n\nEdit the buffer anyway,\nignoring the disk file"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 proceed t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 ["No\n\nDon't modify the buffer\n" yield t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174 nil
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 ["No\n\nDon't modify the buffer\nbut revert it" revert t]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176 ))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 (popup-dialog-box dbox)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 (catch 'auast-done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 (while t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 (let ((event (next-command-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181 (cond ((and (misc-user-event-p event) (eq (event-object event) 'proceed))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 (throw 'auast-done nil))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 ((and (misc-user-event-p event) (eq (event-object event) 'yield))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 (signal 'file-supersession (list fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 ((and (misc-user-event-p event) (eq (event-object event) 'revert))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 (or (equal fn (buffer-file-name))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 (error
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 "ask-user-about-supersession-threat called bogusly"))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 (revert-buffer nil t)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190 (signal 'file-supersession
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 (list fn "(reverted)")))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192 ((button-release-event-p event) ;; don't beep twice
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 nil)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194 (t
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 (beep)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196 (message "please answer the dialog box"))))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199 ;;; top-level
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 (defun ask-user-about-lock (fn opponent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 "Ask user what to do when he wants to edit FILE but it is locked by USER.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 This function has a choice of three things to do:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205 do (signal 'file-locked (list FILE USER))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 to refrain from editing the file
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 return t (grab the lock on the file)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 return nil (edit the file even though it is locked).
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 You can rewrite it to use any criterion you like to choose which one to do."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 (discard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 (if (and (fboundp 'popup-dialog-box)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 (or (button-press-event-p last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 (button-release-event-p last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 (misc-user-event-p last-command-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 (ask-user-about-lock-dbox fn opponent)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 (ask-user-about-lock-minibuf fn opponent)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 ;;;###autoload
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 (defun ask-user-about-supersession-threat (fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 "Ask a user who is about to modify an obsolete buffer what to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221 This function has two choices: it can return, in which case the modification
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 of the buffer will proceed, or it can (signal 'file-supersession (file)),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 in which case the proposed buffer modification will not be made.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
225 You can rewrite this to use any criterion you like to choose which one to do.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 The buffer in question is current when this function is called."
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
227 (discard-input)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
228 (if (and (fboundp 'popup-dialog-box)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 (or (button-press-event-p last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 (button-release-event-p last-command-event)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 (misc-user-event-p last-command-event)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232 (ask-user-about-supersession-threat-dbox fn)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
233 (ask-user-about-supersession-threat-minibuf fn)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 ;;; userlock.el ends here