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: Mon, 30 Sep 2019 20:47:10 +0100 Message-ID: <87sgodftxd.fsf@tcd.ie> References: <87zhirdv75.fsf@gnus.org> <87ftki1xby.fsf@gnus.jao.io> 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="195721"; 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 Mon Sep 30 21:48:17 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 1iF1ea-000ohZ-7x for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Sep 2019 21:48:16 +0200 Original-Received: from localhost ([::1]:56464 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF1eY-0000yp-Dz for geb-bug-gnu-emacs@m.gmane.org; Mon, 30 Sep 2019 15:48:14 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:40815) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iF1eP-0000yS-FX for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 15:48:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iF1eN-0003OD-UH for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 15:48:05 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:51705) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iF1eM-0003Ne-Ky for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 15:48:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1iF1eM-0004Gp-Gp for bug-gnu-emacs@gnu.org; Mon, 30 Sep 2019 15:48:02 -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: Mon, 30 Sep 2019 19:48:02 +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.156987284916370 (code B ref 37515); Mon, 30 Sep 2019 19:48:02 +0000 Original-Received: (at 37515) by debbugs.gnu.org; 30 Sep 2019 19:47:29 +0000 Original-Received: from localhost ([127.0.0.1]:60526 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iF1dp-0004Fy-4T for submit@debbugs.gnu.org; Mon, 30 Sep 2019 15:47:29 -0400 Original-Received: from mail-wm1-f45.google.com ([209.85.128.45]:36732) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1iF1dm-0004Fk-Ij for 37515@debbugs.gnu.org; Mon, 30 Sep 2019 15:47:27 -0400 Original-Received: by mail-wm1-f45.google.com with SMTP id m18so743721wmc.1 for <37515@debbugs.gnu.org>; Mon, 30 Sep 2019 12:47:26 -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=hocW1tdu2Z3r18z9p50hkknqhaMpEKgLprFyAzOS9o0=; b=fg/4UrXDKWD5gtXP+hmCqyZFNbv7sP7nf+hiZj+3iQGHrh29BdiVsi2hD18nNMjCH3 m3p8zxl7YwHweqVq7CtYKNeKNUhpJITv4qgZ7H83dBNY0p39td8ZjlCuJ3jVHwS1iCT+ v1IowEfrNfxhV7OwGq4sqQ93/zD4FTGzQHupXF+z8sVYew0mahBHruFwO+WI2MXk40hT 0jX+Zj5N/CgIR09n3guDMH6iJmueGLxkf/wkSCvc8HlJxDp4aHHt/Tb8nG/vNnR8dh8x x7b4L7x4qC0uTrxLM4G6p7ss9wQUQ0PBiXRZVvGYe2P0A6Tfpz2kGDJ/DT9nrhzd0yXP HEgQ== 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=hocW1tdu2Z3r18z9p50hkknqhaMpEKgLprFyAzOS9o0=; b=iTF4F7rAqYSh8RkxVKLhiMT68zKdaUPwii1RThHEDrBNkKRUTwjVinudtIM2lw0yfM pWcjcIJ8waGVC05R5QvYxfmrsqyjOjLVHdUCFWlInDPdtgaJ+DXOmPGBHzvgfK+pE5hO w2YMPMiu1/62oND9616jLgQepOcBoXjQr1q4ay5uKkSvKZXnLq9A7Xg3w2YQN39yiLZj 5WA+sUmAE4zt2+D6tgGNgv3dZbEtm4QEUpUNb3NWRygygRCeWWUNJQvTuVeiR+ETGRHr TLCJq9LqDV5mv7lxEn6SsUMbtKKVzUOYa2pvYy7hOFgsxiUdiKkAOYHblz8dQL2WZUIi StUQ== X-Gm-Message-State: APjAAAUicm6I0+n1Lk252oeUkx0hoeZrLXTz7eZfvaZqo8AK/mXzGTap qSLyUf9a3m8/57CiZD+ZFP8c3Q== X-Google-Smtp-Source: APXvYqwhNvmz284lGHbKWgUp0xWbzYT5/nWGBaCXgkRPUQqNwIFWZ0fTX4NYpUSTVOECHUwtI8kR3Q== X-Received: by 2002:a7b:c7c5:: with SMTP id z5mr586996wmk.37.1569872840614; Mon, 30 Sep 2019 12:47:20 -0700 (PDT) Original-Received: from localhost ([2a02:8084:20e2:c380:92bd:1bfd:38fc:fae2]) by smtp.gmail.com with ESMTPSA id a7sm28641309wra.43.2019.09.30.12.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Sep 2019 12:47:19 -0700 (PDT) In-Reply-To: <87ftki1xby.fsf@gnus.jao.io> (Jose A. Ortega Ruiz's message of "Thu, 26 Sep 2019 23:56:01 +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:167943 Archived-At: --=-=-= Content-Type: text/plain Thank you for working on this, Yamaoka-san. Some further changes are needed to fully support the help-echo property. Firstly, help-echo functions expect an overlay as their second argument when the object that had the property is an overlay (button). Secondly, help-echo values can be forms in addition to strings and functions. Lastly, (info "(elisp) Button Properties") needs updating to reflect the supported values of the help-echo button property. The following patch should do all this. I will push it in the next few days if there are no objections. WDYT? --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=0001-Further-improve-button.el-support-for-help-echo.patch >From e91c4b5f6710565344e419b25be496316a1f3e71 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): New test. --- doc/lispref/display.texi | 19 ++++++++++++++----- lisp/button.el | 26 ++++++++++++++++---------- test/lisp/button-tests.el | 37 +++++++++++++++++++++++++++++++++++++ 3 files changed, 67 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..052306f791 100644 --- a/test/lisp/button-tests.el +++ b/test/lisp/button-tests.el @@ -37,4 +37,41 @@ button-at (widget-create 'link "link widget") (should-not (button-at (1- (point)))))) +(ert-deftest button--help-echo () + "Test `button--help-echo' behavior." + (with-temp-buffer + ;; Text property buttons. + (let ((button (insert-text-button "text" 'help-echo "string"))) + (should (equal (button--help-echo button) "string"))) + (let ((button (insert-text-button "text" 'help-echo '(concat "form")))) + (should (equal (button--help-echo button) "form"))) + (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)) + "function")) + (button (insert-text-button "text" 'help-echo help))) + (should (equal (button--help-echo button) "function"))) + ;; Overlay buttons. + (let ((button (insert-button "overlay" 'help-echo "string"))) + (should (equal (button--help-echo button) "string"))) + (let ((button (insert-button "overlay" 'help-echo '(concat "form")))) + (should (equal (button--help-echo button) "form"))) + (letrec ((owin (selected-window)) + (obuf (current-buffer)) + (opos (point)) + (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)) + "function")) + (button (insert-button "overlay" 'help-echo help))) + (should (equal (button--help-echo button) "function"))))) + ;;; button-tests.el ends here -- 2.23.0 --=-=-= Content-Type: text/plain Thanks, -- Basil --=-=-=--