all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* jit-lock timer etc.
@ 2006-08-21 11:12 Richard Stallman
  2006-08-21 11:39 ` Kim F. Storm
  0 siblings, 1 reply; 43+ messages in thread
From: Richard Stallman @ 2006-08-21 11:12 UTC (permalink / raw)


Here's my patch to make the jit-lock timer reschedule itself
instead of waiting.  It uses current-idle-time, which I have tested
and checked in, but I can't easily tell whether steath fontification
is working.  So I would like someone to test this before I check it in.

I have not yet tried to read the other proposed change to this code.
I was too tired when I saw it.

*** jit-lock.el	17 Aug 2006 11:21:10 -0400	1.54
--- jit-lock.el	18 Aug 2006 07:57:36 -0400	
***************
*** 171,176 ****
--- 171,180 ----
  
  (defvar jit-lock-stealth-timer nil
    "Timer for stealth fontification in Just-in-time Lock mode.")
+ (defvar jit-lock-stealth-resume-timer nil
+   "Timer for resuming stealth fontification in Just-in-time Lock mode.
+ When time stealth fontification finishes one batch, it reschedules
+ itself using this timer.")
  (defvar jit-lock-context-timer nil
    "Timer for context fontification in Just-in-time Lock mode.")
  (defvar jit-lock-defer-timer nil
***************
*** 225,230 ****
--- 229,241 ----
  		 (run-with-idle-timer jit-lock-stealth-time t
  				      'jit-lock-stealth-fontify)))
  
+ 	 ;; Set up an idle timer for stealth fontification to resume,
+ 	 ;; but don't activate it now.
+ 	 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
+ 	   (setq jit-lock-stealth-resume-timer (timer-create))
+ 	   (timer-set-function jit-lock-stealth-resume-timer
+ 			       'jit-lock-stealth-fontify))
+ 
  	 ;; Init deferred fontification timer.
  	 (when (and jit-lock-defer-time (null jit-lock-defer-timer))
  	   (setq jit-lock-defer-timer
***************
*** 449,454 ****
--- 460,466 ----
  This functions is called after Emacs has been idle for
  `jit-lock-stealth-time' seconds."
    ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
