+(defun jit-lock-deferred-fontify ()
+ "Fontify what was deferred."
+ (when jit-lock-defer-buffers
+ ;; Mark the deferred regions back to `fontified = nil'
+ (dolist (buffer jit-lock-defer-buffers)
+ (when (buffer-live-p buffer)
+ (with-current-buffer buffer
+ ;; (message "Jit-Defer %s" (buffer-name))
+ (with-buffer-prepared-for-jit-lock
+ (let ((pos (point-min)))
+ (while
+ (progn
+ (when (eq (get-text-property pos 'fontified) 'defer)
+ (put-text-property
+ pos (setq pos (next-single-property-change
+ pos 'fontified nil (point-max)))
+ 'fontified nil))
+ (setq pos (next-single-property-change pos 'fontified)))))))))
+ (setq jit-lock-defer-buffers nil)
+ ;; Force fontification of the visible parts.
+ (let ((jit-lock-defer-time nil))
+ ;; (message "Jit-Defer Now")
+ (sit-for 0)
+ ;; (message "Jit-Defer Done")
+ )))
+
+
+(defun jit-lock-context-fontify ()
+ "Refresh fontification to take new context into account."
+ (dolist (buffer (buffer-list))
+ (with-current-buffer buffer
+ (when jit-lock-context-unfontify-pos
+ ;; (message "Jit-Context %s" (buffer-name))
+ (save-restriction
+ (widen)
+ (when (and (>= jit-lock-context-unfontify-pos (point-min))
+ (< jit-lock-context-unfontify-pos (point-max)))
+ ;; If we're in text that matches a complex multi-line
+ ;; font-lock pattern, make sure the whole text will be
+ ;; redisplayed eventually.
+ ;; Despite its name, we treat jit-lock-defer-multiline here
+ ;; rather than in jit-lock-defer since it has to do with multiple
+ ;; lines, i.e. with context.
+ (when (get-text-property jit-lock-context-unfontify-pos
+ 'jit-lock-defer-multiline)
+ (setq jit-lock-context-unfontify-pos
+ (or (previous-single-property-change
+ jit-lock-context-unfontify-pos
+ 'jit-lock-defer-multiline)
+ (point-min))))
+ (with-buffer-prepared-for-jit-lock
+ ;; Force contextual refontification.
+ (remove-text-properties
+ jit-lock-context-unfontify-pos (point-max)
+ '(fontified nil jit-lock-defer-multiline nil)))
+ (setq jit-lock-context-unfontify-pos (point-max))))))))
+