Mercurial > emacs
comparison lisp/jit-lock.el @ 32152:00f38571e2b1
(with-buffer-unmodified): Use unwind-protect.
(jit-lock-mode): Make sure font-lock-keywords-only is bound before use.
(jit-lock-functions): New var.
(jit-lock-function-1): Use it if non-nil.
Don't switch the syntax-table. Don't set parse-sexp-lookup-properties.
Set the `fontified' property before doing the fontification to avoid
repeatedly going through the same error.
Don't turn errors into messages.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Thu, 05 Oct 2000 01:27:55 +0000 |
parents | dd9436a06050 |
children | b3596a2daf42 |
comparison
equal
deleted
inserted
replaced
32151:903746da4148 | 32152:00f38571e2b1 |
---|---|
35 (eval-when-compile | 35 (eval-when-compile |
36 (defmacro with-buffer-unmodified (&rest body) | 36 (defmacro with-buffer-unmodified (&rest body) |
37 "Eval BODY, preserving the current buffer's modified state." | 37 "Eval BODY, preserving the current buffer's modified state." |
38 (let ((modified (make-symbol "modified"))) | 38 (let ((modified (make-symbol "modified"))) |
39 `(let ((,modified (buffer-modified-p))) | 39 `(let ((,modified (buffer-modified-p))) |
40 ,@body | 40 (unwind-protect |
41 (unless ,modified | 41 (progn ,@body) |
42 (restore-buffer-modified-p nil))))) | 42 (unless ,modified |
43 (restore-buffer-modified-p nil)))))) | |
43 | 44 |
44 (defmacro with-buffer-prepared-for-jit-lock (&rest body) | 45 (defmacro with-buffer-prepared-for-jit-lock (&rest body) |
45 "Execute BODY in current buffer, overriding several variables. | 46 "Execute BODY in current buffer, overriding several variables. |
46 Preserves the `buffer-modified-p' state of the current buffer." | 47 Preserves the `buffer-modified-p' state of the current buffer." |
47 `(with-buffer-unmodified | 48 `(with-buffer-unmodified |
135 | 136 |
136 (defvar jit-lock-mode nil | 137 (defvar jit-lock-mode nil |
137 "Non-nil means Just-in-time Lock mode is active.") | 138 "Non-nil means Just-in-time Lock mode is active.") |
138 (make-variable-buffer-local 'jit-lock-mode) | 139 (make-variable-buffer-local 'jit-lock-mode) |
139 | 140 |
141 (defvar jit-lock-functions nil | |
142 "Functions to do the actual fontification. | |
143 They are called with two arguments: the START and END of the region to fontify.") | |
140 | 144 |
141 (defvar jit-lock-first-unfontify-pos nil | 145 (defvar jit-lock-first-unfontify-pos nil |
142 "Consider text after this position as unfontified. | 146 "Consider text after this position as unfontified. |
143 If nil, contextual fontification is disabled.") | 147 If nil, contextual fontification is disabled.") |
144 (make-variable-buffer-local 'jit-lock-first-unfontify-pos) | 148 (make-variable-buffer-local 'jit-lock-first-unfontify-pos) |
214 'jit-lock-stealth-fontify))) | 218 'jit-lock-stealth-fontify))) |
215 | 219 |
216 ;; Initialize deferred contextual fontification if requested. | 220 ;; Initialize deferred contextual fontification if requested. |
217 (when (or (eq jit-lock-defer-contextually 'always) | 221 (when (or (eq jit-lock-defer-contextually 'always) |
218 (and (not (eq jit-lock-defer-contextually 'never)) | 222 (and (not (eq jit-lock-defer-contextually 'never)) |
223 (boundp 'font-lock-keywords-only) | |
219 (null font-lock-keywords-only))) | 224 (null font-lock-keywords-only))) |
220 (setq jit-lock-first-unfontify-pos (point-max))) | 225 (setq jit-lock-first-unfontify-pos (point-max))) |
221 | 226 |
222 ;; Setup our after-change-function | 227 ;; Setup our after-change-function |
223 ;; and remove font-lock's (if any). | 228 ;; and remove font-lock's (if any). |
274 (with-buffer-prepared-for-jit-lock | 279 (with-buffer-prepared-for-jit-lock |
275 (save-excursion | 280 (save-excursion |
276 (save-restriction | 281 (save-restriction |
277 (widen) | 282 (widen) |
278 (let ((end (min (point-max) (+ start jit-lock-chunk-size))) | 283 (let ((end (min (point-max) (+ start jit-lock-chunk-size))) |
279 (parse-sexp-lookup-properties font-lock-syntactic-keywords) | |
280 (font-lock-beginning-of-syntax-function nil) | 284 (font-lock-beginning-of-syntax-function nil) |
281 (old-syntax-table (syntax-table)) | 285 next) |
282 next font-lock-start font-lock-end) | |
283 (when font-lock-syntax-table | |
284 (set-syntax-table font-lock-syntax-table)) | |
285 (save-match-data | 286 (save-match-data |
286 (condition-case error | 287 ;; Fontify chunks beginning at START. The end of a |
287 ;; Fontify chunks beginning at START. The end of a | 288 ;; chunk is either `end', or the start of a region |
288 ;; chunk is either `end', or the start of a region | 289 ;; before `end' that has already been fontified. |
289 ;; before `end' that has already been fontified. | 290 (while start |
290 (while start | 291 ;; Determine the end of this chunk. |
291 ;; Determine the end of this chunk. | 292 (setq next (or (text-property-any start end 'fontified t) |
292 (setq next (or (text-property-any start end 'fontified t) | 293 end)) |
293 end)) | 294 |
294 | 295 ;; Decide which range of text should be fontified. |
295 ;; Decide which range of text should be fontified. | 296 ;; The problem is that START and NEXT may be in the |
296 ;; The problem is that START and NEXT may be in the | 297 ;; middle of something matched by a font-lock regexp. |
297 ;; middle of something matched by a font-lock regexp. | 298 ;; Until someone has a better idea, let's start |
298 ;; Until someone has a better idea, let's start | 299 ;; at the start of the line containing START and |
299 ;; at the start of the line containing START and | 300 ;; stop at the start of the line following NEXT. |
300 ;; stop at the start of the line following NEXT. | 301 (goto-char next) |
301 (goto-char next) | 302 (setq next (line-beginning-position 2)) |
302 (setq font-lock-end (line-beginning-position 2)) | 303 (goto-char start) |
303 (goto-char start) | 304 (setq start (line-beginning-position)) |
304 (setq font-lock-start (line-beginning-position)) | |
305 | 305 |
306 ;; Fontify the chunk, and mark it as fontified. | 306 ;; Fontify the chunk, and mark it as fontified. |
307 (font-lock-fontify-region font-lock-start font-lock-end nil) | 307 ;; We mark it first, to make sure that we don't indefinitely |
308 (add-text-properties start next '(fontified t)) | 308 ;; re-execute this fontification if an error occurs. |
309 (add-text-properties start next '(fontified t)) | |
310 (if jit-lock-functions | |
311 (run-hook-with-args 'jit-lock-functions start next) | |
312 (font-lock-fontify-region start next)) | |
309 | 313 |
310 ;; Find the start of the next chunk, if any. | 314 ;; Find the start of the next chunk, if any. |
311 (setq start (text-property-any next end 'fontified nil))) | 315 (setq start (text-property-any next end 'fontified nil))))))))) |
312 | |
313 ((error quit) | |
314 (message "Fontifying region...%s" error)))) | |
315 | |
316 ;; Restore previous buffer settings. | |
317 (set-syntax-table old-syntax-table)))))) | |
318 | 316 |
319 | 317 |
320 ;;; Stealth fontification. | 318 ;;; Stealth fontification. |
321 | 319 |
322 (defsubst jit-lock-stealth-chunk-start (around) | 320 (defsubst jit-lock-stealth-chunk-start (around) |