Function: markdown-ts--host-ranges-notifier

markdown-ts--host-ranges-notifier is a byte-compiled function defined in markdown-ts-mode.el.gz.

Signature

(markdown-ts--host-ranges-notifier RANGES PARSER)

Documentation

Prune stale code block overlays after the host parser reparses.

RANGES is a list of (START . END) cons cells marking regions where the markdown parse tree changed. For each markdown-ts-code-block overlay intersecting a changed range, verify that a containing fenced_code_block node still exists in the host tree. If not, the fences were deleted, so delete the overlay to avoid running commands in a stale block context.

Source Code

;; Defined in /usr/src/emacs/lisp/textmodes/markdown-ts-mode.el.gz
(defun markdown-ts--host-ranges-notifier (ranges _parser)
  "Prune stale code block overlays after the host parser reparses.
RANGES is a list of (START . END) cons cells marking regions where
the markdown parse tree changed.  For each `markdown-ts-code-block'
overlay intersecting a changed range, verify that a containing
`fenced_code_block' node still exists in the host tree.  If not,
the fences were deleted, so delete the overlay to avoid running
commands in a stale block context."
  (dolist (range ranges)
    (let ((beg (car range))
          (end (cdr range)))
      (dolist (ov (overlays-in beg end))
        (when (overlay-get ov 'markdown-ts-code-block)
          (let* ((ov-start (overlay-start ov))
                 (node (and ov-start
                            (treesit-node-at ov-start 'markdown))))
            (unless (and node
                         (treesit-parent-until
                          node "\\`fenced_code_block\\'" t))
              (delete-overlay ov))))))))