From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcin Borkowski Newsgroups: gmane.emacs.help Subject: Re: Any infrastructure to select one of a few options in Emacs core? Date: Mon, 09 May 2016 20:08:43 +0200 Message-ID: <877ff3cdec.fsf@mbork.pl> References: <87shxrczlt.fsf@mbork.pl> <12f1c4cf-ee4a-444e-bfc3-1e703d3ad50d@default> <87h9e7ck96.fsf@mbork.pl> <878tzjcg3x.fsf@mbork.pl> <86f9c662-a9ec-4bf5-ab0d-8f66d4e0fcf5@default> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1462817356 23764 80.91.229.3 (9 May 2016 18:09:16 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 May 2016 18:09:16 +0000 (UTC) Cc: Help Gnu Emacs mailing list , Oleh Krehel , Kaushal Modi To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 09 20:09:09 2016 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1azpcB-0006J1-Iz for geh-help-gnu-emacs@m.gmane.org; Mon, 09 May 2016 20:09:07 +0200 Original-Received: from localhost ([::1]:42776 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpcA-0007Hd-Li for geh-help-gnu-emacs@m.gmane.org; Mon, 09 May 2016 14:09:06 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49489) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpbz-0007DT-RG for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:08:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azpbu-0001Lq-Pc for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:08:54 -0400 Original-Received: from mail.mojserwer.eu ([2a01:5e00:2:52::8]:45707) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azpbu-0001Lf-I1 for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:08:50 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by mail.mojserwer.eu (Postfix) with ESMTP id CC887B520D6; Mon, 9 May 2016 20:08:49 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mail.mojserwer.eu Original-Received: from mail.mojserwer.eu ([127.0.0.1]) by localhost (mail.mojserwer.eu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id k1qJvca3vtQz; Mon, 9 May 2016 20:08:47 +0200 (CEST) Original-Received: from localhost (98-171.echostar.pl [213.156.98.171]) by mail.mojserwer.eu (Postfix) with ESMTPSA id 4659AB520D3; Mon, 9 May 2016 20:08:47 +0200 (CEST) User-agent: mu4e 0.9.13; emacs 25.1.50.9 In-reply-to: <86f9c662-a9ec-4bf5-ab0d-8f66d4e0fcf5@default> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 2a01:5e00:2:52::8 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "help-gnu-emacs" Xref: news.gmane.org gmane.emacs.help:109915 Archived-At: On 2016-05-09, at 19:27, Drew Adams wrote: >> > completing-read >> >> Yes and no. I thought about it, and rejected the idea: I want all the >> options to be visible without pressing TAB. Also, each option might >> need more than one line (and the number of lines may vary between >> options), so I don't like the idea of using minibuffer at all. > > It's still not clear from your description what you mean by "select" > one of the options. OK, so let us assume that I want the user to select one of the three strings: "spam", "eggs" and "emacs". (Note: in my use case they would not be string literals.) Then, I'd like to be able to say, e.g., something like this: (ask-user-for-option "What would you like to eat?" '("spam" "ham" "eggs")) and have something like --8<---------------cut here---------------start------------->8--- Wat would you like to eat? 1. spam 2. ham 3. eggs --8<---------------cut here---------------end--------------->8--- displayed (perhaps in a *temp* buffer or so), and wait for the user to press 1, 2 or 3. Then, the above form returns the selected string. It would probably be also useful to be able to give it e.g. cons cells with the car being the string and the cdr the value returned in case of selecting this particular string. Also, it should be customizable: one user might like digit keys, another one letters, for instance. Also, the choices should be clickable for those poor souls addicted to rodents. In a more advanced scenario, the menu might be "non-modal", i.e. do not use `read-key' or something like that, but a dynamically crafted mode (probably descendant of special-mode), in which various keys/clicks would launch a callback function given to the hypothetical `ask-user-for-option' with the selected choice as a parameter. Best, -- Marcin Borkowski http://octd.wmi.amu.edu.pl/en/Marcin_Borkowski Faculty of Mathematics and Computer Science Adam Mickiewicz University