diff options
| author | Basil L. Contovounesios | 2019-09-27 00:04:33 +0100 |
|---|---|---|
| committer | Basil L. Contovounesios | 2019-10-03 23:05:14 +0100 |
| commit | 0fc8177414801e428ca184e8a9ba8b79a291c15a (patch) | |
| tree | 7ed7df57104eee1e0beaa6074efba73670adf3b0 /lisp | |
| parent | 660d509acd9da23d9795b5aaa12a5453e6c61bbd (diff) | |
| download | emacs-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.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." | |||
| 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. |
| 472 | If N is 0, move to the start of any button at point. | 480 | If N is 0, move to the start of any button at point. |
| 473 | If WRAP is non-nil, moving past either end of the buffer continues from the | 481 | If WRAP is non-nil, moving past either end of the buffer continues from the |
| 474 | other end. | 482 | other end. |
| 475 | If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. | 483 | If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property |
| 476 | Any button with a non-nil `skip' property is skipped over. | 484 | is displayed. Any button with a non-nil `skip' property is |
| 485 | skipped over. | ||
| 477 | 486 | ||
| 478 | If NO-ERROR, return nil if no further buttons could be found | 487 | If NO-ERROR, return nil if no further buttons could be found |
| 479 | instead of erroring out. | 488 | instead 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." | |||
| 522 | If N is 0, move to the start of any button at point. | 527 | If N is 0, move to the start of any button at point. |
| 523 | If WRAP is non-nil, moving past either end of the buffer continues from the | 528 | If WRAP is non-nil, moving past either end of the buffer continues from the |
| 524 | other end. | 529 | other end. |
| 525 | If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed. | 530 | If DISPLAY-MESSAGE is non-nil, the button's `help-echo' property |
| 526 | Any button with a non-nil `skip' property is skipped over. | 531 | is displayed. Any button with a non-nil `skip' property is |
| 532 | skipped over. | ||
| 527 | 533 | ||
| 528 | If NO-ERROR, return nil if no further buttons could be found | 534 | If NO-ERROR, return nil if no further buttons could be found |
| 529 | instead of erroring out. | 535 | instead of erroring out. |