From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: Any infrastructure to select one of a few options in Emacs core? Date: Mon, 09 May 2016 20:36:54 +0200 Organization: Informatimago Message-ID: <87wpn3axix.fsf@kuiper.lan.informatimago.com> 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> <877ff3cdec.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: ger.gmane.org 1462819087 19675 80.91.229.3 (9 May 2016 18:38:07 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 May 2016 18:38:07 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Mon May 09 20:37:53 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 1azq3n-0004i7-Av for geh-help-gnu-emacs@m.gmane.org; Mon, 09 May 2016 20:37:39 +0200 Original-Received: from localhost ([::1]:42917 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azq3m-0007UZ-Hk for geh-help-gnu-emacs@m.gmane.org; Mon, 09 May 2016 14:37:38 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58591) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azq3a-0007S3-VX for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:37:28 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1azq3X-0001Os-LM for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:37:26 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:41288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1azq3X-0001OF-7C for help-gnu-emacs@gnu.org; Mon, 09 May 2016 14:37:23 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1azq3T-0004GB-50 for help-gnu-emacs@gnu.org; Mon, 09 May 2016 20:37:19 +0200 Original-Received: from amontsouris-655-1-42-96.w90-44.abo.wanadoo.fr ([90.44.213.96]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 May 2016 20:37:19 +0200 Original-Received: from pjb by amontsouris-655-1-42-96.w90-44.abo.wanadoo.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 May 2016 20:37:19 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 64 Original-X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: amontsouris-655-1-42-96.w90-44.abo.wanadoo.fr Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9 033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR mV+hO/VvFAAAAABJRU5ErkJggg== X-Accept-Language: fr, es, en User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:MTg1N2NiOTJiYWRjMjIwNmQ5YTNiYjY1NjhmZDUwODM3OGQ1YTdkYw== X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:109917 Archived-At: Marcin Borkowski writes: > 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 > > Wat would you like to eat? > > 1. spam > > 2. ham > > 3. eggs > > 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. You can use a popup menu for that. (let ((options '("spam" "ham" "eggs"))) (x-popup-menu (let ((mp (mouse-position))) (list (list (cadr mp) (cddr mp)) (selected-window))) (list "menu" (cons "What would yuo like to eat?" (mapcar (lambda (option) (cons option option)) options))))) -- __Pascal Bourguignon__ http://www.informatimago.com/ “The factory of the future will have only two employees, a man and a dog. The man will be there to feed the dog. The dog will be there to keep the man from touching the equipment.” -- Carl Bass CEO Autodesk