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.bugs Subject: bug#37515: 27.0.50; button.el doesn't support help-echo function Date: Tue, 01 Oct 2019 13:29:48 +0100 Message-ID: <87zhik3ayr.fsf@tcd.ie> References: <87zhirdv75.fsf@gnus.org> <87ftki1xby.fsf@gnus.jao.io> <87sgodftxd.fsf@tcd.ie> <874l0tftm6.fsf@tcd.ie> 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="45158"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) Cc: Katsumi Yamaoka , Lars Ingebrigtsen , 37515@debbugs.gnu.org To: "Jose A. Ortega Ruiz" Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Tue Oct 01 14:30:23 2019 Return-path: Envelope-to: geb-bug-gnu-emacs@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 1iFHIM-000BaS-Ii for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Oct 2019 14:30:22 +0200 Original-Received: from localhost ([::1]:41394 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFHIL-0002vv-Ax for geb-bug-gnu-emacs@m.gmane.org; Tue, 01 Oct 2019 08:30:21 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:44309) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iFHI5-0002s9-Eq for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2019 08:30:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iFHI3-0002A3-NV for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2019 08:30:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:52190) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iFHI3-00029k-JG for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2019 08:30:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iFHI3-0003xX-Bb for bug-gnu-emacs@gnu.org; Tue, 01 Oct 2019 08:30:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: "Basil L. Contovounesios" Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Tue, 01 Oct 2019 12:30:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 37515 X-GNU-PR-Package: emacs Original-Received: via spool by 37515-submit@debbugs.gnu.org id=B37515.156993300015175 (code B ref 37515); Tue, 01 Oct 2019 12:30:03 +0000 Original-Received: (at 37515) by debbugs.gnu.org; 1 Oct 2019 12:30:00 +0000 Original-Received: from localhost ([127.0.0.1]:32777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iFHHz-0003wg-EQ for submit@debbugs.gnu.org; Tue, 01 Oct 2019 08:29:59 -0400 Original-Received: from mail-wr1-f54.google.com ([209.85.221.54]:41905) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iFHHw-0003wS-Mc for 37515@debbugs.gnu.org; Tue, 01 Oct 2019 08:29:57 -0400 Original-Received: by mail-wr1-f54.google.com with SMTP id h7so15288394wrw.8 for <37515@debbugs.gnu.org>; Tue, 01 Oct 2019 05:29: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=ORJswrLvRoGdkf3ucVjOz331V0Q5Oqg1sa9ikOb0o08=; b=O8ejcRE9YcjoCsF6yxBSESv/LfppmnqNe19veq1baUtfYBLGyxe6XsVcRUgkwm+bC1 5PVaT9Q8dfh2jW0BNER51Z2MEErtEVEKeUeWYIgm4SArluUhOcjM1iCVMAa4Rk81TT+s 5mj/Lt8e6lsCTw6TuoAVWWYFJrX4WTQymyyUqnm/fHKiOC6jBvo5+gbg6DgCpv5zo1Ay vt+sXp4LS8hOaIX04ldwRq07MdGbuNwG/7FMyhDxj+OgT4aylh7iALuCKMrDGRJjWLx4 rPB0tbphrsPEl4ab4F0MGjeddjYg0EXCf+7ACV5Az1IG8e/EwrhVTgaX578DwAxdBRtF CUtg== 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=ORJswrLvRoGdkf3ucVjOz331V0Q5Oqg1sa9ikOb0o08=; b=hDhdZT7DErbiqfV8Z1xNff7HuQu3Y61QbIFdBcEsQ1kX/Nv49msneDZAyPDbg7QY1P mdxQyZL6yksioGUYraOJgOpPvVFcvovnnZ+PIvHQvvZpWkeq/jrqbiJvsv6JyQSKGGW4 ftb18bTsYm5YWGO4QMrAkN6tAEMCvp0vGvsMC/Ms4kMUUfkQkMSGxUEZzzS4t6rsB5xC eYqc9YFpjFwm0SaFYiFuW5PAbBvKKrZyHTUrb+srXTUwx5+N9gP4evpO7VB95QwNNl3S nMSP4xH96L2C5RLFjNwKlILfWlbMmv3/2yJwF4vhS8rfUv3LikeO1MJcNL6DrVcg8sE1 PGcw== X-Gm-Message-State: APjAAAXQeKVogEMsa448OYaL5V/UuxzU7lBG7GcIt0ApWKvQ7B9OofPI +jsUEfpCcbeXtdD/jrx73jbyOQ== X-Google-Smtp-Source: APXvYqz/OCpMKVezIZx0YNv7QqaWjprdorxtX82kYSJ+4mJmk69N8OVWm7L7B+o0M3B8aRyq+czk+g== X-Received: by 2002:adf:f401:: with SMTP id g1mr5177974wro.275.1569932990820; Tue, 01 Oct 2019 05:29:50 -0700 (PDT) Original-Received: from localhost ([134.226.214.210]) by smtp.gmail.com with ESMTPSA id c6sm18081772wrm.71.2019.10.01.05.29.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Oct 2019 05:29:49 -0700 (PDT) In-Reply-To: <874l0tftm6.fsf@tcd.ie> (Basil L. Contovounesios's message of "Mon, 30 Sep 2019 20:53:53 +0100") 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: 209.51.188.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:167983 Archived-At: --=-=-= Content-Type: text/plain "Basil L. Contovounesios" writes: > "Basil L. Contovounesios" writes: > >> diff --git a/lisp/button.el b/lisp/button.el >> index 9112e518b0..ae2488bac6 100644 >> --- a/lisp/button.el >> +++ b/lisp/button.el >> @@ -470,13 +470,22 @@ push-button >> (button-activate button use-mouse-action) >> 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)))) > > Note that I intend to enable lexical-binding in button.el in a future > patch, in which case this call to eval will not need changing. Er, I was confused when I wrote this - whether button.el uses lexical-binding is irrelevant to the lexical evaluation of forms. The following is an updated patch which tests form evaluation under both dynamic and lexical scoping. I still intend to push it soon, if there are no objections. --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Further-improve-button.el-support-for-help-echo.patch >From bb58dc2ab253b92b4e5683136d12eb86a3473410 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Fri, 27 Sep 2019 00:04:33 +0100 Subject: [PATCH] Further improve button.el support for help-echo The last change to forward-button added support for help-echo values that are functions. This patch fixes the arguments passed to such functions and further adds support for help-echo values that are forms (bug#37515). * doc/lispref/display.texi (Button Properties): Fix description of help-echo button property. * lisp/button.el (button--help-echo): New function. (forward-button): Use it. (backward-button): Clarify help-echo reference in docstring. * test/lisp/button-tests.el (button--help-echo-string) (button--help-echo-form, button--help-echo-function): New tests. --- doc/lispref/display.texi | 19 +++++++++---- lisp/button.el | 26 +++++++++++------- test/lisp/button-tests.el | 56 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 86 insertions(+), 15 deletions(-) diff --git a/doc/lispref/display.texi b/doc/lispref/display.texi index 64b24f712a..d2074aa60c 100644 --- a/doc/lispref/display.texi +++ b/doc/lispref/display.texi @@ -6606,14 +6606,23 @@ Button Properties The button type. @xref{Button Types}. @item help-echo -@kindex help-index @r{(button property)} -A string displayed by the Emacs tool-tip help system; by default, -@code{"mouse-2, RET: Push this button"}. +@kindex help-echo @r{(button property)} +A string displayed by the Emacs tooltip help system; by default, +@code{"mouse-2, RET: Push this button"}. Alternatively, a function +that returns, or a form that evaluates to, a string to be displayed or +@code{nil}. For details see @ref{Text help-echo}. + +The function is called with three arguments, @var{window}, +@var{object}, and @var{pos}. The second argument, @var{object}, is +either the overlay that had the property (for overlay buttons), or the +buffer containing the button (for text property buttons). The other +arguments have the same meaning as for the special text property +@code{help-echo}. @item follow-link @kindex follow-link @r{(button property)} -The follow-link property, defining how a @key{mouse-1} click behaves -on this button, @xref{Clickable Text}. +The @code{follow-link} property, defining how a @key{mouse-1} click +behaves on this button, @xref{Clickable Text}. @item button @kindex button @r{(button property)} diff --git a/lisp/button.el b/lisp/button.el index 9112e518b0..ae2488bac6 100644 --- a/lisp/button.el +++ b/lisp/button.el @@ -470,13 +470,22 @@ push-button (button-activate button use-mouse-action) 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)))) + (defun forward-button (n &optional wrap display-message no-error) "Move to the Nth next button, or Nth previous button if N is negative. If N is 0, move to the start of any button at point. If WRAP is non-nil, moving past either end of the buffer continues from the other end. -If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. -Any button with a non-nil `skip' property is skipped over. +If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property +is displayed. Any button with a non-nil `skip' property is +skipped over. If NO-ERROR, return nil if no further buttons could be found instead of erroring out. @@ -509,13 +518,9 @@ forward-button (unless (button-get button 'skip) (setq n (1- n))))))) (if (null button) - (if no-error - nil + (unless no-error (user-error (if wrap "No buttons!" "No more buttons"))) - (let ((msg (and display-message (button-get button 'help-echo)))) - (when (functionp msg) - (setq msg (funcall msg (selected-window) (current-buffer) - (button-start button)))) + (let ((msg (and display-message (button--help-echo button)))) (when msg (message "%s" msg))) button))) @@ -525,8 +530,9 @@ backward-button If N is 0, move to the start of any button at point. If WRAP is non-nil, moving past either end of the buffer continues from the other end. -If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. -Any button with a non-nil `skip' property is skipped over. +If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property +is displayed. Any button with a non-nil `skip' property is +skipped over. If NO-ERROR, return nil if no further buttons could be found instead of erroring out. diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el index d54a992ab8..44a7ea6f6e 100644 --- a/test/lisp/button-tests.el +++ b/test/lisp/button-tests.el @@ -37,4 +37,60 @@ button-at (widget-create 'link "link widget") (should-not (button-at (1- (point)))))) +(ert-deftest 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"))) + ;; Overlay buttons. + (let ((button (insert-button "overlay" 'help-echo "overlay help"))) + (should (equal (button--help-echo button) "overlay help"))))) + +(ert-deftest button--help-echo-form () + "Test `button--help-echo' with forms." + (with-temp-buffer + ;; Test text property buttons with dynamic scoping. + (let* ((help (make-symbol "help")) + (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"))) + ;; Test overlay buttons with lexical scoping. + (setq lexical-binding t) + (let* ((help (make-symbol "help")) + (form `(funcall (let ((,help "lexical form")) + (lambda () ,help)))) + (button (insert-button "overlay" 'help-echo form))) + (set help "dynamic form") + (should (equal (button--help-echo button) "lexical form"))))) + +(ert-deftest button--help-echo-function () + "Test `button--help-echo' with functions." + (with-temp-buffer + ;; Text property buttons. + (let* ((owin (selected-window)) + (obuf (current-buffer)) + (opos (point)) + (help (lambda (win obj pos) + (should (eq win owin)) + (should (eq obj obuf)) + (should (= pos opos)) + "text function")) + (button (insert-text-button "text" 'help-echo help))) + (should (equal (button--help-echo button) "text function")) + ;; Overlay buttons. + (setq help (lambda (win obj pos) + (should (eq win owin)) + (should (overlayp obj)) + (should (eq obj button)) + (should (eq (overlay-buffer obj) obuf)) + (should (= (overlay-start obj) opos)) + (should (= pos opos)) + "overlay function")) + (setq opos (point)) + (setq button (insert-button "overlay" 'help-echo help)) + (should (equal (button--help-echo button) "overlay function"))))) + ;;; button-tests.el ends here -- 2.23.0 --=-=-= Content-Type: text/plain Thanks, -- Basil --=-=-=--