From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: "Basil L. Contovounesios" Newsgroups: gmane.emacs.devel Subject: Re: Escaping a string for substitute-command-keys Date: Sat, 05 Oct 2019 20:53:48 +0100 Message-ID: <87k19jrmsz.fsf@tcd.ie> References: <14423aa7-36c3-9ab7-6483-d43624f99e17@gmail.com> <83pnjd7pud.fsf@gnu.org> <83h84p7nih.fsf@gnu.org> <875zl32ob0.fsf@tcd.ie> <831rvr41p2.fsf@gnu.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="49189"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: cpitclaudel@gmail.com, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Oct 05 21:54:07 2019 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([209.51.188.17]) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1iGq7y-000Cg8-RN for ged-emacs-devel@m.gmane.org; Sat, 05 Oct 2019 21:54:07 +0200 Original-Received: from localhost ([::1]:58652 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGq7x-0005w3-P5 for ged-emacs-devel@m.gmane.org; Sat, 05 Oct 2019 15:54:05 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:38768) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iGq7q-0005vw-Rx for emacs-devel@gnu.org; Sat, 05 Oct 2019 15:54:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iGq7p-0003H6-69 for emacs-devel@gnu.org; Sat, 05 Oct 2019 15:53:58 -0400 Original-Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]:41298) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iGq7o-0003Gd-MD for emacs-devel@gnu.org; Sat, 05 Oct 2019 15:53:57 -0400 Original-Received: by mail-wr1-x42c.google.com with SMTP id q9so10837838wrm.8 for ; Sat, 05 Oct 2019 12:53:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tcd-ie.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=4orewQhuCwpf/gaOSlqM2w43LrNgNvg3fRgXHqgDObI=; b=TuAG1/iEvtAL6jVmPHVyXRcrY0o/FaYrJ0BKHj8Rc2jiKwVY4uKS26ovfRS563WIuG ZKOQ1l3iwx8J8koR4WuyuZufPRYdGs0pm5LsUuc4lIH8iOiw/S3fVgwRrS5tB4w+Xvzv jjYooFDPGMjVATycosAZpVzTsEZXNKI1icgeGzc5bL+ka+S1tVaB2qHLFWX4PZTkMVWR 8vF21l6Bivi44HYzFABsF67tWracS7H3gCQRhO+syYWzkPHMsaVTChATm65sANLdqDvi ENZBhZ1BFCvuJqQdld1p4Y6UOx5wSqyNHp2lsRPAevJpBIenW9HzIIa1ZR2GWb7auEjh dQVA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=4orewQhuCwpf/gaOSlqM2w43LrNgNvg3fRgXHqgDObI=; b=tjdyS9bY8mFNXsBpLKa5Z651LZLw2HWbaDG5hZ2rRKrVq4t1kuxQzesQKfdo4T8omy KNb/txzkIf4J5JGa2BEieU05E++6dTJ7tR5yBqosr8aUJLjQjhwfxvnzBlIW4DLeA0c+ niJDPZ2VN5U4XzZT0O9fsvpxW1N0BSefxABCaQsjxs86hQ5/w4syMsUANF9kRcAk/dUG dJIoPCc5qRojYZ0nnNB0qQptKq3WvApNWRbrUzzC2VSpaMP1MsAnas7c5a7jCrWeyM9Z uWDl/bJOTEv7TOdMU9UcjtnK82l4QMnT9prHLDocczzIPAWtFlfdO5Acz9WK0Qv9NyHK 4qRQ== X-Gm-Message-State: APjAAAUKeNrxOyNtdILL6a2BApL7vscZFfBMnMPB0CJCWHKdm331aaWq 6yDiXU8n+CE4bOHvi7OuBk9Ugg== X-Google-Smtp-Source: APXvYqzVnkEvKnC1M8NgR5N378OVYomy+ysVwQdBpoXEukHjilNDKKTarjb2cG4p8TirON8YPAjGtg== X-Received: by 2002:a5d:4ecf:: with SMTP id s15mr15891418wrv.234.1570305235004; Sat, 05 Oct 2019 12:53:55 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id f8sm8310262wmb.37.2019.10.05.12.53.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2019 12:53:54 -0700 (PDT) In-Reply-To: <831rvr41p2.fsf@gnu.org> (Eli Zaretskii's message of "Sat, 05 Oct 2019 19:06:01 +0300") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::42c X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:240632 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Eli Zaretskii writes: >> From: "Basil L. Contovounesios" >> Cc: Cl=C3=A9ment Pit-Claudel , Eli >> Zaretskii >> , emacs-devel@gnu.org >> Date: Sat, 05 Oct 2019 16:40:35 +0100 >>=20 >> Another source of inconsistency is {forward,backward}-button, which >> display help-echo values in the echo area when called interactively. >> Currently, they perform no command name substitution. Should they? > > IMO, all displays of help-echo should look the same way. So, would something like the following be acceptable? Cl=C3=A9ment, do you envision this working against any of your planned changes? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Substitute-command-keys-in-button-help-echo-values.patch >From 745a68d371d20fa3a98e3ea0e270e477d85a11d0 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Sat, 5 Oct 2019 19:51:38 +0100 Subject: [PATCH] Substitute command keys in button help-echo values For consistency with tooltips displayed via show-help-function, make forward-button also substitute command keys in the help-echo values it displays in the echo area. For discussion, see the following thread: https://lists.gnu.org/archive/html/emacs-devel/2019-10/msg00090.html * lisp/button.el (button--help-echo): Pass resulting string through substitute-command-keys for consistency with show-help-function. * test/lisp/button-tests.el (button-tests--map): New test keymap. (button--help-echo-string, button--help-echo-form) (button--help-echo-function): Use it to test command key substitution in help-echo strings. --- lisp/button.el | 18 ++++++++++++------ test/lisp/button-tests.el | 35 ++++++++++++++++++++++------------- 2 files changed, 34 insertions(+), 19 deletions(-) diff --git a/lisp/button.el b/lisp/button.el index 04e77ca904..8d073aaceb 100644 --- a/lisp/button.el +++ b/lisp/button.el @@ -468,12 +468,18 @@ push-button t)))) (defun button--help-echo (button) - "Evaluate BUTTON's `help-echo' property and return its value." - (let ((help (button-get button 'help-echo))) - (if (functionp help) - (let ((obj (if (overlayp button) button (current-buffer)))) - (funcall help (selected-window) obj (button-start button))) - (eval help lexical-binding)))) + "Evaluate BUTTON's `help-echo' property and return its value. +If the result is non-nil, pass it through +`substitute-command-keys' before returning it, as is done for +`show-help-function'." + (let* ((help (button-get button 'help-echo)) + (help (if (functionp help) + (funcall help + (selected-window) + (if (overlayp button) button (current-buffer)) + (button-start button)) + (eval help lexical-binding)))) + (and help (substitute-command-keys help)))) (defun forward-button (n &optional wrap display-message no-error) "Move to the Nth next button, or Nth previous button if N is negative. diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el index 44a7ea6f6e..73e3a764b3 100644 --- a/test/lisp/button-tests.el +++ b/test/lisp/button-tests.el @@ -21,6 +21,12 @@ (require 'ert) +(defvar button-tests--map + (let ((map (make-sparse-keymap))) + (define-key map "x" #'ignore) + map) + "Keymap for testing command substitution.") + (ert-deftest button-at () "Test `button-at' behavior." (with-temp-buffer @@ -41,11 +47,13 @@ button--help-echo-string "Test `button--help-echo' with strings." (with-temp-buffer ;; Text property buttons. - (let ((button (insert-text-button "text" 'help-echo "text help"))) - (should (equal (button--help-echo button) "text help"))) + (let ((button (insert-text-button + "text" 'help-echo "text: \\\\[ignore]"))) + (should (equal (button--help-echo button) "text: x"))) ;; Overlay buttons. - (let ((button (insert-button "overlay" 'help-echo "overlay help"))) - (should (equal (button--help-echo button) "overlay help"))))) + (let ((button (insert-button "overlay" 'help-echo + "overlay: \\\\[ignore]"))) + (should (equal (button--help-echo button) "overlay: x"))))) (ert-deftest button--help-echo-form () "Test `button--help-echo' with forms." @@ -55,16 +63,17 @@ button--help-echo-form (form `(funcall (let ((,help "lexical form")) (lambda () ,help)))) (button (insert-text-button "text" 'help-echo form))) - (set help "dynamic form") - (should (equal (button--help-echo button) "dynamic form"))) + (set help "dynamic: \\\\[ignore]") + (should (equal (button--help-echo button) "dynamic: x"))) ;; Test overlay buttons with lexical scoping. (setq lexical-binding t) (let* ((help (make-symbol "help")) - (form `(funcall (let ((,help "lexical form")) - (lambda () ,help)))) + (form `(funcall + (let ((,help "lexical: \\\\[ignore]")) + (lambda () ,help)))) (button (insert-button "overlay" 'help-echo form))) (set help "dynamic form") - (should (equal (button--help-echo button) "lexical form"))))) + (should (equal (button--help-echo button) "lexical: x"))))) (ert-deftest button--help-echo-function () "Test `button--help-echo' with functions." @@ -77,9 +86,9 @@ button--help-echo-function (should (eq win owin)) (should (eq obj obuf)) (should (= pos opos)) - "text function")) + "text: \\\\[ignore]")) (button (insert-text-button "text" 'help-echo help))) - (should (equal (button--help-echo button) "text function")) + (should (equal (button--help-echo button) "text: x")) ;; Overlay buttons. (setq help (lambda (win obj pos) (should (eq win owin)) @@ -88,9 +97,9 @@ button--help-echo-function (should (eq (overlay-buffer obj) obuf)) (should (= (overlay-start obj) opos)) (should (= pos opos)) - "overlay function")) + "overlay: \\\\[ignore]")) (setq opos (point)) (setq button (insert-button "overlay" 'help-echo help)) - (should (equal (button--help-echo button) "overlay function"))))) + (should (equal (button--help-echo button) "overlay: x"))))) ;;; button-tests.el ends here -- 2.23.0 --=-=-= Content-Type: text/plain Thanks, -- Basil --=-=-=--