during a single command loop, we use this variable to debounce
calls to `treesit--pre-redisplay'.")
-(defun treesit--font-lock-mark-ranges-to-fontify (ranges _parser)
+(defun treesit--font-lock-mark-ranges-to-fontify (ranges)
"A notifier that marks ranges that needs refontification.
For RANGES and PARSER see `treesit-parser-add-notifier'.
(car (treesit-parser-list))))
(defun treesit--pre-redisplay (&rest _)
- "Force a reparse on the primary parser and mark regions to be fontified.
-
-The actual work is carried out by
-`treesit--font-lock-mark-ranges-to-fontify', which see."
+ "Force a reparse on primary parser and mark regions to be fontified."
(unless (eq treesit--pre-redisplay-tick (buffer-chars-modified-tick))
(when treesit-primary-parser
- ;; Force a reparse on the primary parser, if everything is setup
- ;; correctly, the parser should call
- ;; `treesit--font-lock-mark-ranges-to-fontify' (which should be a
- ;; notifier function of the primary parser).
- (treesit-parser-root-node treesit-primary-parser))
+ ;; Force a reparse on the primary parser and update embedded
+ ;; parser ranges in the changed ranges.
+ (let ((affected-ranges (treesit-parser-changed-regions
+ treesit-primary-parser)))
+ (when affected-ranges
+ (treesit--font-lock-mark-ranges-to-fontify affected-ranges))))
(setq treesit--pre-redisplay-tick (buffer-chars-modified-tick))))
"Search for the next outline heading in the syntax tree.
For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in
`outline-search-function'."
+ (treesit--pre-redisplay)
(if looking-at
(when (treesit-outline--at-point) (pos-bol))
level))
-(defun treesit--after-change (beg end _len)
- "Force updating the ranges in BEG...END.
-Expected to be called after each text change."
- (treesit-update-ranges beg end))
-
;;; Hideshow mode
(defun treesit-hs-block-end ()
. treesit-font-lock-fontify-region)))
(treesit-font-lock-recompute-features)
(add-hook 'pre-redisplay-functions #'treesit--pre-redisplay 0 t)
- (when treesit-primary-parser
- (treesit-parser-add-notifier
- treesit-primary-parser #'treesit--font-lock-mark-ranges-to-fontify))
(treesit-validate-font-lock-rules treesit-font-lock-settings))
;; Syntax
(add-hook 'syntax-propertize-extend-region-functions
(setq treesit-outline-predicate
#'treesit-outline-predicate--from-imenu))
(setq-local outline-search-function #'treesit-outline-search
- outline-level #'treesit-outline-level)
- (add-hook 'outline-after-change-functions #'treesit--after-change nil t))
+ outline-level #'treesit-outline-level))
;; Remove existing local parsers.
(dolist (ov (overlays-in (point-min) (point-max)))