diff --git a/font-latex.el b/font-latex.el index 8b1fec60..1468edd6 100644 --- a/font-latex.el +++ b/font-latex.el @@ -1003,9 +1003,6 @@ The car is used for subscript, the cdr is used for superscripts." The form should be the same as in `font-lock-syntactic-keywords'.") (make-variable-buffer-local 'font-latex-syntactic-keywords-extra) -;; Set and updated in `font-latex-set-syntactic-keywords'. -(defvar font-latex-doctex-syntactic-keywords nil) - (defun font-latex-set-syntactic-keywords () "Set the variable `font-latex-syntactic-keywords'. This function can be used to refresh the variable in case other @@ -1028,8 +1025,7 @@ have changed." (regexp-opt verb-macros-with-braces)) font-latex-syntactic-keywords nil) (unless (= (length verb-envs) 0) - (add-to-list - 'font-latex-syntactic-keywords + (push `(,(concat "^[ \t]*\\\\begin *{\\(?:" verb-envs "\\)}" ;; Some environments accept an optional and/or mandatory @@ -1053,9 +1049,17 @@ have changed." ;; catches the case where verbatim content is written ;; immediately after the \begin{verbatim}. "\\(\n\\|.\\)") - (1 "|" t))) - (add-to-list - 'font-latex-syntactic-keywords + (1 "|") + ;; Span non-nil `syntax-multiline' property over + ;; \begin{verbatim}[WHOLE OPTIONAL ARGUMENT] so that editing + ;; inside the multi-line optional arguments won't turn off + ;; verbatim faces inside the environments even when those + ;; contents are very large. + (0 (ignore + (put-text-property (match-beginning 0) (match-end 0) + 'syntax-multiline t)))) + font-latex-syntactic-keywords) + (push ;; Using the newline character for the syntax property often ;; resulted in fontification problems when text was inserted at ;; the end of the verbatim environment. That's why we now use @@ -1063,10 +1067,10 @@ have changed." ;; `font-latex-make-user-keywords' to remove the spurious ;; fontification of the backslash. `(,(concat "\\(\\\\\\)end *{\\(?:" verb-envs "\\)}") - (1 "|" t)))) + (1 "|")) + font-latex-syntactic-keywords)) (unless (= (length verb-macros-with-delims) 0) - (add-to-list - 'font-latex-syntactic-keywords + (push `(,(concat "\\\\\\(?:" verb-macros-with-delims "\\)" ;; Some macros take an optional argument. This is ;; the same line as above for environments. @@ -1074,29 +1078,46 @@ have changed." ;; An opening curly brace as delimiter is valid, but ;; allowing it might screw up fontification of stuff ;; like "\url{...} foo \textbf{<--!...}". - "\\([^a-z@*\n\f{]\\).*?" + "\\([^a-z@*\n\f{]\\)") + (1 (prog1 "\"" + (skip-chars-forward (string ?^ (preceding-char)) + (line-end-position)) + (if (eolp) + nil + (let ((p (point))) + (put-text-property p (1+ p) 'syntax-table + (string-to-syntax "\"")) ;; Give an escape char at the end of the verbatim ;; construct punctuation syntax. Prevents wrong ;; fontification of stuff like "\verb|foo\|". - "\\(" (regexp-quote TeX-esc) "*\\)\\(\\1\\)") - (1 "\"") (2 ".") (3 "\"")))) + (save-excursion + (when (> 0 (skip-chars-backward "\\\\")) + (put-text-property (point) p 'syntax-table + (string-to-syntax "."))))))))) + font-latex-syntactic-keywords)) (unless (= (length verb-macros-with-braces) 0) - (add-to-list - 'font-latex-syntactic-keywords + (push `(,(concat "\\\\\\(?:" verb-macros-with-braces "\\)" ;; Some macros take an optional argument. This is ;; the same line as above for environments. "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?" "\\({\\).*?[^\\]\\(?:\\\\\\\\\\)*\\(}\\)") - (1 "|") (2 "|"))))) + (1 "|") (2 "|")) + font-latex-syntactic-keywords))) (when font-latex-syntactic-keywords-extra (nconc font-latex-syntactic-keywords font-latex-syntactic-keywords-extra)) ;; Cater for docTeX mode. - (setq font-latex-doctex-syntactic-keywords - (append font-latex-syntactic-keywords - ;; For docTeX comment-in-doc. - '(("\\(\\^\\)\\^A" (1 (font-latex-doctex-^^A))))))) - + (if (derived-mode-p 'doctex-mode) + (setq font-latex-syntactic-keywords + (append font-latex-syntactic-keywords + ;; For docTeX comment-in-doc. + '(("\\(\\^\\)\\^A" (1 (font-latex-doctex-^^A))))))) + ;; + (setq syntax-propertize-function + (byte-compile + (eval '(syntax-propertize-rules + font-latex-syntactic-keywords) + t)))) ;;; Syntactic fontification @@ -1258,15 +1279,6 @@ triggers Font Lock to recognize the change." (when (fboundp 'font-lock-flush) (font-lock-flush))) -(defun font-latex-syntax-propertize-function (start end) - "The `syntax-propertize-function' for (La)TeX documents." - (with-no-warnings - (let ((font-lock-syntactic-keywords - (if (derived-mode-p 'doctex-mode) - font-latex-doctex-syntactic-keywords - font-latex-syntactic-keywords))) - (font-lock-fontify-syntactic-keywords-region start end)))) - ;;;###autoload (defun font-latex-setup () "Setup this buffer for LaTeX font-lock. Usually called from a hook." @@ -1297,10 +1309,9 @@ triggers Font Lock to recognize the change." font-latex-extend-region-backwards-command-in-braces font-latex-extend-region-backwards-quotation font-latex-extend-region-backwards-math) - (syntax-propertize-function - . font-latex-syntax-propertize-function) (syntax-propertize-extend-region-functions syntax-propertize-wholelines + syntax-propertize-multiline font-latex-sp-extend-region-backwards-verb-env)))) ;; Add the mode-dependent stuff to the basic variables defined above. (if (eq major-mode 'doctex-mode) @@ -2232,8 +2243,6 @@ set to french, and >>german<< (and 8-bit) are used if set to german." (defface font-latex-doctex-preprocessor-face '((t (:inherit (font-latex-doctex-documentation-face - font-lock-builtin-face ; Emacs 21 does not provide - ; the preprocessor face. font-lock-preprocessor-face)))) "Face used to highlight preprocessor directives in docTeX mode." :group 'font-latex-highlighting-faces) @@ -2266,17 +2275,13 @@ set to french, and >>german<< (and 8-bit) are used if set to german." ;; syntax-table can't deal with. We could turn it ;; into a non-comment, or use `\n%' or `%^' as the comment. ;; Instead, we include it in the ^^A comment. - (eval-when-compile (string-to-syntax "< b")) - ;; FIXME: Those `eval-when-compile' shouldn't be needed any - ;; more since the byte-compiler will precompute those calls - ;; anyway (because `string-to-syntax' is marked as pure). - (eval-when-compile (string-to-syntax ">")))) + (string-to-syntax "< b") + (string-to-syntax ">"))) (let ((end (line-end-position))) (if (< end (point-max)) (put-text-property end (1+ end) 'syntax-table - (eval-when-compile - (string-to-syntax "> b"))))) - (eval-when-compile (string-to-syntax "< b"))))) + (string-to-syntax "> b")))) + (string-to-syntax "< b")))) ;; Copy and adaptation of `doctex-font-lock-syntactic-face-function' ;; in `tex-mode.el' of CVS Emacs (March 2004) @@ -2298,16 +2303,6 @@ set to french, and >>german<< (and 8-bit) are used if set to german." ;; latex-mode, then please just add `font-latex-setup' to `latex-mode-hook' ;; yourself. -;;; Byte-compilation of generated functions -;; Not needed now that we generate the code via a macro. -;; (when (byte-code-function-p -;; (symbol-function 'font-latex-make-built-in-keywords)) -;; (dolist (elt font-latex-built-in-keyword-classes) -;; (let ((name (nth 0 elt))) -;; (byte-compile (intern (concat "font-latex-match-" name))) -;; (byte-compile (intern (concat "font-latex-match-" name "-make")))))) - - ;; Provide ourselves: (provide 'font-latex)