aboutsummaryrefslogtreecommitdiffstats
path: root/lisp
diff options
context:
space:
mode:
authorBasil L. Contovounesios2019-09-27 00:04:33 +0100
committerBasil L. Contovounesios2019-10-03 23:05:14 +0100
commit0fc8177414801e428ca184e8a9ba8b79a291c15a (patch)
tree7ed7df57104eee1e0beaa6074efba73670adf3b0 /lisp
parent660d509acd9da23d9795b5aaa12a5453e6c61bbd (diff)
downloademacs-0fc8177414801e428ca184e8a9ba8b79a291c15a.tar.gz
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')
-rw-r--r--lisp/button.el26
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."
467 (button-activate button use-mouse-action) 467 (button-activate button use-mouse-action)
468 t)))) 468 t))))
469 469
470(defun button--help-echo (button)
471 "Evaluate BUTTON's `help-echo' property and return its value."
472 (let ((help (button-get button 'help-echo)))
473 (if (functionp help)
474 (let ((obj (if (overlayp button) button (current-buffer))))
475 (funcall help (selected-window) obj (button-start button)))
476 (eval help lexical-binding))))
477
470(defun forward-button (n &optional wrap display-message no-error) 478(defun forward-button (n &optional wrap display-message no-error)
471 "Move to the Nth next button, or Nth previous button if N is negative. 479 "Move to the Nth next button, or Nth previous button if N is negative.
472If N is 0, move to the start of any button at point. 480If N is 0, move to the start of any button at point.
473If WRAP is non-nil, moving past either end of the buffer continues from the 481If WRAP is non-nil, moving past either end of the buffer continues from the
474other end. 482other end.
475If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. 483If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property
476Any button with a non-nil `skip' property is skipped over. 484is displayed. Any button with a non-nil `skip' property is
485skipped over.
477 486
478If NO-ERROR, return nil if no further buttons could be found 487If NO-ERROR, return nil if no further buttons could be found
479instead of erroring out. 488instead of erroring out.
@@ -506,13 +515,9 @@ Returns the button found."
506 (unless (button-get button 'skip) 515 (unless (button-get button 'skip)
507 (setq n (1- n))))))) 516 (setq n (1- n)))))))
508 (if (null button) 517 (if (null button)
509 (if no-error 518 (unless no-error
510 nil
511 (user-error (if wrap "No buttons!" "No more buttons"))) 519 (user-error (if wrap "No buttons!" "No more buttons")))
512 (let ((msg (and display-message (button-get button 'help-echo)))) 520 (let ((msg (and display-message (button--help-echo button))))
513 (when (functionp msg)
514 (setq msg (funcall msg (selected-window) (current-buffer)
515 (button-start button))))
516 (when msg 521 (when msg
517 (message "%s" msg))) 522 (message "%s" msg)))
518 button))) 523 button)))
@@ -522,8 +527,9 @@ Returns the button found."
522If N is 0, move to the start of any button at point. 527If N is 0, move to the start of any button at point.
523If WRAP is non-nil, moving past either end of the buffer continues from the 528If WRAP is non-nil, moving past either end of the buffer continues from the
524other end. 529other end.
525If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. 530If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property
526Any button with a non-nil `skip' property is skipped over. 531is displayed. Any button with a non-nil `skip' property is
532skipped over.
527 533
528If NO-ERROR, return nil if no further buttons could be found 534If NO-ERROR, return nil if no further buttons could be found
529instead of erroring out. 535instead of erroring out.