unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Setting jit-lock-defer-time disables font locking.
@ 2006-03-19 17:25 Alan Mackenzie
  2006-03-20  7:37 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Alan Mackenzie @ 2006-03-19 17:25 UTC (permalink / raw)


Emacs 22.

Start a session with jit-lock enabled and jit-lock-defer-time set to nil.
(This is the default configuration).  Set jit-lock-defer-time to a
non-nil value, either directly or through M-x customize-group <ret>
jit-lock <ret>.  Edit a buffer.  After-change font-locking is now
broken.

The reason for this problem is that jit-lock-function (the defun called
directly from the display engine) sets the text property 'fontified to
'defer whenever jit-lock-defer-time is non-nil.  However, when the
pertinent timer hasn't been activated, the handling function
(jit-lock-deferred-fontify) never gets called.

I have fixed that in the following patch by also checking that the timer
is active in jit-lock-function.

However, this still seems suboptimal - a user might well be experimenting with
jit-lock-defer by customizing jit-lock-defer-time, and will get very frustrated
on discovering his changes only take effect after restarting Emacs - if he ever
discovers this.  So I've added customize :set functions to do this -
these changes now take place immediately.

I think there's another bug: jit-lock-contextually's doc-string says it
has three distinct values:  nil, t, and anything else (e.g.
'syntax-driven).  I can't see any code which codes up 'syntax-driven.  (I
haven't done anything to correct this in my patch.


2006-03-18  Alan Mackenzie  <acm@acm.acm>

	* jit-lock.el (jit-lock-function): Check jit-lock-defer-timer is
	active before setting 'fontified to 'defer.

	* jit-lock.el (jit-lock-\(stealth\|context\|defer\)-time and
	jit-lock-contextually): Give these options customize :set
	functions, the new functions jit-lock-modify-timer,
	jit-lock-modify-context-timer, and
	jit-lock-switch-contextual-fontification.


Index: NEWS
===================================================================
RCS file: /cvsroot/emacs/emacs/etc/NEWS,v
retrieving revision 1.1323
diff -c -r1.1323 NEWS
*** NEWS	18 Mar 2006 13:55:31 -0000	1.1323
--- NEWS	19 Mar 2006 16:48:53 -0000
***************
*** 917,922 ****
--- 917,925 ----
  jit-lock-context-time determines the delay after which contextual
  refontification takes place.
  
+ *** When the customizable variables jit-lock-\(stealth\|context\|defer\)-time
+ and jit-lock-contextually are customized, they now take effect immediately.
+ 
  ** Menu support:
  
  ---



Index: jit-lock.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/jit-lock.el,v
retrieving revision 1.50
diff -c -r1.50 jit-lock.el
*** jit-lock.el	15 Mar 2006 22:26:08 -0000	1.50
--- jit-lock.el	19 Mar 2006 17:05:08 -0000
***************
*** 58,63 ****
--- 58,133 ----
  
  \f
  ;;; Customization.
+ (defun jit-lock-modify-timer (delay-time-symbol pause)
+   "Manipulate a jit-lock TIMER to reflect the new time PAUSE.
+ 
+ DELAY-TIME-SYMBOL is one of jit-lock's three variables containing a timeout,
+ `jit-lock-context-time', `jit-lock-defer-time', or `jit-lock-stealth-time'.
+ 
+ PAUSE is the new timeout, in seconds, to give to the associated timer.  When
+ it is a positive number, the timer will be (re)started with that timeout.  If
+ it is nil or zero, the timer will be stopped.
+ 
+ This function is usable as a customize \":set\" function."
+   (let (timer function)
+     (cond ((eq delay-time-symbol 'jit-lock-context-time)
+ 	   (setq timer 'jit-lock-context-timer
+ 		 function 'jit-lock-context-fontify))
+ 	  ((eq delay-time-symbol 'jit-lock-defer-time)
+ 	   (setq timer 'jit-lock-defer-timer
+ 		 function 'jit-lock-deferred-fontify))
+ 	  ((eq delay-time-symbol 'jit-lock-stealth-time)
+ 	    (setq timer 'jit-lock-stealth-timer
+ 		  function 'jit-lock-stealth-fontify)))
+     (when timer
+       (when (symbol-value timer)	; timer is already running
+ 	(cancel-timer (symbol-value timer))
+ 	(set timer nil))
+       (if (and pause (> pause 0))
+ 	  (set timer (run-with-idle-timer pause t function)))
+       (set delay-time-symbol pause))))
+ 
+ (defun jit-lock-modify-context-timer (symbol pause)
+   "Manipulate the timer `jit-lock-context-timer'.
+ 
+ SYMBOL must be `jit-lock-context-time'.  PAUSE is the new value to give it, a
+ stricly positive number.  If `jit-lock-contextually' is enabled, we restart
+ the associated timer with this new timeout.
+ 
+ This function is usable as a customize \":set\" function."
+   (when (eq symbol 'jit-lock-context-time)
+     (if (not (and (numberp pause) (> pause 0)))
+ 	(message "jit-lock-modify-context-timer:  %s is not a positive number"
+ 	       pause))
+     (if jit-lock-contextually
+ 	(jit-lock-modify-timer 'jit-lock-context-time pause))
+     (setq jit-lock-context-time pause)))
+ 
+ (defun jit-lock-switch-contextual-fontification (symbol value)
+   "Set the new value VALUE into `jit-lock-contextually', and
+ activate/deactivate contextual fontification as requested.  SYMBOL must be
+ 'jit-lock-contextually.
+ 
+ The variable `jit-lock-context-unfontify-pos' gets set appropriately in each
+ buffer where jit-lock is currently enabled.
+ 
+ This function is usually called as a \":set\" function from customize."
+   ;; Note (ACM, 2006/3/19): according to its doc-string, jit-lock should
+   ;; distinguish 3 values, nil, t, and other.  It only actually distinguishes
+   ;; nil and non-nil.  FIXME!!!
+   (when (eq symbol 'jit-lock-contextually)
+     (let ((buffers (buffer-list))
+ 	  (jit-lock-context-time jit-lock-context-time)) ; Protect from modification.
+       (when (or (and value (not jit-lock-contextually))
+ 		(and (not value) jit-lock-contextually))
+ 	(while buffers
+ 	  (with-current-buffer (pop buffers)
+ 	    (when jit-lock-mode
+ 	      (setq jit-lock-context-unfontify-pos
+ 		    (if value (point-max)))))))
+       (jit-lock-modify-timer 'jit-lock-context-time
+ 			     (and value jit-lock-context-time))
+       (setq jit-lock-contextually value))))
  
  (defgroup jit-lock nil
    "Font Lock support mode to fontify just-in-time."
***************
*** 77,86 ****
  Stealth fontification occurs if there is no input within this time.
  If nil, stealth fontification is never performed.
  
! The value of this variable is used when JIT Lock mode is turned on."
    :type '(choice (const :tag "never" nil)
  		 (number :tag "seconds"))
!   :group 'jit-lock)
  
  
  (defcustom jit-lock-stealth-nice 0.5
--- 147,160 ----
  Stealth fontification occurs if there is no input within this time.
  If nil, stealth fontification is never performed.
  
! If you change this variable other than by the \"customize\" facility, you
! should do so by
!   \(jit-lock-modify-timer 'jit-lock-stealth-time <new value>)
! if you want the new value to take immediate effect."
    :type '(choice (const :tag "never" nil)
  		 (number :tag "seconds"))
!   :group 'jit-lock
!   :set 'jit-lock-modify-timer)
  
  
  (defcustom jit-lock-stealth-nice 0.5
***************
*** 132,154 ****
  fontification occurs only if syntactic fontification is performed using the
  buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
  
! The value of this variable is used when JIT Lock mode is turned on."
    :type '(choice (const :tag "never" nil)
  		 (const :tag "always" t)
  		 (other :tag "syntax-driven" syntax-driven))
    :group 'jit-lock)
  
  (defcustom jit-lock-context-time 0.5
!   "Idle time after which text is contextually refontified, if applicable."
    :type '(number :tag "seconds")
    :group 'jit-lock)
  
  (defcustom jit-lock-defer-time nil ;; 0.25
    "Idle time after which deferred fontification should take place.
! If nil, fontification is not deferred."
    :group 'jit-lock
    :type '(choice (const :tag "never" nil)
! 	         (number :tag "seconds")))
  \f
  ;;; Variables that are not customizable.
  
--- 206,244 ----
  fontification occurs only if syntactic fontification is performed using the
  buffer mode's syntax table, i.e., only if `font-lock-keywords-only' is nil.
  
! If you change this variable other than by the \"customize\" facility, you
! should do so by
!   \(jit-lock-switch-contextual-fontification 'jit-lock-contextually <new value>)
! if you want the new value to take immediate effect."
    :type '(choice (const :tag "never" nil)
  		 (const :tag "always" t)
  		 (other :tag "syntax-driven" syntax-driven))
+   :set 'jit-lock-switch-contextual-fontification
    :group 'jit-lock)
  
  (defcustom jit-lock-context-time 0.5
!   "Idle time after which text is contextually refontified, if applicable.
! 
! If you change this variable other than by the \"customize\" facility, you
! should do so by
!   \(jit-lock-modify-context-timer 'jit-lock-context-time <new value>)
! if you want the new value to take immediate effect."
    :type '(number :tag "seconds")
+   :set 'jit-lock-modify-context-timer
    :group 'jit-lock)
  
  (defcustom jit-lock-defer-time nil ;; 0.25
    "Idle time after which deferred fontification should take place.
! If nil, fontification is not deferred.
! 
! If you change this variable other than by the \"customize\" facility, you
! should do so by
!   \(jit-lock-modify-timer 'jit-lock-defer-time <new value>)
! if you want the new value to take immediate effect."
    :group 'jit-lock
    :type '(choice (const :tag "never" nil)
! 	         (number :tag "seconds"))
!   :set 'jit-lock-modify-timer)
  \f
  ;;; Variables that are not customizable.
  
***************
*** 301,307 ****
  This function is added to `fontification-functions' when `jit-lock-mode'
  is active."
    (when (and jit-lock-mode (not memory-full))
!     (if (null jit-lock-defer-time)
  	;; No deferral.
  	(jit-lock-fontify-now start (+ start jit-lock-chunk-size))
        ;; Record the buffer for later fontification.
--- 391,398 ----
  This function is added to `fontification-functions' when `jit-lock-mode'
  is active."
    (when (and jit-lock-mode (not memory-full))
!     (if (or (null jit-lock-defer-time)
! 	    (null jit-lock-defer-timer))
  	;; No deferral.
  	(jit-lock-fontify-now start (+ start jit-lock-chunk-size))
        ;; Record the buffer for later fontification.




-- 
Alan Mackenzie (Munich, Germany)

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

* Re: Setting jit-lock-defer-time disables font locking.
  2006-03-19 17:25 Setting jit-lock-defer-time disables font locking Alan Mackenzie
@ 2006-03-20  7:37 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2006-03-20  7:37 UTC (permalink / raw)
  Cc: emacs-devel

> Start a session with jit-lock enabled and jit-lock-defer-time set to nil.
> (This is the default configuration).  Set jit-lock-defer-time to a
> non-nil value, either directly or through M-x customize-group <ret>
> jit-lock <ret>.  Edit a buffer.  After-change font-locking is now
> broken.

> The reason for this problem is that jit-lock-function (the defun called
> directly from the display engine) sets the text property 'fontified to
> 'defer whenever jit-lock-defer-time is non-nil.  However, when the
> pertinent timer hasn't been activated, the handling function
> (jit-lock-deferred-fontify) never gets called.

Indeed.  I think the patch below DTRT.

> However, this still seems suboptimal - a user might well be experimenting
> with jit-lock-defer by customizing jit-lock-defer-time, and will get very
> frustrated on discovering his changes only take effect after restarting
> Emacs - if he ever discovers this.  So I've added customize :set functions
> to do this - these changes now take place immediately.

These look overkill to me (many Emacs options don't take effect until you
restart some part of it), but otherwise seem harmless.

> I think there's another bug: jit-lock-contextually's doc-string says it
> has three distinct values:  nil, t, and anything else (e.g.
> 'syntax-driven).  I can't see any code which codes up 'syntax-driven.

There is:

	 ;; Initialize contextual fontification if requested.
	 (when (eq jit-lock-contextually t)
	   (unless jit-lock-context-timer
[...]
  (when (and contextual jit-lock-contextually)
    (set (make-local-variable 'jit-lock-contextually) t))


> + *** When the customizable variables
> + jit-lock-\(stealth\|context\|defer\)-time and jit-lock-contextually are
> + customized, they now take effect immediately.

The NEWS is already much too long.  Let's not add this kind of "news".


        Stefan


--- jit-lock.el	07 fév 2006 12:22:36 -0500	1.48
+++ jit-lock.el	20 mar 2006 02:24:50 -0500	
@@ -301,7 +301,7 @@
 This function is added to `fontification-functions' when `jit-lock-mode'
 is active."
   (when (and jit-lock-mode (not memory-full))
-    (if (null jit-lock-defer-time)
+    (if (null jit-lock-defer-timer)
 	;; No deferral.
 	(jit-lock-fontify-now start (+ start jit-lock-chunk-size))
       ;; Record the buffer for later fontification.
@@ -510,7 +510,7 @@
 		   (setq pos (next-single-property-change pos 'fontified)))))))))
     (setq jit-lock-defer-buffers nil)
     ;; Force fontification of the visible parts.
-    (let ((jit-lock-defer-time nil))
+    (let ((jit-lock-defer-timer nil))
       ;; (message "Jit-Defer Now")
       (sit-for 0)
       ;; (message "Jit-Defer Done")

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

end of thread, other threads:[~2006-03-20  7:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-03-19 17:25 Setting jit-lock-defer-time disables font locking Alan Mackenzie
2006-03-20  7:37 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).