;; Copyright (C) 1985 Free Software Foundation ;; This file is part of GNU Emacs. ;; GNU Emacs is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY. No author or distributor ;; accepts responsibility to anyone for the consequences of using it ;; or for whether it serves any particular purpose or works at all, ;; unless he says so in writing. Refer to the GNU Emacs General Public ;; License for full details. ;; Everyone is granted permission to copy, modify and redistribute ;; GNU Emacs, but only under the conditions described in the ;; GNU Emacs General Public License. A copy of this license is ;; supposed to have been given to you along with GNU Emacs so you ;; can know your rights and responsibilities. It should be in a ;; file named COPYING. Among other things, the copyright notice ;; and this notice must be preserved on all copies. (put 'file-locked 'error-conditions '(file-locked file-error error)) (defun ask-user-about-lock (fn opponent) "Ask user what to do when he wants to edit FILE but it is locked by USER. This function has a choice of three things to do: do (signal 'buffer-file-locked (list FILE USER)) to refrain from editing the file return t (grab the lock on the file) return nil (edit the file even though it is locked). You can rewrite it to use any criterion you like to choose which one to do." (discard-input) (save-window-excursion (let (answer) (while (null answer) (message "%s is locking %s: action (s, q, p, ?)? :" opponent fn) (let ((tem (let ((inhibit-quit t)) (prog1 (downcase (read-char)) (setq quit-flag nil))))) (if (= tem help-char) (ask-user-about-lock-help) (setq answer (assoc tem '((?s . t) (?q . yield) (?\C-g . yield) (?p . nil) (?? . help)))) (cond ((null answer) (message "Please type q, s, or p; or ? for help") (sit-for 3)) ((eq (cdr answer) 'help) (ask-user-about-lock-help) (setq answer nil)) ((eq (cdr answer) 'yield) (signal 'file-locked (list "File is locked" fn opponent))))))) (cdr answer)))) (defun ask-user-about-lock-help () (with-output-to-temp-buffer "*Help*" (princ "It has been detected that you want to modify a file that someone else has already started modifying in EMACS. You can steal the file (s); (S)he becomes the intruder if (s)he ever unmodifies the file and tries again. You can proceed (p); you edit at your own (and his/her) risk. You can quit (q).")))