(defun jit-lock--run-functions-new (beg end &optional last-fun) (let ((tight-beg nil) (tight-end nil) ; The region we have fully fontified. (loose-beg beg) (loose-end end)) ; The maximum region we have fontified ; with at least some of ; `jit-lock-functions'. (run-hook-wrapped 'jit-lock-functions (lambda (fun) (if (eq fun last-fun) ;; If an earlier function in a recursive call has enlarged ;; the region being fontified, we need to re-run `last-fun'. (progn (when (< loose-beg beg) (pcase-let* ((res (funcall fun loose-beg beg)) (`(,this-beg . ,this-end) (if (eq (car-safe res) 'jit-lock-bounds) (cdr res) (cons loose-beg beg)))) (setq loose-beg this-beg))) (when (> loose-end end) (pcase-let* ((res (funcall fun end loose-end)) (`(,this-beg . ,this-end) (if (eq (car-safe res) 'jit-lock-bounds) (cdr res) (cons end loose-end)))) (setq loose-end this-end))) t) ; quit `run-hook-wrapped'. (pcase-let* ;; The first function in `jit-lock-functions' can expand ;; the region into `tight-beg' and `tight-end'. These ;; arguments are passed to the next function (if any). ;; Subsequently, the expanded region from any function is ;; stored in `loose-beg' and `loose-end', and is likewise ;; passed to the next function. ((res (funcall fun loose-beg loose-end)) (`(,this-beg . ,this-end) (if (eq (car-safe res) 'jit-lock-bounds) (cdr res) (cons beg end)))) ;;;; NEW STOUGH, 2021-09-07 (when (< this-beg loose-beg) (let ((sub-beg (car (jit-lock--run-functions this-beg loose-beg fun)))) (setq loose-beg this-beg))) (when (> this-end loose-end) (jit-lock--run-functions loose-end this-end) (setq loose-end this-end)) ;;;; END OF NEW STOUGH (or tight-beg (setq tight-beg (min this-beg beg))) (or tight-end (setq tight-end (max this-end end))) (setq loose-beg (min loose-beg this-beg)) (setq loose-end (max loose-end this-end)) nil)))) ; Carry on executing the hook. `(,(or tight-beg beg) ,(or tight-end end) ,loose-beg ,loose-end)))