]> code.delx.au - gnu-emacs/commitdiff
(font-lock-extend-jit-lock-region-after-change): New fun.
authorStefan Monnier <monnier@iro.umontreal.ca>
Tue, 1 Aug 2006 18:58:18 +0000 (18:58 +0000)
committerStefan Monnier <monnier@iro.umontreal.ca>
Tue, 1 Aug 2006 18:58:18 +0000 (18:58 +0000)
(font-lock-turn-on-thing-lock): Use it.

lisp/ChangeLog
lisp/font-lock.el

index 0540072e0c70ad1eb7a5af920caaa686aa509f13..039c0ad90fcf4018af7d89cf9795e890539367f6 100644 (file)
@@ -1,5 +1,8 @@
 2006-08-01  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+       * font-lock.el (font-lock-extend-jit-lock-region-after-change): New fun.
+       (font-lock-turn-on-thing-lock): Use it.
+
        * longlines.el (longlines-show-region): Make it work on read-only
        buffers as well.
 
index 207d3b88f86d5ace92147b720c6b3703e70f216f..ecf54895c1cbc95210dc5733eb0024a3f3efdee2 100644 (file)
@@ -893,7 +893,11 @@ The value of this variable is used when Font Lock mode is turned on."
           (set (make-local-variable 'font-lock-fontified) t)
           ;; Use jit-lock.
           (jit-lock-register 'font-lock-fontify-region
-                             (not font-lock-keywords-only))))))
+                             (not font-lock-keywords-only))
+           ;; Tell jit-lock how we extend the region to refontify.
+           (add-hook 'jit-lock-after-change-extend-region-functions
+                     'font-lock-extend-jit-lock-region-after-change
+                     nil t)))))
 
 (defun font-lock-turn-off-thing-lock ()
   (cond ((and (boundp 'fast-lock-mode) fast-lock-mode)
@@ -1096,6 +1100,35 @@ what properties to clear before refontifying a region.")
                end (progn (goto-char end) (line-beginning-position 2))))
        (font-lock-fontify-region beg end)))))
 
+(defvar jit-lock-start) (defvar jit-lock-end)
+(defun font-lock-extend-jit-lock-region-after-change (beg end old-len)
+  (let ((region (font-lock-extend-region beg end old-len)))
+    (if region
+        (setq jit-lock-start (min jit-lock-start (car region))
+              jit-lock-end (max jit-lock-end (cdr region)))
+      (save-excursion
+        (goto-char beg)
+        (forward-line 0)
+        (setq jit-lock-start
+              (min jit-lock-start
+                   (if (and (not (eobp))
+                            (get-text-property (point) 'font-lock-multiline))
+                       (or (previous-single-property-change
+                            (point) 'font-lock-multiline)
+                           (point-min))
+                     (point))))
+        (goto-char end)
+        (forward-line 1)
+        (setq jit-lock-end
+              (max jit-lock-end
+                   (if (and (not (bobp))
+                            (get-text-property (1- (point))
+                                               'font-lock-multiline))
+                       (or (next-single-property-change
+                            (1- (point)) 'font-lock-multiline)
+                           (point-max))
+                     (point))))))))
+
 (defun font-lock-fontify-block (&optional arg)
   "Fontify some lines the way `font-lock-fontify-buffer' would.
 The lines could be a function or paragraph, or a specified number of lines.