emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Setting jit-lock-defer-time disables font locking.


From: Alan Mackenzie
Subject: Setting jit-lock-defer-time disables font locking.
Date: Sun, 19 Mar 2006 17:25:35 +0000 (GMT)

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  <address@hidden>

        * 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 ----
  
  
  ;;; 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")))
  
  ;;; 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)
  
  ;;; 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)






reply via email to

[Prev in Thread] Current Thread [Next in Thread]