diff options
| author | Mauro Aranda | 2020-08-07 13:14:41 +0200 |
|---|---|---|
| committer | Lars Ingebrigtsen | 2020-08-07 13:36:55 +0200 |
| commit | 95b60c84b3bbed262d0af75bc69d4df9cb2cd9eb (patch) | |
| tree | 1a42fcf748db2b90681f749ddf8f6b2497bd75b0 /lisp/button.el | |
| parent | c32d6b21b81bed54d9738816c9164157ab6165c3 (diff) | |
| download | emacs-95b60c84b3bbed262d0af75bc69d4df9cb2cd9eb.tar.gz emacs-95b60c84b3bbed262d0af75bc69d4df9cb2cd9eb.zip | |
Add new commands to describe buttons and widgets
* lisp/help-fns.el (describe-widget-functions): New variable, used by
describe-widget.
(describe-widget): New command, to display information about a widget.
* lisp/button.el (button-describe): New command, for describing a button.
(button--describe): Helper function for button-describe.
* lisp/wid-edit.el (widget-describe): New command, for describing a
widget.
(widget--resolve-parent-action): Helper function, to allow
widget-describe to display more useful information (bug#139).
Diffstat (limited to 'lisp/button.el')
| -rw-r--r-- | lisp/button.el | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/lisp/button.el b/lisp/button.el index d9c36a0375c..941b9fe720a 100644 --- a/lisp/button.el +++ b/lisp/button.el | |||
| @@ -555,6 +555,51 @@ Returns the button found." | |||
| 555 | (interactive "p\nd\nd") | 555 | (interactive "p\nd\nd") |
| 556 | (forward-button (- n) wrap display-message no-error)) | 556 | (forward-button (- n) wrap display-message no-error)) |
| 557 | 557 | ||
| 558 | (defun button--describe (properties) | ||
| 559 | "Describe a button's PROPERTIES (an alist) in a *Help* buffer. | ||
| 560 | This is a helper function for `button-describe', in order to be possible to | ||
| 561 | use `help-setup-xref'. | ||
| 562 | |||
| 563 | Each element of PROPERTIES should be of the form (PROPERTY . VALUE)." | ||
| 564 | (help-setup-xref (list #'button--describe properties) | ||
| 565 | (called-interactively-p 'interactive)) | ||
| 566 | (with-help-window (help-buffer) | ||
| 567 | (with-current-buffer (help-buffer) | ||
| 568 | (insert (format-message "This button's type is `%s'." | ||
| 569 | (alist-get 'type properties))) | ||
| 570 | (dolist (prop '(action mouse-action)) | ||
| 571 | (let ((name (symbol-name prop)) | ||
| 572 | (val (alist-get prop properties))) | ||
| 573 | (when (functionp val) | ||
| 574 | (insert "\n\n" | ||
| 575 | (propertize (capitalize name) 'face 'bold) | ||
| 576 | "\nThe " name " of this button is") | ||
| 577 | (if (symbolp val) | ||
| 578 | (progn | ||
| 579 | (insert (format-message " `%s',\nwhich is " val)) | ||
| 580 | (describe-function-1 val)) | ||
| 581 | (insert "\n") | ||
| 582 | (princ val)))))))) | ||
| 583 | |||
| 584 | (defun button-describe (&optional button-or-pos) | ||
| 585 | "Display a buffer with information about the button at point. | ||
| 586 | |||
| 587 | When called from Lisp, pass BUTTON-OR-POS as the button to describe, or a | ||
| 588 | buffer position where a button is present. If BUTTON-OR-POS is nil, the | ||
| 589 | button at point is the button to describe." | ||
| 590 | (interactive "d") | ||
| 591 | (let* ((button (cond ((integer-or-marker-p button-or-pos) | ||
| 592 | (button-at button-or-pos)) | ||
| 593 | ((null button-or-pos) (button-at (point))) | ||
| 594 | ((overlayp button-or-pos) button-or-pos))) | ||
| 595 | (props (and button | ||
| 596 | (mapcar (lambda (prop) | ||
| 597 | (cons prop (button-get button prop))) | ||
| 598 | '(type action mouse-action))))) | ||
| 599 | (when props | ||
| 600 | (button--describe props) | ||
| 601 | t))) | ||
| 602 | |||
| 558 | (provide 'button) | 603 | (provide 'button) |
| 559 | 604 | ||
| 560 | ;;; button.el ends here | 605 | ;;; button.el ends here |