emacs-pretest-bug
[Top][All Lists]
Advanced

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

Re: perl mode color highlighting working badly


From: Stefan Monnier
Subject: Re: perl mode color highlighting working badly
Date: Tue, 01 Nov 2005 02:29:21 -0500
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

> The patches did change things.
> When I edit the file and go quickly ( CNTL-END ) to the bottom there is about
> a 6 second delay before it gets there.
> Then I went down from the top a few pages and aded a " character to start a
> string. I scanned page by page to the bottom and everything was colored as a
> quoted string.

Looking at it some more I think the patch was going in the right direction
but didn't go far enough.  The patch below should hopefully fix
your problems.  Also I'm reasonably satisfied with it: it doesn't seem like
a bad hack any more.

And actually I believe that several other major modes will want to use
font-lock-syntax-props-depend-on-themselves.


        Stefan


Index: lisp/progmodes/perl-mode.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/progmodes/perl-mode.el,v
retrieving revision 1.61
diff -u -r1.61 perl-mode.el
--- lisp/progmodes/perl-mode.el 7 Sep 2005 19:54:49 -0000       1.61
+++ lisp/progmodes/perl-mode.el 1 Nov 2005 07:27:45 -0000
@@ -533,6 +533,8 @@
                              . perl-font-lock-syntactic-keywords)
                             (font-lock-syntactic-face-function
                              . perl-font-lock-syntactic-face-function)
+                             (font-lock-fontify-syntactically-eagerly . t)
+                             (font-lock-syntax-props-depend-on-themselves . t)
                             (parse-sexp-lookup-properties . t)))
   ;; Tell imenu how to handle Perl.
   (set (make-local-variable 'imenu-generic-expression)
Index: font-lock.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/font-lock.el,v
retrieving revision 1.280
diff -u -u -b -r1.280 font-lock.el
--- font-lock.el        31 Oct 2005 16:41:14 -0000      1.280
+++ font-lock.el        1 Nov 2005 07:25:16 -0000
@@ -1028,6 +1028,20 @@
 Useful for things like RMAIL and Info where the whole buffer is not
 a very meaningful entity to highlight.")
 
+(defvar font-lock-fontify-syntactically-eagerly nil
+  "If non-nil, apply `font-lock-fontify-syntactically-region' eagerly.
+For modes which set syntax-table properties from
+`font-lock-syntactic-face-function', it may be necessary to also apply
+`font-lock-fontify-syntactically-region' on all the buffer before point,
+which is what happens if this variable is non-nil.")
+
+(defvar font-lock-syntax-props-depend-on-themselves nil
+  "If non-nil, syntax-table changes may influence syntactic keywords.
+If the syntax-table properties set by syntactic-keywords themselves depend
+on syntax-table properties set on the text before it by syntactic-keywords,
+this variable should be set to non-nil, so that whenever syntaxtic-keywords
+is applied, the subsequent text is marked for syntactic re-fontification.")
+
 (defun font-lock-default-fontify-region (beg end loudly)
   (save-buffer-state
       ((parse-sexp-lookup-properties
@@ -1059,10 +1073,30 @@
           (unless (bolp) (setq end (line-beginning-position 2)))
          ;; Now do the fontification.
          (font-lock-unfontify-region beg end)
+          (let ((sbeg beg))
+            (cond
+             ((< font-lock-syntactically-fontified sbeg)
+              ;; Ensure the syntax-table prop is properly set on the text
+              ;; before beg.
+              (setq sbeg (max font-lock-syntactically-fontified (point-min)))
+              (setq font-lock-syntactically-fontified end))
+             ((and font-lock-syntax-props-depend-on-themselves
+                   (> font-lock-syntactically-fontified end))
+              ;; If the syntax-table properties set by
+              ;; font-lock-syntactic-keywords themselves depend on
+              ;; syntax-table props set in the text above it, then we'll
+              ;; need to update all the syntax-table props below end.
+              (setq font-lock-syntactically-fontified end)))
          (when font-lock-syntactic-keywords
-           (font-lock-fontify-syntactic-keywords-region beg end))
+              (font-lock-fontify-syntactic-keywords-region sbeg end))
          (unless font-lock-keywords-only
-           (font-lock-fontify-syntactically-region beg end loudly))
+              (font-lock-fontify-syntactically-region
+               ;; For modes which set syntax-table properties from
+               ;; font-lock-syntactic-face-function, it may be necessary to
+               ;; also apply font-lock-fontify-syntactically-region on all
+               ;; the buffer before point.
+               (if font-lock-fontify-syntactically-eagerly sbeg beg)
+               end loudly)))
          (font-lock-fontify-keywords-region beg end loudly))
       ;; Clean up.
       (set-syntax-table old-syntax-table))))
@@ -1277,11 +1311,6 @@
 (defun font-lock-fontify-syntactic-keywords-region (start end)
   "Fontify according to `font-lock-syntactic-keywords' between START and END.
 START should be at the beginning of a line."
-  ;; Ensure the beginning of the file is properly syntactic-fontified.
-  (when (and font-lock-syntactically-fontified
-            (< font-lock-syntactically-fontified start))
-    (setq start (max font-lock-syntactically-fontified (point-min)))
-    (setq font-lock-syntactically-fontified end))
   ;; If `font-lock-syntactic-keywords' is a symbol, get the real keywords.
   (when (symbolp font-lock-syntactic-keywords)
     (setq font-lock-syntactic-keywords (font-lock-eval-keywords
@@ -1573,9 +1602,9 @@
   (cond ((not (and (listp keywords) (symbolp (car keywords))))
         keywords)
        ((numberp level)
-        (or (nth level keywords) (car (reverse keywords))))
+        (or (nth level keywords) (car (last keywords))))
        ((eq level t)
-        (car (reverse keywords)))
+        (car (last keywords)))
        (t
         (car keywords))))
 




reply via email to

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