Subject: Re: bug#13542: 24.3.50; args-out-of-range in jit-lock-fontify-now

From: Stefan Monnier <[email-masked]>
Date: Wed, 30 Jan 2013 12:06:05 -0500

> The issue is that the min value for the region to be fontified is
> calculated with the buffer temporarily widened (by the function
> ‘jit-lock-stealth-chunk-start’), but ‘jit-lock-fontify-now’ does not
> widen the buffer.

That's a left over from the 2002-10-01 change that decided that jit-lock
should not widen.  I've installed the patch below which should fix
the problem.

        Stefan

=== modified file 'lisp/jit-lock.el'
--- lisp/jit-lock.el	2013-01-13 01:23:48 +0000
+++ lisp/jit-lock.el	2013-01-30 16:59:53 +0000
@@ -439,8 +435,6 @@
 Value is nil if there is nothing more to fontify."
   (if (zerop (buffer-size))
       nil
-    (save-restriction
-      (widen)
       (let* ((next (text-property-not-all around (point-max) 'fontified t))
 	     (prev (previous-single-property-change around 'fontified))
 	     (prop (get-text-property (max (point-min) (1- around))
@@ -473,7 +467,7 @@
 			   ((null next) start)
 			   ((< (- around start) (- next around)) start)
 			   (t next))))
-	result))))
+      result)))
 
 (defun jit-lock-stealth-fontify (&optional repeat)
   "Fontify buffers stealthily.
@@ -564,6 +558,8 @@
 	(when jit-lock-context-unfontify-pos
 	  ;; (message "Jit-Context %s" (buffer-name))
 	  (save-restriction
+            ;; Don't be blindsided by narrowing that starts in the middle
+            ;; of a jit-lock-defer-multiline.
 	    (widen)
 	    (when (and (>= jit-lock-context-unfontify-pos (point-min))
 		       (< jit-lock-context-unfontify-pos (point-max)))