;;; jit-lock.el --- just-in-time fontification -*- lexical-binding: t -*-
-;; Copyright (C) 1998, 2000-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000-2016 Free Software Foundation, Inc.
;; Author: Gerd Moellmann <gerd@gnu.org>
;; Keywords: faces files
(`(,this-beg . ,this-end)
(if (eq (car-safe res) 'jit-lock-bounds)
(cdr res) (cons beg end))))
- (setq tight-beg (max tight-beg (or this-beg (point-min))))
- (setq tight-end (max tight-end (or this-end (point-max))))
- (setq loose-beg (max loose-beg this-beg))
+ ;; If all functions don't fontify the same region, we currently
+ ;; just try to "still be correct". But we could go further and for
+ ;; the chunks of text that was fontified by some functions but not
+ ;; all, we could add text-properties indicating which functions were
+ ;; already run to avoid running them redundantly when we get to
+ ;; those chunks.
+ (setq tight-beg (max (or tight-beg (point-min)) this-beg))
+ (setq tight-end (min (or tight-end (point-max)) this-end))
+ (setq loose-beg (min loose-beg this-beg))
(setq loose-end (max loose-end this-end))
nil)))
`(,(min tight-beg beg) ,(max tight-end end) ,loose-beg ,loose-end)))
(save-excursion
(unless start (setq start (point-min)))
(setq end (if end (min end (point-max)) (point-max)))
- ;; This did bind `font-lock-beginning-of-syntax-function' to
- ;; nil at some point, for an unknown reason. Don't do this; it
- ;; can make highlighting slow due to expensive calls to
- ;; `parse-partial-sexp' in function
- ;; `font-lock-fontify-syntactically-region'. Example: paging
- ;; from the end of a buffer to its start, can do repeated
- ;; `parse-partial-sexp' starting from `point-min', which can
- ;; take a long time in a large buffer.
(let ((orig-start start) next)
(save-match-data
;; Fontify chunks beginning at START. The end of a
;; `tight' is the part we've fully refontified, and `loose'
;; is the part we've partly refontified (some of the
;; functions have refontified it but maybe not all).
- ((`(,tight-beg ,tight-end ,loose-beg ,loose-end)
+ ((`(,tight-beg ,tight-end ,loose-beg ,_loose-end)
(condition-case err
(jit-lock--run-functions start next)
;; If the user quits (which shouldn't happen in normal
(quit (put-text-property start next 'fontified nil)
(signal (car err) (cdr err))))))
- ;; In case we fontified more than requested, take note.
+ ;; In case we fontified more than requested, take advantage of the
+ ;; good news.
(when (or (< tight-beg start) (> tight-end next))
(put-text-property tight-beg tight-end 'fontified t))
'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-timer nil))
+ (let ((buffers jit-lock-defer-buffers)
+ (jit-lock-defer-timer nil))
+ (setq jit-lock-defer-buffers nil)
;; (message "Jit-Defer Now")
- (sit-for 0)
+ (unless (redisplay) ;FIXME: Should we `force'?
+ (setq jit-lock-defer-buffers buffers))
;; (message "Jit-Defer Done")
)))
(let ((jit-lock-start start)
(jit-lock-end end))
(with-buffer-prepared-for-jit-lock
- (run-hook-with-args 'jit-lock-after-change-extend-region-functions
- start end old-len)
- ;; Make sure we change at least one char (in case of deletions).
- (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
- ;; Request refontification.
- (put-text-property jit-lock-start jit-lock-end 'fontified nil))
+ (run-hook-with-args 'jit-lock-after-change-extend-region-functions
+ start end old-len)
+ ;; Make sure we change at least one char (in case of deletions).
+ (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
+ ;; Request refontification.
+ (save-restriction
+ (widen)
+ (put-text-property jit-lock-start jit-lock-end 'fontified nil)))
;; Mark the change for deferred contextual refontification.
(when jit-lock-context-unfontify-pos
(setq jit-lock-context-unfontify-pos