diff options
| author | Stefan Monnier | 2004-01-30 00:20:46 +0000 |
|---|---|---|
| committer | Stefan Monnier | 2004-01-30 00:20:46 +0000 |
| commit | 7b4d9d3bb7394268acaa693ee73bb45864a355a1 (patch) | |
| tree | d93716b9c3cf1c62f6a3177fa7fd6d27b0f2360e | |
| parent | f415f2d726bbaf8f3b5ac9d87a00ad61ec39cd79 (diff) | |
| download | emacs-7b4d9d3bb7394268acaa693ee73bb45864a355a1.tar.gz emacs-7b4d9d3bb7394268acaa693ee73bb45864a355a1.zip | |
(jit-lock-context-time, jit-lock-context-timer): New var.
(with-buffer-unmodified, with-buffer-prepared-for-jit-lock):
Add edebug info.
(jit-lock-mode): Setup/cancel the new timer.
(jit-lock-context-fontify): New fun. Extracted from
context fontification code of jit-lock-stealth-fontify.
(jit-lock-stealth-fontify): Don't do context fontification any more.
| -rw-r--r-- | lisp/jit-lock.el | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/lisp/jit-lock.el b/lisp/jit-lock.el index 3a0e3911fa8..67b1bfbe022 100644 --- a/lisp/jit-lock.el +++ b/lisp/jit-lock.el | |||
| @@ -32,6 +32,7 @@ | |||
| 32 | (eval-when-compile | 32 | (eval-when-compile |
| 33 | (defmacro with-buffer-unmodified (&rest body) | 33 | (defmacro with-buffer-unmodified (&rest body) |
| 34 | "Eval BODY, preserving the current buffer's modified state." | 34 | "Eval BODY, preserving the current buffer's modified state." |
| 35 | (declare (debug t)) | ||
| 35 | (let ((modified (make-symbol "modified"))) | 36 | (let ((modified (make-symbol "modified"))) |
| 36 | `(let ((,modified (buffer-modified-p))) | 37 | `(let ((,modified (buffer-modified-p))) |
| 37 | (unwind-protect | 38 | (unwind-protect |
| @@ -42,6 +43,7 @@ | |||
| 42 | (defmacro with-buffer-prepared-for-jit-lock (&rest body) | 43 | (defmacro with-buffer-prepared-for-jit-lock (&rest body) |
| 43 | "Execute BODY in current buffer, overriding several variables. | 44 | "Execute BODY in current buffer, overriding several variables. |
| 44 | Preserves the `buffer-modified-p' state of the current buffer." | 45 | Preserves the `buffer-modified-p' state of the current buffer." |
| 46 | (declare (debug t)) | ||
| 45 | `(with-buffer-unmodified | 47 | `(with-buffer-unmodified |
| 46 | (let ((buffer-undo-list t) | 48 | (let ((buffer-undo-list t) |
| 47 | (inhibit-read-only t) | 49 | (inhibit-read-only t) |
| @@ -123,7 +125,7 @@ means where modification on a line causes syntactic change on subsequent lines, | |||
| 123 | those subsequent lines are not refontified to reflect their new context. | 125 | those subsequent lines are not refontified to reflect their new context. |
| 124 | If t, means fontification occurs on those lines modified and all | 126 | If t, means fontification occurs on those lines modified and all |
| 125 | subsequent lines. This means those subsequent lines are refontified to reflect | 127 | subsequent lines. This means those subsequent lines are refontified to reflect |
| 126 | their new syntactic context, either immediately or when scrolling into them. | 128 | their new syntactic context, after `jit-lock-context-time' seconds. |
| 127 | If any other value, e.g., `syntax-driven', means syntactically true | 129 | If any other value, e.g., `syntax-driven', means syntactically true |
| 128 | fontification occurs only if syntactic fontification is performed using the | 130 | fontification occurs only if syntactic fontification is performed using the |
| 129 | buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil. | 131 | buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil. |
| @@ -134,6 +136,10 @@ The value of this variable is used when JIT Lock mode is turned on." | |||
| 134 | (other :tag "syntax-driven" syntax-driven)) | 136 | (other :tag "syntax-driven" syntax-driven)) |
| 135 | :group 'jit-lock) | 137 | :group 'jit-lock) |
| 136 | 138 | ||
| 139 | (defcustom jit-lock-context-time 0.5 | ||
| 140 | "Idle time after which text is contextually refontified, if applicable." | ||
| 141 | :type '(number :tag "seconds")) | ||
| 142 | |||
| 137 | (defcustom jit-lock-defer-time nil ;; 0.25 | 143 | (defcustom jit-lock-defer-time nil ;; 0.25 |
| 138 | "Idle time after which deferred fontification should take place. | 144 | "Idle time after which deferred fontification should take place. |
| 139 | If nil, fontification is not deferred." | 145 | If nil, fontification is not deferred." |
| @@ -160,7 +166,8 @@ If nil, contextual fontification is disabled.") | |||
| 160 | 166 | ||
| 161 | (defvar jit-lock-stealth-timer nil | 167 | (defvar jit-lock-stealth-timer nil |
| 162 | "Timer for stealth fontification in Just-in-time Lock mode.") | 168 | "Timer for stealth fontification in Just-in-time Lock mode.") |
| 163 | 169 | (defvar jit-lock-context-timer nil | |
| 170 | "Timer for context fontification in Just-in-time Lock mode.") | ||
| 164 | (defvar jit-lock-defer-timer nil | 171 | (defvar jit-lock-defer-timer nil |
| 165 | "Timer for deferred fontification in Just-in-time Lock mode.") | 172 | "Timer for deferred fontification in Just-in-time Lock mode.") |
| 166 | 173 | ||
| @@ -190,7 +197,7 @@ following ways: | |||
| 190 | 197 | ||
| 191 | - Deferred context fontification if `jit-lock-contextually' is | 198 | - Deferred context fontification if `jit-lock-contextually' is |
| 192 | non-nil. This means fontification updates the buffer corresponding to | 199 | non-nil. This means fontification updates the buffer corresponding to |
| 193 | true syntactic context, after `jit-lock-stealth-time' seconds of Emacs | 200 | true syntactic context, after `jit-lock-context-time' seconds of Emacs |
| 194 | idle time, while Emacs remains idle. Otherwise, fontification occurs | 201 | idle time, while Emacs remains idle. Otherwise, fontification occurs |
| 195 | on modified lines only, and subsequent lines can remain fontified | 202 | on modified lines only, and subsequent lines can remain fontified |
| 196 | corresponding to previous syntactic contexts. This is useful where | 203 | corresponding to previous syntactic contexts. This is useful where |
| @@ -221,6 +228,10 @@ the variable `jit-lock-stealth-nice'." | |||
| 221 | 228 | ||
| 222 | ;; Initialize contextual fontification if requested. | 229 | ;; Initialize contextual fontification if requested. |
| 223 | (when (eq jit-lock-contextually t) | 230 | (when (eq jit-lock-contextually t) |
| 231 | (unless jit-lock-context-timer | ||
| 232 | (setq jit-lock-context-timer | ||
| 233 | (run-with-idle-timer jit-lock-context-time t | ||
| 234 | 'jit-lock-context-fontify))) | ||
| 224 | (setq jit-lock-context-unfontify-pos | 235 | (setq jit-lock-context-unfontify-pos |
| 225 | (or jit-lock-context-unfontify-pos (point-max)))) | 236 | (or jit-lock-context-unfontify-pos (point-max)))) |
| 226 | 237 | ||
| @@ -231,7 +242,8 @@ the variable `jit-lock-stealth-nice'." | |||
| 231 | ;; Turn Just-in-time Lock mode off. | 242 | ;; Turn Just-in-time Lock mode off. |
| 232 | (t | 243 | (t |
| 233 | ;; Cancel our idle timers. | 244 | ;; Cancel our idle timers. |
| 234 | (when (and (or jit-lock-stealth-timer jit-lock-defer-timer) | 245 | (when (and (or jit-lock-stealth-timer jit-lock-defer-timer |
| 246 | jit-lock-context-timer) | ||
| 235 | ;; Only if there's no other buffer using them. | 247 | ;; Only if there's no other buffer using them. |
| 236 | (not (catch 'found | 248 | (not (catch 'found |
| 237 | (dolist (buf (buffer-list)) | 249 | (dolist (buf (buffer-list)) |
| @@ -240,6 +252,9 @@ the variable `jit-lock-stealth-nice'." | |||
| 240 | (when jit-lock-stealth-timer | 252 | (when jit-lock-stealth-timer |
| 241 | (cancel-timer jit-lock-stealth-timer) | 253 | (cancel-timer jit-lock-stealth-timer) |
| 242 | (setq jit-lock-stealth-timer nil)) | 254 | (setq jit-lock-stealth-timer nil)) |
| 255 | (when jit-lock-context-timer | ||
| 256 | (cancel-timer jit-lock-context-timer) | ||
| 257 | (setq jit-lock-context-timer nil)) | ||
| 243 | (when jit-lock-defer-timer | 258 | (when jit-lock-defer-timer |
| 244 | (cancel-timer jit-lock-defer-timer) | 259 | (cancel-timer jit-lock-defer-timer) |
| 245 | (setq jit-lock-defer-timer nil))) | 260 | (setq jit-lock-defer-timer nil))) |
| @@ -425,28 +440,6 @@ This functions is called after Emacs has been idle for | |||
| 425 | (concat "JIT stealth lock " | 440 | (concat "JIT stealth lock " |
| 426 | (buffer-name))) | 441 | (buffer-name))) |
| 427 | 442 | ||
| 428 | ;; Perform deferred unfontification, if any. | ||
| 429 | (when jit-lock-context-unfontify-pos | ||
| 430 | (save-restriction | ||
| 431 | (widen) | ||
| 432 | (when (and (>= jit-lock-context-unfontify-pos (point-min)) | ||
| 433 | (< jit-lock-context-unfontify-pos (point-max))) | ||
| 434 | ;; If we're in text that matches a complex multi-line | ||
| 435 | ;; font-lock pattern, make sure the whole text will be | ||
| 436 | ;; redisplayed eventually. | ||
| 437 | (when (get-text-property jit-lock-context-unfontify-pos | ||
| 438 | 'jit-lock-defer-multiline) | ||
| 439 | (setq jit-lock-context-unfontify-pos | ||
| 440 | (or (previous-single-property-change | ||
| 441 | jit-lock-context-unfontify-pos | ||
| 442 | 'jit-lock-defer-multiline) | ||
| 443 | (point-min)))) | ||
| 444 | (with-buffer-prepared-for-jit-lock | ||
| 445 | (remove-text-properties | ||
| 446 | jit-lock-context-unfontify-pos (point-max) | ||
| 447 | '(fontified nil jit-lock-defer-multiline nil))) | ||
| 448 | (setq jit-lock-context-unfontify-pos (point-max))))) | ||
| 449 | |||
| 450 | ;; In the following code, the `sit-for' calls cause a | 443 | ;; In the following code, the `sit-for' calls cause a |
| 451 | ;; redisplay, so it's required that the | 444 | ;; redisplay, so it's required that the |
| 452 | ;; buffer-modified flag of a buffer that is displayed | 445 | ;; buffer-modified flag of a buffer that is displayed |
| @@ -502,6 +495,36 @@ This functions is called after Emacs has been idle for | |||
| 502 | ))) | 495 | ))) |
| 503 | 496 | ||
| 504 | 497 | ||
| 498 | (defun jit-lock-context-fontify () | ||
| 499 | "Refresh fontification to take new context into account." | ||
| 500 | (dolist (buffer (buffer-list)) | ||
| 501 | (with-current-buffer buffer | ||
| 502 | (when jit-lock-context-unfontify-pos | ||
| 503 | ;; (message "Jit-Context %s" (buffer-name)) | ||
| 504 | (save-restriction | ||
| 505 | (widen) | ||
| 506 | (when (and (>= jit-lock-context-unfontify-pos (point-min)) | ||
| 507 | (< jit-lock-context-unfontify-pos (point-max))) | ||
| 508 | ;; If we're in text that matches a complex multi-line | ||
| 509 | ;; font-lock pattern, make sure the whole text will be | ||
| 510 | ;; redisplayed eventually. | ||
| 511 | ;; Despite its name, we treat jit-lock-defer-multiline here | ||
| 512 | ;; rather than in jit-lock-defer since it has to do with multiple | ||
| 513 | ;; lines, i.e. with context. | ||
| 514 | (when (get-text-property jit-lock-context-unfontify-pos | ||
| 515 | 'jit-lock-defer-multiline) | ||
| 516 | (setq jit-lock-context-unfontify-pos | ||
| 517 | (or (previous-single-property-change | ||
| 518 | jit-lock-context-unfontify-pos | ||
| 519 | 'jit-lock-defer-multiline) | ||
| 520 | (point-min)))) | ||
| 521 | (with-buffer-prepared-for-jit-lock | ||
| 522 | ;; Force contextual refontification. | ||
| 523 | (remove-text-properties | ||
| 524 | jit-lock-context-unfontify-pos (point-max) | ||
| 525 | '(fontified nil jit-lock-defer-multiline nil))) | ||
| 526 | (setq jit-lock-context-unfontify-pos (point-max)))))))) | ||
| 527 | |||
| 505 | (defun jit-lock-after-change (start end old-len) | 528 | (defun jit-lock-after-change (start end old-len) |
| 506 | "Mark the rest of the buffer as not fontified after a change. | 529 | "Mark the rest of the buffer as not fontified after a change. |
| 507 | Installed on `after-change-functions'. | 530 | Installed on `after-change-functions'. |