diff options
| author | Stefan Monnier | 2000-10-05 01:27:55 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2000-10-05 01:27:55 +0000 |
| commit | be390cb3d8e55003c1a5ed5e4efce791aa86892f (patch) | |
| tree | 3a8ad3453e04ad1ff598b3215fe5baa6c323d74b | |
| parent | 22aca18670e217db83cadf7aa6eeb1d8aad9b48b (diff) | |
| download | emacs-be390cb3d8e55003c1a5ed5e4efce791aa86892f.tar.gz emacs-be390cb3d8e55003c1a5ed5e4efce791aa86892f.zip | |
(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.
| -rw-r--r-- | lisp/jit-lock.el | 74 |
1 files changed, 36 insertions, 38 deletions
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 8bf3bf7b4ac..a08dbffc2ea 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el | |||
| @@ -37,9 +37,10 @@ | |||
| 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. |
| @@ -137,6 +138,9 @@ The value of this variable is used when JIT Lock mode is turned on." | |||
| 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. |
| @@ -216,6 +220,7 @@ the variable `jit-lock-stealth-nice'." | |||
| 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 | ||
| @@ -276,45 +281,38 @@ is active." | |||
| 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. |