comparison lisp/jit-lock.el @ 53755:9bd36e762e48

(jit-lock-stealth-fontify): Allow quit. (jit-lock-fontify-now): Handle the `quit' case. (jit-lock-contextually): Rename from jit-lock-defer-contextually.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 30 Jan 2004 00:08:38 +0000
parents f790b749630e
children bbadbe04fc3d
comparison
equal deleted inserted replaced
53754:27c158d8e571 53755:9bd36e762e48
113 "*If non-nil, means stealth fontification should show status messages." 113 "*If non-nil, means stealth fontification should show status messages."
114 :type 'boolean 114 :type 'boolean
115 :group 'jit-lock) 115 :group 'jit-lock)
116 116
117 117
118 (defcustom jit-lock-defer-contextually 'syntax-driven 118 (defvaralias 'jit-lock-defer-contextually 'jit-lock-contextually)
119 "*If non-nil, means deferred fontification should be syntactically true. 119 (defcustom jit-lock-contextually 'syntax-driven
120 If nil, means deferred fontification occurs only on those lines modified. This 120 "*If non-nil, means fontification should be syntactically true.
121 If nil, means fontification occurs only on those lines modified. This
121 means where modification on a line causes syntactic change on subsequent lines, 122 means where modification on a line causes syntactic change on subsequent lines,
122 those subsequent lines are not refontified to reflect their new context. 123 those subsequent lines are not refontified to reflect their new context.
123 If t, means deferred fontification occurs on those lines modified and all 124 If t, means fontification occurs on those lines modified and all
124 subsequent lines. This means those subsequent lines are refontified to reflect 125 subsequent lines. This means those subsequent lines are refontified to reflect
125 their new syntactic context, either immediately or when scrolling into them. 126 their new syntactic context, either immediately or when scrolling into them.
126 If any other value, e.g., `syntax-driven', means deferred syntactically true 127 If any other value, e.g., `syntax-driven', means syntactically true
127 fontification occurs only if syntactic fontification is performed using the 128 fontification occurs only if syntactic fontification is performed using the
128 buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil. 129 buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
129 130
130 The value of this variable is used when JIT Lock mode is turned on." 131 The value of this variable is used when JIT Lock mode is turned on."
131 :type '(choice (const :tag "never" nil) 132 :type '(choice (const :tag "never" nil)
185 - Stealthy buffer fontification if `jit-lock-stealth-time' is non-nil. 186 - Stealthy buffer fontification if `jit-lock-stealth-time' is non-nil.
186 This means remaining unfontified areas of buffers are fontified if Emacs has 187 This means remaining unfontified areas of buffers are fontified if Emacs has
187 been idle for `jit-lock-stealth-time' seconds, while Emacs remains idle. 188 been idle for `jit-lock-stealth-time' seconds, while Emacs remains idle.
188 This is useful if any buffer has any deferred fontification. 189 This is useful if any buffer has any deferred fontification.
189 190
190 - Deferred context fontification if `jit-lock-defer-contextually' is 191 - Deferred context fontification if `jit-lock-contextually' is
191 non-nil. This means fontification updates the buffer corresponding to 192 non-nil. This means fontification updates the buffer corresponding to
192 true syntactic context, after `jit-lock-stealth-time' seconds of Emacs 193 true syntactic context, after `jit-lock-stealth-time' seconds of Emacs
193 idle time, while Emacs remains idle. Otherwise, fontification occurs 194 idle time, while Emacs remains idle. Otherwise, fontification occurs
194 on modified lines only, and subsequent lines can remain fontified 195 on modified lines only, and subsequent lines can remain fontified
195 corresponding to previous syntactic contexts. This is useful where 196 corresponding to previous syntactic contexts. This is useful where
217 (setq jit-lock-defer-timer 218 (setq jit-lock-defer-timer
218 (run-with-idle-timer jit-lock-defer-time t 219 (run-with-idle-timer jit-lock-defer-time t
219 'jit-lock-deferred-fontify))) 220 'jit-lock-deferred-fontify)))
220 221
221 ;; Initialize contextual fontification if requested. 222 ;; Initialize contextual fontification if requested.
222 (when (eq jit-lock-defer-contextually t) 223 (when (eq jit-lock-contextually t)
223 (setq jit-lock-context-unfontify-pos 224 (setq jit-lock-context-unfontify-pos
224 (or jit-lock-context-unfontify-pos (point-max)))) 225 (or jit-lock-context-unfontify-pos (point-max))))
225 226
226 ;; Setup our hooks. 227 ;; Setup our hooks.
227 (add-hook 'after-change-functions 'jit-lock-after-change nil t) 228 (add-hook 'after-change-functions 'jit-lock-after-change nil t)
252 "Register FUN as a fontification function to be called in this buffer. 253 "Register FUN as a fontification function to be called in this buffer.
253 FUN will be called with two arguments START and END indicating the region 254 FUN will be called with two arguments START and END indicating the region
254 that needs to be (re)fontified. 255 that needs to be (re)fontified.
255 If non-nil, CONTEXTUAL means that a contextual fontification would be useful." 256 If non-nil, CONTEXTUAL means that a contextual fontification would be useful."
256 (add-hook 'jit-lock-functions fun nil t) 257 (add-hook 'jit-lock-functions fun nil t)
257 (when (and contextual jit-lock-defer-contextually) 258 (when (and contextual jit-lock-contextually)
258 (set (make-local-variable 'jit-lock-defer-contextually) t)) 259 (set (make-local-variable 'jit-lock-contextually) t))
259 (jit-lock-mode t)) 260 (jit-lock-mode t))
260 261
261 (defun jit-lock-unregister (fun) 262 (defun jit-lock-unregister (fun)
262 "Unregister FUN as a fontification function. 263 "Unregister FUN as a fontification function.
263 Only applies to the current buffer." 264 Only applies to the current buffer."
334 335
335 ;; Fontify the chunk, and mark it as fontified. 336 ;; Fontify the chunk, and mark it as fontified.
336 ;; We mark it first, to make sure that we don't indefinitely 337 ;; We mark it first, to make sure that we don't indefinitely
337 ;; re-execute this fontification if an error occurs. 338 ;; re-execute this fontification if an error occurs.
338 (put-text-property start next 'fontified t) 339 (put-text-property start next 'fontified t)
339 (run-hook-with-args 'jit-lock-functions start next) 340 (condition-case err
341 (run-hook-with-args 'jit-lock-functions start next)
342 ;; If the user quits (which shouldn't happen in normal on-the-fly
343 ;; jit-locking), make sure the fontification will be performed
344 ;; before displaying the block again.
345 (quit (put-text-property start next 'fontified nil)
346 (funcall 'signal (car err) (cdr err))))
340 347
341 ;; Find the start of the next chunk, if any. 348 ;; Find the start of the next chunk, if any.
342 (setq start (text-property-any next end 'fontified nil)))))))) 349 (setq start (text-property-any next end 'fontified nil))))))))
343 350
344 351
394 (unless (or executing-kbd-macro 401 (unless (or executing-kbd-macro
395 (window-minibuffer-p (selected-window))) 402 (window-minibuffer-p (selected-window)))
396 (let ((buffers (buffer-list)) 403 (let ((buffers (buffer-list))
397 minibuffer-auto-raise 404 minibuffer-auto-raise
398 message-log-max) 405 message-log-max)
399 (while (and buffers (not (input-pending-p))) 406 (with-local-quit
400 (let ((buffer (car buffers))) 407 (while (and buffers (not (input-pending-p)))
401 (setq buffers (cdr buffers)) 408 (with-current-buffer (pop buffers)
402
403 (with-current-buffer buffer
404 (when jit-lock-mode 409 (when jit-lock-mode
405 ;; This is funny. Calling sit-for with 3rd arg non-nil 410 ;; This is funny. Calling sit-for with 3rd arg non-nil
406 ;; so that it doesn't redisplay, internally calls 411 ;; so that it doesn't redisplay, internally calls
407 ;; wait_reading_process_input also with a parameter 412 ;; wait_reading_process_input also with a parameter
408 ;; saying "don't redisplay." Since this function here 413 ;; saying "don't redisplay." Since this function here