Function: push-button

push-button is an interactive and byte-compiled function defined in button.el.gz.

Signature

(push-button &optional POS USE-MOUSE-ACTION)

Documentation

Perform the action specified by a button at location POS.

POS may be either a buffer position, a mouse-event, or a touchscreen-down event. If USE-MOUSE-ACTION is non-nil, invoke the button's mouse-action property instead of its action property; if the button has no mouse-action, the value of action is used instead.

If POS is a touchscreen-down event, wait for the corresponding touchscreen-up event before calling push-button.

The action in both cases may be either a function to call or a marker to display and is invoked using button-activate (which see).

POS defaults to point, except when push-button is invoked interactively as the result of a mouse-event or touchscreen event, in which case, the position in the event event is used.

If there's no button at POS, do nothing and return nil, otherwise return t.

To get a description of the function that will be invoked when pushing a button, use the button-describe command.

View in manual

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/button.el.gz
;;; User commands

(defun push-button (&optional pos use-mouse-action)
  "Perform the action specified by a button at location POS.
POS may be either a buffer position, a mouse-event, or a
`touchscreen-down' event.  If USE-MOUSE-ACTION is non-nil, invoke
the button's `mouse-action' property instead of its `action'
property; if the button has no `mouse-action', the value of
`action' is used instead.

If POS is a `touchscreen-down' event, wait for the corresponding
`touchscreen-up' event before calling `push-button'.

The action in both cases may be either a function to call or a
marker to display and is invoked using `button-activate' (which
see).

POS defaults to point, except when `push-button' is invoked
interactively as the result of a mouse-event or touchscreen
event, in which case, the position in the event event is used.

If there's no button at POS, do nothing and return nil, otherwise
return t.

To get a description of the function that will be invoked when
pushing a button, use the `button-describe' command."
  (interactive
   (list (if (integerp last-command-event) (point) last-command-event)))
  (if (and (not (integerp pos)) (eventp pos))
      ;; POS is a mouse event; switch to the proper window/buffer
      (let ((posn (event-start pos)))
	(with-current-buffer (window-buffer (posn-window posn))
          (let* ((str (posn-string posn))
                 (str-button (and str (get-text-property (cdr str) 'button (car str)))))
	    (if str-button
                ;; mode-line, header-line, or display string event.
                (button-activate str t)
              (if (eq (car-safe pos) 'touchscreen-down)
                  ;; If touch-screen-track tap returns nil, then the
                  ;; tap was canceled.
                  (when (touch-screen-track-tap pos nil nil t)
                    (push-button (posn-point posn) t))
                (push-button (posn-point posn) t))))))
    ;; POS is just normal position
    (let ((button (button-at (or pos (point)))))
      (when button
	(button-activate button use-mouse-action)
	t))))