(cursor-sensor-tangible-pos): Prefer shortening the motion

When moving to the middle of an intangible chunk, and either end
of the chunk would result in a movement in the right direction, prefer
the shorter movement, since it's easier for the users to repeat a
movement than to "go back".
(see https://lists.gnu.org/archive/html/emacs-devel/2025-12/msg00686.html)

* lisp/emacs-lisp/cursor-sensor.el (cursor-sensor-tangible-pos):
Refine the choice.
This commit is contained in:
Stefan Monnier 2025-12-23 22:43:51 -05:00
parent 068d94074b
commit fc117f1d3b

View file

@ -109,9 +109,14 @@ By convention, this is a list of symbols where each symbol stands for the
;; 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 nextpos prevpos))
((> oldpos curpos) (or prevpos nextpos))
((< 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))