1
Fork 0
mirror of git://git.sv.gnu.org/emacs.git synced 2025-12-05 22:20:24 -08:00

Use 'read-char-choice' in 'ask-user-about-lock' (bug#79664)

* lisp/userlock.el (ask-user-about-lock): Use 'read-char-choice'
instead of 'read-char'.

* lisp/subr.el (read-char-choice-with-read-key): Add fallback
cond-branch to show a message with required keys.
This commit is contained in:
Juri Linkov 2025-11-04 20:02:28 +02:00
parent d9ddf0d075
commit 89f0853f1e
2 changed files with 18 additions and 9 deletions

View file

@ -3745,7 +3745,16 @@ causes it to evaluate `help-form' and display the result."
((and (null esc-flag) (eq char ?\e)) ((and (null esc-flag) (eq char ?\e))
(setq esc-flag t)) (setq esc-flag t))
((memq char '(?\C-g ?\e)) ((memq char '(?\C-g ?\e))
(keyboard-quit)))))))) (keyboard-quit))))
(t
(beep)
(message "Please type %s"
(substitute-command-keys
(mapconcat (lambda (c)
(format "\\`%s'"
(single-key-description c)))
chars ", ")))
(sit-for 3))))))
;; Display the question with the answer. But without cursor-in-echo-area. ;; Display the question with the answer. But without cursor-in-echo-area.
(message "%s%s" prompt (char-to-string char)) (message "%s%s" prompt (char-to-string char))
char)) char))

View file

@ -51,7 +51,8 @@ You can redefine this function to choose among those three alternatives
in any way you like." in any way you like."
(discard-input) (discard-input)
(save-window-excursion (save-window-excursion
(let (answer short-opponent short-file) (let ((choices `(?s ?q ?p ?S ?Q ?P ?\C-g ?? ,help-char))
prompt short-opponent short-file answer)
(setq short-file (setq short-file
(if (> (length file) 22) (if (> (length file) 22)
(concat "..." (substring file (- (length file) 22))) (concat "..." (substring file (- (length file) 22)))
@ -63,16 +64,15 @@ in any way you like."
(concat (substring opponent 0 13) "..." (concat (substring opponent 0 13) "..."
(match-string 0 opponent))) (match-string 0 opponent)))
opponent)) opponent))
(setq prompt (format-message
(substitute-command-keys
"%s locked by %s: (\\`s', \\`q', \\`p', \\`?')? ")
short-file short-opponent))
(while (null answer) (while (null answer)
(when noninteractive (when noninteractive
(signal 'file-locked (list file opponent "Cannot resolve lock conflict in batch mode"))) (signal 'file-locked (list file opponent "Cannot resolve lock conflict in batch mode")))
(message (substitute-command-keys (let ((tem (prog1 (downcase (read-char-choice prompt choices t))
"%s locked by %s: (\\`s', \\`q', \\`p', \\`?')? ") (setq quit-flag nil))))
short-file short-opponent)
(let ((tem (let ((inhibit-quit t)
(cursor-in-echo-area t))
(prog1 (downcase (read-char))
(setq quit-flag nil)))))
(if (= tem help-char) (if (= tem help-char)
(ask-user-about-lock-help) (ask-user-about-lock-help)
(setq answer (assoc tem '((?s . t) (setq answer (assoc tem '((?s . t)