From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Jean Louis Newsgroups: gmane.emacs.help Subject: New function: rcd-multiple-choice-by-list Date: Mon, 17 May 2021 19:58:29 +0300 Message-ID: Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="21869"; mail-complaints-to="usenet@ciao.gmane.io" To: Help GNU Emacs Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Mon May 17 19:05:00 2021 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ligfs-0005RH-6H for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 May 2021 19:05:00 +0200 Original-Received: from localhost ([::1]:53464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ligfq-0001Ub-Ci for geh-help-gnu-emacs@m.gmane-mx.org; Mon, 17 May 2021 13:04:58 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:42450) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ligaK-0001S9-0q for help-gnu-emacs@gnu.org; Mon, 17 May 2021 12:59:16 -0400 Original-Received: from stw1.rcdrun.com ([217.170.207.13]:57465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1ligaH-0000RP-Km for help-gnu-emacs@gnu.org; Mon, 17 May 2021 12:59:15 -0400 Original-Received: from localhost ([::ffff:154.230.124.187]) (AUTH: PLAIN admin, TLS: TLS1.3,256bits,ECDHE_RSA_AES_256_GCM_SHA384) by stw1.rcdrun.com with ESMTPSA id 00000000000ADF02.0000000060A2A0BF.00000DDF; Mon, 17 May 2021 09:58:38 -0700 Received-SPF: pass client-ip=217.170.207.13; envelope-from=support1@rcdrun.com; helo=stw1.rcdrun.com X-Spam_score_int: 2 X-Spam_score: 0.2 X-Spam_bar: / X-Spam_report: (0.2 / 5.0 requ) BAYES_40=-0.001, HEADER_FROM_DIFFERENT_DOMAINS=0.249, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.io gmane.emacs.help:129835 Archived-At: 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/