]> git.eshelyaron.com Git - emacs.git/commitdiff
Use 'help-key-binding' face in userlock.el
authorStefan Kangas <stefan@marxist.se>
Wed, 10 Mar 2021 02:29:50 +0000 (03:29 +0100)
committerStefan Kangas <stefan@marxist.se>
Wed, 10 Mar 2021 03:14:43 +0000 (04:14 +0100)
* lisp/userlock.el (userlock--fontify-key): New function.
(ask-user-about-lock, ask-user-about-lock-help,
(ask-user-about-supersession-threat)
(ask-user-about-supersession-help): Add face 'help-key-binding' to
displayed keys.

lisp/userlock.el

index a340ff85b2dfab23381916aac477a40f66d18605..0ef3c7770b75d251b8c3399efa0f895b23876b3a 100644 (file)
 
 (define-error 'file-locked "File is locked" 'file-error)
 
+(defun userlock--fontify-key (key)
+  "Add the `help-key-binding' face to string KEY."
+  (propertize key 'face 'help-key-binding))
+
 ;;;###autoload
 (defun ask-user-about-lock (file opponent)
   "Ask user what to do when he wants to edit FILE but it is locked by OPPONENT.
@@ -64,8 +68,12 @@ in any way you like."
                          (match-string 0 opponent)))
              opponent))
       (while (null answer)
-       (message "%s locked by %s: (s, q, p, ?)? "
-                short-file short-opponent)
+        (message "%s locked by %s: (%s, %s, %s, %s)? "
+                 short-file short-opponent
+                 (userlock--fontify-key "s")
+                 (userlock--fontify-key "q")
+                 (userlock--fontify-key "p")
+                 (userlock--fontify-key "?"))
        (if noninteractive (error "Cannot resolve lock conflict in batch mode"))
        (let ((tem (let ((inhibit-quit t)
                         (cursor-in-echo-area t))
@@ -80,7 +88,12 @@ in any way you like."
                                      (?? . help))))
            (cond ((null answer)
                   (beep)
-                  (message "Please type q, s, or p; or ? for help")
+                   (message "Please type %s, %s, or %s; or %s for help"
+                            (userlock--fontify-key "q")
+                            (userlock--fontify-key "s")
+                            (userlock--fontify-key "p")
+                            ;; FIXME: Why do we use "?" here and "C-h" below?
+                            (userlock--fontify-key "?"))
                   (sit-for 3))
                  ((eq (cdr answer) 'help)
                   (ask-user-about-lock-help)
@@ -91,14 +104,19 @@ in any way you like."
 
 (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
+    (with-current-buffer standard-output
+      (insert
+       (format
+        "It has been detected that you want to modify a file that someone else has
 already started modifying in Emacs.
 
-You can <s>teal the file; the other user becomes the
+You can <%s>teal the file; the other user becomes the
   intruder if (s)he ever unmodifies the file and then changes it again.
-You can <p>roceed; you edit at your own (and the other user's) risk.
-You can <q>uit; don't modify this file.")
-    (with-current-buffer standard-output
+You can <%s>roceed; you edit at your own (and the other user's) risk.
+You can <%s>uit; don't modify this file."
+        (userlock--fontify-key "s")
+        (userlock--fontify-key "p")
+        (userlock--fontify-key "q")))
       (help-mode))))
 
 (define-error 'file-supersession nil 'file-error)
@@ -151,8 +169,13 @@ The buffer in question is current when this function is called."
   (save-window-excursion
     (let ((prompt
           (format "%s changed on disk; \
-really edit the buffer? (y, n, r or C-h) "
-                  (file-name-nondirectory filename)))
+really edit the buffer? (%s, %s, %s or %s) "
+                   (file-name-nondirectory filename)
+                   (userlock--fontify-key "y")
+                   (userlock--fontify-key "n")
+                   (userlock--fontify-key "r")
+                   ;; FIXME: Why do we use "C-h" here and "?" above?
+                   (userlock--fontify-key "C-h")))
          (choices '(?y ?n ?r ?? ?\C-h))
          answer)
       (when noninteractive
@@ -177,20 +200,28 @@ really edit the buffer? (y, n, r or C-h) "
 
 (defun ask-user-about-supersession-help ()
   (with-output-to-temp-buffer "*Help*"
-    (princ
-     (substitute-command-keys
-      "You want to modify a buffer whose disk file has changed
+    (let ((revert-buffer-binding
+           ;; This takes place in the original buffer.
+           (substitute-command-keys "\\[revert-buffer]")))
+      (with-current-buffer standard-output
+        (insert
+         (format
+          "You want to modify a buffer whose disk file has changed
 since you last read it in or saved it with this buffer.
 
-If you say `y' to go ahead and modify this buffer,
+If you say %s to go ahead and modify this buffer,
 you risk ruining the work of whoever rewrote the file.
-If you say `r' to revert, the contents of the buffer are refreshed
+If you say %s to revert, the contents of the buffer are refreshed
 from the file on disk.
-If you say `n', the change you started to make will be aborted.
-
-Usually, you should type `n' and then `\\[revert-buffer]',
-to get the latest version of the file, then make the change again."))
-    (with-current-buffer standard-output
-      (help-mode))))
+If you say %s, the change you started to make will be aborted.
+
+Usually, you should type %s and then %s,
+to get the latest version of the file, then make the change again."
+          (userlock--fontify-key "y")
+          (userlock--fontify-key "r")
+          (userlock--fontify-key "n")
+          (userlock--fontify-key "n")
+          revert-buffer-binding))
+        (help-mode)))))
 
 ;;; userlock.el ends here