Function: majutsu-diff--color-words-shadow-pos

majutsu-diff--color-words-shadow-pos is a natively compiled function defined in majutsu-diff.el.

Signature

(majutsu-diff--color-words-shadow-pos CURSOR)

Documentation

Compute shadow cursor position for color-words geometry at CURSOR.

Return buffer position, or nil if no mapping is possible.

Map using non-token offsets to align shared context. When CURSOR sits inside a token span, prefer a token span anchored at the same offset on the other side; otherwise fall back to the non-token stream.

Source Code

;; Defined in /nix/store/jagqw3nms546pad0gxi5f3wsckk6pji7-emacs-packages-deps/share/emacs/site-lisp/majutsu-diff.el
(defun majutsu-diff--color-words-shadow-pos (cursor)
  "Compute shadow cursor position for color-words geometry at CURSOR.
Return buffer position, or nil if no mapping is possible.

Map using non-token offsets to align shared context.  When CURSOR sits
inside a token span, prefer a token span anchored at the same offset on
the other side; otherwise fall back to the non-token stream."
  (let ((region-ov (majutsu-diff--color-words--region-overlay-at cursor)))
    (when region-ov
      (let* ((region-other (overlay-get region-ov 'majutsu-color-words-region-other))
             (from-spans (overlay-get region-ov 'majutsu-color-words-non-token))
             (to-spans (and region-other
                            (overlay-get region-other 'majutsu-color-words-non-token)))
             (from-tokens (overlay-get region-ov 'majutsu-color-words-token-anchors))
             (to-tokens (and region-other
                             (overlay-get region-other 'majutsu-color-words-token-anchors)))
             (offset (or (majutsu-diff--color-words--span-stream-offset
                          cursor from-spans)
                         (and from-tokens 0)))
             (scaled (cond
                      ((and to-spans offset)
                       (min offset (1- (majutsu-diff--color-words--span-stream-length
                                        to-spans))))
                      (offset offset))))
        (when (and offset scaled)
          (let* ((from-bucket (cdr (assoc offset from-tokens)))
                 (to-bucket (cdr (assoc scaled to-tokens)))
                 (token-hit (and from-bucket
                                 (seq-find (lambda (span)
                                             (and (<= (car span) cursor)
                                                  (< cursor (cdr span))))
                                           from-bucket))))
            (cond
             ((and token-hit to-bucket)
              (car (car to-bucket)))
             (to-spans
              (majutsu-diff--color-words--span-stream-pos scaled to-spans)))))))))