comparison lisp/jit-lock.el @ 27537:d04b7ce72b4a

(jit-lock-function): Widen before calculating end position. (jit-lock-stealth-chunk-start): Rewritten.
author Gerd Moellmann <gerd@gnu.org>
date Mon, 31 Jan 2000 19:47:38 +0000
parents 9d8fff117316
children e83a7193f612
comparison
equal deleted inserted replaced
27536:e640e22d23c8 27537:d04b7ce72b4a
240 "Fontify current buffer starting at position START. 240 "Fontify current buffer starting at position START.
241 This function is added to `fontification-functions' when `jit-lock-mode' 241 This function is added to `fontification-functions' when `jit-lock-mode'
242 is active." 242 is active."
243 (when jit-lock-mode 243 (when jit-lock-mode
244 (with-buffer-prepared-for-font-lock 244 (with-buffer-prepared-for-font-lock
245 (let ((end (min (point-max) (+ start jit-lock-chunk-size))) 245 (save-excursion
246 (parse-sexp-lookup-properties font-lock-syntactic-keywords) 246 (save-restriction
247 (old-syntax-table (syntax-table)) 247 (widen)
248 (font-lock-beginning-of-syntax-function nil) 248 (let ((end (min (point-max) (+ start jit-lock-chunk-size)))
249 next font-lock-start font-lock-end) 249 (parse-sexp-lookup-properties font-lock-syntactic-keywords)
250 (when font-lock-syntax-table 250 (font-lock-beginning-of-syntax-function nil)
251 (set-syntax-table font-lock-syntax-table)) 251 (old-syntax-table (syntax-table))
252 (save-excursion 252 next font-lock-start font-lock-end)
253 (save-restriction 253 (when font-lock-syntax-table
254 (widen) 254 (set-syntax-table font-lock-syntax-table))
255 (save-match-data 255 (save-match-data
256 (condition-case error 256 (condition-case error
257 ;; Fontify chunks beginning at START. The end of a 257 ;; Fontify chunks beginning at START. The end of a
258 ;; chunk is either `end', or the start of a region 258 ;; chunk is either `end', or the start of a region
259 ;; before `end' that has already been fontified. 259 ;; before `end' that has already been fontified.
279 279
280 ;; Find the start of the next chunk, if any. 280 ;; Find the start of the next chunk, if any.
281 (setq start (text-property-any next end 'fontified nil))) 281 (setq start (text-property-any next end 'fontified nil)))
282 282
283 ((error quit) 283 ((error quit)
284 (message "Fontifying region...%s" error)))))) 284 (message "Fontifying region...%s" error))))
285 285
286 ;; Restore previous buffer settings. 286 ;; Restore previous buffer settings.
287 (set-syntax-table old-syntax-table))))) 287 (set-syntax-table old-syntax-table)))))))
288 288
289 289
290 (defun jit-lock-after-fontify-buffer () 290 (defun jit-lock-after-fontify-buffer ()
291 "Mark the current buffer as fontified. 291 "Mark the current buffer as fontified.
292 Called from `font-lock-after-fontify-buffer." 292 Called from `font-lock-after-fontify-buffer."
305 ;;; Stealth fontification. 305 ;;; Stealth fontification.
306 306
307 (defsubst jit-lock-stealth-chunk-start (around) 307 (defsubst jit-lock-stealth-chunk-start (around)
308 "Return the start of the next chunk to fontify around position AROUND.. 308 "Return the start of the next chunk to fontify around position AROUND..
309 Value is nil if there is nothing more to fontify." 309 Value is nil if there is nothing more to fontify."
310 (save-restriction 310 (if (zerop (buffer-size))
311 (widen) 311 nil
312 (let ((prev (previous-single-property-change around 'fontified)) 312 (save-restriction
313 (next (text-property-any around (point-max) 'fontified nil)) 313 (widen)
314 (prop (get-text-property around 'fontified))) 314 (let* ((next (text-property-any around (point-max) 'fontified nil))
315 (cond ((and (null prop) 315 (prev (previous-single-property-change around 'fontified))
316 (< around (point-max))) 316 (prop (get-text-property (max (point-min) (1- around))
317 ;; Text at position AROUND is not fontified. The value of 317 'fontified))
318 ;; prev, if non-nil, is the start of the region of 318 (start (cond
319 ;; unfontified text. As a special case, prop will always 319 ((null prev)
320 ;; be nil at point-max. So don't handle that case here. 320 ;; There is no property change between AROUND
321 (max (or prev (point-min)) 321 ;; and the start of the buffer. If PROP is
322 (- around jit-lock-chunk-size))) 322 ;; non-nil, everything in front of AROUND is
323 323 ;; fontified, otherwise nothing is fontified.
324 ((null prev) 324 (if prop
325 ;; Text at AROUND is fontified, and everything up to 325 nil
326 ;; point-min is. Return the value of next. If that is 326 (max (point-min)
327 ;; nil, there is nothing left to fontify. 327 (- around (/ jit-lock-chunk-size 2)))))
328 next) 328 (prop
329 329 ;; PREV is the start of a region of fontified
330 ((or (null next) 330 ;; text containing AROUND. Start fontfifying a
331 (< (- around prev) (- next around))) 331 ;; chunk size before the end of the unfontified
332 ;; We either have no unfontified text following AROUND, or 332 ;; region in front of that.
333 ;; the unfontified text in front of AROUND is nearer. The 333 (max (or (previous-single-property-change prev 'fontified)
334 ;; value of prev is the end of the region of unfontified 334 (point-min))
335 ;; text in front of AROUND. 335 (- prev jit-lock-chunk-size)))
336 (let ((start (previous-single-property-change prev 'fontified))) 336 (t
337 (max (or start (point-min)) 337 ;; PREV is the start of a region of unfontified
338 (- prev jit-lock-chunk-size)))) 338 ;; text containing AROUND. Start at PREV or
339 339 ;; chunk size in front of AROUND, whichever is
340 (t 340 ;; nearer.
341 next))))) 341 (max prev (- around jit-lock-chunk-size)))))
342 342 (result (cond ((null start) next)
343 ((null next) start)
344 ((< (- around start) (- next around)) start)
345 (t next))))
346 result))))
347
343 348
344 (defun jit-lock-stealth-fontify () 349 (defun jit-lock-stealth-fontify ()
345 "Fontify buffers stealthily. 350 "Fontify buffers stealthily.
346 This functions is called after Emacs has been idle for 351 This functions is called after Emacs has been idle for
347 `jit-lock-stealth-time' seconds." 352 `jit-lock-stealth-time' seconds."
348 (unless (or executing-kbd-macro 353 (unless (or executing-kbd-macro
349 (window-minibuffer-p (selected-window))) 354 (window-minibuffer-p (selected-window)))
350 (let ((buffers (buffer-list)) 355 (let ((buffers (buffer-list))
351 minibuffer-auto-raise 356 minibuffer-auto-raise
352 message-log-max) 357 message-log-max)
353 (while (and buffers 358 (while (and buffers (not (input-pending-p)))
354 (not (input-pending-p)))
355 (let ((buffer (car buffers))) 359 (let ((buffer (car buffers)))
356 (setq buffers (cdr buffers)) 360 (setq buffers (cdr buffers))
361
357 (with-current-buffer buffer 362 (with-current-buffer buffer
358 (when jit-lock-mode 363 (when jit-lock-mode
359 ;; This is funny. Calling sit-for with 3rd arg non-nil 364 ;; This is funny. Calling sit-for with 3rd arg non-nil
360 ;; so that it doesn't redisplay, internally calls 365 ;; so that it doesn't redisplay, internally calls
361 ;; wait_reading_process_input also with a parameter 366 ;; wait_reading_process_input also with a parameter
371 ;; save-restriction/widen here. 376 ;; save-restriction/widen here.
372 377
373 (with-temp-message (if jit-lock-stealth-verbose 378 (with-temp-message (if jit-lock-stealth-verbose
374 (concat "JIT stealth lock " 379 (concat "JIT stealth lock "
375 (buffer-name))) 380 (buffer-name)))
376 381
377 ;; Perform deferred unfontification, if any. 382 ;; Perform deferred unfontification, if any.
378 (when jit-lock-first-unfontify-pos 383 (when jit-lock-first-unfontify-pos
379 (save-restriction 384 (save-restriction
380 (widen) 385 (widen)
381 (when (and (>= jit-lock-first-unfontify-pos (point-min)) 386 (when (and (>= jit-lock-first-unfontify-pos (point-min))
386 (setq jit-lock-first-unfontify-pos nil)))) 391 (setq jit-lock-first-unfontify-pos nil))))
387 392
388 (let (start 393 (let (start
389 (nice (or jit-lock-stealth-nice 0)) 394 (nice (or jit-lock-stealth-nice 0))
390 (point (point))) 395 (point (point)))
391 (while (and (setq start 396 (while (and (setq start (jit-lock-stealth-chunk-start point))
392 (jit-lock-stealth-chunk-start point))
393 (sit-for nice)) 397 (sit-for nice))
394 398
395 ;; Wait a little if load is too high. 399 ;; Wait a little if load is too high.
396 (when (and jit-lock-stealth-load 400 (when (and jit-lock-stealth-load
397 (> (car (load-average)) jit-lock-stealth-load)) 401 (> (car (load-average)) jit-lock-stealth-load))