mu4e-helpers: allow passing key to mu4e-read-option
Can be useful for non-interactive use.
This commit is contained in:
@ -174,14 +174,14 @@ If optional KEY is provided, use that instead of asking user."
|
|||||||
(let ((choice) (chosen) (inhibit-quit nil))
|
(let ((choice) (chosen) (inhibit-quit nil))
|
||||||
(while (not chosen)
|
(while (not chosen)
|
||||||
(message nil);; this seems needed...
|
(message nil);; this seems needed...
|
||||||
(setq choice (read-char-exclusive prompt))
|
(setq choice (or key (read-char-exclusive prompt)))
|
||||||
(if (eq choice 27) (keyboard-quit)) ;; quit if ESC is pressed
|
(if (eq choice 27) (keyboard-quit)) ;; quit if ESC is pressed
|
||||||
(setq chosen (or (member choice choices)
|
(setq chosen (or (member choice choices)
|
||||||
(member (downcase choice) choices)
|
(member (downcase choice) choices)
|
||||||
(member (upcase choice) choices))))
|
(member (upcase choice) choices))))
|
||||||
(car chosen)))
|
(car chosen)))
|
||||||
|
|
||||||
(defun mu4e-read-option (prompt options)
|
(defun mu4e-read-option (prompt options &optional key)
|
||||||
"Ask user for an option from a list on the input area.
|
"Ask user for an option from a list on the input area.
|
||||||
PROMPT describes a multiple-choice question to the user. OPTIONS
|
PROMPT describes a multiple-choice question to the user. OPTIONS
|
||||||
describe the options, and is a list of cells describing
|
describe the options, and is a list of cells describing
|
||||||
@ -202,6 +202,9 @@ user can then choose by typing CHAR. Example:
|
|||||||
User now will be presented with a list: \"Choose an animal:
|
User now will be presented with a list: \"Choose an animal:
|
||||||
[M]onkey, [G]nu, [x]Moose\".
|
[M]onkey, [G]nu, [x]Moose\".
|
||||||
|
|
||||||
|
If optional character KEY is provied, use that instead of asking
|
||||||
|
the user.
|
||||||
|
|
||||||
Function returns the cdr of the list element."
|
Function returns the cdr of the list element."
|
||||||
(let* ((prompt (mu4e-format "%s" prompt))
|
(let* ((prompt (mu4e-format "%s" prompt))
|
||||||
(optionsstr
|
(optionsstr
|
||||||
@ -223,7 +226,8 @@ Function returns the cdr of the list element."
|
|||||||
" [" (propertize "C-g" 'face 'mu4e-highlight-face)
|
" [" (propertize "C-g" 'face 'mu4e-highlight-face)
|
||||||
" to cancel]")
|
" to cancel]")
|
||||||
;; the allowable chars
|
;; the allowable chars
|
||||||
(seq-map (lambda(elm) (string-to-char (car elm))) options)))
|
(seq-map (lambda(elm) (string-to-char (car elm))) options)
|
||||||
|
key))
|
||||||
(chosen
|
(chosen
|
||||||
(seq-find
|
(seq-find
|
||||||
(lambda (option) (eq response (string-to-char (car option))))
|
(lambda (option) (eq response (string-to-char (car option))))
|
||||||
|
|||||||
Reference in New Issue
Block a user