unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
* New function: rcd-multiple-choice-by-list
@ 2021-05-17 16:58 Jean Louis
  0 siblings, 0 replies; only message in thread
From: Jean Louis @ 2021-05-17 16:58 UTC (permalink / raw)
  To: Help GNU Emacs

I have made this function to help with easier construction of choices
for the new Emacs built-in function `read-multiple-choice'. I am using
this to open up emails in multiple Maildirs. One has to send a
function to it that will act on the value of the choice.

It loops over the choices until user presses `q'.

Sample use:

(rcd-multiple-choice-by-list '("Jimmy" "Johnny" "Laura") 'ignore)

Instead of `ignore' function one can use other function that will act
on the value given by the pressed key.

(defun rcd-multiple-choice-by-list (list rcd-function &optional prompt description)
  "Run RCD-FUNCTION on results of multiple choice LIST of strings.

It uses `q' char to quit thus its value will not be used.
PROMPT is optional just as DESCRIPTION."
  (let* ((prompt (or prompt "Choose: "))
	 (choices '((?q "Quit")))
	 (key ?A))
    (mapc (lambda (item)
	    (when (= key ?q) (setq key (1+ key)))
	    (push (list key item description) choices)
	    (setq key (1+ key)))
	  list)
    (while (not (= 113 key))
      (let* ((selection (read-multiple-choice prompt (reverse choices)))
	     (new-key (car selection))
	     (value (cadr selection)))
	(setq key new-key)
	(unless (= 113 new-key)
	  (funcall rcd-function value))))))


Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

Sign an open letter in support of Richard M. Stallman
https://stallmansupport.org/
https://rms-support-letter.github.io/




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-05-17 16:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-05-17 16:58 New function: rcd-multiple-choice-by-list Jean Louis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).