]> code.delx.au - gnu-emacs/blobdiff - lisp/jit-lock.el
Publicize cl--generic-all-functions
[gnu-emacs] / lisp / jit-lock.el
index d271a447756cdb4f11d4b7b957645cea75a0c9b8..810c2205160ecbd091b98fca6921b3d5546754c9 100644 (file)
@@ -1,6 +1,6 @@
 ;;; jit-lock.el --- just-in-time fontification  -*- lexical-binding: t -*-
 
-;; Copyright (C) 1998, 2000-2015 Free Software Foundation, Inc.
+;; Copyright (C) 1998, 2000-2016 Free Software Foundation, Inc.
 
 ;; Author: Gerd Moellmann <gerd@gnu.org>
 ;; Keywords: faces files
@@ -362,9 +362,15 @@ is active."
             (`(,this-beg . ,this-end)
              (if (eq (car-safe res) 'jit-lock-bounds)
                  (cdr res) (cons beg end))))
-         (setq tight-beg (max tight-beg (or this-beg (point-min))))
-         (setq tight-end (max tight-end (or this-end (point-max))))
-         (setq loose-beg (max loose-beg this-beg))
+         ;; If all functions don't fontify the same region, we currently
+         ;; just try to "still be correct".  But we could go further and for
+         ;; the chunks of text that was fontified by some functions but not
+         ;; all, we could add text-properties indicating which functions were
+         ;; already run to avoid running them redundantly when we get to
+         ;; those chunks.
+         (setq tight-beg (max (or tight-beg (point-min)) this-beg))
+         (setq tight-end (min (or tight-end (point-max)) this-end))
+         (setq loose-beg (min loose-beg this-beg))
          (setq loose-end (max loose-end this-end))
          nil)))
     `(,(min tight-beg beg) ,(max tight-end end) ,loose-beg ,loose-end)))
@@ -376,14 +382,6 @@ Defaults to the whole buffer.  END can be out of bounds."
    (save-excursion
      (unless start (setq start (point-min)))
      (setq end (if end (min end (point-max)) (point-max)))
-     ;; This did bind `font-lock-beginning-of-syntax-function' to
-     ;; nil at some point, for an unknown reason.  Don't do this; it
-     ;; can make highlighting slow due to expensive calls to
-     ;; `parse-partial-sexp' in function
-     ;; `font-lock-fontify-syntactically-region'.  Example: paging
-     ;; from the end of a buffer to its start, can do repeated
-     ;; `parse-partial-sexp' starting from `point-min', which can
-     ;; take a long time in a large buffer.
      (let ((orig-start start) next)
        (save-match-data
         ;; Fontify chunks beginning at START.  The end of a
@@ -402,7 +400,7 @@ Defaults to the whole buffer.  END can be out of bounds."
                ;; `tight' is the part we've fully refontified, and `loose'
                ;; is the part we've partly refontified (some of the
                ;; functions have refontified it but maybe not all).
-               ((`(,tight-beg ,tight-end ,loose-beg ,loose-end)
+               ((`(,tight-beg ,tight-end ,loose-beg ,_loose-end)
                  (condition-case err
                      (jit-lock--run-functions start next)
                    ;; If the user quits (which shouldn't happen in normal
@@ -411,7 +409,8 @@ Defaults to the whole buffer.  END can be out of bounds."
                    (quit (put-text-property start next 'fontified nil)
                          (signal (car err) (cdr err))))))
 
-             ;; In case we fontified more than requested, take note.
+             ;; In case we fontified more than requested, take advantage of the
+             ;; good news.
              (when (or (< tight-beg start) (> tight-end next))
                (put-text-property tight-beg tight-end 'fontified t))
 
@@ -576,11 +575,13 @@ non-nil in a repeated invocation of this function."
                      'fontified nil))
                   (setq pos (next-single-property-change
                               pos 'fontified)))))))))
-    (setq jit-lock-defer-buffers nil)
     ;; Force fontification of the visible parts.
-    (let ((jit-lock-defer-timer nil))
+    (let ((buffers jit-lock-defer-buffers)
+          (jit-lock-defer-timer nil))
+      (setq jit-lock-defer-buffers nil)
       ;; (message "Jit-Defer Now")
-      (sit-for 0)
+      (unless (redisplay)                       ;FIXME: Should we `force'?
+        (setq jit-lock-defer-buffers buffers))
       ;; (message "Jit-Defer Done")
       )))
 
@@ -643,12 +644,14 @@ will take place when text is fontified stealthily."
     (let ((jit-lock-start start)
           (jit-lock-end end))
       (with-buffer-prepared-for-jit-lock
-          (run-hook-with-args 'jit-lock-after-change-extend-region-functions
-                              start end old-len)
-          ;; Make sure we change at least one char (in case of deletions).
-          (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
-          ;; Request refontification.
-          (put-text-property jit-lock-start jit-lock-end 'fontified nil))
+       (run-hook-with-args 'jit-lock-after-change-extend-region-functions
+                          start end old-len)
+       ;; Make sure we change at least one char (in case of deletions).
+       (setq jit-lock-end (min (max jit-lock-end (1+ start)) (point-max)))
+       ;; Request refontification.
+       (save-restriction
+        (widen)
+        (put-text-property jit-lock-start jit-lock-end 'fontified nil)))
       ;; Mark the change for deferred contextual refontification.
       (when jit-lock-context-unfontify-pos
         (setq jit-lock-context-unfontify-pos