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 /test | |
| 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 'test')
| -rw-r--r-- | test/lisp/button-tests.el | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/test/lisp/button-tests.el b/test/lisp/button-tests.el index d54a992ab89..44a7ea6f6e5 100644 --- a/test/lisp/button-tests.el +++ b/test/lisp/button-tests.el | |||
| @@ -37,4 +37,60 @@ | |||
| 37 | (widget-create 'link "link widget") | 37 | (widget-create 'link "link widget") |
| 38 | (should-not (button-at (1- (point)))))) | 38 | (should-not (button-at (1- (point)))))) |
| 39 | 39 | ||
| 40 | (ert-deftest button--help-echo-string () | ||
| 41 | "Test `button--help-echo' with strings." | ||
| 42 | (with-temp-buffer | ||
| 43 | ;; Text property buttons. | ||
| 44 | (let ((button (insert-text-button "text" 'help-echo "text help"))) | ||
| 45 | (should (equal (button--help-echo button) "text help"))) | ||
| 46 | ;; Overlay buttons. | ||
| 47 | (let ((button (insert-button "overlay" 'help-echo "overlay help"))) | ||
| 48 | (should (equal (button--help-echo button) "overlay help"))))) | ||
| 49 | |||
| 50 | (ert-deftest button--help-echo-form () | ||
| 51 | "Test `button--help-echo' with forms." | ||
| 52 | (with-temp-buffer | ||
| 53 | ;; Test text property buttons with dynamic scoping. | ||
| 54 | (let* ((help (make-symbol "help")) | ||
| 55 | (form `(funcall (let ((,help "lexical form")) | ||
| 56 | (lambda () ,help)))) | ||
| 57 | (button (insert-text-button "text" 'help-echo form))) | ||
| 58 | (set help "dynamic form") | ||
| 59 | (should (equal (button--help-echo button) "dynamic form"))) | ||
| 60 | ;; Test overlay buttons with lexical scoping. | ||
| 61 | (setq lexical-binding t) | ||
| 62 | (let* ((help (make-symbol "help")) | ||
| 63 | (form `(funcall (let ((,help "lexical form")) | ||
| 64 | (lambda () ,help)))) | ||
| 65 | (button (insert-button "overlay" 'help-echo form))) | ||
| 66 | (set help "dynamic form") | ||
| 67 | (should (equal (button--help-echo button) "lexical form"))))) | ||
| 68 | |||
| 69 | (ert-deftest button--help-echo-function () | ||
| 70 | "Test `button--help-echo' with functions." | ||
| 71 | (with-temp-buffer | ||
| 72 | ;; Text property buttons. | ||
| 73 | (let* ((owin (selected-window)) | ||
| 74 | (obuf (current-buffer)) | ||
| 75 | (opos (point)) | ||
| 76 | (help (lambda (win obj pos) | ||
| 77 | (should (eq win owin)) | ||
| 78 | (should (eq obj obuf)) | ||
| 79 | (should (= pos opos)) | ||
| 80 | "text function")) | ||
| 81 | (button (insert-text-button "text" 'help-echo help))) | ||
| 82 | (should (equal (button--help-echo button) "text function")) | ||
| 83 | ;; Overlay buttons. | ||
| 84 | (setq help (lambda (win obj pos) | ||
| 85 | (should (eq win owin)) | ||
| 86 | (should (overlayp obj)) | ||
| 87 | (should (eq obj button)) | ||
| 88 | (should (eq (overlay-buffer obj) obuf)) | ||
| 89 | (should (= (overlay-start obj) opos)) | ||
| 90 | (should (= pos opos)) | ||
| 91 | "overlay function")) | ||
| 92 | (setq opos (point)) | ||
| 93 | (setq button (insert-button "overlay" 'help-echo help)) | ||
| 94 | (should (equal (button--help-echo button) "overlay function"))))) | ||
| 95 | |||
| 40 | ;;; button-tests.el ends here | 96 | ;;; button-tests.el ends here |