From 89f0853f1e902778076ae63d0cb21f99d824cbac Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Tue, 4 Nov 2025 20:02:28 +0200 Subject: [PATCH] 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. --- lisp/subr.el | 11 ++++++++++- lisp/userlock.el | 16 ++++++++-------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/lisp/subr.el b/lisp/subr.el index ef08618f467..a5f8ead0a1b 100644 --- a/lisp/subr.el +++ b/lisp/subr.el @@ -3745,7 +3745,16 @@ causes it to evaluate `help-form' and display the result." ((and (null esc-flag) (eq char ?\e)) (setq esc-flag t)) ((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. (message "%s%s" prompt (char-to-string char)) char)) diff --git a/lisp/userlock.el b/lisp/userlock.el index 583e13e8b2f..9c1c73cbc8c 100644 --- a/lisp/userlock.el +++ b/lisp/userlock.el @@ -51,7 +51,8 @@ You can redefine this function to choose among those three alternatives in any way you like." (discard-input) (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 (if (> (length file) 22) (concat "..." (substring file (- (length file) 22))) @@ -63,16 +64,15 @@ in any way you like." (concat (substring opponent 0 13) "..." (match-string 0 opponent))) opponent)) + (setq prompt (format-message + (substitute-command-keys + "%s locked by %s: (\\`s', \\`q', \\`p', \\`?')? ") + short-file short-opponent)) (while (null answer) (when noninteractive (signal 'file-locked (list file opponent "Cannot resolve lock conflict in batch mode"))) - (message (substitute-command-keys - "%s locked by %s: (\\`s', \\`q', \\`p', \\`?')? ") - short-file short-opponent) - (let ((tem (let ((inhibit-quit t) - (cursor-in-echo-area t)) - (prog1 (downcase (read-char)) - (setq quit-flag nil))))) + (let ((tem (prog1 (downcase (read-char-choice prompt choices t)) + (setq quit-flag nil)))) (if (= tem help-char) (ask-user-about-lock-help) (setq answer (assoc tem '((?s . t)