diff options
| -rw-r--r-- | lisp/userlock.el | 28 |
1 files changed, 21 insertions, 7 deletions
diff --git a/lisp/userlock.el b/lisp/userlock.el index 7844f4544bf..21c531312d6 100644 --- a/lisp/userlock.el +++ b/lisp/userlock.el | |||
| @@ -32,21 +32,35 @@ | |||
| 32 | ;;; Code: | 32 | ;;; Code: |
| 33 | 33 | ||
| 34 | (put 'file-locked 'error-conditions '(file-locked file-error error)) | 34 | (put 'file-locked 'error-conditions '(file-locked file-error error)) |
| 35 | (put 'file-locked 'error-message "File is locked") | ||
| 35 | 36 | ||
| 36 | ;;;###autoload | 37 | ;;;###autoload |
| 37 | (defun ask-user-about-lock (fn opponent) | 38 | (defun ask-user-about-lock (file opponent) |
| 38 | "Ask user what to do when he wants to edit FILE but it is locked by USER. | 39 | "Ask user what to do when he wants to edit FILE but it is locked by OPPONENT. |
| 39 | This function has a choice of three things to do: | 40 | This function has a choice of three things to do: |
| 40 | do (signal 'buffer-file-locked (list FILE USER)) | 41 | do (signal 'buffer-file-locked (list FILE OPPONENT)) |
| 41 | to refrain from editing the file | 42 | to refrain from editing the file |
| 42 | return t (grab the lock on the file) | 43 | return t (grab the lock on the file) |
| 43 | return nil (edit the file even though it is locked). | 44 | return nil (edit the file even though it is locked). |
| 44 | You can rewrite it to use any criterion you like to choose which one to do." | 45 | You can redefine this function to choose among those three alternatives |
| 46 | in any way you like." | ||
| 45 | (discard-input) | 47 | (discard-input) |
| 46 | (save-window-excursion | 48 | (save-window-excursion |
| 47 | (let (answer) | 49 | (let (answer short-opponent short-file) |
| 50 | (setq short-file | ||
| 51 | (if (> (length file) 22) | ||
| 52 | (concat "..." (substring file (- (length file) 22))) | ||
| 53 | file)) | ||
| 54 | (setq short-opponent | ||
| 55 | (if (> (length opponent) 25) | ||
| 56 | (save-match-data | ||
| 57 | (string-match " (pid [0-9]+)" opponent) | ||
| 58 | (concat (substring opponent 0 13) "..." | ||
| 59 | (match-string 0 opponent))) | ||
| 60 | opponent)) | ||
| 48 | (while (null answer) | 61 | (while (null answer) |
| 49 | (message "%s is locking %s: action (s, q, p, ?)? " opponent fn) | 62 | (message "%s locked by %s: (s, q, p, ?)? " |
| 63 | short-file short-opponent) | ||
| 50 | (let ((tem (let ((inhibit-quit t) | 64 | (let ((tem (let ((inhibit-quit t) |
| 51 | (cursor-in-echo-area t)) | 65 | (cursor-in-echo-area t)) |
| 52 | (prog1 (downcase (read-char)) | 66 | (prog1 (downcase (read-char)) |
| @@ -66,7 +80,7 @@ You can rewrite it to use any criterion you like to choose which one to do." | |||
| 66 | (ask-user-about-lock-help) | 80 | (ask-user-about-lock-help) |
| 67 | (setq answer nil)) | 81 | (setq answer nil)) |
| 68 | ((eq (cdr answer) 'yield) | 82 | ((eq (cdr answer) 'yield) |
| 69 | (signal 'file-locked (list "File is locked" fn opponent))))))) | 83 | (signal 'file-locked (list file opponent))))))) |
| 70 | (cdr answer)))) | 84 | (cdr answer)))) |
| 71 | 85 | ||
| 72 | (defun ask-user-about-lock-help () | 86 | (defun ask-user-about-lock-help () |