diff --git a/font-latex.el b/font-latex.el index a56d3ce1..d6f56ecf 100644 --- a/font-latex.el +++ b/font-latex.el @@ -1005,6 +1005,10 @@ have changed." (unless (= (length verb-macros-with-delims) 0) (add-to-list 'font-latex-syntactic-keywords `(,(concat "\\\\\\(?:" verb-macros-with-delims "\\)" + ;; Some macros take an optional + ;; argument. This is the same line as + ;; above for environments. + "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?" ;; An opening curly brace as delimiter ;; is valid, but allowing it might screw ;; up fontification of stuff like @@ -1019,6 +1023,10 @@ have changed." (unless (= (length verb-macros-with-braces) 0) (add-to-list 'font-latex-syntactic-keywords `(,(concat "\\\\\\(?:" verb-macros-with-braces "\\)" + ;; Some macros take an optional + ;; argument. This is the same line as + ;; above for environments. + "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?" "\\({\\).*?[^\\]\\(?:\\\\\\\\\\)*\\(}\\)") (1 "|") (2 "|"))))) (when font-latex-syntactic-keywords-extra diff --git a/style/listings.el b/style/listings.el index 074428b4..e04045e5 100644 --- a/style/listings.el +++ b/style/listings.el @@ -404,8 +404,7 @@ with user-defined values via the \"lstdefinestyle\" macro." (eq TeX-install-font-lock 'font-latex-setup)) (font-latex-add-keywords '(("lstnewenvironment" "{[[{{")) 'function) (font-latex-add-keywords '(("lstinputlisting" "[{")) 'reference) - (font-latex-add-keywords '(("lstinline" "[{") ; The second argument should - ; actually be verbatim. + (font-latex-add-keywords '(("lstinline" "[") ("lstlistoflistings" "")) 'textual) (font-latex-add-keywords '(("lstalias" "{{") diff --git a/style/minted.el b/style/minted.el index 4d2877a6..d8309449 100644 --- a/style/minted.el +++ b/style/minted.el @@ -1,6 +1,6 @@ ;;; minted.el --- AUCTeX style for `minted.sty' (v2.4.1) -;; Copyright (C) 2014-2016 Free Software Foundation, Inc. +;; Copyright (C) 2014-2017 Free Software Foundation, Inc. ;; Author: Tassilo Horn ;; Maintainer: address@hidden @@ -246,29 +246,38 @@ are loaded." (add-to-list 'LaTeX-indent-environment-list `(,env* current-indentation) t) (add-to-list 'LaTeX-verbatim-environments-local env) (add-to-list 'LaTeX-verbatim-environments-local env*))) - ;; \newmint{foo}{opts} => \foo|code| - ;; \newmint[macname]{foo}{opts} => \macname|code| + ;; \newmint{foo}{opts} => \foo[key=vals]|code| + ;; \newmint[macname]{foo}{opts} => \macname[key=vals]|code| (dolist (name-lang LaTeX-minted-auto-newmint) (let ((lang (if (> (length (car name-lang)) 0) (car name-lang) (cadr name-lang)))) - (add-to-list 'TeX-auto-symbol lang) + (add-to-list 'TeX-auto-symbol + `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local ] + TeX-arg-verb)) (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang))) - ;; \newmintinline{foo}{opts} => \fooinline|code| - ;; \newmintinline[macname]{foo}{opts} => \macname|code| + ;; \newmintinline{foo}{opts} => \fooinline[key=vals]|code| or + ;; \fooinline[key=vals]{code} + ;; \newmintinline[macname]{foo}{opts} => \macname[key=vals]|code| or + ;; \macname[key=vals]{code} (dolist (name-lang LaTeX-minted-auto-newmintinline) (let ((lang (if (> (length (car name-lang)) 0) (car name-lang) - (cadr name-lang)))) - (add-to-list 'TeX-auto-symbol lang) - (add-to-list 'LaTeX-verbatim-macros-with-delims-local (concat lang "inline")))) - ;; \newmintedfile{foo}{opts} => \foofile{file-name} - ;; \newmintedfile[macname]{foo}{opts} => \macname{file-name} + (concat (cadr name-lang) "inline")))) + (add-to-list 'TeX-auto-symbol + `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local ] + TeX-arg-verb)) + (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang) + (add-to-list 'LaTeX-verbatim-macros-with-braces-local lang))) + ;; \newmintedfile{foo}{opts} => \foofile[key=vals]{file-name} + ;; \newmintedfile[macname]{foo}{opts} => \macname[key=vals]{file-name} (dolist (name-lang LaTeX-minted-auto-newmintedfile) (let ((lang (if (> (length (car name-lang)) 0) (car name-lang) - (cadr name-lang)))) - (add-to-list 'TeX-auto-symbol (list lang 'TeX-arg-file)))) + (concat (cadr name-lang) "file")))) + (add-to-list 'TeX-auto-symbol + `(,lang [ TeX-arg-key-val LaTeX-minted-key-val-options-local ] + TeX-arg-file)))) (when (and (fboundp 'font-latex-update-font-lock) (eq TeX-install-font-lock 'font-latex-setup)) ;; Refresh font-locking so that the verbatim envs take effect. @@ -280,6 +289,47 @@ are loaded." (add-hook 'TeX-auto-cleanup-hook #'LaTeX-minted-auto-cleanup t) (add-hook 'TeX-update-style-hook #'TeX-auto-parse t) +(defun LaTeX-minted-add-syntactic-keywords-extra (type macro) + "Add MACRO from minted.sty to `font-latex-syntactic-keywords-extra'. +TYPE is one of the symbols \\='brace or \\='delim indicating how +verbatim text is enclosed after the macro. MACRO is a string or +a list of strings." + (let ((macro (if (listp macro) + (regexp-opt macro) + macro)) + (syntax (if (eq type 'brace) + '((1 "|") (2 "|")) + '((1 "\"") (2 ".") (3 "\"")))) + regexp) + (setq regexp `(,(concat + ;; The backslash + (regexp-quote TeX-esc) + ;; Name of the macro(s) + macro + ;; The optional argument + "\\(?:\\[[^][]*\\(?:\\[[^][]*\\][^][]*\\)*\\]\\)?" + ;; The first mandatory argument + "\\(?:{[^}]+}\\)" + ;; With 'brace, allow braced sub-groups otherwise we + ;; stop matching to early. With 'delim, copy + ;; font-latex.el: + (if (eq type 'brace) + (concat "\\({\\)" + "\\(?:[^}{]*" + "\\(?:{[^}{]*" + "\\(?:{[^}{]*" + "\\(?:{[^}{]*}[^}{]*\\)*" + "}[^}{]*\\)*" + "}[^}{]*\\)*" + "\\)" + "\\(}\\)") + (concat + ;; Opening delimiter + "\\(address@hidden).*?" + ;; Closing delimiter + "\\(" (regexp-quote TeX-esc) "*\\)\\(\\1\\)"))))) + (add-to-list 'font-latex-syntactic-keywords-extra (append regexp syntax)))) + (TeX-add-style-hook "minted" (lambda () @@ -355,9 +405,6 @@ are loaded." (add-to-list (make-local-variable 'LaTeX-indent-environment-list) '("minted" current-indentation) t) (add-to-list 'LaTeX-verbatim-environments-local "minted") - ;; FIXME: That doesn't work because \mintinline has 2 args and only the - ;; second argument is verbatim. - ;;(add-to-list 'LaTeX-verbatim-macros-with-delims-local "mintinline") ;; Fontification (when (and (fboundp 'font-latex-add-keywords) @@ -368,15 +415,21 @@ are loaded." ("setmintedinline" "[{") ("newminted" "[{{") ("newmint" "[{{") - ("newmintedinline" "[{{") - ("newmintedfile" "[{{") - ;; FIXME: Those have the form \mint{lang}|code| - ;; so ideally the verbatim arg should be - ;; recognized. - "mint" "mintinline") + ("newmintinline" "[{{") + ("newmintedfile" "[{{")) 'function) - (font-latex-add-keywords '(("inputminted" "[{{")) + (font-latex-add-keywords '(("inputminted" "[{{") + ("mint" "[{") + ("mintinline" "[{")) 'textual) + ;; Add \mint & \mintinline to + ;; `font-latex-syntactic-keywords-extra' and cater for their + ;; special syntax: \mint[optional]{lang}{verbatim} or + ;; \mint[optional]{lang}|verbatim| + (LaTeX-minted-add-syntactic-keywords-extra 'brace + '("mint" "mintinline")) + (LaTeX-minted-add-syntactic-keywords-extra 'delim + '("mint" "mintinline")) ;; Tell font-lock about the update. (font-latex-update-font-lock t))) LaTeX-dialect)