Function: treesit--font-lock-mark-ranges-to-fontify

treesit--font-lock-mark-ranges-to-fontify is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit--font-lock-mark-ranges-to-fontify RANGES PARSER)

Documentation

A notifier that marks ranges that needs refontification.

For RANGES and PARSER see treesit-parser-add-notifier.

After the parser reparses, we get the changed ranges, and
1) update non-primary parsers' ranges in the changed ranges
2) mark these ranges as to-be-fontified,
3) tell syntax-ppss to start reparsing from the min point of the
   ranges.

We need to mark to-be-fontified ranges before redisplay starts working, because sometimes the range edited by the user is not the only range that needs to be refontified. For example, when the user types the final slash of a C block comment /* xxx */, not only do we need to fontify the slash, but also the whole block comment, which previously wasn't fontified as comment due to incomplete parse tree.

Source Code

;; Defined in /usr/src/emacs/lisp/treesit.el.gz
(defun treesit--font-lock-mark-ranges-to-fontify (ranges _parser)
  "A notifier that marks ranges that needs refontification.

For RANGES and PARSER see `treesit-parser-add-notifier'.

After the parser reparses, we get the changed ranges, and
1) update non-primary parsers' ranges in the changed ranges
2) mark these ranges as to-be-fontified,
3) tell `syntax-ppss' to start reparsing from the min point of the
   ranges.

We need to mark to-be-fontified ranges before redisplay starts working,
because sometimes the range edited by the user is not the only range
that needs to be refontified.  For example, when the user types the
final slash of a C block comment /* xxx */, not only do we need to
fontify the slash, but also the whole block comment, which previously
wasn't fontified as comment due to incomplete parse tree."
  (dolist (range ranges)
    ;; 1. Update ranges.
    (treesit-update-ranges (car range) (cdr range))
    ;; 2. Mark the changed ranges to be fontified.
    (when treesit--font-lock-verbose
      (message "Notifier received range: %s-%s"
               (car range) (cdr range)))
    (with-silent-modifications
      (put-text-property (car range) (cdr range) 'fontified nil))
    ;; 3. Set `treesit--syntax-propertize-start'.
    (if (null treesit--syntax-propertize-start)
        (setq treesit--syntax-propertize-start (car range))
      (setq treesit--syntax-propertize-start
            (min treesit--syntax-propertize-start (car range))))))