Function: treesit--pre-redisplay

treesit--pre-redisplay is a byte-compiled function defined in treesit.el.gz.

Signature

(treesit--pre-redisplay &rest _)

Documentation

Force reparse and consequently run all notifiers.

One of the notifiers is treesit--font-lock-notifier, which will mark the region whose syntax has changed to "need to refontify".

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--pre-redisplay (&rest _)
  "Force reparse and consequently run all notifiers.

One of the notifiers is `treesit--font-lock-notifier', which will
mark the region whose syntax has changed to \"need to refontify\".

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."
  (unless (eq treesit--pre-redisplay-tick (buffer-chars-modified-tick))
    ;; `treesit-update-ranges' will force the host language's parser to
    ;; reparse and set correct ranges for embedded parsers.  Then
    ;; `treesit-parser-root-node' will force those parsers to reparse.
    (treesit-update-ranges)
    ;; Force repase on _all_ the parsers might not be necessary, but
    ;; this is probably the most robust way.
    (dolist (parser (treesit-parser-list))
      (treesit-parser-root-node parser))
    (setq treesit--pre-redisplay-tick (buffer-chars-modified-tick))))