Function: mouse-on-link-p

mouse-on-link-p is a byte-compiled function defined in mouse.el.gz.

Signature

(mouse-on-link-p POS)

Documentation

Return non-nil if POS is on a link in the current buffer.

POS must specify a buffer position in the current buffer, as a list of the form returned by the event-start and event-end functions, or a mouse event location in the selected window (see event-start). However, if mouse-1-click-in-non-selected-windows is non-nil, POS may be a mouse event location in any window.

A clickable link is identified by one of the following methods:

- If the character at POS has a non-nil follow-link text or
overlay property, the value of that property determines what to do.

- If there is a local key-binding or a keybinding at position POS
for the follow-link event, the binding of that event determines what to do.

The resulting value determines whether POS is inside a link:

- If the value is mouse-face, POS is inside a link if there
is a non-nil mouse-face property at POS. Return t in this case.

- If the value is a function, FUNC, POS is inside a link if
the call (FUNC POS) returns non-nil. Return the return value from that call. Arg is (posn-point POS) if POS is a mouse event.

- Otherwise, return the value itself.

The return value is interpreted as follows:

- If it is an array, the mouse-1 event is translated into the
first element of that array, i.e. the action of the mouse-1 click is the local or global binding of that event.

- Otherwise, the mouse-1 event is translated into a mouse-2 event
at the same position.

View in manual

Probably introduced at or before Emacs version 22.1.

Source Code

;; Defined in /usr/src/emacs/lisp/mouse.el.gz
(defun mouse-on-link-p (pos)
  "Return non-nil if POS is on a link in the current buffer.
POS must specify a buffer position in the current buffer, as a list
of the form returned by the `event-start' and `event-end' functions,
or a mouse event location in the selected window (see `event-start').
However, if `mouse-1-click-in-non-selected-windows' is non-nil,
POS may be a mouse event location in any window.

A clickable link is identified by one of the following methods:

- If the character at POS has a non-nil `follow-link' text or
overlay property, the value of that property determines what to do.

- If there is a local key-binding or a keybinding at position POS
for the `follow-link' event, the binding of that event determines
what to do.

The resulting value determines whether POS is inside a link:

- If the value is `mouse-face', POS is inside a link if there
is a non-nil `mouse-face' property at POS.  Return t in this case.

- If the value is a function, FUNC, POS is inside a link if
the call (FUNC POS) returns non-nil.  Return the return value
from that call.  Arg is (posn-point POS) if POS is a mouse event.

- Otherwise, return the value itself.

The return value is interpreted as follows:

- If it is an array, the mouse-1 event is translated into the
first element of that array, i.e. the action of the mouse-1
click is the local or global binding of that event.

- Otherwise, the mouse-1 event is translated into a mouse-2 event
at the same position."
  (let ((action
	 (and (or (not (consp pos))
		  mouse-1-click-in-non-selected-windows
		  (eq (selected-window) (posn-window pos)))
	      (or (mouse-posn-property pos 'follow-link)
                  (let ((area (posn-area pos)))
                    (when area
                      (key-binding (vector area 'follow-link) nil t pos)))
		  (key-binding [follow-link] nil t pos)))))
    (cond
     ((eq action 'mouse-face)
      (and (mouse-posn-property pos 'mouse-face) t))
     ((functionp action)
      ;; FIXME: This seems questionable if the click is not in a buffer.
      ;; Should we instead decide that `action' takes a `posn'?
      (if (consp pos)
	  (with-current-buffer (window-buffer (posn-window pos))
	    (funcall action (posn-point pos)))
	(funcall action pos)))
     (t action))))