From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: John Mastro Newsgroups: gmane.emacs.help Subject: Re: Any infrastructure to select one of a few options in Emacs core? Date: Fri, 20 May 2016 16:52:30 -0700 Message-ID: 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> <87mvnlers6.fsf@mbork.pl> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1463788652 14146 80.91.229.3 (20 May 2016 23:57:32 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Fri, 20 May 2016 23:57:32 +0000 (UTC) Cc: Oleh Krehel , Kaushal Modi To: Help Gnu Emacs mailing list Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat May 21 01:57:31 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 1b3uIJ-0002kb-2t for geh-help-gnu-emacs@m.gmane.org; Sat, 21 May 2016 01:57:27 +0200 Original-Received: from localhost ([::1]:38176 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3uII-0001CK-Ac for geh-help-gnu-emacs@m.gmane.org; Fri, 20 May 2016 19:57:26 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:51357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3uDs-00055F-L4 for help-gnu-emacs@gnu.org; Fri, 20 May 2016 19:52:53 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1b3uDq-0003ZT-PA for help-gnu-emacs@gnu.org; Fri, 20 May 2016 19:52:51 -0400 Original-Received: from mail-yw0-x234.google.com ([2607:f8b0:4002:c05::234]:32808) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1b3uDq-0003ZJ-KT for help-gnu-emacs@gnu.org; Fri, 20 May 2016 19:52:50 -0400 Original-Received: by mail-yw0-x234.google.com with SMTP id x194so123933804ywd.0 for ; Fri, 20 May 2016 16:52:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=1Awhl29Cg8ZmZ6oatlDscMlsLBRejI+RDZBmG8K1Vg4=; b=Do7yzzU0XQHvogKNgk6sF1AL7LZAQdBMAjjQ2DEH6LJtPHMqVXKPWWrHBzamVq/7AJ m/tXWbSi6FNSEj9rONJm/21M9zcvmGAlAY4U4SjAgzOcvy1/wB51r4xF6W2HlG82Mlww caaJpmF8m8CmBAhzjML3q+jXq0NltkYEY6hUHXhZcbC5u6PlIVkKkwKmh2Zqco8L58t5 q4PWJk0Zv0MvCRUZMXpCUDIF1CcUacg4jN1ZfzwayENb5/kKtDmDByjtWr0ttM98NdIm xW+gRaKneeZhTDhRafqHFQnZ6mKIE+xJ2rFp/whlwb/Lqg+fymM2AYFAMoPSNkAGCFqy Xl7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=1Awhl29Cg8ZmZ6oatlDscMlsLBRejI+RDZBmG8K1Vg4=; b=XGEXMLf6F4sfayCURcyn2BAhyAo10JXSDBuwJGvYvVfBrif4CXmBV8hs5JXB1Ja2Hc Vy0MoxwNcWhVyql7J36bm9s0C4BSq/LBRRhtCXsACHB9msbxrOmOG48k404Uea/a6gb/ 3A4CJ6Ip+JyuFj1zir0d1MFC7zXjTRW/8tJQlEJXgGXrp0gNe0QLyyRXXWHvOSMNxjQS HFT/EniJ+N17A0bHPMGSx8Ela1m4B/dIvHW2KguazCYtU7iqk5DnlmHv42xpS1U64Mtb mJEFyNeCqI+Sf3XDKcNLITKdufLGhP+Qso2m+B+idJkC4gqPYmcN/coLXuZ22OR8m85J 9PAA== X-Gm-Message-State: AOPr4FXVekDbGo9BwYk3l4gSnTjot+gyYNOkZ6djo4PsMVqDav4kumpLdzVFotNW+vZf2TDEziOmyCA5FHNsDg== X-Received: by 10.129.106.196 with SMTP id f187mr3410056ywc.262.1463788370048; Fri, 20 May 2016 16:52:50 -0700 (PDT) Original-Received: by 10.37.98.203 with HTTP; Fri, 20 May 2016 16:52:30 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:4002:c05::234 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:110082 Archived-At: John Mastro wrote: > I played around with a few cosmetic changes to your function and ended > up with this: I realized that, for my use case, it makes more sense to let the caller specify the characters rather than automatically using the digits 1-9. So I ended up with this instead, which is also a bit shorter and simpler. (defun read-choice (prompt choices) (let ((cursor-in-echo-area t) (prompt (if (get-text-property 0 'face prompt) prompt (propertize prompt 'face 'minibuffer-prompt)))) (save-window-excursion (pop-to-buffer " *Read choice*" t t) (setq-local cursor-type nil) (erase-buffer) (pcase-dolist (`(,char ,description) choices) (insert (propertize (string char) 'face 'font-lock-variable-name-face) (format " %s\n" description))) (goto-char (point-min)) (fit-window-to-buffer) (or (assoc (read-key prompt) choices) (user-error "Invalid selection"))))) In Emacs's master branch (but not the emacs-25 release branch) there's a new function `read-multiple-choice' that's similar in purpose and worth a look. John