aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2020-06-04 09:58:22 -0400
committerStefan Monnier2020-06-04 09:58:22 -0400
commitcdadb7a97cbed523af9f52705d8b03e91d17313f (patch)
tree8b9df10b3c84c489842167f9cfdf3e61974850b2
parent4fff6502368e87b3c031589a1a96267243f868b0 (diff)
downloademacs-cdadb7a97cbed523af9f52705d8b03e91d17313f.tar.gz
emacs-cdadb7a97cbed523af9f52705d8b03e91d17313f.zip
* 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 `font-latex.el`. 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.
-rw-r--r--lisp/font-lock.el21
1 files changed, 19 insertions, 2 deletions
diff --git a/lisp/font-lock.el b/lisp/font-lock.el
index e0955b74abc..5cda4a693db 100644
--- a/lisp/font-lock.el
+++ b/lisp/font-lock.el
@@ -575,6 +575,7 @@ This is normally set via `font-lock-defaults'.")
575 "Non-nil means use this syntax table for fontifying. 575 "Non-nil means use this syntax table for fontifying.
576If this is nil, the major mode's syntax table is used. 576If this is nil, the major mode's syntax table is used.
577This is normally set via `font-lock-defaults'.") 577This is normally set via `font-lock-defaults'.")
578(defvar-local font-lock--syntax-table-affects-ppss nil)
578 579
579(defvar font-lock-mark-block-function nil 580(defvar font-lock-mark-block-function nil
580 "Non-nil means use this function to mark a block of text. 581 "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."
1610 (regexp-quote 1611 (regexp-quote
1611 (replace-regexp-in-string "^ *" "" comment-end)))) 1612 (replace-regexp-in-string "^ *" "" comment-end))))
1612 ;; Find the `start' state. 1613 ;; Find the `start' state.
1613 (state (syntax-ppss start)) 1614 (state (if (or syntax-ppss-table
1615 (not font-lock--syntax-table-affects-ppss))
1616 (syntax-ppss start)
1617 ;; If `syntax-ppss' doesn't have its own syntax-table and
1618 ;; we have installed our own syntax-table which
1619 ;; differs from the standard one in ways which affects PPSS,
1620 ;; then we can't use `syntax-ppss' since that would pollute
1621 ;; and be polluted by its cache.
1622 (parse-partial-sexp (point-min) start)))
1614 face beg) 1623 face beg)
1615 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name))) 1624 (if loudly (message "Fontifying %s... (syntactically...)" (buffer-name)))
1616 ;; 1625 ;;
@@ -1907,6 +1916,7 @@ Sets various variables using `font-lock-defaults' and
1907 ;; Case fold during regexp fontification? 1916 ;; Case fold during regexp fontification?
1908 (setq-local font-lock-keywords-case-fold-search (nth 2 defaults)) 1917 (setq-local font-lock-keywords-case-fold-search (nth 2 defaults))
1909 ;; Syntax table for regexp and syntactic fontification? 1918 ;; Syntax table for regexp and syntactic fontification?
1919 (kill-local-variable 'font-lock--syntax-table-affects-ppss)
1910 (if (null (nth 3 defaults)) 1920 (if (null (nth 3 defaults))
1911 (setq-local font-lock-syntax-table nil) 1921 (setq-local font-lock-syntax-table nil)
1912 (setq-local font-lock-syntax-table (copy-syntax-table (syntax-table))) 1922 (setq-local font-lock-syntax-table (copy-syntax-table (syntax-table)))
@@ -1916,7 +1926,14 @@ Sets various variables using `font-lock-defaults' and
1916 (dolist (char (if (numberp (car selem)) 1926 (dolist (char (if (numberp (car selem))
1917 (list (car selem)) 1927 (list (car selem))
1918 (mapcar #'identity (car selem)))) 1928 (mapcar #'identity (car selem))))
1919 (modify-syntax-entry char syntax font-lock-syntax-table))))) 1929 (unless (memq (car (aref font-lock-syntax-table char))
1930 '(1 2 3)) ;"." "w" "_"
1931 (setq font-lock--syntax-table-affects-ppss t))
1932 (modify-syntax-entry char syntax font-lock-syntax-table)
1933 (unless (memq (car (aref font-lock-syntax-table char))
1934 '(1 2 3)) ;"." "w" "_"
1935 (setq font-lock--syntax-table-affects-ppss t))
1936 ))))
1920 ;; (nth 4 defaults) used to hold `font-lock-beginning-of-syntax-function', 1937 ;; (nth 4 defaults) used to hold `font-lock-beginning-of-syntax-function',
1921 ;; but that was removed in 25.1, so if it's a cons cell, we assume that 1938 ;; but that was removed in 25.1, so if it's a cons cell, we assume that
1922 ;; it's part of the variable alist. 1939 ;; it's part of the variable alist.