-;;; jit-lock.el --- just-in-time fontification
+;;; jit-lock.el --- just-in-time fontification -*- lexical-binding: t -*-
;; Copyright (C) 1998, 2000-2013 Free Software Foundation, Inc.
\f
;;; Variables that are not customizable.
-(defvar jit-lock-mode nil
+(defvar-local jit-lock-mode nil
"Non-nil means Just-in-time Lock mode is active.")
-(make-variable-buffer-local 'jit-lock-mode)
-(defvar jit-lock-functions nil
+(defvar-local jit-lock-functions nil
"Functions to do the actual fontification.
They are called with two arguments: the START and END of the region to fontify.")
-(make-variable-buffer-local 'jit-lock-functions)
-(defvar jit-lock-context-unfontify-pos nil
+(defvar-local jit-lock-context-unfontify-pos nil
"Consider text after this position as contextually unfontified.
If nil, contextual fontification is disabled.")
-(make-variable-buffer-local 'jit-lock-context-unfontify-pos)
-
(defvar jit-lock-stealth-timer nil
"Timer for stealth fontification in Just-in-time Lock mode.")
When this minor mode is enabled, jit-lock runs as little code as possible
during redisplay and moves the rest to a timer, where things
like `debug-on-error' and Edebug can be used."
- :global t
+ :global t :group 'jit-lock
(when jit-lock-defer-timer
(cancel-timer jit-lock-defer-timer)
(setq jit-lock-defer-timer nil))
If non-nil, CONTEXTUAL means that a contextual fontification would be useful."
(add-hook 'jit-lock-functions fun nil t)
(when (and contextual jit-lock-contextually)
- (set (make-local-variable 'jit-lock-contextually) t))
+ (setq-local jit-lock-contextually t))
(jit-lock-mode t))
(defun jit-lock-unregister (fun)
;; eagerly extend the refontified region with
;; jit-lock-after-change-extend-region-functions.
(when (< start orig-start)
- (run-with-timer 0 nil 'jit-lock-force-redisplay
- (current-buffer) start orig-start))
+ (run-with-timer 0 nil #'jit-lock-force-redisplay
+ (copy-marker start) (copy-marker orig-start)))
;; Find the start of the next chunk, if any.
(setq start (text-property-any next end 'fontified nil))))))))
-(defun jit-lock-force-redisplay (buf start end)
+(defun jit-lock-force-redisplay (start end)
"Force the display engine to re-render buffer BUF from START to END."
- (with-current-buffer buf
- (with-buffer-prepared-for-jit-lock
- ;; Don't cause refontification (it's already been done), but just do
- ;; some random buffer change, so as to force redisplay.
- (put-text-property start end 'fontified t))))
-
-
+ (when (marker-buffer start)
+ (with-current-buffer (marker-buffer start)
+ (with-buffer-prepared-for-jit-lock
+ (when (> end (point-max))
+ (setq end (point-max) start (min start end)))
+ (when (< start (point-min))
+ (setq start (point-min) end (max start end)))
+ ;; Don't cause refontification (it's already been done), but just do
+ ;; some random buffer change, so as to force redisplay.
+ (put-text-property start end 'fontified t)))))
\f
;;; Stealth fontification.
Value is nil if there is nothing more to fontify."
(if (zerop (buffer-size))
nil
- (save-restriction
- (widen)
- (let* ((next (text-property-not-all around (point-max) 'fontified t))
- (prev (previous-single-property-change around 'fontified))
- (prop (get-text-property (max (point-min) (1- around))
- 'fontified))
- (start (cond
- ((null prev)
- ;; There is no property change between AROUND
- ;; and the start of the buffer. If PROP is
- ;; non-nil, everything in front of AROUND is
- ;; fontified, otherwise nothing is fontified.
- (if (eq prop t)
- nil
- (max (point-min)
- (- around (/ jit-lock-chunk-size 2)))))
- ((eq prop t)
- ;; PREV is the start of a region of fontified
- ;; text containing AROUND. Start fontifying a
- ;; chunk size before the end of the unfontified
- ;; region in front of that.
- (max (or (previous-single-property-change prev 'fontified)
- (point-min))
- (- prev jit-lock-chunk-size)))
- (t
- ;; PREV is the start of a region of unfontified
- ;; text containing AROUND. Start at PREV or
- ;; chunk size in front of AROUND, whichever is
- ;; nearer.
- (max prev (- around jit-lock-chunk-size)))))
- (result (cond ((null start) next)
- ((null next) start)
- ((< (- around start) (- next around)) start)
- (t next))))
- result))))
+ (let* ((next (text-property-not-all around (point-max) 'fontified t))
+ (prev (previous-single-property-change around 'fontified))
+ (prop (get-text-property (max (point-min) (1- around))
+ 'fontified))
+ (start (cond
+ ((null prev)
+ ;; There is no property change between AROUND
+ ;; and the start of the buffer. If PROP is
+ ;; non-nil, everything in front of AROUND is
+ ;; fontified, otherwise nothing is fontified.
+ (if (eq prop t)
+ nil
+ (max (point-min)
+ (- around (/ jit-lock-chunk-size 2)))))
+ ((eq prop t)
+ ;; PREV is the start of a region of fontified
+ ;; text containing AROUND. Start fontifying a
+ ;; chunk size before the end of the unfontified
+ ;; region in front of that.
+ (max (or (previous-single-property-change prev 'fontified)
+ (point-min))
+ (- prev jit-lock-chunk-size)))
+ (t
+ ;; PREV is the start of a region of unfontified
+ ;; text containing AROUND. Start at PREV or
+ ;; chunk size in front of AROUND, whichever is
+ ;; nearer.
+ (max prev (- around jit-lock-chunk-size)))))
+ (result (cond ((null start) next)
+ ((null next) start)
+ ((< (- around start) (- next around)) start)
+ (t next))))
+ result)))
(defun jit-lock-stealth-fontify (&optional repeat)
"Fontify buffers stealthily.
(cancel-timer jit-lock-stealth-repeat-timer))
(unless (or executing-kbd-macro
memory-full
- (window-minibuffer-p (selected-window))
+ (window-minibuffer-p)
;; For first invocation set up `jit-lock-stealth-buffers'.
;; In repeated invocations it's already been set up.
(null (if repeat
(when jit-lock-context-unfontify-pos
;; (message "Jit-Context %s" (buffer-name))
(save-restriction
- (widen)
+ ;; Don't be blindsided by narrowing that starts in the middle
+ ;; of a jit-lock-defer-multiline.
+ (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