diff --git a/lisp/treesit.el b/lisp/treesit.el index 893e21ec0c5..aef61d2e68b 100644 --- a/lisp/treesit.el +++ b/lisp/treesit.el @@ -2020,7 +2020,7 @@ Because `pre-redisplay-functions' could be called multiple times 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'. @@ -2074,17 +2074,15 @@ parser." (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)))) @@ -4072,6 +4070,7 @@ this variable takes priority.") "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)) @@ -4158,11 +4157,6 @@ For BOUND, MOVE, BACKWARD, LOOKING-AT, see the descriptions in 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 () @@ -4374,9 +4368,6 @@ before calling this function." . 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 @@ -4462,8 +4453,7 @@ before calling this function." (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)))