diff options
author | Basil L. Contovounesios <contovob@tcd.ie> | 2019-09-27 00:04:33 +0100 |
---|---|---|
committer | Basil L. Contovounesios <contovob@tcd.ie> | 2019-10-03 23:05:14 +0100 |
commit | 0fc8177414801e428ca184e8a9ba8b79a291c15a (patch) | |
tree | 7ed7df57104eee1e0beaa6074efba73670adf3b0 /lisp/button.el | |
parent | 660d509acd9da23d9795b5aaa12a5453e6c61bbd (diff) | |
download | emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.tar.gz emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.tar.bz2 emacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.zip |
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.
Diffstat (limited to 'lisp/button.el')
-rw-r--r-- | lisp/button.el | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lisp/button.el b/lisp/button.el index 32efc2f95be..04e77ca904f 100644 --- a/lisp/button.el +++ b/lisp/button.el @@ -467,13 +467,22 @@ return t." (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. @@ -506,13 +515,9 @@ Returns the button found." (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))) @@ -522,8 +527,9 @@ Returns the button found." 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. |