Function: cursor-sensor-tangible-pos

cursor-sensor-tangible-pos is a byte-compiled function defined in cursor-sensor.el.gz.

Signature

(cursor-sensor-tangible-pos CURPOS WINDOW)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/cursor-sensor.el.gz
(defun cursor-sensor-tangible-pos (curpos window)
  (when (cursor-sensor--intangible-p curpos)
    ;; Find the two nearest tangible positions.
    (let ((nextpos curpos)
          (prevpos curpos)
          (oldpos (window-parameter window 'cursor-intangible--last-point)))
      (while (if (>= nextpos (point-max))
                 (when (cursor-sensor--intangible-p nextpos) (setq nextpos nil))
               (setq nextpos
                     (if (get-char-property nextpos 'cursor-intangible)
                         (next-single-char-property-change
                          nextpos 'cursor-intangible nil (point-max))
                       (1+ nextpos)))
               (cursor-sensor--intangible-p nextpos)))
      (while (if (<= prevpos (point-min))
                 (when (cursor-sensor--intangible-p prevpos) (setq prevpos nil))
               (setq prevpos
                     (if (get-char-property (1- prevpos) 'cursor-intangible)
                         (previous-single-char-property-change
                          prevpos 'cursor-intangible nil (point-min))
                       (1- prevpos)))
               (cursor-sensor--intangible-p prevpos)))
      ;; Pick the preferred one depending on the direction of the motion.
      ;; Goals, from most important to least important:
      ;; - Prefer a tangible position.
      ;; - Preserve the overall direction of the motion.
      ;; - Prefer shortening the motion over lengthening it.
      (cond
       ((< oldpos curpos)
        (or (and prevpos (< oldpos prevpos) prevpos) ;Prefer shorter motion.
            nextpos prevpos))
       ((> oldpos curpos)
        (or (and nextpos (> oldpos nextpos) nextpos) ;Prefer shorter motion.
            prevpos nextpos))
       (t
        (or (and prevpos nextpos
                 (< (- nextpos curpos) (- curpos prevpos))
                 nextpos)
            prevpos nextpos))))))