Add "Package:" file headers to denote built-in packages.
[emacs.git] / lisp / jit-lock.el
blob1bc61d8d9fcdd67d4197689a4b732e3bf2a90843
1 ;;; jit-lock.el --- just-in-time fontification
3 ;; Copyright (C) 1998, 2000, 2001, 2002, 2003, 2004,
4 ;; 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
6 ;; Author: Gerd Moellmann <gerd@gnu.org>
7 ;; Keywords: faces files
8 ;; Package: emacs
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;;; Commentary:
27 ;; Just-in-time fontification, triggered by C redisplay code.
29 ;;; Code:
32 (eval-when-compile
33 (require 'cl)
35 (defmacro with-buffer-unmodified (&rest body)
36 "Eval BODY, preserving the current buffer's modified state."
37 (declare (debug t))
38 (let ((modified (make-symbol "modified")))
39 `(let ((,modified (buffer-modified-p)))
40 (unwind-protect
41 (progn ,@body)
42 (unless ,modified
43 (restore-buffer-modified-p nil))))))
45 (defmacro with-buffer-prepared-for-jit-lock (&rest body)
46 "Execute BODY in current buffer, overriding several variables.
47 Preserves the `buffer-modified-p' state of the current buffer."
48 (declare (debug t))
49 `(let ((buffer-undo-list t)
50 (inhibit-read-only t)
51 (inhibit-point-motion-hooks t)
52 (inhibit-modification-hooks t)
53 deactivate-mark
54 buffer-file-name
55 buffer-file-truename)
56 ;; Do reset the modification status from within the let, since
57 ;; otherwise set-buffer-modified-p may try to unlock the file.
58 (with-buffer-unmodified
59 ,@body))))
63 ;;; Customization.
65 (defgroup jit-lock nil
66 "Font Lock support mode to fontify just-in-time."
67 :version "21.1"
68 :group 'font-lock)
70 (defcustom jit-lock-chunk-size 500
71 "Jit-lock fontifies chunks of at most this many characters at a time.
73 This variable controls both display-time and stealth fontification."
74 :type 'integer
75 :group 'jit-lock)
78 (defcustom jit-lock-stealth-time nil
79 "Time in seconds to wait before beginning stealth fontification.
80 Stealth fontification occurs if there is no input within this time.
81 If nil, stealth fontification is never performed.
83 The value of this variable is used when JIT Lock mode is turned on."
84 :type '(choice (const :tag "never" nil)
85 (number :tag "seconds" :value 16))
86 :group 'jit-lock)
89 (defcustom jit-lock-stealth-nice 0.5
90 "Time in seconds to pause between chunks of stealth fontification.
91 Each iteration of stealth fontification is separated by this amount of time,
92 thus reducing the demand that stealth fontification makes on the system.
93 If nil, means stealth fontification is never paused.
94 To reduce machine load during stealth fontification, at the cost of stealth
95 taking longer to fontify, you could increase the value of this variable.
96 See also `jit-lock-stealth-load'."
97 :type '(choice (const :tag "never" nil)
98 (number :tag "seconds"))
99 :group 'jit-lock)
102 (defcustom jit-lock-stealth-load
103 (if (condition-case nil (load-average) (error)) 200)
104 "Load in percentage above which stealth fontification is suspended.
105 Stealth fontification pauses when the system short-term load average (as
106 returned by the function `load-average' if supported) goes above this level,
107 thus reducing the demand that stealth fontification makes on the system.
108 If nil, means stealth fontification is never suspended.
109 To reduce machine load during stealth fontification, at the cost of stealth
110 taking longer to fontify, you could reduce the value of this variable.
111 See also `jit-lock-stealth-nice'."
112 :type (if (condition-case nil (load-average) (error))
113 '(choice (const :tag "never" nil)
114 (integer :tag "load"))
115 '(const :format "%t: unsupported\n" nil))
116 :group 'jit-lock)
119 (defcustom jit-lock-stealth-verbose nil
120 "If non-nil, means stealth fontification should show status messages."
121 :type 'boolean
122 :group 'jit-lock)
125 (defvaralias 'jit-lock-defer-contextually 'jit-lock-contextually)
126 (defcustom jit-lock-contextually 'syntax-driven
127 "If non-nil, means fontification should be syntactically true.
128 If nil, means fontification occurs only on those lines modified. This
129 means where modification on a line causes syntactic change on subsequent lines,
130 those subsequent lines are not refontified to reflect their new context.
131 If t, means fontification occurs on those lines modified and all
132 subsequent lines. This means those subsequent lines are refontified to reflect
133 their new syntactic context, after `jit-lock-context-time' seconds.
134 If any other value, e.g., `syntax-driven', means syntactically true
135 fontification occurs only if syntactic fontification is performed using the
136 buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
138 The value of this variable is used when JIT Lock mode is turned on."
139 :type '(choice (const :tag "never" nil)
140 (const :tag "always" t)
141 (other :tag "syntax-driven" syntax-driven))
142 :group 'jit-lock)
144 (defcustom jit-lock-context-time 0.5
145 "Idle time after which text is contextually refontified, if applicable."
146 :type '(number :tag "seconds")
147 :group 'jit-lock)
149 (defcustom jit-lock-defer-time nil ;; 0.25
150 "Idle time after which deferred fontification should take place.
151 If nil, fontification is not deferred."
152 :group 'jit-lock
153 :type '(choice (const :tag "never" nil)
154 (number :tag "seconds")))
156 ;;; Variables that are not customizable.
158 (defvar jit-lock-mode nil
159 "Non-nil means Just-in-time Lock mode is active.")
160 (make-variable-buffer-local 'jit-lock-mode)
162 (defvar jit-lock-functions nil
163 "Functions to do the actual fontification.
164 They are called with two arguments: the START and END of the region to fontify.")
165 (make-variable-buffer-local 'jit-lock-functions)
167 (defvar jit-lock-context-unfontify-pos nil
168 "Consider text after this position as contextually unfontified.
169 If nil, contextual fontification is disabled.")
170 (make-variable-buffer-local 'jit-lock-context-unfontify-pos)
173 (defvar jit-lock-stealth-timer nil
174 "Timer for stealth fontification in Just-in-time Lock mode.")
175 (defvar jit-lock-stealth-repeat-timer nil
176 "Timer for repeated stealth fontification in Just-in-time Lock mode.")
177 (defvar jit-lock-context-timer nil
178 "Timer for context fontification in Just-in-time Lock mode.")
179 (defvar jit-lock-defer-timer nil
180 "Timer for deferred fontification in Just-in-time Lock mode.")
182 (defvar jit-lock-defer-buffers nil
183 "List of buffers with pending deferred fontification.")
184 (defvar jit-lock-stealth-buffers nil
185 "List of buffers that are being fontified stealthily.")
187 ;;; JIT lock mode
189 (defun jit-lock-mode (arg)
190 "Toggle Just-in-time Lock mode.
191 Turn Just-in-time Lock mode on if and only if ARG is non-nil.
192 Enable it automatically by customizing group `font-lock'.
194 When Just-in-time Lock mode is enabled, fontification is different in the
195 following ways:
197 - Demand-driven buffer fontification triggered by Emacs C code.
198 This means initial fontification of the whole buffer does not occur.
199 Instead, fontification occurs when necessary, such as when scrolling
200 through the buffer would otherwise reveal unfontified areas. This is
201 useful if buffer fontification is too slow for large buffers.
203 - Stealthy buffer fontification if `jit-lock-stealth-time' is non-nil.
204 This means remaining unfontified areas of buffers are fontified if Emacs has
205 been idle for `jit-lock-stealth-time' seconds, while Emacs remains idle.
206 This is useful if any buffer has any deferred fontification.
208 - Deferred context fontification if `jit-lock-contextually' is
209 non-nil. This means fontification updates the buffer corresponding to
210 true syntactic context, after `jit-lock-context-time' seconds of Emacs
211 idle time, while Emacs remains idle. Otherwise, fontification occurs
212 on modified lines only, and subsequent lines can remain fontified
213 corresponding to previous syntactic contexts. This is useful where
214 strings or comments span lines.
216 Stealth fontification only occurs while the system remains unloaded.
217 If the system load rises above `jit-lock-stealth-load' percent, stealth
218 fontification is suspended. Stealth fontification intensity is controlled via
219 the variable `jit-lock-stealth-nice'."
220 (setq jit-lock-mode arg)
221 (cond (;; Turn Just-in-time Lock mode on.
222 jit-lock-mode
224 ;; Mark the buffer for refontification.
225 (jit-lock-refontify)
227 ;; Install an idle timer for stealth fontification.
228 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
229 (setq jit-lock-stealth-timer
230 (run-with-idle-timer jit-lock-stealth-time t
231 'jit-lock-stealth-fontify)))
233 ;; Create, but do not activate, the idle timer for repeated
234 ;; stealth fontification.
235 (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer))
236 (setq jit-lock-stealth-repeat-timer (timer-create))
237 (timer-set-function jit-lock-stealth-repeat-timer
238 'jit-lock-stealth-fontify '(t)))
240 ;; Init deferred fontification timer.
241 (when (and jit-lock-defer-time (null jit-lock-defer-timer))
242 (setq jit-lock-defer-timer
243 (run-with-idle-timer jit-lock-defer-time t
244 'jit-lock-deferred-fontify)))
246 ;; Initialize contextual fontification if requested.
247 (when (eq jit-lock-contextually t)
248 (unless jit-lock-context-timer
249 (setq jit-lock-context-timer
250 (run-with-idle-timer jit-lock-context-time t
251 'jit-lock-context-fontify)))
252 (setq jit-lock-context-unfontify-pos
253 (or jit-lock-context-unfontify-pos (point-max))))
255 ;; Setup our hooks.
256 (add-hook 'after-change-functions 'jit-lock-after-change nil t)
257 (add-hook 'fontification-functions 'jit-lock-function))
259 ;; Turn Just-in-time Lock mode off.
261 ;; Cancel our idle timers.
262 (when (and (or jit-lock-stealth-timer jit-lock-defer-timer
263 jit-lock-context-timer)
264 ;; Only if there's no other buffer using them.
265 (not (catch 'found
266 (dolist (buf (buffer-list))
267 (with-current-buffer buf
268 (when jit-lock-mode (throw 'found t)))))))
269 (when jit-lock-stealth-timer
270 (cancel-timer jit-lock-stealth-timer)
271 (setq jit-lock-stealth-timer nil))
272 (when jit-lock-context-timer
273 (cancel-timer jit-lock-context-timer)
274 (setq jit-lock-context-timer nil))
275 (when jit-lock-defer-timer
276 (cancel-timer jit-lock-defer-timer)
277 (setq jit-lock-defer-timer nil)))
279 ;; Remove hooks.
280 (remove-hook 'after-change-functions 'jit-lock-after-change t)
281 (remove-hook 'fontification-functions 'jit-lock-function))))
283 (defun jit-lock-register (fun &optional contextual)
284 "Register FUN as a fontification function to be called in this buffer.
285 FUN will be called with two arguments START and END indicating the region
286 that needs to be (re)fontified.
287 If non-nil, CONTEXTUAL means that a contextual fontification would be useful."
288 (add-hook 'jit-lock-functions fun nil t)
289 (when (and contextual jit-lock-contextually)
290 (set (make-local-variable 'jit-lock-contextually) t))
291 (jit-lock-mode t))
293 (defun jit-lock-unregister (fun)
294 "Unregister FUN as a fontification function.
295 Only applies to the current buffer."
296 (remove-hook 'jit-lock-functions fun t)
297 (unless jit-lock-functions (jit-lock-mode nil)))
299 ;; This function is used to prevent font-lock-fontify-buffer from
300 ;; fontifying eagerly the whole buffer. This is important for
301 ;; things like CWarn mode which adds/removes a few keywords and
302 ;; does a refontify (which takes ages on large files).
303 (defun jit-lock-refontify (&optional beg end)
304 "Force refontification of the region BEG..END (default whole buffer)."
305 (with-buffer-prepared-for-jit-lock
306 (save-restriction
307 (widen)
308 (put-text-property (or beg (point-min)) (or end (point-max))
309 'fontified nil))))
311 ;;; On demand fontification.
313 (defun jit-lock-function (start)
314 "Fontify current buffer starting at position START.
315 This function is added to `fontification-functions' when `jit-lock-mode'
316 is active."
317 (when (and jit-lock-mode (not memory-full))
318 (if (null jit-lock-defer-timer)
319 ;; No deferral.
320 (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
321 ;; Record the buffer for later fontification.
322 (unless (memq (current-buffer) jit-lock-defer-buffers)
323 (push (current-buffer) jit-lock-defer-buffers))
324 ;; Mark the area as defer-fontified so that the redisplay engine
325 ;; is happy and so that the idle timer can find the places to fontify.
326 (with-buffer-prepared-for-jit-lock
327 (put-text-property start
328 (next-single-property-change
329 start 'fontified nil
330 (min (point-max) (+ start jit-lock-chunk-size)))
331 'fontified 'defer)))))
333 (defun jit-lock-fontify-now (&optional start end)
334 "Fontify current buffer from START to END.
335 Defaults to the whole buffer. END can be out of bounds."
336 (with-buffer-prepared-for-jit-lock
337 (save-excursion
338 (unless start (setq start (point-min)))
339 (setq end (if end (min end (point-max)) (point-max)))
340 ;; This did bind `font-lock-beginning-of-syntax-function' to
341 ;; nil at some point, for an unknown reason. Don't do this; it
342 ;; can make highlighting slow due to expensive calls to
343 ;; `parse-partial-sexp' in function
344 ;; `font-lock-fontify-syntactically-region'. Example: paging
345 ;; from the end of a buffer to its start, can do repeated
346 ;; `parse-partial-sexp' starting from `point-min', which can
347 ;; take a long time in a large buffer.
348 (let ((orig-start start) next)
349 (save-match-data
350 ;; Fontify chunks beginning at START. The end of a
351 ;; chunk is either `end', or the start of a region
352 ;; before `end' that has already been fontified.
353 (while (and start (< start end))
354 ;; Determine the end of this chunk.
355 (setq next (or (text-property-any start end 'fontified t)
356 end))
358 ;; Decide which range of text should be fontified.
359 ;; The problem is that START and NEXT may be in the
360 ;; middle of something matched by a font-lock regexp.
361 ;; Until someone has a better idea, let's start
362 ;; at the start of the line containing START and
363 ;; stop at the start of the line following NEXT.
364 (goto-char next) (setq next (line-beginning-position 2))
365 (goto-char start) (setq start (line-beginning-position))
367 ;; Make sure the contextual refontification doesn't re-refontify
368 ;; what's already been refontified.
369 (when (and jit-lock-context-unfontify-pos
370 (< jit-lock-context-unfontify-pos next)
371 (>= jit-lock-context-unfontify-pos start)
372 ;; Don't move boundary forward if we have to
373 ;; refontify previous text. Otherwise, we risk moving
374 ;; it past the end of the multiline property and thus
375 ;; forget about this multiline region altogether.
376 (not (get-text-property start 'jit-lock-defer-multiline)))
377 (setq jit-lock-context-unfontify-pos next))
379 ;; Fontify the chunk, and mark it as fontified.
380 ;; We mark it first, to make sure that we don't indefinitely
381 ;; re-execute this fontification if an error occurs.
382 (put-text-property start next 'fontified t)
383 (condition-case err
384 (run-hook-with-args 'jit-lock-functions start next)
385 ;; If the user quits (which shouldn't happen in normal on-the-fly
386 ;; jit-locking), make sure the fontification will be performed
387 ;; before displaying the block again.
388 (quit (put-text-property start next 'fontified nil)
389 (funcall 'signal (car err) (cdr err))))
391 ;; The redisplay engine has already rendered the buffer up-to
392 ;; `orig-start' and won't notice if the above jit-lock-functions
393 ;; changed the appearance of any part of the buffer prior
394 ;; to that. So if `start' is before `orig-start', we need to
395 ;; cause a new redisplay cycle after this one so that any changes
396 ;; are properly reflected on screen.
397 ;; To make such repeated redisplay happen less often, we can
398 ;; eagerly extend the refontified region with
399 ;; jit-lock-after-change-extend-region-functions.
400 (when (< start orig-start)
401 (run-with-timer 0 nil 'jit-lock-force-redisplay
402 (current-buffer) start orig-start))
404 ;; Find the start of the next chunk, if any.
405 (setq start (text-property-any next end 'fontified nil))))))))
407 (defun jit-lock-force-redisplay (buf start end)
408 "Force the display engine to re-render buffer BUF from START to END."
409 (with-current-buffer buf
410 (with-buffer-prepared-for-jit-lock
411 ;; Don't cause refontification (it's already been done), but just do
412 ;; some random buffer change, so as to force redisplay.
413 (put-text-property start end 'fontified t))))
417 ;;; Stealth fontification.
419 (defsubst jit-lock-stealth-chunk-start (around)
420 "Return the start of the next chunk to fontify around position AROUND.
421 Value is nil if there is nothing more to fontify."
422 (if (zerop (buffer-size))
424 (save-restriction
425 (widen)
426 (let* ((next (text-property-not-all around (point-max) 'fontified t))
427 (prev (previous-single-property-change around 'fontified))
428 (prop (get-text-property (max (point-min) (1- around))
429 'fontified))
430 (start (cond
431 ((null prev)
432 ;; There is no property change between AROUND
433 ;; and the start of the buffer. If PROP is
434 ;; non-nil, everything in front of AROUND is
435 ;; fontified, otherwise nothing is fontified.
436 (if (eq prop t)
438 (max (point-min)
439 (- around (/ jit-lock-chunk-size 2)))))
440 ((eq prop t)
441 ;; PREV is the start of a region of fontified
442 ;; text containing AROUND. Start fontifying a
443 ;; chunk size before the end of the unfontified
444 ;; region in front of that.
445 (max (or (previous-single-property-change prev 'fontified)
446 (point-min))
447 (- prev jit-lock-chunk-size)))
449 ;; PREV is the start of a region of unfontified
450 ;; text containing AROUND. Start at PREV or
451 ;; chunk size in front of AROUND, whichever is
452 ;; nearer.
453 (max prev (- around jit-lock-chunk-size)))))
454 (result (cond ((null start) next)
455 ((null next) start)
456 ((< (- around start) (- next around)) start)
457 (t next))))
458 result))))
460 (defun jit-lock-stealth-fontify (&optional repeat)
461 "Fontify buffers stealthily.
462 This function is called repeatedly after Emacs has become idle for
463 `jit-lock-stealth-time' seconds. Optional argument REPEAT is expected
464 non-nil in a repeated invocation of this function."
465 ;; Cancel timer for repeated invocations.
466 (unless repeat
467 (cancel-timer jit-lock-stealth-repeat-timer))
468 (unless (or executing-kbd-macro
469 memory-full
470 (window-minibuffer-p (selected-window))
471 ;; For first invocation set up `jit-lock-stealth-buffers'.
472 ;; In repeated invocations it's already been set up.
473 (null (if repeat
474 jit-lock-stealth-buffers
475 (setq jit-lock-stealth-buffers (buffer-list)))))
476 (let ((buffer (car jit-lock-stealth-buffers))
477 (delay 0)
478 minibuffer-auto-raise
479 message-log-max
480 start)
481 (if (and jit-lock-stealth-load
482 (> (car (load-average)) jit-lock-stealth-load))
483 ;; Wait a little if load is too high.
484 (setq delay jit-lock-stealth-time)
485 (if (buffer-live-p buffer)
486 (with-current-buffer buffer
487 (if (and jit-lock-mode
488 (setq start (jit-lock-stealth-chunk-start (point))))
489 ;; Fontify one block of at most `jit-lock-chunk-size'
490 ;; characters.
491 (with-temp-message (if jit-lock-stealth-verbose
492 (concat "JIT stealth lock "
493 (buffer-name)))
494 (jit-lock-fontify-now start
495 (+ start jit-lock-chunk-size))
496 ;; Run again after `jit-lock-stealth-nice' seconds.
497 (setq delay (or jit-lock-stealth-nice 0)))
498 ;; Nothing to fontify here. Remove this buffer from
499 ;; `jit-lock-stealth-buffers' and run again immediately.
500 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
501 ;; Buffer is no longer live. Remove it from
502 ;; `jit-lock-stealth-buffers' and run again immediately.
503 (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
504 ;; Call us again.
505 (when jit-lock-stealth-buffers
506 (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
507 (timer-inc-time jit-lock-stealth-repeat-timer delay)
508 (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))))
511 ;;; Deferred fontification.
513 (defun jit-lock-deferred-fontify ()
514 "Fontify what was deferred."
515 (when (and jit-lock-defer-buffers (not memory-full))
516 ;; Mark the deferred regions back to `fontified = nil'
517 (dolist (buffer jit-lock-defer-buffers)
518 (when (buffer-live-p buffer)
519 (with-current-buffer buffer
520 ;; (message "Jit-Defer %s" (buffer-name))
521 (with-buffer-prepared-for-jit-lock
522 (let ((pos (point-min)))
523 (while
524 (progn
525 (when (eq (get-text-property pos 'fontified) 'defer)
526 (put-text-property
527 pos (setq pos (next-single-property-change
528 pos 'fontified nil (point-max)))
529 'fontified nil))
530 (setq pos (next-single-property-change pos 'fontified)))))))))
531 (setq jit-lock-defer-buffers nil)
532 ;; Force fontification of the visible parts.
533 (let ((jit-lock-defer-timer nil))
534 ;; (message "Jit-Defer Now")
535 (sit-for 0)
536 ;; (message "Jit-Defer Done")
540 (defun jit-lock-context-fontify ()
541 "Refresh fontification to take new context into account."
542 (unless memory-full
543 (dolist (buffer (buffer-list))
544 (with-current-buffer buffer
545 (when jit-lock-context-unfontify-pos
546 ;; (message "Jit-Context %s" (buffer-name))
547 (save-restriction
548 (widen)
549 (when (and (>= jit-lock-context-unfontify-pos (point-min))
550 (< jit-lock-context-unfontify-pos (point-max)))
551 ;; If we're in text that matches a complex multi-line
552 ;; font-lock pattern, make sure the whole text will be
553 ;; redisplayed eventually.
554 ;; Despite its name, we treat jit-lock-defer-multiline here
555 ;; rather than in jit-lock-defer since it has to do with multiple
556 ;; lines, i.e. with context.
557 (when (get-text-property jit-lock-context-unfontify-pos
558 'jit-lock-defer-multiline)
559 (setq jit-lock-context-unfontify-pos
560 (or (previous-single-property-change
561 jit-lock-context-unfontify-pos
562 'jit-lock-defer-multiline)
563 (point-min))))
564 (with-buffer-prepared-for-jit-lock
565 ;; Force contextual refontification.
566 (remove-text-properties
567 jit-lock-context-unfontify-pos (point-max)
568 '(fontified nil jit-lock-defer-multiline nil)))
569 (setq jit-lock-context-unfontify-pos (point-max)))))))))
571 (defvar jit-lock-start) (defvar jit-lock-end) ; Dynamically scoped variables.
572 (defvar jit-lock-after-change-extend-region-functions nil
573 "Hook that can extend the text to refontify after a change.
574 This is run after every buffer change. The functions are called with
575 the three arguments of `after-change-functions': START END OLD-LEN.
576 The extended region to refontify is returned indirectly by modifying
577 the variables `jit-lock-start' and `jit-lock-end'.
579 Note that extending the region this way is not strictly necessary, except
580 that the nature of the redisplay code tends to otherwise leave some of
581 the rehighlighted text displayed with the old highlight until the next
582 redisplay (see comment about repeated redisplay in `jit-lock-fontify-now').")
584 (defun jit-lock-after-change (start end old-len)
585 "Mark the rest of the buffer as not fontified after a change.
586 Installed on `after-change-functions'.
587 START and END are the start and end of the changed text. OLD-LEN
588 is the pre-change length.
589 This function ensures that lines following the change will be refontified
590 in case the syntax of those lines has changed. Refontification
591 will take place when text is fontified stealthily."
592 (when (and jit-lock-mode (not memory-full))
593 (let ((jit-lock-start start)
594 (jit-lock-end end))
595 (with-buffer-prepared-for-jit-lock
596 (run-hook-with-args 'jit-lock-after-change-extend-region-functions
597 start end old-len)
598 ;; Make sure we change at least one char (in case of deletions).
599 (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
600 ;; Request refontification.
601 (put-text-property jit-lock-start jit-lock-end 'fontified nil))
602 ;; Mark the change for deferred contextual refontification.
603 (when jit-lock-context-unfontify-pos
604 (setq jit-lock-context-unfontify-pos
605 ;; Here we use `start' because nothing guarantees that the
606 ;; text between start and end will be otherwise refontified:
607 ;; usually it will be refontified by virtue of being
608 ;; displayed, but if it's outside of any displayed area in the
609 ;; buffer, only jit-lock-context-* will re-fontify it.
610 (min jit-lock-context-unfontify-pos jit-lock-start))))))
612 (provide 'jit-lock)
614 ;; arch-tag: 56b5de6e-f581-453b-bb97-49c39372ff9e
615 ;;; jit-lock.el ends here