[Top][All Lists]

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

master cdadb7a: * lisp/font-lock.el (font-lock--syntax-table-affects-pps

From: Stefan Monnier
Subject: master cdadb7a: * lisp/font-lock.el (font-lock--syntax-table-affects-ppss): New var
Date: Thu, 4 Jun 2020 09:58:28 -0400 (EDT)

branch: master
commit cdadb7a97cbed523af9f52705d8b03e91d17313f
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    * lisp/font-lock.el (font-lock--syntax-table-affects-ppss): New var
    This tries to make `font-lock-syntax-table` work correctly even when
    it changes the parsing of strings and comments, as was the case in
    We should probably deprecate the use of `font-lock-syntax-table` since
    the present fix is still not 100% and since it comes with performance
    problems in large files.
    (font-lock-set-defaults): Set it.
    (font-lock-fontify-syntactically-region): Don't use `syntax-ppss`
    when we think that `font-lock-syntax-table` would interfere.
 lisp/font-lock.el | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e0955b7..5cda4a6 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -575,6 +575,7 @@ This is normally set via `font-lock-defaults'.")
   "Non-nil means use this syntax table for fontifying.
 If this is nil, the major mode's syntax table is used.
 This is normally set via `font-lock-defaults'.")
+(defvar-local font-lock--syntax-table-affects-ppss nil)
 (defvar font-lock-mark-block-function nil
   "Non-nil means use this function to mark a block of text.
@@ -1610,7 +1611,15 @@ START should be at the beginning of a line."
                (replace-regexp-in-string "^ *" "" comment-end))))
           ;; Find the `start' state.
-          (state (syntax-ppss start))
+          (state (if (or syntax-ppss-table
+                         (not font-lock--syntax-table-affects-ppss))
+                     (syntax-ppss start)
+                   ;; If `syntax-ppss' doesn't have its own syntax-table and
+                   ;; we have installed our own syntax-table which
+                   ;; differs from the standard one in ways which affects PPSS,
+                   ;; then we can't use `syntax-ppss' since that would pollute
+                   ;; and be polluted by its cache.
+                   (parse-partial-sexp (point-min) start)))
           face beg)
       (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
@@ -1907,6 +1916,7 @@ Sets various variables using `font-lock-defaults' and
       ;; Case fold during regexp fontification?
       (setq-local font-lock-keywords-case-fold-search (nth 2 defaults))
       ;; Syntax table for regexp and syntactic fontification?
+      (kill-local-variable 'font-lock--syntax-table-affects-ppss)
       (if (null (nth 3 defaults))
           (setq-local font-lock-syntax-table nil)
        (setq-local font-lock-syntax-table (copy-syntax-table (syntax-table)))
@@ -1916,7 +1926,14 @@ Sets various variables using `font-lock-defaults' and
            (dolist (char (if (numberp (car selem))
                              (list (car selem))
                            (mapcar #'identity (car selem))))
-             (modify-syntax-entry char syntax font-lock-syntax-table)))))
+             (unless (memq (car (aref font-lock-syntax-table char))
+                           '(1 2 3))    ;"." "w" "_"
+               (setq font-lock--syntax-table-affects-ppss t))
+             (modify-syntax-entry char syntax font-lock-syntax-table)
+             (unless (memq (car (aref font-lock-syntax-table char))
+                           '(1 2 3))    ;"." "w" "_"
+               (setq font-lock--syntax-table-affects-ppss t))
+             ))))
       ;; (nth 4 defaults) used to hold 
       ;; but that was removed in 25.1, so if it's a cons cell, we assume that
       ;; it's part of the variable alist.

reply via email to

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