help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New function: rcd-multiple-choice-by-list


From: Jean Louis
Subject: New function: rcd-multiple-choice-by-list
Date: Mon, 17 May 2021 19:58:29 +0300

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 via email to

[Prev in Thread] Current Thread [Next in Thread]