From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Juri Linkov Newsgroups: gmane.emacs.bugs Subject: bug#32738: 26.1.50; 'read-answer' allows only single characters as short answers Date: Sun, 16 Sep 2018 01:42:37 +0300 Organization: LINKOV.NET Message-ID: <87in361ixu.fsf@mail.linkov.net> References: <83y3c3i12c.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: blaine.gmane.org 1537051568 2690 195.159.176.226 (15 Sep 2018 22:46:08 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 15 Sep 2018 22:46:08 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (x86_64-pc-linux-gnu) Cc: 32738@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 16 00:46:04 2018 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1JKF-0000bF-BT for geb-bug-gnu-emacs@m.gmane.org; Sun, 16 Sep 2018 00:46:03 +0200 Original-Received: from localhost ([::1]:56996 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1JML-0007Pk-IE for geb-bug-gnu-emacs@m.gmane.org; Sat, 15 Sep 2018 18:48:13 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:49357) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1g1JMB-0007PQ-6f for bug-gnu-emacs@gnu.org; Sat, 15 Sep 2018 18:48:04 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1g1JMA-0000Sc-0I for bug-gnu-emacs@gnu.org; Sat, 15 Sep 2018 18:48:03 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:37546) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1g1JM9-0000QT-Rc for bug-gnu-emacs@gnu.org; Sat, 15 Sep 2018 18:48:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1g1JM9-0001aV-Ig for bug-gnu-emacs@gnu.org; Sat, 15 Sep 2018 18:48:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Juri Linkov Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 15 Sep 2018 22:48:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32738 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32738-submit@debbugs.gnu.org id=B32738.15370516786094 (code B ref 32738); Sat, 15 Sep 2018 22:48:01 +0000 Original-Received: (at 32738) by debbugs.gnu.org; 15 Sep 2018 22:47:58 +0000 Original-Received: from localhost ([127.0.0.1]:41804 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1JM5-0001aD-GP for submit@debbugs.gnu.org; Sat, 15 Sep 2018 18:47:58 -0400 Original-Received: from pop.dreamhost.com ([64.90.62.162]:58682 helo=pdx1-sub0-mail-a20.g.dreamhost.com) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1g1JM3-0001a5-H7 for 32738@debbugs.gnu.org; Sat, 15 Sep 2018 18:47:56 -0400 Original-Received: from pdx1-sub0-mail-a20.g.dreamhost.com (localhost [127.0.0.1]) by pdx1-sub0-mail-a20.g.dreamhost.com (Postfix) with ESMTP id 50BFB8103C; Sat, 15 Sep 2018 15:47:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=linkov.net; h=from:to:cc :subject:references:date:in-reply-to:message-id:mime-version :content-type; s=linkov.net; bh=1uVmYGOa68Adq7iU24u9b61DmH4=; b= lVNH3FuerHR22BQGMxksUFdmlWi+mfajEFzNXNhRHxCWc9+YkhTeZtlnDvqD2geX CLnu4aNIDaIgZphQi5x2i4Rca0MkgF7mQT3SzbiddU0FG9lnM6kU7yq2zBrst2eT bjKsO4ZJXrcCdyvxwyfl16i1Dv9TfASIkXvnlrGjc3M= Original-Received: from localhost.linkov.net (m91-129-107-237.cust.tele2.ee [91.129.107.237]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: jurta@jurta.org) by pdx1-sub0-mail-a20.g.dreamhost.com (Postfix) with ESMTPSA id 7734E8103A; Sat, 15 Sep 2018 15:47:52 -0700 (PDT) X-DH-BACKEND: pdx1-sub0-mail-a20 X-DH-BACKEND: pdx1-sub0-mail-a20 In-Reply-To: <83y3c3i12c.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 15 Sep 2018 12:04:27 +0300") X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:150340 Archived-At: > This is a feature request. > > The new function read-answer allows only single-character short answers, > and formats them with %c in the prompt displayed to the user. This has > several disadvantages: > > . Function keys cannot be used as short answers. For example, it > would be good to be able to use F1 for "help", but it is currently > impossible. > > . Character events that aren't valid characters, such as C-M-h, > cannot be used, because %c barfs when it sees a character event > with modifiers (it doesn't pass the 'characterp' test). > > . Control characters, like C-h, are shown as raw bytes, with their > special face, thus standing out unnecessarily. > > It would be nice if these restrictions could be lifted. Do you think it should support only characters with modifiers like C-M-h, or also key sequences? I guess the latter since this will lift all restrictions on the KEY arg of define-key. Since read-answer should still support single-character for backward-compatibility, this means adding key sequences as a new feature, so all of these will work: (read-answer "Question: " `(("help0" ?h "show help") ("help1" ,(kbd "") "show help") ("help2" ,(kbd "C-M-h") "show help") ("help3" ,(kbd "C-h") "show help"))) diff --git a/lisp/emacs-lisp/map-ynp.el b/lisp/emacs-lisp/map-ynp.el index a61c0adc8f..262284aaf1 100644 --- a/lisp/emacs-lisp/map-ynp.el +++ b/lisp/emacs-lisp/map-ynp.el @@ -308,14 +308,18 @@ read-answer (format "%s(%s) " question (mapconcat (lambda (a) (if short - (format "%c" (nth 1 a)) + (if (characterp (nth 1 a)) + (format "%c" (nth 1 a)) + (key-description (nth 1 a))) (nth 0 a))) answers-with-help ", "))) (message (format "Please answer %s." (mapconcat (lambda (a) (format "`%s'" (if short - (string (nth 1 a)) + (if (characterp (nth 1 a)) + (string (nth 1 a)) + (key-description (nth 1 a))) (nth 0 a)))) answers-with-help " or "))) (short-answer-map @@ -325,13 +329,15 @@ read-answer (let ((map (make-sparse-keymap))) (set-keymap-parent map minibuffer-local-map) (dolist (a answers-with-help) - (define-key map (vector (nth 1 a)) + (define-key map (if (characterp (nth 1 a)) + (vector (nth 1 a)) + (nth 1 a)) (lambda () (interactive) (delete-minibuffer-contents) (insert (nth 0 a)) (exit-minibuffer)))) - (define-key map [remap self-insert-command] + (define-key map [t] (lambda () (interactive) (delete-minibuffer-contents) @@ -370,7 +376,10 @@ read-answer (mapconcat (lambda (a) (format "`%s'%s to %s" - (if short (string (nth 1 a)) (nth 0 a)) + (if short (if (characterp (nth 1 a)) + (string (nth 1 a)) + (key-description (nth 1 a))) + (nth 0 a)) (if short (format " (%s)" (nth 0 a)) "") (nth 2 a))) answers-with-help ",\n")