+(defun mouse--down-1-maybe-follows-link (&optional _prompt)
+ "Turn `mouse-1' events into `mouse-2' events if follows-link.
+Expects to be bound to `down-mouse-1' in `key-translation-map'."
+ (if (or (null mouse-1-click-follows-link)
+ (not (eq (if (eq mouse-1-click-follows-link 'double)
+ 'double-down-mouse-1 'down-mouse-1)
+ (car-safe last-input-event)))
+ (not (mouse-on-link-p (event-start last-input-event)))
+ (and (not mouse-1-click-in-non-selected-windows)
+ (not (eq (selected-window)
+ (posn-window (event-start last-input-event))))))
+ nil
+ (let ((this-event last-input-event)
+ (timedout
+ (sit-for (if (numberp mouse-1-click-follows-link)
+ (/ (abs mouse-1-click-follows-link) 1000.0)
+ 0))))
+ (if (if (and (numberp mouse-1-click-follows-link)
+ (>= mouse-1-click-follows-link 0))
+ timedout (not timedout))
+ nil
+
+ (let ((event (read-event)))
+ (if (eq (car-safe event) (if (eq mouse-1-click-follows-link 'double)
+ 'double-mouse-1 'mouse-1))
+ ;; Turn the mouse-1 into a mouse-2 to follow links.
+ (let ((newup (if (eq mouse-1-click-follows-link 'double)
+ 'double-mouse-2 'mouse-2))
+ (newdown (if (eq mouse-1-click-follows-link 'double)
+ 'double-down-mouse-2 'down-mouse-2)))
+ ;; If mouse-2 has never been done by the user, it doesn't have
+ ;; the necessary property to be interpreted correctly.
+ (put newup 'event-kind (get (car event) 'event-kind))
+ (put newdown 'event-kind (get (car this-event) 'event-kind))
+ (push (cons newup (cdr event)) unread-command-events)
+ ;; Modify the event in place, so read-key-sequence doesn't
+ ;; generate a second fake prefix key (see fake_prefixed_keys in
+ ;; src/keyboard.c).
+ (setcar this-event newdown)
+ (vector this-event))
+ (push event unread-command-events)
+ nil))))))
+
+(define-key key-translation-map [down-mouse-1]
+ #'mouse--down-1-maybe-follows-link)
+(define-key key-translation-map [double-down-mouse-1]
+ #'mouse--down-1-maybe-follows-link)