+   (cancel-timer jit-lock-stealth-resume-timer)
    (unless (or executing-kbd-macro
  	      memory-full
  	      (window-minibuffer-p (selected-window)))
***************
*** 457,512 ****
  	  minibuffer-auto-raise
  	  message-log-max)
        (with-local-quit
! 	(while (and buffers (not (input-pending-p)))
  	  (with-current-buffer (pop buffers)
! 	    (when jit-lock-mode
! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	      ;; so that it doesn't redisplay, internally calls
! 	      ;; wait_reading_process_input also with a parameter
! 	      ;; saying "don't redisplay."  Since this function here
! 	      ;; is called periodically, this effectively leads to
! 	      ;; process output not being redisplayed at all because
! 	      ;; redisplay_internal is never called.  (That didn't
! 	      ;; work in the old redisplay either.)  So, we learn that
! 	      ;; we mustn't call sit-for that way here.  But then, we
! 	      ;; have to be cautious not to call sit-for in a widened
! 	      ;; buffer, since this could display hidden parts of that
! 	      ;; buffer.  This explains the seemingly weird use of
! 	      ;; save-restriction/widen here.
! 
! 	      (with-temp-message (if jit-lock-stealth-verbose
! 				     (concat "JIT stealth lock "
! 					     (buffer-name)))
! 
! 		;; In the following code, the `sit-for' calls cause a
! 		;; redisplay, so it's required that the
! 		;; buffer-modified flag of a buffer that is displayed
! 		;; has the right value---otherwise the mode line of
! 		;; an unmodified buffer would show a `*'.
! 		(let (start
! 		      (nice (or jit-lock-stealth-nice 0))
! 		      (point (point-min)))
! 		  (while (and (setq start
! 				    (jit-lock-stealth-chunk-start point))
! 			      ;; In case sit-for runs any timers,
! 			      ;; give them the expected current buffer.
! 			      (with-current-buffer outer-buffer
! 				(sit-for nice)))
! 
! 		    ;; fontify a block.
! 		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; If stealth jit-locking is done backwards, this leads to
! 		    ;; excessive O(n^2) refontification.   -stef
! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
! 		    ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		    ;; Wait a little if load is too high.
! 		    (when (and jit-lock-stealth-load
! 			       (> (car (load-average)) jit-lock-stealth-load))
! 		      ;; In case sit-for runs any timers,
! 		      ;; give them the expected current buffer.
! 		      (with-current-buffer outer-buffer
! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))
  
  
  \f
--- 469,527 ----
  	  minibuffer-auto-raise
  	  message-log-max)
        (with-local-quit
! 	(when (and jit-lock-mode buffers (not (input-pending-p)))
  	  (with-current-buffer (pop buffers)
! 	    ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	    ;; so that it doesn't redisplay, internally calls
! 	    ;; wait_reading_process_input also with a parameter
! 	    ;; saying "don't redisplay."  Since this function here
! 	    ;; is called periodically, this effectively leads to
! 	    ;; process output not being redisplayed at all because
! 	    ;; redisplay_internal is never called.  (That didn't
! 	    ;; work in the old redisplay either.)  So, we learn that
! 	    ;; we mustn't call sit-for that way here.  But then, we
! 	    ;; have to be cautious not to call sit-for in a widened
! 	    ;; buffer, since this could display hidden parts of that
! 	    ;; buffer.  This explains the seemingly weird use of
! 	    ;; save-restriction/widen here.
! 
! 	    (with-temp-message (if jit-lock-stealth-verbose
! 				   (concat "JIT stealth lock "
! 					   (buffer-name)))
! 
! 	      ;; In the following code, the `sit-for' calls cause a
! 	      ;; redisplay, so it's required that the
! 	      ;; buffer-modified flag of a buffer that is displayed
! 	      ;; has the right value---otherwise the mode line of
! 	      ;; an unmodified buffer would show a `*'.
! 	      (let (start
! 		    (nice (or jit-lock-stealth-nice 0))
! 		    (point (point-min)))
! 		(while (and (setq start
! 				  (jit-lock-stealth-chunk-start point))
! 			    ;; In case sit-for runs any timers,
! 			    ;; give them the expected current buffer.
! 			    (with-current-buffer outer-buffer
! 			      (sit-for nice)))
! 
! 		  ;; fontify a block.
! 		  (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		  ;; If stealth jit-locking is done backwards, this leads to
! 		  ;; excessive O(n^2) refontification.   -stef
! 		  ;; (when (>= jit-lock-context-unfontify-pos start)
! 		  ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		  ;; Wait a little if load is too high.
! 		  (when (and jit-lock-stealth-load
! 			     (> (car (load-average)) jit-lock-stealth-load))
! 		    ;; Make this timer resume jit-lock in a few
! 		    ;; seconds.  Compute an idleness time suitably
! 		    ;; larger than the current one.
! 		    (timer-set-idle-time jit-lock-stealth-resume-timer
! 					 (current-idle-time))
! 		    (timer-inc-time (or jit-lock-stealth-time 30))
! 		    (timer-activate-when-idle
! 		     jit-lock-stealth-resume-timer t)))))))))))
  
  
  \f

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 11:12 jit-lock timer etc Richard Stallman
@ 2006-08-21 11:39 ` Kim F. Storm
  2006-08-21 16:57   ` martin rudalics
  0 siblings, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-21 11:39 UTC (permalink / raw)
  Cc: emacs-devel

Richard Stallman <rms@gnu.org> writes:

> Here's my patch to make the jit-lock timer reschedule itself
> instead of waiting.  It uses current-idle-time, which I have tested
> and checked in, but I can't easily tell whether steath fontification
> is working.  So I would like someone to test this before I check it in.
>
> I have not yet tried to read the other proposed change to this code.
> I was too tired when I saw it.

I strongly prefer the other change proposed by Martin Rudalics which
avoids calling sit-for at all in the timer handler.  I have installed
Martin's patch, and I haven't seen the "cursor disappearing" bug since!

However, the approach taken by Martin can be improved by using your
new current-idle-time to install a proper idle timer to resume jit-lock.

Martin, would you like to try to update your patch ?



>
> *** jit-lock.el	17 Aug 2006 11:21:10 -0400	1.54
> --- jit-lock.el	18 Aug 2006 07:57:36 -0400	
> ***************
> *** 171,176 ****
> --- 171,180 ----
>   
>   (defvar jit-lock-stealth-timer nil
>     "Timer for stealth fontification in Just-in-time Lock mode.")
> + (defvar jit-lock-stealth-resume-timer nil
> +   "Timer for resuming stealth fontification in Just-in-time Lock mode.
> + When time stealth fontification finishes one batch, it reschedules
> + itself using this timer.")
>   (defvar jit-lock-context-timer nil
>     "Timer for context fontification in Just-in-time Lock mode.")
>   (defvar jit-lock-defer-timer nil
> ***************
> *** 225,230 ****
> --- 229,241 ----
>   		 (run-with-idle-timer jit-lock-stealth-time t
>   				      'jit-lock-stealth-fontify)))
>   
> + 	 ;; Set up an idle timer for stealth fontification to resume,
> + 	 ;; but don't activate it now.
> + 	 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
> + 	   (setq jit-lock-stealth-resume-timer (timer-create))
> + 	   (timer-set-function jit-lock-stealth-resume-timer
> + 			       'jit-lock-stealth-fontify))
> + 
>   	 ;; Init deferred fontification timer.
>   	 (when (and jit-lock-defer-time (null jit-lock-defer-timer))
>   	   (setq jit-lock-defer-timer
> ***************
> *** 449,454 ****
> --- 460,466 ----
>   This functions is called after Emacs has been idle for
>   `jit-lock-stealth-time' seconds."
>     ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
> +   (cancel-timer jit-lock-stealth-resume-timer)
>     (unless (or executing-kbd-macro
>   	      memory-full
>   	      (window-minibuffer-p (selected-window)))
> ***************
> *** 457,512 ****
>   	  minibuffer-auto-raise
>   	  message-log-max)
>         (with-local-quit
> ! 	(while (and buffers (not (input-pending-p)))
>   	  (with-current-buffer (pop buffers)
> ! 	    (when jit-lock-mode
> ! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
> ! 	      ;; so that it doesn't redisplay, internally calls
> ! 	      ;; wait_reading_process_input also with a parameter
> ! 	      ;; saying "don't redisplay."  Since this function here
> ! 	      ;; is called periodically, this effectively leads to
> ! 	      ;; process output not being redisplayed at all because
> ! 	      ;; redisplay_internal is never called.  (That didn't
> ! 	      ;; work in the old redisplay either.)  So, we learn that
> ! 	      ;; we mustn't call sit-for that way here.  But then, we
> ! 	      ;; have to be cautious not to call sit-for in a widened
> ! 	      ;; buffer, since this could display hidden parts of that
> ! 	      ;; buffer.  This explains the seemingly weird use of
> ! 	      ;; save-restriction/widen here.
> ! 
> ! 	      (with-temp-message (if jit-lock-stealth-verbose
> ! 				     (concat "JIT stealth lock "
> ! 					     (buffer-name)))
> ! 
> ! 		;; In the following code, the `sit-for' calls cause a
> ! 		;; redisplay, so it's required that the
> ! 		;; buffer-modified flag of a buffer that is displayed
> ! 		;; has the right value---otherwise the mode line of
> ! 		;; an unmodified buffer would show a `*'.
> ! 		(let (start
> ! 		      (nice (or jit-lock-stealth-nice 0))
> ! 		      (point (point-min)))
> ! 		  (while (and (setq start
> ! 				    (jit-lock-stealth-chunk-start point))
> ! 			      ;; In case sit-for runs any timers,
> ! 			      ;; give them the expected current buffer.
> ! 			      (with-current-buffer outer-buffer
> ! 				(sit-for nice)))
> ! 
> ! 		    ;; fontify a block.
> ! 		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
> ! 		    ;; If stealth jit-locking is done backwards, this leads to
> ! 		    ;; excessive O(n^2) refontification.   -stef
> ! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
> ! 		    ;;   (setq jit-lock-context-unfontify-pos end))
> ! 
> ! 		    ;; Wait a little if load is too high.
> ! 		    (when (and jit-lock-stealth-load
> ! 			       (> (car (load-average)) jit-lock-stealth-load))
> ! 		      ;; In case sit-for runs any timers,
> ! 		      ;; give them the expected current buffer.
> ! 		      (with-current-buffer outer-buffer
> ! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))
>   
>   
>   \f
> --- 469,527 ----
>   	  minibuffer-auto-raise
>   	  message-log-max)
>         (with-local-quit
> ! 	(when (and jit-lock-mode buffers (not (input-pending-p)))
>   	  (with-current-buffer (pop buffers)
> ! 	    ;; This is funny.  Calling sit-for with 3rd arg non-nil
> ! 	    ;; so that it doesn't redisplay, internally calls
> ! 	    ;; wait_reading_process_input also with a parameter
> ! 	    ;; saying "don't redisplay."  Since this function here
> ! 	    ;; is called periodically, this effectively leads to
> ! 	    ;; process output not being redisplayed at all because
> ! 	    ;; redisplay_internal is never called.  (That didn't
> ! 	    ;; work in the old redisplay either.)  So, we learn that
> ! 	    ;; we mustn't call sit-for that way here.  But then, we
> ! 	    ;; have to be cautious not to call sit-for in a widened
> ! 	    ;; buffer, since this could display hidden parts of that
> ! 	    ;; buffer.  This explains the seemingly weird use of
> ! 	    ;; save-restriction/widen here.
> ! 
> ! 	    (with-temp-message (if jit-lock-stealth-verbose
> ! 				   (concat "JIT stealth lock "
> ! 					   (buffer-name)))
> ! 
> ! 	      ;; In the following code, the `sit-for' calls cause a
> ! 	      ;; redisplay, so it's required that the
> ! 	      ;; buffer-modified flag of a buffer that is displayed
> ! 	      ;; has the right value---otherwise the mode line of
> ! 	      ;; an unmodified buffer would show a `*'.
> ! 	      (let (start
> ! 		    (nice (or jit-lock-stealth-nice 0))
> ! 		    (point (point-min)))
> ! 		(while (and (setq start
> ! 				  (jit-lock-stealth-chunk-start point))
> ! 			    ;; In case sit-for runs any timers,
> ! 			    ;; give them the expected current buffer.
> ! 			    (with-current-buffer outer-buffer
> ! 			      (sit-for nice)))
> ! 
> ! 		  ;; fontify a block.
> ! 		  (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
> ! 		  ;; If stealth jit-locking is done backwards, this leads to
> ! 		  ;; excessive O(n^2) refontification.   -stef
> ! 		  ;; (when (>= jit-lock-context-unfontify-pos start)
> ! 		  ;;   (setq jit-lock-context-unfontify-pos end))
> ! 
> ! 		  ;; Wait a little if load is too high.
> ! 		  (when (and jit-lock-stealth-load
> ! 			     (> (car (load-average)) jit-lock-stealth-load))
> ! 		    ;; Make this timer resume jit-lock in a few
> ! 		    ;; seconds.  Compute an idleness time suitably
> ! 		    ;; larger than the current one.
> ! 		    (timer-set-idle-time jit-lock-stealth-resume-timer
> ! 					 (current-idle-time))
> ! 		    (timer-inc-time (or jit-lock-stealth-time 30))
> ! 		    (timer-activate-when-idle
> ! 		     jit-lock-stealth-resume-timer t)))))))))))
>   
>   
>   \f

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 11:39 ` Kim F. Storm
@ 2006-08-21 16:57   ` martin rudalics
  2006-08-21 18:51     ` Chong Yidong
  0 siblings, 1 reply; 43+ messages in thread
From: martin rudalics @ 2006-08-21 16:57 UTC (permalink / raw)
  Cc: rms, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 283 bytes --]

 > Martin, would you like to try to update your patch ?

Apparently, my patch works also without restricting the values of
`run-at-time' as I did earlier.  Could you please try the attached
revision with "pathological" values for `jit-lock-stealth-time' and
`jit-lock-stealth-nice'.

[-- Attachment #2: jit-lock.patch --]
[-- Type: text/plain, Size: 4971 bytes --]

*** jit-lock.el.~1.54.~	Mon Aug 21 14:35:24 2006
--- jit-lock.el	Mon Aug 21 18:14:28 2006
***************
*** 444,512 ****
  	result))))


! (defun jit-lock-stealth-fontify ()
    "Fontify buffers stealthily.
! This functions is called after Emacs has been idle for
! `jit-lock-stealth-time' seconds."
!   ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
!   (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window)))
!     (let ((buffers (buffer-list))
! 	  (outer-buffer (current-buffer))
  	  minibuffer-auto-raise
! 	  message-log-max)
!       (with-local-quit
! 	(while (and buffers (not (input-pending-p)))
! 	  (with-current-buffer (pop buffers)
! 	    (when jit-lock-mode
! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	      ;; so that it doesn't redisplay, internally calls
! 	      ;; wait_reading_process_input also with a parameter
! 	      ;; saying "don't redisplay."  Since this function here
! 	      ;; is called periodically, this effectively leads to
! 	      ;; process output not being redisplayed at all because
! 	      ;; redisplay_internal is never called.  (That didn't
! 	      ;; work in the old redisplay either.)  So, we learn that
! 	      ;; we mustn't call sit-for that way here.  But then, we
! 	      ;; have to be cautious not to call sit-for in a widened
! 	      ;; buffer, since this could display hidden parts of that
! 	      ;; buffer.  This explains the seemingly weird use of
! 	      ;; save-restriction/widen here.
! 
  	      (with-temp-message (if jit-lock-stealth-verbose
  				     (concat "JIT stealth lock "
  					     (buffer-name)))
! 
! 		;; In the following code, the `sit-for' calls cause a
! 		;; redisplay, so it's required that the
! 		;; buffer-modified flag of a buffer that is displayed
! 		;; has the right value---otherwise the mode line of
! 		;; an unmodified buffer would show a `*'.
! 		(let (start
! 		      (nice (or jit-lock-stealth-nice 0))
! 		      (point (point-min)))
! 		  (while (and (setq start
! 				    (jit-lock-stealth-chunk-start point))
! 			      ;; In case sit-for runs any timers,
! 			      ;; give them the expected current buffer.
! 			      (with-current-buffer outer-buffer
! 				(sit-for nice)))
! 
! 		    ;; fontify a block.
! 		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; If stealth jit-locking is done backwards, this leads to
! 		    ;; excessive O(n^2) refontification.   -stef
! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
! 		    ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		    ;; Wait a little if load is too high.
! 		    (when (and jit-lock-stealth-load
! 			       (> (car (load-average)) jit-lock-stealth-load))
! 		      ;; In case sit-for runs any timers,
! 		      ;; give them the expected current buffer.
! 		      (with-current-buffer outer-buffer
! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))


  \f
--- 444,491 ----
  	result))))


! (defun jit-lock-stealth-fontify (&optional repeat)
    "Fontify buffers stealthily.
! This function is called repeatedly after Emacs has become idle for
! `jit-lock-stealth-time' seconds.  Optional argument REPEAT is expected
! non-nil in a repeated invocation of this function."
!   (unless (or (input-pending-p)
! 	      executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window))
! 	      (null (if repeat
! 			;; In repeated invocations `jit-lock-stealth-buffers'
! 			;; has been already set up.
! 			jit-lock-stealth-buffers
! 		      ;; In first invocation set up `jit-lock-stealth-buffers'
! 		      ;; from `buffer-list'.
! 		      (setq jit-lock-stealth-buffers (buffer-list)))))
!     (let ((buffer (car jit-lock-stealth-buffers))
  	  minibuffer-auto-raise
! 	  message-log-max
! 	  start load-delay)
!       (when (or (not jit-lock-stealth-load)
! 		(or (<= (car (load-average)) jit-lock-stealth-load)
! 		    ;; If load is too high, remember this in `load-delay'.
! 		    (not (setq load-delay t))))
! 	(with-current-buffer buffer
! 	  (if (and jit-lock-mode
! 		   (setq start (jit-lock-stealth-chunk-start (point))))
! 	      ;; Fontify one block of at most `jit-lock-chunk-size' characters.
  	      (with-temp-message (if jit-lock-stealth-verbose
  				     (concat "JIT stealth lock "
  					     (buffer-name)))
! 		(jit-lock-fontify-now start (+ start jit-lock-chunk-size)))
! 	    ;; Nothing to fontify here.  Remove this buffer from
! 	    ;; `jit-lock-stealth-buffers'.
! 	    (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers)))))
!       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
! 	;; Call us again.
! 	(run-at-time
! 	 ;; If load was too high, call again after `jit-lock-stealth-time'
! 	 ;; seconds.  Otherwise repeat after `jit-lock-stealth-nice' seconds.
! 	 (if load-delay jit-lock-stealth-time (or jit-lock-stealth-nice 0))
! 	 nil 'jit-lock-stealth-fontify t)))))


  \f

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 16:57   ` martin rudalics
@ 2006-08-21 18:51     ` Chong Yidong
  2006-08-21 22:22       ` martin rudalics
  0 siblings, 1 reply; 43+ messages in thread
From: Chong Yidong @ 2006-08-21 18:51 UTC (permalink / raw)
  Cc: emacs-devel, rms, Kim F. Storm

martin rudalics <rudalics@gmx.at> writes:

>> Martin, would you like to try to update your patch ?
>
> Apparently, my patch works also without restricting the values of
> `run-at-time' as I did earlier.  Could you please try the attached
> revision with "pathological" values for `jit-lock-stealth-time' and
> `jit-lock-stealth-nice'.

The patch looks very good to me.  I have just one serious question
plus a few nitpicks:

Each time Emacs becomes idle, `jit-lock-stealth-fontify' is called;
with this patch, it requeues itself as a non-idle timer until it
finishes fontifying.  What happens if Emacs becomes idle again before
fontification finishes?  (This may happen if jit-lock-stealth-time is
very short, or if a timer or process filter makes Emacs idle.)  It
seems to me that this will set off another series of non-idle timers,
which is not what we want.

I think that if jit-lock-stealth-fontify is called with no argument,
and fontification is proceeding, it should do nothing.  One way to do
this is to introduce a new `jit-lock-stealth-fontifying' variable.
(This may not work well if stealth fontification is so slow that the
buffer list changes significantly before fontification finishes, but I
think there's not much we can do about this.)

Now the nitpicks.  First, jit-lock-stealth-buffers should be
defvar'ed.

Second, this part is rather hard to read:

    (let (....
          load-delay)
      (when (or (not jit-lock-stealth-load)
                (or (<= (car (load-average)) jit-lock-stealth-load)
                    (not (setq load-delay t))))
         ...))

I suggest changing it to

    (let (...
	  (load-delay (and jit-lock-stealth-load
			   (>= (car (load-average)) jit-lock-stealth-load))))
      (when (not load-delay)
         ...))

Finally, is it really necessary to test jit-lock-stealth-time here?
If it's invalid, jit-lock-stealth-fontify wouldn't get called in the
first place.

  (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
    (run-at-time
      (if load-delay jit-lock-stealth-time (or jit-lock-stealth-nice 0))
      nil 'jit-lock-stealth-fontify t))

Other than that, I think this proposal is good.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 18:51     ` Chong Yidong
@ 2006-08-21 22:22       ` martin rudalics
  2006-08-21 23:26         ` Chong Yidong
                           ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-21 22:22 UTC (permalink / raw)
  Cc: emacs-devel, rms, Kim F. Storm

[-- Attachment #1: Type: text/plain, Size: 2708 bytes --]

 > Each time Emacs becomes idle, `jit-lock-stealth-fontify' is called;
 > with this patch, it requeues itself as a non-idle timer until it
 > finishes fontifying.  What happens if Emacs becomes idle again before
 > fontification finishes?  (This may happen if jit-lock-stealth-time is
 > very short, or if a timer or process filter makes Emacs idle.)  It
 > seems to me that this will set off another series of non-idle timers,
 > which is not what we want.
 > I think that if jit-lock-stealth-fontify is called with no argument,
 > and fontification is proceeding, it should do nothing.

Not really.  `buffer-list' may have changed in between and I have to
recalculate `jit-lock-stealth-buffers'.  I also should care about the
liveness of my buffers here.  Anyway your reasoning is valid, I could
pile up a sequence of timers all working on the same possibly stale
version of `jit-lock-stealth-buffers'.  Sooner or later they should stop
but that's no justification for what I wrote.

 > One way to do
 > this is to introduce a new `jit-lock-stealth-fontifying' variable.
 > (This may not work well if stealth fontification is so slow that the
 > buffer list changes significantly before fontification finishes, but I
 > think there's not much we can do about this.)

I'll simply use another timer.

 > Now the nitpicks.  First, jit-lock-stealth-buffers should be
 > defvar'ed.

It _was_ in my first patch.  Please convince yourself that I'm not
completely imbecile.

 > Second, this part is rather hard to read:
 >
 >     (let (....
 >           load-delay)
 >       (when (or (not jit-lock-stealth-load)
 >                 (or (<= (car (load-average)) jit-lock-stealth-load)
 >                     (not (setq load-delay t))))
 >          ...))
 > I suggest changing it to
 >
 >     (let (...
 > 	  (load-delay (and jit-lock-stealth-load
 > 			   (>= (car (load-average)) jit-lock-stealth-load))))
 >       (when (not load-delay)
 >          ...))
 >

I want to call myself with a zero delay when there's nothing to fontify
in the car of `jit-lock-stealth-buffers' and there are buffers left.
But you're right, obviously.

 > Finally, is it really necessary to test jit-lock-stealth-time here?
 > If it's invalid, jit-lock-stealth-fontify wouldn't get called in the
 > first place.
 >
 >   (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
 >     (run-at-time
 >       (if load-delay jit-lock-stealth-time (or jit-lock-stealth-nice 0))
 >       nil 'jit-lock-stealth-fontify t))
 >

Paranoia.  The user could have set this to nil in between two calls.
Emacs timers are vindictive.

 > Other than that, I think this proposal is good.

Not much left, I suppose.  Please look again at the new patch.

[-- Attachment #2: jit-lock.patch --]
[-- Type: text/plain, Size: 5626 bytes --]

*** jit-lock.el.~1.54.~	Mon Aug 21 14:35:24 2006
--- jit-lock.el	Tue Aug 22 00:14:42 2006
***************
*** 444,513 ****
  	result))))


! (defun jit-lock-stealth-fontify ()
    "Fontify buffers stealthily.
! This functions is called after Emacs has been idle for
! `jit-lock-stealth-time' seconds."
!   ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
!   (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window)))
!     (let ((buffers (buffer-list))
! 	  (outer-buffer (current-buffer))
  	  minibuffer-auto-raise
! 	  message-log-max)
!       (with-local-quit
! 	(while (and buffers (not (input-pending-p)))
! 	  (with-current-buffer (pop buffers)
! 	    (when jit-lock-mode
! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	      ;; so that it doesn't redisplay, internally calls
! 	      ;; wait_reading_process_input also with a parameter
! 	      ;; saying "don't redisplay."  Since this function here
! 	      ;; is called periodically, this effectively leads to
! 	      ;; process output not being redisplayed at all because
! 	      ;; redisplay_internal is never called.  (That didn't
! 	      ;; work in the old redisplay either.)  So, we learn that
! 	      ;; we mustn't call sit-for that way here.  But then, we
! 	      ;; have to be cautious not to call sit-for in a widened
! 	      ;; buffer, since this could display hidden parts of that
! 	      ;; buffer.  This explains the seemingly weird use of
! 	      ;; save-restriction/widen here.
! 
! 	      (with-temp-message (if jit-lock-stealth-verbose
! 				     (concat "JIT stealth lock "
! 					     (buffer-name)))
! 
! 		;; In the following code, the `sit-for' calls cause a
! 		;; redisplay, so it's required that the
! 		;; buffer-modified flag of a buffer that is displayed
! 		;; has the right value---otherwise the mode line of
! 		;; an unmodified buffer would show a `*'.
! 		(let (start
! 		      (nice (or jit-lock-stealth-nice 0))
! 		      (point (point-min)))
! 		  (while (and (setq start
! 				    (jit-lock-stealth-chunk-start point))
! 			      ;; In case sit-for runs any timers,
! 			      ;; give them the expected current buffer.
! 			      (with-current-buffer outer-buffer
! 				(sit-for nice)))
! 
! 		    ;; fontify a block.
  		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; If stealth jit-locking is done backwards, this leads to
! 		    ;; excessive O(n^2) refontification.   -stef
! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
! 		    ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		    ;; Wait a little if load is too high.
! 		    (when (and jit-lock-stealth-load
! 			       (> (car (load-average)) jit-lock-stealth-load))
! 		      ;; In case sit-for runs any timers,
! 		      ;; give them the expected current buffer.
! 		      (with-current-buffer outer-buffer
! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))
! 

  \f
  ;;; Deferred fontification.
--- 444,507 ----
  	result))))


! (defvar jit-lock-stealth-buffers nil
!   "List of buffers that should be fontified stealthily.")
! 
! (defvar jit-lock-stealth-repeat-timer nil
!   "Timer for repeated stealth fontification.")
! 
! (defun jit-lock-stealth-fontify (&optional repeat)
    "Fontify buffers stealthily.
! This function is called repeatedly after Emacs has become idle for
! `jit-lock-stealth-time' seconds.  Optional argument REPEAT is expected
! non-nil in a repeated invocation of this function."
!   (unless (or (input-pending-p)
! 	      executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window))
! 	      (null (if repeat
! 			;; In repeated invocations `jit-lock-stealth-buffers'
! 			;; has been already set up.
! 			jit-lock-stealth-buffers
! 		      ;; In first invocation set up `jit-lock-stealth-buffers'
! 		      ;; from `buffer-list'.
! 		      (setq jit-lock-stealth-buffers (buffer-list)))))
!     (when (timerp jit-lock-stealth-repeat-timer)
!       ;; Cancel timer for repated invocations.
!       (cancel-timer jit-lock-stealth-repeat-timer))
!     (let ((buffer (car jit-lock-stealth-buffers))
  	  minibuffer-auto-raise
! 	  message-log-max
! 	  start delay)
!       (if (and jit-lock-stealth-load
! 	       (> (car (load-average)) jit-lock-stealth-load))
! 	  ;; If load is too high, run again after `jit-lock-stealth-time'
! 	  ;; seconds.
! 	  (setq delay jit-lock-stealth-time)
! 	(if (buffer-live-p buffer)
! 	    (with-current-buffer buffer
! 	      (if (and jit-lock-mode
! 		       (setq start (jit-lock-stealth-chunk-start (point))))
! 		  ;; Fontify one block of at most `jit-lock-chunk-size'
! 		  ;; characters.
! 		  (with-temp-message (if jit-lock-stealth-verbose
! 					 (concat "JIT stealth lock "
! 						 (buffer-name)))
  		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; Run again after `jit-lock-stealth-nice' seconds.
! 		    (setq delay (or jit-lock-stealth-nice 0)))
! 		;; Nothing to fontify here.  Remove this buffer from
! 		;; `jit-lock-stealth-buffers' and run again immediately.
! 		(setq delay 0)
! 		(setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
! 	  ;; Buffer is no more live, remove it from `jit-lock-stealth-buffers'
! 	  ;; and run again instantaneously.
! 	  (setq delay 0)
! 	  (setq jit-lock-stealth-buffers (cdr jit-lock-stealth-buffers))))
!       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
! 	;; Call us again.
! 	(setq jit-lock-stealth-repeat-timer
! 	      (run-at-time delay nil 'jit-lock-stealth-fontify t))))))

  \f
  ;;; Deferred fontification.

[-- Attachment #3: Type: text/plain, Size: 142 bytes --]

_______________________________________________
Emacs-devel mailing list
Emacs-devel@gnu.org
http://lists.gnu.org/mailman/listinfo/emacs-devel

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 22:22       ` martin rudalics
@ 2006-08-21 23:26         ` Chong Yidong
  2006-08-22  7:18         ` Kim F. Storm
  2006-08-22 15:41         ` Richard Stallman
  2 siblings, 0 replies; 43+ messages in thread
From: Chong Yidong @ 2006-08-21 23:26 UTC (permalink / raw)
  Cc: Kim F. Storm, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> Other than that, I think this proposal is good.
>
> Not much left, I suppose.  Please look again at the new patch.

Looks OK to me.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 22:22       ` martin rudalics
  2006-08-21 23:26         ` Chong Yidong
@ 2006-08-22  7:18         ` Kim F. Storm
  2006-08-22 15:41         ` Richard Stallman
  2 siblings, 0 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-22  7:18 UTC (permalink / raw)
  Cc: Chong Yidong, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>
> Not much left, I suppose.  Please look again at the new patch.

I've installed it locally, and it is running just fine.

Thanks.


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-21 22:22       ` martin rudalics
  2006-08-21 23:26         ` Chong Yidong
  2006-08-22  7:18         ` Kim F. Storm
@ 2006-08-22 15:41         ` Richard Stallman
  2006-08-23 12:27           ` martin rudalics
  2 siblings, 1 reply; 43+ messages in thread
From: Richard Stallman @ 2006-08-22 15:41 UTC (permalink / raw)
  Cc: cyd, emacs-devel, storm

I have now read your patch, and I think it is a good approach.
However, this

    !       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
    ! 	;; Call us again.
    ! 	(setq jit-lock-stealth-repeat-timer
    ! 	      (run-at-time delay nil 'jit-lock-stealth-fontify t))))))

creates an ordinary timer, not an idle timer.
It will run even if Emacs is not idle.

I think this ought to use run-with-idle-timer
and current-idle-time, as in my patch.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-22 15:41         ` Richard Stallman
@ 2006-08-23 12:27           ` martin rudalics
  2006-08-23 13:09             ` Kim F. Storm
                               ` (2 more replies)
  0 siblings, 3 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-23 12:27 UTC (permalink / raw)
  Cc: cyd, emacs-devel, storm

 > I have now read your patch, and I think it is a good approach.
 > However, this
 >
 >     !       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
 >     ! 	;; Call us again.
 >     ! 	(setq jit-lock-stealth-repeat-timer
 >     ! 	      (run-at-time delay nil 'jit-lock-stealth-fontify t))))))
 >
 > creates an ordinary timer, not an idle timer.
 > It will run even if Emacs is not idle.

It simply tries to mimic the behavior of `jit-lock-stealth-fontify'
without sit-fors.  The ordinary timer is considered to substitute the
original "(while (and buffers ..." loop.

 > I think this ought to use run-with-idle-timer
 > and current-idle-time, as in my patch.

I was not able to accomplish that since the idle timer does not trigger.
In analogy to your patch I replaced the above by

       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
	;; Call us again.
	(timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
	(timer-inc-time jit-lock-stealth-repeat-timer delay)
	(timer-activate-when-idle jit-lock-stealth-repeat-timer t)

but I suspect that calling `timer-set-idle-time' with the return value
of `current-idle-time' does not DTRT:


(timer-set-idle-time timer secs &optional repeat)

Set the trigger idle time of timer to _secs_.


(current-idle-time)

Return the current length of Emacs idleness.
The value is returned as a list of _three integers_.


I tried to replace `timer-set-idle-time' with `timer-set-time' but without
avail.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-23 12:27           ` martin rudalics
@ 2006-08-23 13:09             ` Kim F. Storm
  2006-08-24  5:20               ` Richard Stallman
  2006-08-24  9:10               ` Kim F. Storm
  2006-08-24  5:20             ` Richard Stallman
  2006-08-24 15:27             ` Chong Yidong
  2 siblings, 2 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-23 13:09 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> I think this ought to use run-with-idle-timer
>> and current-idle-time, as in my patch.
>
> I was not able to accomplish that since the idle timer does not trigger.


I can hardly imagine emacs being idle for more than 2^28 seconds, so
it seems safe to simplify it to return a cons (SECS . USECS)  [see patch below]

> In analogy to your patch I replaced the above by
>
>       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
> 	;; Call us again.
> 	(timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
> 	(timer-inc-time jit-lock-stealth-repeat-timer delay)
> 	(timer-activate-when-idle jit-lock-stealth-repeat-timer t)
>
> but I suspect that calling `timer-set-idle-time' with the return value
> of `current-idle-time' does not DTRT:

With the above change to current-idle-time, it seems the following
should work:

       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
	;; Call us again.
        (let ((idle (current-idle-time)))
          (when idle
	    (timer-set-idle-time jit-lock-stealth-repeat-timer delay)
	    (timer-inc-time jit-lock-stealth-repeat-timer (car idle) (cdr idle))
	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))


Notice the swap in the args in the first two calls.
That's because inc-time accepts an USECS arg, while set-idle-time doesn't.



*** keyboard.c	21 Aug 2006 21:38:31 +0200	1.872
--- keyboard.c	23 Aug 2006 14:54:50 +0200	
***************
*** 4561,4571 ****
  
  DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
         /* Return the current length of Emacs idleness.
! The value is returned as a list of three integers.  The first has the
! most significant 16 bits of the seconds, while the second has the
! least significant 16 bits.  The third integer gives the microsecond
! count.
! 
  The microsecond count is zero on systems that do not provide
  resolution finer than a second.  */)
    ()
--- 4561,4567 ----
  
  DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
         /* Return the current length of Emacs idleness.
! The value is returned as a cons (SECS . USECS).
  The microsecond count is zero on systems that do not provide
  resolution finer than a second.  */)
    ()
***************
*** 4578,4588 ****
      {
        EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
  
!       XSETINT (result[0], (EMACS_SECS (idleness_now) >> 16) & 0xffff);
!       XSETINT (result[1], (EMACS_SECS (idleness_now) >> 0)  & 0xffff);
!       XSETINT (result[2], EMACS_USECS (idleness_now));
! 
!       return Flist (3, result);
      }
  
    return Qnil;
--- 4574,4581 ----
      {
        EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
  
!       return Fcons (make_number (EMACS_SECS (idleness_now)),
! 		    make_number (EMACS_USECS (idleness_now)));
      }
  
    return Qnil;



-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-23 12:27           ` martin rudalics
  2006-08-23 13:09             ` Kim F. Storm
@ 2006-08-24  5:20             ` Richard Stallman
  2006-08-24  7:48               ` Kim F. Storm
  2006-08-24 12:21               ` martin rudalics
  2006-08-24 15:27             ` Chong Yidong
  2 siblings, 2 replies; 43+ messages in thread
From: Richard Stallman @ 2006-08-24  5:20 UTC (permalink / raw)
  Cc: cyd, emacs-devel, storm

     > creates an ordinary timer, not an idle timer.
     > It will run even if Emacs is not idle.

    It simply tries to mimic the behavior of `jit-lock-stealth-fontify'
    without sit-fors.

But it doesn't.  If the user types something, sit-for will return, but
the arrival of input has no effect on the (ordinary) timer.

     > I think this ought to use run-with-idle-timer
     > and current-idle-time, as in my patch.

    I was not able to accomplish that since the idle timer does not trigger.
    In analogy to your patch I replaced the above by

	   (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
	    ;; Call us again.
	    (timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
	    (timer-inc-time jit-lock-stealth-repeat-timer delay)
	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)

    but I suspect that calling `timer-set-idle-time' with the return value
    of `current-idle-time' does not DTRT:

Please try using time-to-seconds to convert.

    I tried to replace `timer-set-idle-time' with `timer-set-time' but without
    avail.

That's like trying to fix a flat tire by breaking the car's windshield.
Why even consider it?

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-23 13:09             ` Kim F. Storm
@ 2006-08-24  5:20               ` Richard Stallman
  2006-08-24  7:47                 ` Kim F. Storm
  2006-08-24  9:10               ` Kim F. Storm
  1 sibling, 1 reply; 43+ messages in thread
From: Richard Stallman @ 2006-08-24  5:20 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

    I can hardly imagine emacs being idle for more than 2^28 seconds, so
    it seems safe to simplify it to return a cons (SECS . USECS)  [see patch below]

I don't want to do that, because it would be incompatible with other
time values.  I'd rather people use time-to-seconds to convert.

However, returning the value in floating point might be a good method.
But if we do that, we should call it float-idle-time.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  5:20               ` Richard Stallman
@ 2006-08-24  7:47                 ` Kim F. Storm
  2006-08-24  7:58                   ` Kim F. Storm
  2006-08-25 20:23                   ` Richard Stallman
  0 siblings, 2 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24  7:47 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     I can hardly imagine emacs being idle for more than 2^28 seconds, so
>     it seems safe to simplify it to return a cons (SECS . USECS)  [see patch below]
>
> I don't want to do that, because it would be incompatible with other
> time values.  

Well, since this is primarily for use in connection with run-with-idle-timer,
it seems more logical to use something which can be used more or less
directly with that function.

>               I'd rather people use time-to-seconds to convert.

time-to-seconds is in time-date.el which isn't pre-loaded.

If we stick to the current value of current-idle-time, should we move
time-to-seconds to subr.el?

>
> However, returning the value in floating point might be a good method.

That would be much better and cleaner, IMO.
And we can leave time-to-seconds where it is!

> But if we do that, we should call it float-idle-time.

Why?

The current name isn't list-with-three-elements-idle-time  :-)

The doc string will tell that the return value is a float.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  5:20             ` Richard Stallman
@ 2006-08-24  7:48               ` Kim F. Storm
  2006-08-24 12:21               ` martin rudalics
  1 sibling, 0 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24  7:48 UTC (permalink / raw)
  Cc: martin rudalics, cyd, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     but I suspect that calling `timer-set-idle-time' with the return value
>     of `current-idle-time' does not DTRT:
>
> Please try using time-to-seconds to convert.

Fixing current-idle-time to return a float would be much cleaner.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  7:47                 ` Kim F. Storm
@ 2006-08-24  7:58                   ` Kim F. Storm
  2006-08-24  9:07                     ` Kim F. Storm
  2006-08-25 20:23                     ` Richard Stallman
  2006-08-25 20:23                   ` Richard Stallman
  1 sibling, 2 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24  7:58 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

>> However, returning the value in floating point might be a good method.
>
> That would be much better and cleaner, IMO.
> And we can leave time-to-seconds where it is!
>
>> But if we do that, we should call it float-idle-time.
>
> The doc string will tell that the return value is a float.

Actually, the return value of the new `current-idle-time' will be
either a float or nil (if not idle).

So the name `float-idle-time' would be misleading!

Shall I fix current-idle-time to return a float or nil?

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  7:58                   ` Kim F. Storm
@ 2006-08-24  9:07                     ` Kim F. Storm
  2006-08-24 14:47                       ` Chong Yidong
  2006-08-25 20:23                     ` Richard Stallman
  1 sibling, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24  9:07 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> storm@cua.dk (Kim F. Storm) writes:
>
>>> However, returning the value in floating point might be a good method.
>>
>> That would be much better and cleaner, IMO.
>> And we can leave time-to-seconds where it is!
>>
>>> But if we do that, we should call it float-idle-time.
>>
>> The doc string will tell that the return value is a float.
>
> Actually, the return value of the new `current-idle-time' will be
> either a float or nil (if not idle).
>
> So the name `float-idle-time' would be misleading!
>
> Shall I fix current-idle-time to return a float or nil?

Here's a patch.


*** keyboard.c	21 Aug 2006 21:38:31 +0200	1.872
--- keyboard.c	24 Aug 2006 10:55:26 +0200	
***************
*** 4560,4588 ****
  }
  
  DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
!        /* Return the current length of Emacs idleness.
! The value is returned as a list of three integers.  The first has the
! most significant 16 bits of the seconds, while the second has the
! least significant 16 bits.  The third integer gives the microsecond
! count.
! 
! The microsecond count is zero on systems that do not provide
! resolution finer than a second.  */)
    ()
  {
-   EMACS_TIME now, idleness_now;
-   Lisp_Object result[3];
  
-   EMACS_GET_TIME (now);
    if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
      {
!       EMACS_SUB_TIME (idleness_now, now, timer_idleness_start_time);
! 
!       XSETINT (result[0], (EMACS_SECS (idleness_now) >> 16) & 0xffff);
!       XSETINT (result[1], (EMACS_SECS (idleness_now) >> 0)  & 0xffff);
!       XSETINT (result[2], EMACS_USECS (idleness_now));
  
!       return Flist (3, result);
      }
  
    return Qnil;
--- 4560,4578 ----
  }
  
  DEFUN ("current-idle-time", Fcurrent_idle_time, Scurrent_idle_time, 0, 0, 0,
!        /* Return the current length of Emacs idleness in seconds.
! The value is a floating point number, or nil if Emacs is not idle.  */)
    ()
  {
  
    if (! EMACS_TIME_NEG_P (timer_idleness_start_time))
      {
!       EMACS_TIME now, idle_time;
!       EMACS_GET_TIME (now);
!       EMACS_SUB_TIME (idle_time, now, timer_idleness_start_time);
  
!       return make_float ((EMACS_SECS (idle_time) * 1e6
! 			  + EMACS_USECS (idle_time)) / 1e6);
      }
  
    return Qnil;

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-23 13:09             ` Kim F. Storm
  2006-08-24  5:20               ` Richard Stallman
@ 2006-08-24  9:10               ` Kim F. Storm
  2006-08-24 12:23                 ` martin rudalics
  1 sibling, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24  9:10 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> With the above change to current-idle-time, it seems the following
> should work:
>
>        (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
> 	;; Call us again.
>         (let ((idle (current-idle-time)))
>           (when idle
> 	    (timer-set-idle-time jit-lock-stealth-repeat-timer delay)
> 	    (timer-inc-time jit-lock-stealth-repeat-timer (car idle) (cdr idle))
> 	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))
>

With the latest version of current-idle-time, this now becomes:


	(when (and jit-lock-stealth-buffers jit-lock-stealth-time)
	;; Call us again.
	 (let ((idle (current-idle-time)))
	   (when idle
	    (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
	    (timer-inc-time jit-lock-stealth-repeat-timer delay)
	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))

[I swapped idle and delay args back again, as using floats DTRT]

It can't get much simpler than that!

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  5:20             ` Richard Stallman
  2006-08-24  7:48               ` Kim F. Storm
@ 2006-08-24 12:21               ` martin rudalics
  1 sibling, 0 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-24 12:21 UTC (permalink / raw)
  Cc: cyd, emacs-devel, storm

> Please try using time-to-seconds to convert.

Sorry, the tire's still flat.  Using

	(let ((message-log-max t)
	      (count 0))
	  (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	  (timer-set-idle-time jit-lock-stealth-repeat-timer
			       (time-to-seconds (current-idle-time)))
	  (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	  (timer-inc-time jit-lock-stealth-repeat-timer (max delay 0.1))
	  (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	  (timer-activate-when-idle jit-lock-stealth-repeat-timer t)
	  (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer))

typically gets me

1 ... [t nil nil nil nil jit-lock-stealth-fontify t nil]
Loading time-date...done
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t nil]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t nil]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]

where every new cycle was caused by a mouse-click to trigger
`jit-lock-stealth-timer'.

(I used "(max delay 0.1)" because I thought that a delay of zero
could cause problems, but there's no difference.)

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  9:10               ` Kim F. Storm
@ 2006-08-24 12:23                 ` martin rudalics
  2006-08-24 12:54                   ` Kim F. Storm
  2006-08-24 13:07                   ` Kim F. Storm
  0 siblings, 2 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-24 12:23 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

> With the latest version of current-idle-time, this now becomes:
>
>
> 	(when (and jit-lock-stealth-buffers jit-lock-stealth-time)
> 	;; Call us again.
> 	 (let ((idle (current-idle-time)))
> 	   (when idle
> 	    (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
> 	    (timer-inc-time jit-lock-stealth-repeat-timer delay)
> 	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))
>
> [I swapped idle and delay args back again, as using floats DTRT]
>
> It can't get much simpler than that!
>

It still doesn't trigger.  With

       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
	;; Call us again.
	(let ((message-log-max t)
	      (count 0))
	  (let ((idle (current-idle-time)))
	    (message "idle ... %s" idle)
	    (when idle
	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	      (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	      (timer-inc-time jit-lock-stealth-repeat-timer (max delay 0.1))
	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
	      (timer-activate-when-idle jit-lock-stealth-repeat-timer t)
	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)))))

I get

idle ... 3.02
1 ... [t nil nil nil nil jit-lock-stealth-fontify t nil]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t nil]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t nil]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
idle ... 3.02
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
idle ... 3.02
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]
idle ... 3.02
1 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
2 ... [t 0 3 20000 nil jit-lock-stealth-fontify t t]
3 ... [t 0 3 120000 nil jit-lock-stealth-fontify t t]
4 ... [nil 0 3 120000 nil jit-lock-stealth-fontify t t]

hence `current-idle-time' always returns the same value.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 12:23                 ` martin rudalics
@ 2006-08-24 12:54                   ` Kim F. Storm
  2006-08-24 13:07                   ` Kim F. Storm
  1 sibling, 0 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24 12:54 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

> It still doesn't trigger.  With

It could be that the new trigger time has somehow passed by
before restarting the idle timer.  Just to rule that out,
could you try with delay = 2 instead of 0.


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 12:23                 ` martin rudalics
  2006-08-24 12:54                   ` Kim F. Storm
@ 2006-08-24 13:07                   ` Kim F. Storm
  2006-08-24 13:11                     ` Kim F. Storm
  2006-08-24 14:16                     ` Chong Yidong
  1 sibling, 2 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24 13:07 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> With the latest version of current-idle-time, this now becomes:
>>
>>
>> 	(when (and jit-lock-stealth-buffers jit-lock-stealth-time)
>> 	;; Call us again.
>> 	 (let ((idle (current-idle-time)))
>> 	   (when idle
>> 	    (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
>> 	    (timer-inc-time jit-lock-stealth-repeat-timer delay)
>> 	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))
>>
>> [I swapped idle and delay args back again, as using floats DTRT]
>>
>> It can't get much simpler than that!
>>
>
> It still doesn't trigger.  With
>
>       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
> 	;; Call us again.
> 	(let ((message-log-max t)
> 	      (count 0))
> 	  (let ((idle (current-idle-time)))
> 	    (message "idle ... %s" idle)
> 	    (when idle
> 	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
> 	      (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
> 	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
> 	      (timer-inc-time jit-lock-stealth-repeat-timer (max delay 0.1))
> 	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)
> 	      (timer-activate-when-idle jit-lock-stealth-repeat-timer t)
> 	      (message "%s ... %s" (setq count (1+ count)) jit-lock-stealth-repeat-timer)))))
>

It seems that reusing the idle timer is broken.
This seems to work:

 	  (let ((idle (current-idle-time)))
 	    (when idle
 	      (run-with-idle-timer (+ idle (max delay 0.1))
                                    nil #'jit-lock-stealth-fontify)))


-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 13:07                   ` Kim F. Storm
@ 2006-08-24 13:11                     ` Kim F. Storm
  2006-08-24 13:34                       ` Kim F. Storm
  2006-08-24 14:16                     ` Chong Yidong
  1 sibling, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24 13:11 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

>
>  	  (let ((idle (current-idle-time)))
>  	    (when idle
>  	      (run-with-idle-timer (+ idle (max delay 0.1))
>                                     nil #'jit-lock-stealth-fontify)))
>

make that:

 	  (let ((idle (current-idle-time)))
            (setq jit-lock-stealth-repeat-timer
                 (and (not idle)
 	              (run-with-idle-timer (+ idle (max delay 0.1))
                                           nil #'jit-lock-stealth-fontify))))
-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 13:11                     ` Kim F. Storm
@ 2006-08-24 13:34                       ` Kim F. Storm
  2006-08-24 18:11                         ` martin rudalics
  0 siblings, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24 13:34 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> storm@cua.dk (Kim F. Storm) writes:
>
>>
>>  	  (let ((idle (current-idle-time)))
>>  	    (when idle
>>  	      (run-with-idle-timer (+ idle (max delay 0.1))
>>                                     nil #'jit-lock-stealth-fontify)))
>>
>
> make that:
>
>  	  (let ((idle (current-idle-time)))
>             (setq jit-lock-stealth-repeat-timer
>                  (and (not idle)
>  	              (run-with-idle-timer (+ idle (max delay 0.1))
>                                            nil #'jit-lock-stealth-fontify))))

Brain damange -- make that:

	  (let ((idle (current-idle-time)))
	     (setq jit-lock-stealth-repeat-timer
		  (and idle
		      (run-with-idle-timer (+ idle (max delay 0.1))
					    nil #'jit-lock-stealth-fontify))))

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 13:07                   ` Kim F. Storm
  2006-08-24 13:11                     ` Kim F. Storm
@ 2006-08-24 14:16                     ` Chong Yidong
  1 sibling, 0 replies; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 14:16 UTC (permalink / raw)
  Cc: martin rudalics, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

>>> With the latest version of current-idle-time, this now becomes:
>>>
>>> 	(when (and jit-lock-stealth-buffers jit-lock-stealth-time)
>>> 	;; Call us again.
>>> 	 (let ((idle (current-idle-time)))
>>> 	   (when idle
>>> 	    (timer-set-idle-time jit-lock-stealth-repeat-timer idle)
>>> 	    (timer-inc-time jit-lock-stealth-repeat-timer delay)
>>> 	    (timer-activate-when-idle jit-lock-stealth-repeat-timer t)))
>
> It seems that reusing the idle timer is broken.
> This seems to work:
>
>  	  (let ((idle (current-idle-time)))
>  	    (when idle
>  	      (run-with-idle-timer (+ idle (max delay 0.1))
>                                     nil #'jit-lock-stealth-fontify)))

Reusing the idle timer is not broken.  Here is simple test case, which
works perfectly.

(setq my-count 0)

(defun my-test-timer ()
  (setq my-count (1+ my-count))
  (message (format "Count: %d" my-count))
  (when (< my-count 5)
    (timer-inc-time my-timer 1)
    (timer-activate-when-idle my-timer t)))

(setq my-timer (run-with-idle-timer 2 nil 'my-test-timer))

Once Emacs is idle for 2 seconds, the echo area message counts from 1
to 5 in intervals of 1 seconds.  If you comment out `timer-inc-time',
the interval becomes instantaneous, as expected.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  9:07                     ` Kim F. Storm
@ 2006-08-24 14:47                       ` Chong Yidong
  0 siblings, 0 replies; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 14:47 UTC (permalink / raw)
  Cc: rudalics, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

>> Shall I fix current-idle-time to return a float or nil?

A more correct course of action is to leave current-idle-time the way
it is, and extend timer-set-idle-time to accept the internal time
format, analogously to timer-set-time.  Then we can submit the value
of current-idle-time directly to timer-set-idle-time.

*** emacs/lisp/emacs-lisp/timer.el.~1.12.~	2006-08-20 09:55:37.000000000 -0400
--- emacs/lisp/emacs-lisp/timer.el	2006-08-24 10:45:48.000000000 -0400
***************
*** 60,73 ****
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (aset timer 1 0)
!   (aset timer 2 0)
!   (aset timer 3 0)
!   (timer-inc-time timer secs)
    (aset timer 4 repeat)
    timer)
  
--- 60,81 ----
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
+ SECS may be an integer, floating point number, or the internal
+ time format (HIGH LOW USECS) returned by, e.g., `current-time'.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (if (consp secs)
!       (progn (aset timer 1 (car secs))
! 	     (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
! 	     (aset timer 3 (or (and (consp (cdr time)) (consp (cdr (cdr time)))
! 				    (nth 2 time))
! 			       0)))
!     (aset timer 1 0)
!     (aset timer 2 0)
!     (aset timer 3 0)
!     (timer-inc-time timer secs))
    (aset timer 4 repeat)
    timer)
  
***************
*** 104,110 ****
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be a fraction."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))
--- 112,118 ----
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be either an integer or a floating point number."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-23 12:27           ` martin rudalics
  2006-08-23 13:09             ` Kim F. Storm
  2006-08-24  5:20             ` Richard Stallman
@ 2006-08-24 15:27             ` Chong Yidong
  2006-08-24 15:40               ` Chong Yidong
  2006-08-24 16:18               ` martin rudalics
  2 siblings, 2 replies; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 15:27 UTC (permalink / raw)
  Cc: storm, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

>> I think this ought to use run-with-idle-timer
>> and current-idle-time, as in my patch.
>
> I was not able to accomplish that since the idle timer does not trigger.
> In analogy to your patch I replaced the above by
>
>       (when (and jit-lock-stealth-buffers jit-lock-stealth-time)
> 	;; Call us again.
> 	(timer-set-idle-time jit-lock-stealth-repeat-timer (current-idle-time))
> 	(timer-inc-time jit-lock-stealth-repeat-timer delay)
> 	(timer-activate-when-idle jit-lock-stealth-repeat-timer t)

I don't know what was wrong with this code since you didn't post it.
It looks like you simply forgot to initialize jit-lock-stealth-repeat-timer,
but I can't be sure.  However, the following patch, based on the last
patch you posted to this list with minimal modifications, works fine
for me.

It applies to the current CVS tree, and uses `current-idle-time'.  It
includes and uses the change to `timer-set-idle-time' which I
previously posted, allowing it to accept the value returned by
`current-idle-time'.

I have verified that the idle timer triggers correctly, stops
correctly when user input comes in, and resumes when Emacs becomes
idle again.


*** emacs/lisp/jit-lock.el.~1.54.~	2006-08-17 11:49:36.000000000 -0400
--- emacs/lisp/jit-lock.el	2006-08-24 11:21:23.000000000 -0400
***************
*** 443,513 ****
  			   (t next))))
  	result))))
  
  
! (defun jit-lock-stealth-fontify ()
    "Fontify buffers stealthily.
! This functions is called after Emacs has been idle for
! `jit-lock-stealth-time' seconds."
!   ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
    (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window)))
!     (let ((buffers (buffer-list))
! 	  (outer-buffer (current-buffer))
  	  minibuffer-auto-raise
! 	  message-log-max)
!       (with-local-quit
! 	(while (and buffers (not (input-pending-p)))
! 	  (with-current-buffer (pop buffers)
! 	    (when jit-lock-mode
! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	      ;; so that it doesn't redisplay, internally calls
! 	      ;; wait_reading_process_input also with a parameter
! 	      ;; saying "don't redisplay."  Since this function here
! 	      ;; is called periodically, this effectively leads to
! 	      ;; process output not being redisplayed at all because
! 	      ;; redisplay_internal is never called.  (That didn't
! 	      ;; work in the old redisplay either.)  So, we learn that
! 	      ;; we mustn't call sit-for that way here.  But then, we
! 	      ;; have to be cautious not to call sit-for in a widened
! 	      ;; buffer, since this could display hidden parts of that
! 	      ;; buffer.  This explains the seemingly weird use of
! 	      ;; save-restriction/widen here.
! 
! 	      (with-temp-message (if jit-lock-stealth-verbose
! 				     (concat "JIT stealth lock "
! 					     (buffer-name)))
! 
! 		;; In the following code, the `sit-for' calls cause a
! 		;; redisplay, so it's required that the
! 		;; buffer-modified flag of a buffer that is displayed
! 		;; has the right value---otherwise the mode line of
! 		;; an unmodified buffer would show a `*'.
! 		(let (start
! 		      (nice (or jit-lock-stealth-nice 0))
! 		      (point (point-min)))
! 		  (while (and (setq start
! 				    (jit-lock-stealth-chunk-start point))
! 			      ;; In case sit-for runs any timers,
! 			      ;; give them the expected current buffer.
! 			      (with-current-buffer outer-buffer
! 				(sit-for nice)))
! 
! 		    ;; fontify a block.
! 		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; If stealth jit-locking is done backwards, this leads to
! 		    ;; excessive O(n^2) refontification.   -stef
! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
! 		    ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		    ;; Wait a little if load is too high.
! 		    (when (and jit-lock-stealth-load
! 			       (> (car (load-average)) jit-lock-stealth-load))
! 		      ;; In case sit-for runs any timers,
! 		      ;; give them the expected current buffer.
! 		      (with-current-buffer outer-buffer
! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))
! 
  
  \f
  ;;; Deferred fontification.
--- 443,511 ----
  			   (t next))))
  	result))))
  
+ (defvar jit-lock-stealth-buffers nil
+   "List of buffers that should be fontified stealthily.")
  
! (defvar jit-lock-stealth-repeat-timer nil
!   "Timer for repeated stealth fontification.")
! 
! (defun jit-lock-stealth-fontify (&optional repeat)
    "Fontify buffers stealthily.
! This function is called repeatedly after Emacs has become idle for
! `jit-lock-stealth-time' seconds.  Optional argument REPEAT is expected
! non-nil in a repeated invocation of this function."
    (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window))
! 	      ;; For first invocation set up `jit-lock-stealth-buffers'.
! 	      ;; In repeated invocations it's already been set up.
! 	      (null (if repeat
! 			jit-lock-stealth-buffers
! 		      (setq jit-lock-stealth-buffers (buffer-list)))))
!     ;; Cancel timer for repeated invocations.
!     (when (timerp jit-lock-stealth-repeat-timer)
!       (cancel-timer jit-lock-stealth-repeat-timer))
!     (let ((buffer (car jit-lock-stealth-buffers))
! 	  (delay 0)
  	  minibuffer-auto-raise
! 	  message-log-max
! 	  start)
!       (if (and jit-lock-stealth-load
! 	       (> (car (load-average)) jit-lock-stealth-load))
! 	  ;; Wait a little if load is too high.
! 	  (setq delay jit-lock-stealth-time)
! 	(if (buffer-live-p buffer)
! 	    (with-current-buffer buffer
! 	      (if (and jit-lock-mode
! 		       (setq start (jit-lock-stealth-chunk-start (point))))
! 		  ;; Fontify one block of at most `jit-lock-chunk-size'
! 		  ;; characters.
! 		  (with-temp-message (if jit-lock-stealth-verbose
! 					 (concat "JIT stealth lock "
! 						 (buffer-name)))
! 		    (jit-lock-fontify-now start
! 					  (+ start jit-lock-chunk-size))
! 		    ;; Run again after `jit-lock-stealth-nice' seconds.
! 		    (setq delay (or jit-lock-stealth-nice 0)))
! 		;; Nothing to fontify here.  Remove this buffer from
! 		;; `jit-lock-stealth-buffers' and run again immediately.
! 		(setq jit-lock-stealth-buffers
! 		      (cdr jit-lock-stealth-buffers))))
! 	  ;; Buffer is no longer live.  Remove it from
! 	  ;; `jit-lock-stealth-buffers' and run again immediately.
! 	  (setq jit-lock-stealth-buffers
! 		(cdr jit-lock-stealth-buffers))))
!       ;; Call us again.
!       (when jit-lock-stealth-buffers
! 	(if repeat
! 	    (progn (timer-set-idle-time
! 		    jit-lock-stealth-repeat-timer (current-idle-time))
! 		   (timer-inc-time jit-lock-stealth-repeat-timer delay)
! 		   (timer-activate-when-idle
! 		    jit-lock-stealth-repeat-timer t))
! 	  (setq jit-lock-stealth-repeat-timer
! 		(run-at-time delay
! 			     nil 'jit-lock-stealth-fontify t)))))))
  
  \f
  ;;; Deferred fontification.
*** emacs/lisp/emacs-lisp/timer.el.~1.12.~	2006-08-20 09:55:37.000000000 -0400
--- emacs/lisp/emacs-lisp/timer.el	2006-08-24 10:45:48.000000000 -0400
***************
*** 60,73 ****
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (aset timer 1 0)
!   (aset timer 2 0)
!   (aset timer 3 0)
!   (timer-inc-time timer secs)
    (aset timer 4 repeat)
    timer)
  
--- 60,81 ----
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
+ SECS may be an integer, floating point number, or the internal
+ time format (HIGH LOW USECS) returned by, e.g., `current-time'.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (if (consp secs)
!       (progn (aset timer 1 (car secs))
! 	     (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
! 	     (aset timer 3 (or (and (consp (cdr time)) (consp (cdr (cdr time)))
! 				    (nth 2 time))
! 			       0)))
!     (aset timer 1 0)
!     (aset timer 2 0)
!     (aset timer 3 0)
!     (timer-inc-time timer secs))
    (aset timer 4 repeat)
    timer)
  
***************
*** 104,110 ****
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be a fraction."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))
--- 112,118 ----
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be either an integer or a floating point number."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 15:27             ` Chong Yidong
@ 2006-08-24 15:40               ` Chong Yidong
  2006-08-24 18:09                 ` martin rudalics
  2006-08-24 16:18               ` martin rudalics
  1 sibling, 1 reply; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 15:40 UTC (permalink / raw)
  Cc: emacs-devel, rms, storm

Chong Yidong <cyd@stupidchicken.com> writes:

> I don't know what was wrong with this code since you didn't post it.
> It looks like you simply forgot to initialize jit-lock-stealth-repeat-timer,
> but I can't be sure.  However, the following patch, based on the last
> patch you posted to this list with minimal modifications, works fine
> for me.
>
> It applies to the current CVS tree, and uses `current-idle-time'.  It
> includes and uses the change to `timer-set-idle-time' which I
> previously posted, allowing it to accept the value returned by
> `current-idle-time'.

> I have verified that the idle timer triggers correctly, stops
> correctly when user input comes in, and resumes when Emacs becomes
> idle again.

There were a few mistakes in the code I posted, incurred during
cutting and pasting.  Please look at this patch instead; and sorry for
the noise.

*** emacs/lisp/jit-lock.el.~1.54.~	2006-08-17 11:49:36.000000000 -0400
--- emacs/lisp/jit-lock.el	2006-08-24 11:39:14.000000000 -0400
***************
*** 443,513 ****
  			   (t next))))
  	result))))
  
  
! (defun jit-lock-stealth-fontify ()
    "Fontify buffers stealthily.
! This functions is called after Emacs has been idle for
! `jit-lock-stealth-time' seconds."
!   ;; I used to check `inhibit-read-only' here, but I can't remember why.  -stef
    (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window)))
!     (let ((buffers (buffer-list))
! 	  (outer-buffer (current-buffer))
  	  minibuffer-auto-raise
! 	  message-log-max)
!       (with-local-quit
! 	(while (and buffers (not (input-pending-p)))
! 	  (with-current-buffer (pop buffers)
! 	    (when jit-lock-mode
! 	      ;; This is funny.  Calling sit-for with 3rd arg non-nil
! 	      ;; so that it doesn't redisplay, internally calls
! 	      ;; wait_reading_process_input also with a parameter
! 	      ;; saying "don't redisplay."  Since this function here
! 	      ;; is called periodically, this effectively leads to
! 	      ;; process output not being redisplayed at all because
! 	      ;; redisplay_internal is never called.  (That didn't
! 	      ;; work in the old redisplay either.)  So, we learn that
! 	      ;; we mustn't call sit-for that way here.  But then, we
! 	      ;; have to be cautious not to call sit-for in a widened
! 	      ;; buffer, since this could display hidden parts of that
! 	      ;; buffer.  This explains the seemingly weird use of
! 	      ;; save-restriction/widen here.
! 
! 	      (with-temp-message (if jit-lock-stealth-verbose
! 				     (concat "JIT stealth lock "
! 					     (buffer-name)))
! 
! 		;; In the following code, the `sit-for' calls cause a
! 		;; redisplay, so it's required that the
! 		;; buffer-modified flag of a buffer that is displayed
! 		;; has the right value---otherwise the mode line of
! 		;; an unmodified buffer would show a `*'.
! 		(let (start
! 		      (nice (or jit-lock-stealth-nice 0))
! 		      (point (point-min)))
! 		  (while (and (setq start
! 				    (jit-lock-stealth-chunk-start point))
! 			      ;; In case sit-for runs any timers,
! 			      ;; give them the expected current buffer.
! 			      (with-current-buffer outer-buffer
! 				(sit-for nice)))
! 
! 		    ;; fontify a block.
! 		    (jit-lock-fontify-now start (+ start jit-lock-chunk-size))
! 		    ;; If stealth jit-locking is done backwards, this leads to
! 		    ;; excessive O(n^2) refontification.   -stef
! 		    ;; (when (>= jit-lock-context-unfontify-pos start)
! 		    ;;   (setq jit-lock-context-unfontify-pos end))
! 
! 		    ;; Wait a little if load is too high.
! 		    (when (and jit-lock-stealth-load
! 			       (> (car (load-average)) jit-lock-stealth-load))
! 		      ;; In case sit-for runs any timers,
! 		      ;; give them the expected current buffer.
! 		      (with-current-buffer outer-buffer
! 			(sit-for (or jit-lock-stealth-time 30))))))))))))))
! 
  
  \f
  ;;; Deferred fontification.
--- 443,512 ----
  			   (t next))))
  	result))))
  
+ (defvar jit-lock-stealth-buffers nil
+   "List of buffers that should be fontified stealthily.")
  
! (defvar jit-lock-stealth-repeat-timer nil
!   "Timer for repeated stealth fontification.")
! 
! (defun jit-lock-stealth-fontify (&optional repeat)
    "Fontify buffers stealthily.
! This function is called repeatedly after Emacs has become idle for
! `jit-lock-stealth-time' seconds.  Optional argument REPEAT is expected
! non-nil in a repeated invocation of this function."
    (unless (or executing-kbd-macro
  	      memory-full
! 	      (window-minibuffer-p (selected-window))
! 	      ;; For first invocation set up `jit-lock-stealth-buffers'.
! 	      ;; In repeated invocations it's already been set up.
! 	      (null (if repeat
! 			jit-lock-stealth-buffers
! 		      (setq jit-lock-stealth-buffers (buffer-list)))))
!     ;; Cancel timer for repeated invocations.
!     (when (timerp jit-lock-stealth-repeat-timer)
!       (cancel-timer jit-lock-stealth-repeat-timer))
!     (let ((buffer (car jit-lock-stealth-buffers))
! 	  (delay 0)
  	  minibuffer-auto-raise
! 	  message-log-max
! 	  start)
!       (if (and jit-lock-stealth-load
! 	       (> (car (load-average)) jit-lock-stealth-load))
! 	  ;; Wait a little if load is too high.
! 	  (setq delay jit-lock-stealth-time)
! 	(if (buffer-live-p buffer)
! 	    (with-current-buffer buffer
! 	      (if (and jit-lock-mode
! 		       (setq start (jit-lock-stealth-chunk-start (point))))
! 		  ;; Fontify one block of at most `jit-lock-chunk-size'
! 		  ;; characters.
! 		  (with-temp-message (if jit-lock-stealth-verbose
! 					 (concat "JIT stealth lock "
! 						 (buffer-name)))
! 		    (jit-lock-fontify-now start
! 					  (+ start jit-lock-chunk-size))
! 		    ;; Run again after `jit-lock-stealth-nice' seconds.
! 		    (setq delay (or jit-lock-stealth-nice 0)))
! 		;; Nothing to fontify here.  Remove this buffer from
! 		;; `jit-lock-stealth-buffers' and run again immediately.
! 		(setq jit-lock-stealth-buffers
! 		      (cdr jit-lock-stealth-buffers))))
! 	  ;; Buffer is no longer live.  Remove it from
! 	  ;; `jit-lock-stealth-buffers' and run again immediately.
! 	  (setq jit-lock-stealth-buffers
! 		(cdr jit-lock-stealth-buffers))))
!       ;; Call us again.
!       (when jit-lock-stealth-buffers
! 	(if repeat
! 	    (progn (timer-set-idle-time
! 		    jit-lock-stealth-repeat-timer (current-idle-time))
! 		   (timer-inc-time jit-lock-stealth-repeat-timer delay)
! 		   (timer-activate-when-idle
! 		    jit-lock-stealth-repeat-timer t))
! 	  (setq jit-lock-stealth-repeat-timer
! 		(run-with-idle-timer (current-idle-time) nil
! 				     'jit-lock-stealth-fontify t))
! 	  (timer-inc-time jit-lock-stealth-repeat-timer delay))))))
  
  \f
  ;;; Deferred fontification.
*** emacs/lisp/emacs-lisp/timer.el.~1.12.~	2006-08-20 09:55:37.000000000 -0400
--- emacs/lisp/emacs-lisp/timer.el	2006-08-24 11:37:18.000000000 -0400
***************
*** 60,73 ****
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (aset timer 1 0)
!   (aset timer 2 0)
!   (aset timer 3 0)
!   (timer-inc-time timer secs)
    (aset timer 4 repeat)
    timer)
  
--- 60,81 ----
  
  (defun timer-set-idle-time (timer secs &optional repeat)
    "Set the trigger idle time of TIMER to SECS.
+ SECS may be an integer, floating point number, or the internal
+ time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
  If optional third argument REPEAT is non-nil, make the timer
  fire each time Emacs is idle for that many seconds."
    (or (timerp timer)
        (error "Invalid timer"))
!   (if (consp secs)
!       (progn (aset timer 1 (car secs))
! 	     (aset timer 2 (if (consp (cdr secs)) (car (cdr secs)) (cdr secs)))
! 	     (aset timer 3 (or (and (consp (cdr secs)) (consp (cdr (cdr secs)))
! 				    (nth 2 secs))
! 			       0)))
!     (aset timer 1 0)
!     (aset timer 2 0)
!     (aset timer 3 0)
!     (timer-inc-time timer secs))
    (aset timer 4 repeat)
    timer)
  
***************
*** 104,110 ****
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be a fraction."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))
--- 112,118 ----
  
  (defun timer-relative-time (time secs &optional usecs)
    "Advance TIME by SECS seconds and optionally USECS microseconds.
! SECS may be either an integer or a floating point number."
    (let ((high (car time))
  	(low (if (consp (cdr time)) (nth 1 time) (cdr time)))
  	(micro (if (numberp (car-safe (cdr-safe (cdr time))))
***************
*** 412,418 ****
  (defun run-with-idle-timer (secs repeat function &rest args)
    "Perform an action the next time Emacs is idle for SECS seconds.
  The action is to call FUNCTION with arguments ARGS.
! SECS may be an integer or a floating point number.
  If Emacs is currently idle, and has been idle for N seconds (N < SECS),
  then it will call FUNCTION in SECS - N seconds from now.
  
--- 420,427 ----
  (defun run-with-idle-timer (secs repeat function &rest args)
    "Perform an action the next time Emacs is idle for SECS seconds.
  The action is to call FUNCTION with arguments ARGS.
! SECS may be an integer, a floating point number, or the internal
! time format (HIGH LOW USECS) returned by, e.g., `current-idle-time'.
  If Emacs is currently idle, and has been idle for N seconds (N < SECS),
  then it will call FUNCTION in SECS - N seconds from now.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 15:27             ` Chong Yidong
  2006-08-24 15:40               ` Chong Yidong
@ 2006-08-24 16:18               ` martin rudalics
  2006-08-24 16:34                 ` Chong Yidong
  2006-08-24 19:48                 ` Chong Yidong
  1 sibling, 2 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-24 16:18 UTC (permalink / raw)
  Cc: emacs-devel, rms, storm

  I don't know what was wrong with this code since you didn't post it.
 > It looks like you simply forgot to initialize jit-lock-stealth-repeat-timer,
 > but I can't be sure.

As suggested by rms for his resume timer I did in `jit-lock-mode':

	 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
	   (setq jit-lock-stealth-timer
		 (run-with-idle-timer jit-lock-stealth-time t
				      'jit-lock-stealth-fontify)))
  	 (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer))
  	   (setq jit-lock-stealth-repeat-timer (timer-create))
  	   (timer-set-function jit-lock-stealth-repeat-timer
  			       'jit-lock-stealth-fontify t))

 > However, the following patch, based on the last
 > patch you posted to this list with minimal modifications, works fine
 > for me.
 >
 > It applies to the current CVS tree, and uses `current-idle-time'.  It
 > includes and uses the change to `timer-set-idle-time' which I
 > previously posted, allowing it to accept the value returned by
 > `current-idle-time'.

Is this Richard's or Kim's version of `current-idle-time'.

 > I have verified that the idle timer triggers correctly, stops
 > correctly when user input comes in, and resumes when Emacs becomes
 > idle again.
 >
 >
 > *** emacs/lisp/jit-lock.el.~1.54.~	2006-08-17 11:49:36.000000000 -0400
 > --- emacs/lisp/jit-lock.el	2006-08-24 11:21:23.000000000 -0400
...
 > ! 	  (setq jit-lock-stealth-repeat-timer
 > ! 		(run-at-time delay
 > ! 			     nil 'jit-lock-stealth-fontify t)))))))

Richard told me not to use `run-at-time' - well it's for the first time
only - but I'll have to justify why I can't `run-with-idle-time' here.

 >   (defun timer-set-idle-time (timer secs &optional repeat)
 >     "Set the trigger idle time of TIMER to SECS.
 > + SECS may be an integer, floating point number, or the internal
 > + time format (HIGH LOW USECS) returned by, e.g., `current-time'.
 >   If optional third argument REPEAT is non-nil, make the timer
 >   fire each time Emacs is idle for that many seconds."
 >     (or (timerp timer)
 >         (error "Invalid timer"))
 > !   (if (consp secs)
 > !       (progn (aset timer 1 (car secs))
 > ! 	     (aset timer 2 (if (consp (cdr time)) (car (cdr time)) (cdr time)))
 > ! 	     (aset timer 3 (or (and (consp (cdr time)) (consp (cdr (cdr time)))
 > ! 				    (nth 2 time))
 > ! 			       0)))
 > !     (aset timer 1 0)
 > !     (aset timer 2 0)
 > !     (aset timer 3 0)
 > !     (timer-inc-time timer secs))
 >     (aset timer 4 repeat)
 >     timer)

Did you compile that?  `time' in here gets me:

In timer-set-idle-time:
timer.el:71:44:Warning: reference to free variable `time'

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 16:18               ` martin rudalics
@ 2006-08-24 16:34                 ` Chong Yidong
  2006-08-24 19:48                 ` Chong Yidong
  1 sibling, 0 replies; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 16:34 UTC (permalink / raw)
  Cc: emacs-devel, rms, storm

martin rudalics <rudalics@gmx.at> writes:

>> It applies to the current CVS tree, and uses `current-idle-time'.  It
>> includes and uses the change to `timer-set-idle-time' which I
>> previously posted, allowing it to accept the value returned by
>> `current-idle-time'.
>
> Is this Richard's or Kim's version of `current-idle-time'.

Richard's --- the version in CVS at the moment.

> Did you compile that?  `time' in here gets me:

See the followup message I posted, containing a corrected patch.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 15:40               ` Chong Yidong
@ 2006-08-24 18:09                 ` martin rudalics
  2006-08-24 19:16                   ` Stefan Monnier
  0 siblings, 1 reply; 43+ messages in thread
From: martin rudalics @ 2006-08-24 18:09 UTC (permalink / raw)
  Cc: storm, rms, emacs-devel

 > There were a few mistakes in the code I posted, incurred during
 > cutting and pasting.  Please look at this patch instead; and sorry for
 > the noise.

It works!  Thanks for finding the problem and solving it!


BTW, what do you think about

       ;; Cancel timer for repeated invocations.
       (when (and (not repeat) (timerp jit-lock-stealth-repeat-timer))
	(cancel-timer jit-lock-stealth-repeat-timer))

and

	(if repeat
	    (let ((cell (memq jit-lock-stealth-repeat-timer timer-idle-list)))
	      (timer-set-idle-time
	       jit-lock-stealth-repeat-timer (current-idle-time))
	      (timer-inc-time jit-lock-stealth-repeat-timer delay)
	      (timer-activate-when-idle jit-lock-stealth-repeat-timer t cell))

We currently allocate a new timer for every chunk we fontify stealthily
and for every buffer in `jit-lock-stealth-buffers'.  Is it worth the
trouble?

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 13:34                       ` Kim F. Storm
@ 2006-08-24 18:11                         ` martin rudalics
  2006-08-24 20:11                           ` Kim F. Storm
  0 siblings, 1 reply; 43+ messages in thread
From: martin rudalics @ 2006-08-24 18:11 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

 > It could be that the new trigger time has somehow passed by
 > before restarting the idle timer.  Just to rule that out,
 > could you try with delay = 2 instead of 0.

I tried a lot of these before without any success.

 >>> 	  (let ((idle (current-idle-time)))
 >>> 	    (when idle
 >>> 	      (run-with-idle-timer (+ idle (max delay 0.1))
 >>>                                    nil #'jit-lock-stealth-fontify)))
 >>>
 >>
 >>make that:
 >>
 >> 	  (let ((idle (current-idle-time)))
 >>            (setq jit-lock-stealth-repeat-timer
 >>                 (and (not idle)
 >> 	              (run-with-idle-timer (+ idle (max delay 0.1))
 >>                                           nil #'jit-lock-stealth-fontify))))
 >
 >
 > Brain damange -- make that:
 >
 > 	  (let ((idle (current-idle-time)))
 > 	     (setq jit-lock-stealth-repeat-timer
 > 		  (and idle
 > 		      (run-with-idle-timer (+ idle (max delay 0.1))
 > 					    nil #'jit-lock-stealth-fontify))))
 >

I must have lost you, all your suggestions set that timer to nil.

Did you try Chong's patch?

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 18:09                 ` martin rudalics
@ 2006-08-24 19:16                   ` Stefan Monnier
  2006-08-24 19:20                     ` Stefan Monnier
  0 siblings, 1 reply; 43+ messages in thread
From: Stefan Monnier @ 2006-08-24 19:16 UTC (permalink / raw)
  Cc: Chong Yidong, emacs-devel, rms, storm

> 	(if repeat
> 	    (let ((cell (memq jit-lock-stealth-repeat-timer timer-idle-list)))
> 	      (timer-set-idle-time
> 	       jit-lock-stealth-repeat-timer (current-idle-time))
> 	      (timer-inc-time jit-lock-stealth-repeat-timer delay)
> 	      (timer-activate-when-idle jit-lock-stealth-repeat-timer t cell))

You mean

     (when repeat
       (timer-set-idle-time
        jit-lock-stealth-repeat-timer (current-idle-time))
       (timer-inc-time jit-lock-stealth-repeat-timer delay)
       (timer-activate-when-idle jit-lock-stealth-repeat-timer t
                                 (memq jit-lock-stealth-repeat-timer
                                       timer-idle-list))))

Shouldn't timer-activate-when-idle simply do it automatically?


        Stefan

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 19:16                   ` Stefan Monnier
@ 2006-08-24 19:20                     ` Stefan Monnier
  0 siblings, 0 replies; 43+ messages in thread
From: Stefan Monnier @ 2006-08-24 19:20 UTC (permalink / raw)
  Cc: Chong Yidong, emacs-devel, rms, storm

> You mean

>      (when repeat
>        (timer-set-idle-time
>         jit-lock-stealth-repeat-timer (current-idle-time))
>        (timer-inc-time jit-lock-stealth-repeat-timer delay)
>        (timer-activate-when-idle jit-lock-stealth-repeat-timer t
>                                  (memq jit-lock-stealth-repeat-timer
>                                        timer-idle-list))))

> Shouldn't timer-activate-when-idle simply do it automatically?

I must be drunk or something.  Just ignore the above,
please,


        Stefan

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 16:18               ` martin rudalics
  2006-08-24 16:34                 ` Chong Yidong
@ 2006-08-24 19:48                 ` Chong Yidong
  2006-08-25  6:00                   ` martin rudalics
  1 sibling, 1 reply; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 19:48 UTC (permalink / raw)
  Cc: emacs-devel, rms, storm

martin rudalics <rudalics@gmx.at> writes:

>  I don't know what was wrong with this code since you didn't post it.
>> It looks like you simply forgot to initialize jit-lock-stealth-repeat-timer,
>> but I can't be sure.
>
> As suggested by rms for his resume timer I did in `jit-lock-mode':
>
> 	 (when (and jit-lock-stealth-time (null jit-lock-stealth-timer))
> 	   (setq jit-lock-stealth-timer
> 		 (run-with-idle-timer jit-lock-stealth-time t
> 				      'jit-lock-stealth-fontify)))
>  	 (when (and jit-lock-stealth-time (null jit-lock-stealth-repeat-timer))
>  	   (setq jit-lock-stealth-repeat-timer (timer-create))
>  	   (timer-set-function jit-lock-stealth-repeat-timer
>  			       'jit-lock-stealth-fontify t))

Now I know why your code didn't work.  The very last line is wrong!
It should be

  (timer-set-function jit-lock-stealth-repeat-timer
                      'jit-lock-stealth-fontify '(t)))

I believe that with this change, everything will work.

(Now that you mention it, it is slightly cleaner to reuse the
repeat-timer than to create a new one each time.)

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 18:11                         ` martin rudalics
@ 2006-08-24 20:11                           ` Kim F. Storm
  2006-08-24 23:41                             ` Chong Yidong
  0 siblings, 1 reply; 43+ messages in thread
From: Kim F. Storm @ 2006-08-24 20:11 UTC (permalink / raw)
  Cc: cyd, rms, emacs-devel

martin rudalics <rudalics@gmx.at> writes:

> Did you try Chong's patch?

No, but I trust your combined efforts will lead to the proper solution,
using RMS' version of current-idle-time and Chong's changes to timer.el.

If you agree that Chong's last version is ok, pls. install it.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 20:11                           ` Kim F. Storm
@ 2006-08-24 23:41                             ` Chong Yidong
  2006-08-25  7:17                               ` Kim F. Storm
  0 siblings, 1 reply; 43+ messages in thread
From: Chong Yidong @ 2006-08-24 23:41 UTC (permalink / raw)
  Cc: martin rudalics, rms, emacs-devel

storm@cua.dk (Kim F. Storm) writes:

> martin rudalics <rudalics@gmx.at> writes:
>
>> Did you try Chong's patch?
>
> No, but I trust your combined efforts will lead to the proper solution,
> using RMS' version of current-idle-time and Chong's changes to timer.el.
>
> If you agree that Chong's last version is ok, pls. install it.

I've committed the changes.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 19:48                 ` Chong Yidong
@ 2006-08-25  6:00                   ` martin rudalics
  0 siblings, 0 replies; 43+ messages in thread
From: martin rudalics @ 2006-08-25  6:00 UTC (permalink / raw)
  Cc: storm, rms, emacs-devel

 >> 	   (timer-set-function jit-lock-stealth-repeat-timer
 >> 			       'jit-lock-stealth-fontify t))
 >
 >
 > Now I know why your code didn't work.  The very last line is wrong!
 > It should be
 >
 >   (timer-set-function jit-lock-stealth-repeat-timer
 >                       'jit-lock-stealth-fontify '(t)))
 >
 > I believe that with this change, everything will work.

Indeed.  I must have tacitly anticipated that `timer-set-function' has a
&rest.  Using `run-with-idle-timer' in `jit-lock-stealth-fontify' as you
did is, however, cleaner anyway.  Thanks for sorting this out.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24 23:41                             ` Chong Yidong
@ 2006-08-25  7:17                               ` Kim F. Storm
  0 siblings, 0 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-25  7:17 UTC (permalink / raw)
  Cc: martin rudalics, rms, emacs-devel

Chong Yidong <cyd@stupidchicken.com> writes:

> I've committed the changes.

Thanks to both you and Martin!

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  7:47                 ` Kim F. Storm
  2006-08-24  7:58                   ` Kim F. Storm
@ 2006-08-25 20:23                   ` Richard Stallman
  2006-08-25 21:27                     ` Chong Yidong
  1 sibling, 1 reply; 43+ messages in thread
From: Richard Stallman @ 2006-08-25 20:23 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

    > However, returning the value in floating point might be a good method.

    That would be much better and cleaner, IMO.
    And we can leave time-to-seconds where it is!

    > But if we do that, we should call it float-idle-time.

    Why?

For consistency with float-time.

I see Yidong has already fixed the bug, by extending
run-with-idle-time to handle this type of value.  But it would still
be useful to add float-idle-time.  Would you like to do that?

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-24  7:58                   ` Kim F. Storm
  2006-08-24  9:07                     ` Kim F. Storm
@ 2006-08-25 20:23                     ` Richard Stallman
  2006-08-25 22:45                       ` Kim F. Storm
  1 sibling, 1 reply; 43+ messages in thread
From: Richard Stallman @ 2006-08-25 20:23 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

    Shall I fix current-idle-time to return a float or nil?

No, but please do add float-idle-time to return either a float or nil
if you want to.

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-25 20:23                   ` Richard Stallman
@ 2006-08-25 21:27                     ` Chong Yidong
  2006-08-26 12:22                       ` Richard Stallman
  0 siblings, 1 reply; 43+ messages in thread
From: Chong Yidong @ 2006-08-25 21:27 UTC (permalink / raw)
  Cc: rudalics, emacs-devel, Kim F. Storm

Richard Stallman <rms@gnu.org> writes:

>     > However, returning the value in floating point might be a good method.
>
>     That would be much better and cleaner, IMO.
>     And we can leave time-to-seconds where it is!
>
>     > But if we do that, we should call it float-idle-time.
>
>     Why?
>
> For consistency with float-time.
>
> I see Yidong has already fixed the bug, by extending
> run-with-idle-time to handle this type of value.  But it would still
> be useful to add float-idle-time.  Would you like to do that?

Is it really necessary to have a separate function for this?  It's
just the same as

  (float-time (current-idle-time))

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-25 20:23                     ` Richard Stallman
@ 2006-08-25 22:45                       ` Kim F. Storm
  0 siblings, 0 replies; 43+ messages in thread
From: Kim F. Storm @ 2006-08-25 22:45 UTC (permalink / raw)
  Cc: rudalics, cyd, emacs-devel

Richard Stallman <rms@gnu.org> writes:

>     Shall I fix current-idle-time to return a float or nil?
>
> No, but please do add float-idle-time to return either a float or nil
> if you want to.

I no longer see a need for it.

-- 
Kim F. Storm <storm@cua.dk> http://www.cua.dk

^ permalink raw reply	[flat|nested] 43+ messages in thread

* Re: jit-lock timer etc.
  2006-08-25 21:27                     ` Chong Yidong
@ 2006-08-26 12:22                       ` Richard Stallman
  0 siblings, 0 replies; 43+ messages in thread
From: Richard Stallman @ 2006-08-26 12:22 UTC (permalink / raw)
  Cc: rudalics, emacs-devel, storm

    Is it really necessary to have a separate function for this?  It's
    just the same as

      (float-time (current-idle-time))

That is simple enough.

^ permalink raw reply	[flat|nested] 43+ messages in thread

end of thread, other threads:[~2006-08-26 12:22 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-21 11:12 jit-lock timer etc Richard Stallman
2006-08-21 11:39 ` Kim F. Storm
2006-08-21 16:57   ` martin rudalics
2006-08-21 18:51     ` Chong Yidong
2006-08-21 22:22       ` martin rudalics
2006-08-21 23:26         ` Chong Yidong
2006-08-22  7:18         ` Kim F. Storm
2006-08-22 15:41         ` Richard Stallman
2006-08-23 12:27           ` martin rudalics
2006-08-23 13:09             ` Kim F. Storm
2006-08-24  5:20               ` Richard Stallman
2006-08-24  7:47                 ` Kim F. Storm
2006-08-24  7:58                   ` Kim F. Storm
2006-08-24  9:07                     ` Kim F. Storm
2006-08-24 14:47                       ` Chong Yidong
2006-08-25 20:23                     ` Richard Stallman
2006-08-25 22:45                       ` Kim F. Storm
2006-08-25 20:23                   ` Richard Stallman
2006-08-25 21:27                     ` Chong Yidong
2006-08-26 12:22                       ` Richard Stallman
2006-08-24  9:10               ` Kim F. Storm
2006-08-24 12:23                 ` martin rudalics
2006-08-24 12:54                   ` Kim F. Storm
2006-08-24 13:07                   ` Kim F. Storm
2006-08-24 13:11                     ` Kim F. Storm
2006-08-24 13:34                       ` Kim F. Storm
2006-08-24 18:11                         ` martin rudalics
2006-08-24 20:11                           ` Kim F. Storm
2006-08-24 23:41                             ` Chong Yidong
2006-08-25  7:17                               ` Kim F. Storm
2006-08-24 14:16                     ` Chong Yidong
2006-08-24  5:20             ` Richard Stallman
2006-08-24  7:48               ` Kim F. Storm
2006-08-24 12:21               ` martin rudalics
2006-08-24 15:27             ` Chong Yidong
2006-08-24 15:40               ` Chong Yidong
2006-08-24 18:09                 ` martin rudalics
2006-08-24 19:16                   ` Stefan Monnier
2006-08-24 19:20                     ` Stefan Monnier
2006-08-24 16:18               ` martin rudalics
2006-08-24 16:34                 ` Chong Yidong
2006-08-24 19:48                 ` Chong Yidong
2006-08-25  6:00                   ` martin rudalics

Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.