summaryrefslogtreecommitdiff
path: root/lisp/button.el
diff options
context:
space:
mode:
authorLars Ingebrigtsen <larsi@gnus.org>2019-07-30 15:21:29 +0200
committerLars Ingebrigtsen <larsi@gnus.org>2019-07-30 15:21:29 +0200
commitb75fb81e362b8afbf37da0d2480676269430694c (patch)
tree82e1f67de4a7f4340b46a2219ed573c9be1c1def /lisp/button.el
parent99156a03bfee8304cf2644470dceb668e6262c98 (diff)
downloademacs-b75fb81e362b8afbf37da0d2480676269430694c.tar.gz
Extend button.el to take callback data
* doc/lispref/display.texi (Button Buffer Commands) (Button Buffer Commands): Document this. * lisp/button.el (backward-button, forward-button): Accept a NO-ERROR parameter. (button-activate): Make it possible to have specific data in the callback action.
Diffstat (limited to 'lisp/button.el')
-rw-r--r--lisp/button.el32
1 files changed, 25 insertions, 7 deletions
diff --git a/lisp/button.el b/lisp/button.el
index 921e84dfa68..ca6f0d3b6ea 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -235,15 +235,19 @@ The action can either be a marker or a function. If it's a
marker then goto it. Otherwise if it is a function then it is
called with BUTTON as only argument. BUTTON is either an
overlay, a buffer position, or (for buttons in the mode-line or
-header-line) a string."
+header-line) a string.
+
+If BUTTON has a `button-data' value, call the function with this
+value instad of BUTTON."
(let ((action (or (and use-mouse-action (button-get button 'mouse-action))
- (button-get button 'action))))
+ (button-get button 'action)))
+ (data (button-get button 'button-data)))
(if (markerp action)
(save-selected-window
(select-window (display-buffer (marker-buffer action)))
(goto-char action)
(recenter 0))
- (funcall action button))))
+ (funcall action (or data button)))))
(defun button-label (button)
"Return BUTTON's text label."
@@ -324,6 +328,10 @@ using `make-text-button'. Note, however, that if there is an existing
face property at the site of the button, the button face may not be visible.
You may want to use `make-button' in that case.
+If the property `button-data' is present, it will later be used
+as the argument for the `action' callback function instead of the
+default argument, which is the button itself.
+
BEG can also be a string, in which case it is made into a button.
Also see `insert-text-button'."
@@ -462,13 +470,17 @@ return t."
(button-activate button use-mouse-action)
t))))
-(defun forward-button (n &optional wrap display-message)
+(defun forward-button (n &optional wrap display-message no-error)
"Move to the Nth next button, or Nth previous button if N is negative.
If N is 0, move to the start of any button at point.
If WRAP is non-nil, moving past either end of the buffer continues from the
other end.
If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed.
Any button with a non-nil `skip' property is skipped over.
+
+If NO-ERROR, return nil if no further buttons could be found
+instead of erroring out.
+
Returns the button found."
(interactive "p\nd\nd")
(let (button)
@@ -497,22 +509,28 @@ Returns the button found."
(unless (button-get button 'skip)
(setq n (1- n)))))))
(if (null button)
- (user-error (if wrap "No buttons!" "No more buttons"))
+ (if no-error
+ nil
+ (user-error (if wrap "No buttons!" "No more buttons")))
(let ((msg (and display-message (button-get button 'help-echo))))
(when msg
(message "%s" msg)))
button)))
-(defun backward-button (n &optional wrap display-message)
+(defun backward-button (n &optional wrap display-message no-error)
"Move to the Nth previous button, or Nth next button if N is negative.
If N is 0, move to the start of any button at point.
If WRAP is non-nil, moving past either end of the buffer continues from the
other end.
If DISPLAY-MESSAGE is non-nil, the button's help-echo string is displayed.
Any button with a non-nil `skip' property is skipped over.
+
+If NO-ERROR, return nil if no further buttons could be found
+instead of erroring out.
+
Returns the button found."
(interactive "p\nd\nd")
- (forward-button (- n) wrap display-message))
+ (forward-button (- n) wrap display-message no-error))
(provide 'button)