Show
Ignore:
Timestamp:
09/09/06 16:30:10 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/jit-lock.el

    r4148 r4161  
    172172(defvar jit-lock-stealth-timer nil 
    173173  "Timer for stealth fontification in Just-in-time Lock mode.") 
     174(defvar jit-lock-stealth-repeat-timer nil 
     175  "Timer for repeated stealth fontification in Just-in-time Lock mode.") 
    174176(defvar jit-lock-context-timer nil 
    175177  "Timer for context fontification in Just-in-time Lock mode.") 
     
    179181(defvar jit-lock-defer-buffers nil 
    180182  "List of buffers with pending deferred fontification.") 
     183(defvar jit-lock-stealth-buffers nil 
     184  "List of buffers that are being fontified stealthily.") 
    181185  
    182186;;; JIT lock mode 
     
    225229                 (run-with-idle-timer jit-lock-stealth-time t 
    226230                                      'jit-lock-stealth-fontify))) 
     231 
     232         ;; Create, but do not activate, the idle timer for repeated 
     233         ;; stealth fontification. 
     234         (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer)) 
     235           (setq jit-lock-stealth-repeat-timer (timer-create)) 
     236           (timer-set-function jit-lock-stealth-repeat-timer 
     237                               'jit-lock-stealth-fontify '(t))) 
    227238 
    228239         ;; Init deferred fontification timer. 
     
    444455        result)))) 
    445456 
    446  
    447 (defun jit-lock-stealth-fontify () 
     457(defun jit-lock-stealth-fontify (&optional repeat) 
    448458  "Fontify buffers stealthily. 
    449 This functions is called after Emacs has been idle for 
    450 `jit-lock-stealth-time' seconds." 
    451   ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef 
     459This function is called repeatedly after Emacs has become idle for 
     460`jit-lock-stealth-time' seconds.  Optional argument REPEAT is expected 
     461non-nil in a repeated invocation of this function." 
     462  ;; Cancel timer for repeated invocations. 
     463  (unless repeat 
     464    (cancel-timer jit-lock-stealth-repeat-timer)) 
    452465  (unless (or executing-kbd-macro 
    453466              memory-full 
    454               (window-minibuffer-p (selected-window))) 
    455     (let ((buffers (buffer-list)) 
    456           (outer-buffer (current-buffer)) 
     467              (window-minibuffer-p (selected-window)) 
     468              ;; For first invocation set up `jit-lock-stealth-buffers'. 
     469              ;; In repeated invocations it's already been set up. 
     470              (null (if repeat 
     471                        jit-lock-stealth-buffers 
     472                      (setq jit-lock-stealth-buffers (buffer-list))))) 
     473    (let ((buffer (car jit-lock-stealth-buffers)) 
     474          (delay 0) 
    457475          minibuffer-auto-raise 
    458           message-log-max) 
    459       (with-local-quit 
    460         (while (and buffers (not (input-pending-p))) 
    461           (with-current-buffer (pop buffers) 
    462             (when jit-lock-mode 
    463               ;; This is funny.  Calling sit-for with 3rd arg non-nil 
    464               ;; so that it doesn't redisplay, internally calls 
    465               ;; wait_reading_process_input also with a parameter 
    466               ;; saying "don't redisplay."  Since this function here 
    467               ;; is called periodically, this effectively leads to 
    468               ;; process output not being redisplayed at all because 
    469               ;; redisplay_internal is never called.  (That didn't 
    470               ;; work in the old redisplay either.)  So, we learn that 
    471               ;; we mustn't call sit-for that way here.  But then, we 
    472               ;; have to be cautious not to call sit-for in a widened 
    473               ;; buffer, since this could display hidden parts of that 
    474               ;; buffer.  This explains the seemingly weird use of 
    475               ;; save-restriction/widen here. 
    476  
    477               (with-temp-message (if jit-lock-stealth-verbose 
    478                                      (concat "JIT stealth lock " 
    479                                              (buffer-name))) 
    480  
    481                 ;; In the following code, the `sit-for' calls cause a 
    482                 ;; redisplay, so it's required that the 
    483                 ;; buffer-modified flag of a buffer that is displayed 
    484                 ;; has the right value---otherwise the mode line of 
    485                 ;; an unmodified buffer would show a `*'. 
    486                 (let (start 
    487                       (nice (or jit-lock-stealth-nice 0)) 
    488                       (point (point-min))) 
    489                   (while (and (setq start 
    490                                     (jit-lock-stealth-chunk-start point)) 
    491                               ;; In case sit-for runs any timers, 
    492                               ;; give them the expected current buffer. 
    493                               (with-current-buffer outer-buffer 
    494                                 (sit-for nice))) 
    495  
    496                     ;; fontify a block. 
    497                     (jit-lock-fontify-now start (+ start jit-lock-chunk-size)) 
    498                     ;; If stealth jit-locking is done backwards, this leads to 
    499                     ;; excessive O(n^2) refontification.   -stef 
    500                     ;; (when (>= jit-lock-context-unfontify-pos start) 
    501                     ;;   (setq jit-lock-context-unfontify-pos end)) 
    502  
    503                     ;; Wait a little if load is too high. 
    504                     (when (and jit-lock-stealth-load 
    505                                (> (car (load-average)) jit-lock-stealth-load)) 
    506                       ;; In case sit-for runs any timers, 
    507                       ;; give them the expected current buffer. 
    508                       (with-current-buffer outer-buffer 
    509                         (sit-for (or jit-lock-stealth-time 30)))))))))))))) 
    510  
     476          message-log-max 
     477          start) 
     478      (if (and jit-lock-stealth-load 
     479               (> (car (load-average)) jit-lock-stealth-load)) 
     480          ;; Wait a little if load is too high. 
     481          (setq delay jit-lock-stealth-time) 
     482        (if (buffer-live-p buffer) 
     483            (with-current-buffer buffer 
     484              (if (and jit-lock-mode 
     485                       (setq start (jit-lock-stealth-chunk-start (point)))) 
     486                  ;; Fontify one block of at most `jit-lock-chunk-size' 
     487                  ;; characters. 
     488                  (with-temp-message (if jit-lock-stealth-verbose 
     489                                         (concat "JIT stealth lock " 
     490                                                 (buffer-name))) 
     491                    (jit-lock-fontify-now start 
     492                                          (+ start jit-lock-chunk-size)) 
     493                    ;; Run again after `jit-lock-stealth-nice' seconds. 
     494                    (setq delay (or jit-lock-stealth-nice 0))) 
     495                ;; Nothing to fontify here.  Remove this buffer from 
     496                ;; `jit-lock-stealth-buffers' and run again immediately. 
     497                (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers)))) 
     498          ;; Buffer is no longer live.  Remove it from 
     499          ;; `jit-lock-stealth-buffers' and run again immediately. 
     500          (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers)))) 
     501      ;; Call us again. 
     502      (when jit-lock-stealth-buffers 
     503        (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time)) 
     504        (timer-inc-time jit-lock-stealth-repeat-timer delay) 
     505        (timer-activate-when-idle jit-lock-stealth-repeat-timer t))))) 
    511506 
    512507