From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Stephen Berman Newsgroups: gmane.emacs.bugs Subject: bug#64046: 30.0.50; Quoting in customize choice tags Date: Thu, 15 Jun 2023 13:39:34 +0200 Message-ID: <87o7lhrm2x.fsf@gmx.net> References: <87v8frihny.fsf@gmx.net> <837cs7we2z.fsf@gnu.org> <47e13491-1654-db22-2f8b-f12195953232@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="18107"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , Stefan Monnier , 64046@debbugs.gnu.org To: Mauro Aranda Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Jun 15 13:40:23 2023 Return-path: Envelope-to: geb-bug-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 1q9lKv-0004Tq-Dw for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 15 Jun 2023 13:40:21 +0200 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1q9lKf-0006AQ-PN; Thu, 15 Jun 2023 07:40:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1q9lKd-0006A1-9l for bug-gnu-emacs@gnu.org; Thu, 15 Jun 2023 07:40:03 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1q9lKc-0008I1-71 for bug-gnu-emacs@gnu.org; Thu, 15 Jun 2023 07:40:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1q9lKb-0001tX-L2 for bug-gnu-emacs@gnu.org; Thu, 15 Jun 2023 07:40:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Stephen Berman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 15 Jun 2023 11:40:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 64046 X-GNU-PR-Package: emacs Original-Received: via spool by 64046-submit@debbugs.gnu.org id=B64046.16868291897252 (code B ref 64046); Thu, 15 Jun 2023 11:40:01 +0000 Original-Received: (at 64046) by debbugs.gnu.org; 15 Jun 2023 11:39:49 +0000 Original-Received: from localhost ([127.0.0.1]:46306 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9lKO-0001su-An for submit@debbugs.gnu.org; Thu, 15 Jun 2023 07:39:48 -0400 Original-Received: from mout.gmx.net ([212.227.17.21]:38245) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1q9lKL-0001sg-OA for 64046@debbugs.gnu.org; Thu, 15 Jun 2023 07:39:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=s31663417; t=1686829176; x=1687433976; i=stephen.berman@gmx.net; bh=Hy+5JGTqKC7MavSzSfTQy2C28xWdvWj6MALpBFS36o8=; h=X-UI-Sender-Class:From:To:Cc:Subject:In-Reply-To:References:Date; b=a+z5FE4WJUOOdOqFTWTKW6+gf93KBkaEQPbNLxpEySR9YDAs8vFzMXykSdd2imS1pdBA6Bx ffQFpzjaqYqUF2JuCZEmOPyMwAKJJ6tN3Yt1fB6mfLPo2eWCLQ6fOwtliTL7V4hoNcfEXZfAo /2RVNenHtLaf6YNUrlinadzUksfr7J76ag749n91KJpAU2ZrJoLwzU/7kVyavpy2s+4cSB9li mJm4i2pVXJm+ptJAiKTbu7trsgx2EDPKiSsrUj+0jTJgbjK9GICYwWqJT4snRUtkem4drEPC6 9UFmBUmE8TaQa5dyX8Rx2dEfi553gIQJg9XnXG0hSP5z/+/6lbHg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Original-Received: from strobelfs ([94.134.196.158]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1N1wll-1pyn2X12nB-012LJN; Thu, 15 Jun 2023 13:39:36 +0200 In-Reply-To: <47e13491-1654-db22-2f8b-f12195953232@gmail.com> (Mauro Aranda's message of "Wed, 14 Jun 2023 17:05:32 -0300") X-Provags-ID: V03:K1:urEoVPL8rz+Jd+W5mrnvA+Sn5J8ha/2/0ryfAzVrrROt/nNXy/K CmJtQhSG9Tklyx21FnzfrVpd4mWGmu1dr3AY1lEWizdyqHE+Fwj61uvnkmcSft3kIaEXrWs AHvIiTr3cty6C+1AdCvbZIG19pBqO9dfBOxfMSSpne0Qo6wwMCj6DfrZWzkMcPUAvYebaHY VhS2Z7OYLr7qYI9IpJu7Q== UI-OutboundReport: notjunk:1;M01:P0:7xLDO7gVsqw=;zY2UnOxTNLrWyxD0LgLDi+2iQ+M v9GdDzuMkzJL2STrdVDBnN3YJEaXfySmNUJHbtUP2D5eE0/2JN8kHBCOqyNeH1O7RwXrxErFN hxP3ksqTLSpPMVhAD8k0/b/XdQDKbHDJ/N5psCp3Q8DmtPYv4Qso8f0EGWCVUCK8DaBzHji9z z8GUSYwGLCprimFuDmjwHx7q782yZOabGjpaeTKB2RnIrQ4FOn5ji2kGIuPF8KTSEfctmT8YP 0TY5555Z5PbpTiylPT3xNNWr7QiRQcShx8hNb/1e3f3xbpsAiSNF8vx+DQenTX7ORiXzup50A EAmXT7PRHQnB78vPimA8SFl9q9McccWlYmofNUz7jM9OVccvaM4H0X9E+M48/LAoVMkHzfkg5 /9s99EYdD+KWb6yEDTf5areIlYZlvT+Hr7knKwNsxDKSptXMmDE5HwaEYeRYMvxwgy1/VWQ1r JiL4loyPBQOpkMlYlbvOmQOF2VaH2G+nwhd+74GFoyTb9hDwGvTSqDNMQuoTlHJPlF2KUdjs6 qOj4ZlO6JMzTT/4p4axWsbPpEoJ1w628GJL7+9JEe15TuD+3slGW974iQG3bvpK88pF6t+e0j y8/0QbpL/1EbEbqR1dchnKOVJvvig0qBmajq9QTHLaf3lEU1QM8Z3YBSY/XvX/Wx6ol6HjAxj ZLstAazUToJWDX+r5/DVH8tERfi8EpLREZFAEOP5terBZVHWcbynx2tiXvgv1cVznqwoOs/3w ER/SxxCJ+2GvWxBAYRfGY7F1z6xgFzWF4VBfiNHQGSA5aqSS6oYbo8UI+fpK7vMH7lks9AnZ X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:263421 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable On Wed, 14 Jun 2023 17:05:32 -0300 Mauro Aranda wr= ote: > Stephen Berman writes: > >> 0. emacs -Q >> 1. Evaluate the following defcustom: >>=C2=A0=C2=A0=C2=A0 (defcustom my-test "a" >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 "Test." >>=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 :type '(choice (string :tag "Use `a'" "a") >>=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 (string :tag "Use `b'" "b"))) >> 2. M-x customize-option RET my-test RET >> 3. In the buffer *Customize Option: My Test* note that in the string >>=C2=A0=C2=A0=C2=A0 "Use =E2=80=98a=E2=80=99" following the "Value Menu" b= utton the quote marks are in >>=C2=A0=C2=A0=C2=A0 the "curve" style (=E2=80=98=E2=80=99). >> 4. Put point on the "Value Menu" button and type RET. >> 5. The buffer " widget-choose" contains these lines: >>=C2=A0=C2=A0=C2=A0 0 =3D Use =E2=80=98a=E2=80=99 >>=C2=A0=C2=A0=C2=A0 1 =3D Use =E2=80=98b=E2=80=99 >>=C2=A0=C2=A0=C2=A0 Note that the quote marks in this buffer are also in t= he "curve" >>=C2=A0=C2=A0=C2=A0 style. >> 6. With the mouse pointer over the "Value Menu" button press mouse-1, >>=C2=A0=C2=A0=C2=A0 popping up a menu titled "Choice" containing these ite= ms: >>=C2=A0=C2=A0=C2=A0 Use `a' >>=C2=A0=C2=A0=C2=A0 Use `b' >>=C2=A0=C2=A0=C2=A0 Note that the quote marks in this menu are in the "gra= ve" style (`') >>=C2=A0=C2=A0=C2=A0 instead of the "curve" style. >> >> The use of the "curve" style in the " widget-choose" buffer is due to >> commit bd3b426ebb7a60045839e97c9da9bfd249fab1f1, but that commit did not >> take popup menus into account.=C2=A0 The attached patch does so. Since t= he >> status quo ante long predates emacs-29 and this is just a stylistic bug, >> I made the patch against master. >> >> In this patch I chose to apply substitute-command-keys just once at the >> beginning of the function `widget-choose', rather than several times >> within the function, but I restricted its application to item tags, so >> other uses of the ITEMS argument should not be affected (and my brief >> testing hasn't found any problem with the patch). > > By moving the call to substitute-command-keys to the beginning, extended > menus simplified with widget--simplify-menu don't benefit anymore from > it.=C2=A0 Perhaps that won't ever show up as a problem, but I think we sh= ould > guard against that. > > To do that, maybe widget--simplify-menu can call substitute-command-keys > when it builds the simplified menu. Thanks for the feedback. You're right, that patch is too superficial; it also fails to do substitution in popup extended menus like the one produced by clicking the "State" button, with the result that in the item "Revert This Session's Customization" the apostrophe is not displayed in the "curve" style. So I revised the patch, attached below, to iterate over the elements of each item in ITEMS, and it now appears to handle substitution with the "State" button display correctly, both as popup menu and as text menu buffer. The latter is the result of applying widget--simplify-menu, if I debugged correctly, so I think this answers your concerns (though the text menu buffer already shows the substitution independently of my patch, due to commit bd3b426ebb). Or have I misunderstood your concerns about widget--simplify-menu? If so, can you give an example where the new patch fails? Steve Berman --=-=-= Content-Type: text/x-patch Content-Disposition: attachment Content-Description: widget-choose patch Content-Transfer-Encoding: quoted-printable diff --git a/lisp/wid-edit.el b/lisp/wid-edit.el index cafd0ad0a4d..234f3d9b74d 100644 =2D-- a/lisp/wid-edit.el +++ b/lisp/wid-edit.el @@ -281,71 +281,79 @@ widget-choose If ITEMS has simple item definitions, then this function returns the VALU= E of the chosen element. If ITEMS is a keymap, then the return value is the s= ymbol in the key vector, as in the argument of `define-key'." - (cond ((and (< (length items) widget-menu-max-size) - event (display-popup-menus-p)) - ;; Mouse click. - (if (keymapp items) - ;; Modify the keymap prompt, and then restore the old one, i= f any. - (let ((prompt (keymap-prompt items))) - (unwind-protect - (progn - (setq items (delete prompt items)) - (push title (cdr items)) - ;; Return just the first element of the list of even= ts. - (car (x-popup-menu event items))) - (setq items (delete title items)) - (when prompt - (push prompt (cdr items))))) - (x-popup-menu event (list title (cons "" items))))) - ((or widget-menu-minibuffer-flag - (> (length items) widget-menu-max-shortcuts)) - (when (keymapp items) - (setq items (widget--simplify-menu items))) - ;; Read the choice of name from the minibuffer. - (setq items (cl-remove-if 'stringp items)) - (let ((val (completing-read (concat title ": ") items nil t))) - (if (stringp val) - (let ((try (try-completion val items))) - (when (stringp try) - (setq val try)) - (cdr (assoc val items)))))) - (t - (when (keymapp items) - (setq items (widget--simplify-menu items))) - ;; Construct a menu of the choices - ;; and then use it for prompting for a single character. - (let* ((next-digit ?0) - alist choice some-choice-enabled value) - (with-current-buffer (get-buffer-create " widget-choose") - (erase-buffer) - (insert "Available choices:\n\n") - (while items - (setq choice (pop items)) - (when (consp choice) - (let* ((name (substitute-command-keys (car choice))) - (function (cdr choice))) - (insert (format "%c =3D %s\n" next-digit name)) - (push (cons next-digit function) alist) - (setq some-choice-enabled t))) - ;; Allocate digits to disabled alternatives - ;; so that the digit of a given alternative never varies. - (setq next-digit (1+ next-digit))) - (insert "\nC-g =3D Quit") - (goto-char (point-min)) - (forward-line)) - (or some-choice-enabled - (error "None of the choices is currently meaningful")) - (save-window-excursion - ;; Select window to be able to scroll it from minibuffer - (with-selected-window - (display-buffer (get-buffer " widget-choose") - '(display-buffer-in-direction - (direction . bottom) - (window-height . fit-window-to-buffer)= )) - (setq value (read-char-choice - (format "%s: " title) - (mapcar #'car alist))))) - (cdr (assoc value alist)))))) + ;; Apply quote substitution to customize choice menu item text, + ;; whether it occurs in a widget buffer or in a popup menu. + (let ((items (mapc (lambda (x) + (when (consp x) + (dotimes (i (1- (length x))) + (when (char-or-string-p (nth i x)) + (setcar (nthcdr i x) + (substitute-command-keys + (car (nthcdr i x)))))))) + items))) + (cond ((and (< (length items) widget-menu-max-size) + event (display-popup-menus-p)) + ;; Mouse click. + (if (keymapp items) + ;; Modify the keymap prompt, and then restore the old one,= if any. + (let ((prompt (keymap-prompt items))) + (unwind-protect + (progn + (setq items (delete prompt items)) + (push title (cdr items)) + ;; Return just the first element of the list of ev= ents. + (car (x-popup-menu event items))) + (setq items (delete title items)) + (when prompt + (push prompt (cdr items))))) + (x-popup-menu event (list title (cons "" items))))) + ((or widget-menu-minibuffer-flag + (> (length items) widget-menu-max-shortcuts)) + (when (keymapp items) + (setq items (widget--simplify-menu items))) + ;; Read the choice of name from the minibuffer. + (setq items (cl-remove-if 'stringp items)) + (let ((val (completing-read (concat title ": ") items nil t))) + (if (stringp val) + (let ((try (try-completion val items))) + (when (stringp try) + (setq val try)) + (cdr (assoc val items)))))) + (t + (when (keymapp items) + (setq items (widget--simplify-menu items))) + ;; Construct a menu of the choices + ;; and then use it for prompting for a single character. + (let ((next-digit ?0) + alist choice some-choice-enabled value) + (with-current-buffer (get-buffer-create " widget-choose") + (erase-buffer) + (insert "Available choices:\n\n") + (while items + (setq choice (pop items)) + (when (consp choice) + (insert (format "%c =3D %s\n" next-digit (car choice))= ) + (push (cons next-digit (cdr choice)) alist) + (setq some-choice-enabled t)) + ;; Allocate digits to disabled alternatives + ;; so that the digit of a given alternative never varies. + (setq next-digit (1+ next-digit))) + (insert "\nC-g =3D Quit") + (goto-char (point-min)) + (forward-line)) + (or some-choice-enabled + (error "None of the choices is currently meaningful")) + (save-window-excursion + ;; Select window to be able to scroll it from minibuffer + (with-selected-window + (display-buffer (get-buffer " widget-choose") + '(display-buffer-in-direction + (direction . bottom) + (window-height . fit-window-to-buffe= r))) + (setq value (read-char-choice + (format "%s: " title) + (mapcar #'car alist))))) + (cdr (assoc value alist))))))) ;;; Widget text specifications. ;; --=-=-=--