aboutsummaryrefslogtreecommitdiffstats
path: root/lisp/button.el
diff options
context:
space:
mode:
Diffstat (limited to 'lisp/button.el')
-rw-r--r--lisp/button.el51
1 files changed, 50 insertions, 1 deletions
diff --git a/lisp/button.el b/lisp/button.el
index d9c36a0375c..03ab59b109c 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -464,8 +464,12 @@ see).
464POS defaults to point, except when `push-button' is invoked 464POS defaults to point, except when `push-button' is invoked
465interactively as the result of a mouse-event, in which case, the 465interactively as the result of a mouse-event, in which case, the
466mouse event is used. 466mouse event is used.
467
467If there's no button at POS, do nothing and return nil, otherwise 468If there's no button at POS, do nothing and return nil, otherwise
468return t." 469return t.
470
471To get a description of what function will called when pushing a
472butting, use the `button-describe' command."
469 (interactive 473 (interactive
470 (list (if (integerp last-command-event) (point) last-command-event))) 474 (list (if (integerp last-command-event) (point) last-command-event)))
471 (if (and (not (integerp pos)) (eventp pos)) 475 (if (and (not (integerp pos)) (eventp pos))
@@ -555,6 +559,51 @@ Returns the button found."
555 (interactive "p\nd\nd") 559 (interactive "p\nd\nd")
556 (forward-button (- n) wrap display-message no-error)) 560 (forward-button (- n) wrap display-message no-error))
557 561
562(defun button--describe (properties)
563 "Describe a button's PROPERTIES (an alist) in a *Help* buffer.
564This is a helper function for `button-describe', in order to be possible to
565use `help-setup-xref'.
566
567Each element of PROPERTIES should be of the form (PROPERTY . VALUE)."
568 (help-setup-xref (list #'button--describe properties)
569 (called-interactively-p 'interactive))
570 (with-help-window (help-buffer)
571 (with-current-buffer (help-buffer)
572 (insert (format-message "This button's type is `%s'."
573 (alist-get 'type properties)))
574 (dolist (prop '(action mouse-action))
575 (let ((name (symbol-name prop))
576 (val (alist-get prop properties)))
577 (when (functionp val)
578 (insert "\n\n"
579 (propertize (capitalize name) 'face 'bold)
580 "\nThe " name " of this button is")
581 (if (symbolp val)
582 (progn
583 (insert (format-message " `%s',\nwhich is " val))
584 (describe-function-1 val))
585 (insert "\n")
586 (princ val))))))))
587
588(defun button-describe (&optional button-or-pos)
589 "Display a buffer with information about the button at point.
590
591When called from Lisp, pass BUTTON-OR-POS as the button to describe, or a
592buffer position where a button is present. If BUTTON-OR-POS is nil, the
593button at point is the button to describe."
594 (interactive "d")
595 (let* ((button (cond ((integer-or-marker-p button-or-pos)
596 (button-at button-or-pos))
597 ((null button-or-pos) (button-at (point)))
598 ((overlayp button-or-pos) button-or-pos)))
599 (props (and button
600 (mapcar (lambda (prop)
601 (cons prop (button-get button prop)))
602 '(type action mouse-action)))))
603 (when props
604 (button--describe props)
605 t)))
606
558(provide 'button) 607(provide 'button)
559 608
560;;; button.el ends here 609;;; button.el ends here