unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Help GNU Emacs <help-gnu-emacs@gnu.org>
Subject: New function: rcd-multiple-choice-by-list
Date: Mon, 17 May 2021 19:58:29 +0300	[thread overview]
Message-ID: <courier.0000000060A2A0BE.00000DDF@stw1.rcdrun.com> (raw)

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/




                 reply	other threads:[~2021-05-17 16:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=courier.0000000060A2A0BE.00000DDF@stw1.rcdrun.com \
    --to=bugs@gnu.support \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).