[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master 51176ee: * lisp/emacs-lisp/map-ynp.el (read-answer): Allow more S
From: |
Juri Linkov |
Subject: |
master 51176ee: * lisp/emacs-lisp/map-ynp.el (read-answer): Allow more SHORT-ANSWER types. |
Date: |
Sun, 8 Dec 2019 18:27:36 -0500 (EST) |
branch: master
commit 51176ee81e8e773d8b6ac06dd153846abee0c0f4
Author: Juri Linkov <address@hidden>
Commit: Juri Linkov <address@hidden>
* lisp/emacs-lisp/map-ynp.el (read-answer): Allow more SHORT-ANSWER types.
Treat SHORT-ANSWER as a character is characterp returns non-nil.
Otherwise, use key-description to print it.
Use catch-all [t] in keymap instead of [remap self-insert-command].
(bug#32738)
---
etc/NEWS | 4 ++++
lisp/emacs-lisp/map-ynp.el | 23 ++++++++++++++++++-----
2 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/etc/NEWS b/etc/NEWS
index ff5ac51..ade9fca 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -255,6 +255,10 @@ The default value is 30000, as the previously hard-coded
threshold.
+++
** The function 'read-passwd' uses "*" as default character to hide passwords.
+** The function 'read-answer' now accepts not only single character
+answers, but also function keys like F1, character events such as C-M-h,
+and control characters like C-h.
+
** Lexical binding is now used when evaluating interactive Elisp forms.
More specifically, lexical-binding is now used for 'M-:', '--eval', as
well as in the "*scratch*" and "*ielm*" buffers.
diff --git a/lisp/emacs-lisp/map-ynp.el b/lisp/emacs-lisp/map-ynp.el
index 5c0e28e..a83e2f1 100644
--- a/lisp/emacs-lisp/map-ynp.el
+++ b/lisp/emacs-lisp/map-ynp.el
@@ -287,6 +287,10 @@ where
SHORT-ANSWER is an abbreviated one-character answer,
HELP-MESSAGE is a string describing the meaning of the answer.
+SHORT-ANSWER is not necessarily a single character answer. It can be
+also a function key like F1, a character event such as C-M-h, or
+a control character like C-h.
+
Example:
\\='((\"yes\" ?y \"perform the action\")
(\"no\" ?n \"skip to the next\")
@@ -312,14 +316,18 @@ When `use-dialog-box' is t, pop up a dialog window to get
user input."
(format "%s(%s) " question
(mapconcat (lambda (a)
(if short
- (format "%c" (nth 1 a))
+ (if (characterp (nth 1 a))
+ (format "%c" (nth 1 a))
+ (key-description (nth 1 a)))
(nth 0 a)))
answers-with-help ", ")))
(message
(format "Please answer %s."
(mapconcat (lambda (a)
(format "`%s'" (if short
- (string (nth 1 a))
+ (if (characterp (nth 1 a))
+ (string (nth 1 a))
+ (key-description (nth 1
a)))
(nth 0 a))))
answers-with-help " or ")))
(short-answer-map
@@ -329,13 +337,15 @@ When `use-dialog-box' is t, pop up a dialog window to get
user input."
(let ((map (make-sparse-keymap)))
(set-keymap-parent map minibuffer-local-map)
(dolist (a answers-with-help)
- (define-key map (vector (nth 1 a))
+ (define-key map (if (characterp (nth 1 a))
+ (vector (nth 1 a))
+ (nth 1 a))
(lambda ()
(interactive)
(delete-minibuffer-contents)
(insert (nth 0 a))
(exit-minibuffer))))
- (define-key map [remap self-insert-command]
+ (define-key map [t]
(lambda ()
(interactive)
(delete-minibuffer-contents)
@@ -374,7 +384,10 @@ When `use-dialog-box' is t, pop up a dialog window to get
user input."
(mapconcat
(lambda (a)
(format "`%s'%s to %s"
- (if short (string (nth 1 a)) (nth 0 a))
+ (if short (if (characterp (nth 1 a))
+ (string (nth 1 a))
+ (key-description (nth 1 a)))
+ (nth 0 a))
(if short (format " (%s)" (nth 0 a)) "")
(nth 2 a)))
answers-with-help ",\n")
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master 51176ee: * lisp/emacs-lisp/map-ynp.el (read-answer): Allow more SHORT-ANSWER types.,
Juri Linkov <=