diff --git a/style/minted.el b/style/minted.el index a4f413d..f0ee994 100644 --- a/style/minted.el +++ b/style/minted.el @@ -1,4 +1,4 @@ -;;; minted.el --- AUCTeX style for `minted.sty' +;;; minted.el --- AUCTeX style for `minted.sty' (v2.4.1) ;; Copyright (C) 2014-2016 Free Software Foundation, Inc. @@ -26,7 +26,7 @@ ;;; Commentary: -;; This file adds support for `minted.sty'. +;; This file adds support for `minted.sty' (v2.4.1) from 2016/10/31. ;;; Code: @@ -35,12 +35,31 @@ (defvar LaTeX-minted-key-val-options '(("autogobble" ("true" "false")) ("baselinestretch" ("auto")) + ("breakafter") + ("breakaftergroup" ("true" "false")) + ("breakaftersymbolpre") + ("breakaftersymbolpost") + ("breakbytoken" ("true" "false")) + ("breakbytokenanywhere" ("true" "false")) + ("breakindent") + ("breaklines" ("true" "false")) + ("breaksymbol") + ("breaksymbolleft") + ("breaksymbolright") + ("breaksymbolindent") + ("breaksymbolindentleft") + ("breaksymbolindentright") + ("breaksymbolsep") + ("breaksymbolsepleft") + ("breaksymbolsepright") ("bgcolor") ("codetagify") + ("curlyquotes" ("true" "false")) ("encoding") ("outencoding") + ("escapeinside") ("firstline") - ("firstnumber" ("auto")) + ("firstnumber" ("auto" "last" "integer")) ("fontfamily" ("tt" "courier" "helvetica")) ("fontseries" ("auto")) ("fontsize" ("auto" "\\tiny" "\\large" "\\scriptsize" "\\Large" @@ -53,12 +72,15 @@ ("framesep") ("funcnamehighlighting" ("true" "false")) ("gobble") + ("highlightcolor") + ("highlightlines") ("keywordcase" ("lower" "upper" "capitalize")) ("label") ("labelposition" ("none" "topline" "bottomline" "all")) ("lastline") ("linenos" ("true" "false")) - ("numbers" ("left" "right")) + ("numberfirstline" ("true" "false")) + ("numbers" ("left" "right" "both" "none")) ("mathescape" ("true" "false")) ("numberblanklines" ("true" "false")) ("numbersep") @@ -69,10 +91,27 @@ ("samepage" ("true" "false")) ("showspaces" ("true" "false")) ("showtabs" ("true" "false")) + ("space") + ("spacecolor") ("startinline" ("true" "false")) - ("style") + ;; FIXME: It would be nice to use the function + ;; `LaTeX-minted-style-list' here, but with a file local var like: + ;; %%% TeX-command-extra-options: "-shell-escape" + ;; in a .tex file, Emacs asks to apply a variable which is not + ;; safe and does not restore the frame; the splitted frame + ;; remains. I couldn't figure out why, so for now, I add the + ;; styles from Pygments version 2.1.3 here. + ("style" ("colorful" "default" "emacs" "friendly" "fruity" "igor" + "lovelace" "manni" "monokai" "murphy" "native" + "paraiso-dark" "paraiso-light" "pastie" "perldoc" + "rrt" "tango" "trac" "vim" "vs" "xcode")) ("stepnumber") + ("stepnumberfromfirst") + ("stepnumberoffsetvalues" ("true" "false")) + ("stripall" ("true" "false")) ("stripnl") + ("tab") + ("tabcolor") ("tabsize") ("texcl" ("true" "false")) ("texcomments" ("true" "false")) @@ -80,11 +119,18 @@ ("xrightmargin")) "Key=value options for minted macros and environments.") +(defvar LaTeX-minted-key-val-options-local nil + "Buffer-local key=value options for minted macros and environments.") +(make-variable-buffer-local 'LaTeX-minted-key-val-options-local) + (defvar LaTeX-minted-pygmentize-program (executable-find "pygmentize")) -(defvar LaTeX-minted-language-list nil) +(defvar LaTeX-minted-language-list nil + "List containing languages provided by pymentize program.") (defun LaTeX-minted-language-list (&rest _ignored) + "Return a list of languages provided by pymentize program. +Update the variable `LaTeX-minted-language-list' if still nil." (or LaTeX-minted-language-list (when LaTeX-minted-pygmentize-program (with-temp-buffer @@ -95,14 +141,63 @@ (while (re-search-forward "^\\*[[:space:]]\\([^:]+\\):" nil t) (dolist (lang (split-string (match-string 1) "[[:space:],]" t)) (push lang languages))) - languages))))) + (setq LaTeX-minted-language-list languages)) + LaTeX-minted-language-list)))) (defun LaTeX-arg-minted-language (optional &optional prompt) + "Insert a selected pygmentize language as argument for macros from minted.sty. +If OPTIONAL is non-nil, insert it as optional argument in +brackets. PROMPT replaces the standard one." (TeX-argument-insert (completing-read (TeX-argument-prompt optional prompt "Language") (LaTeX-minted-language-list)) optional)) +(defvar LaTeX-minted-style-list nil + "List containing styles provided by pymentize program.") + +(defun LaTeX-minted-style-list (&rest _ignored) + "Return a list of styles provided by pymentize program. +Update the variable `LaTeX-minted-style-list' if still nil." + (or LaTeX-minted-style-list + (when LaTeX-minted-pygmentize-program + (with-temp-buffer + (shell-command (concat LaTeX-minted-pygmentize-program " -L styles") + (current-buffer)) + (goto-char (point-min)) + (let (styles) + (while (re-search-forward "^\\*[[:space:]]\\([^:]+\\):" nil t) + (dolist (style (split-string (match-string 1) "[[:space:],]" t)) + (push style styles))) + (setq LaTeX-minted-style-list styles)) + LaTeX-minted-style-list)))) + +(defun LaTeX-arg-minted-style (optional &optional prompt) + "Insert a selected pygmentize style as argument for macros from minted.sty. +If OPTIONAL is non-nil, insert it as optional argument in +brackets. PROMPT replaces the standard one." + (TeX-argument-insert + (completing-read (TeX-argument-prompt optional prompt "Style") + (LaTeX-minted-style-list)) + optional)) + +(defun LaTeX-minted-update-key-vals () + "Update color related key-vals in `LaTeX-minted-key-val-options-local'." + (when (or (and (member "xcolor" (TeX-style-list)) + (LaTeX-xcolor-definecolor-list)) + (and (member "color" (TeX-style-list)) + (LaTeX-color-definecolor-list))) + (let* ((colorkeys '("bgcolor" "highlightcolor" + "rulecolor" "spacecolor" "tabcolor")) + (opts (copy-alist LaTeX-minted-key-val-options-local))) + (dolist (key colorkeys) + (assq-delete-all (car (assoc key opts)) opts) + (push (list key (or (mapcar #'car (LaTeX-xcolor-definecolor-list)) + (mapcar #'car (LaTeX-color-definecolor-list)))) + opts)) + (setq LaTeX-minted-key-val-options-local + (copy-alist opts))))) + (defvar LaTeX-minted-auto-newminted nil) (defvar LaTeX-minted-newminted-regexp '("\\\\newminted\\(?:\\[\\([^]]+\\)\\]\\)?{\\([^}]+\\)}{[^}]*}" @@ -127,7 +222,9 @@ (setq LaTeX-minted-auto-newminted nil LaTeX-minted-auto-newmint nil LaTeX-minted-auto-newmintinline nil - LaTeX-minted-auto-newmintedfile nil)) + LaTeX-minted-auto-newmintedfile nil + LaTeX-minted-language-list nil + LaTeX-minted-style-list nil)) (defun LaTeX-minted-auto-cleanup () ;; \newminted{lang}{opts} => new langcode and langcode* envs. @@ -174,7 +271,9 @@ ;; Refresh font-locking so that the verbatim envs take effect. (font-latex-set-syntactic-keywords) (setq font-lock-set-defaults nil) - (font-lock-set-defaults))) + (font-lock-set-defaults)) + ;; Also update the key=vals + (LaTeX-minted-update-key-vals)) (add-hook 'TeX-auto-prepare-hook #'LaTeX-minted-auto-prepare t) (add-hook 'TeX-auto-cleanup-hook #'LaTeX-minted-auto-cleanup t) @@ -183,25 +282,64 @@ (TeX-add-style-hook "minted" (lambda () + + ;; Activate local-version of key=vals + (setq LaTeX-minted-key-val-options-local + (copy-alist LaTeX-minted-key-val-options)) + ;; New symbols (TeX-add-symbols '("mint" LaTeX-arg-minted-language TeX-arg-verb) '("mintinline" LaTeX-arg-minted-language TeX-arg-verb) - '("listoflistings") '("newminted" ["Environment Name"] LaTeX-arg-minted-language - (TeX-arg-key-val LaTeX-minted-key-val-options)) + (TeX-arg-key-val LaTeX-minted-key-val-options-local)) '("newmint" ["Macro Name"] LaTeX-arg-minted-language - (TeX-arg-key-val LaTeX-minted-key-val-options)) + (TeX-arg-key-val LaTeX-minted-key-val-options-local)) '("newmintinline" ["Macro Name"] LaTeX-arg-minted-language - (TeX-arg-key-val LaTeX-minted-key-val-options)) + (TeX-arg-key-val LaTeX-minted-key-val-options-local)) '("newmintedfile" ["Macro Name"] LaTeX-arg-minted-language - (TeX-arg-key-val LaTeX-minted-key-val-options))) + (TeX-arg-key-val LaTeX-minted-key-val-options-local)) + ;; 3.3 Formatting source code + '("inputminted" + [ TeX-arg-key-val LaTeX-minted-key-val-options-local ] + (LaTeX-arg-minted-language) + TeX-arg-file) + ;; 3.4 Using different styles + '("usemintedstyle" + [ LaTeX-arg-minted-language ] LaTeX-arg-minted-style) + ;; 5.2 Macro option usage + '("setminted" + [ LaTeX-arg-minted-language ] + (TeX-arg-key-val LaTeX-minted-key-val-options-local)) + '("setmintedinline" + [ LaTeX-arg-minted-language ] + (TeX-arg-key-val LaTeX-minted-key-val-options-local))) ;; New environments (LaTeX-add-environments - '("minted" LaTeX-env-args [TeX-arg-key-val LaTeX-minted-key-val-options] - LaTeX-arg-minted-language) - '("listing" ["Float Position"])) + '("minted" LaTeX-env-args [TeX-arg-key-val LaTeX-minted-key-val-options-local] + LaTeX-arg-minted-language)) + + ;; 4 Floating listings: If option "newfloat" is given, run the + ;; style hook and use the interface provided by the style, + ;; otherwise add "listing" manually + (if (or (LaTeX-provided-package-options-member "minted" "newfloat") + (LaTeX-provided-package-options-member "minted" "newfloat=true")) + (progn + (TeX-run-style-hooks "newfloat") + (LaTeX-add-newfloat-DeclareFloatingEnvironments + '("listing" "verbatim"))) + (progn + (LaTeX-add-environments '("listing" ["Float Position"])) + (TeX-add-symbols '("listoflistings") + '("listingscaption") + '("listoflistingscaption")) + (add-to-list (make-local-variable 'LaTeX-indent-environment-list) + '("listing" current-indentation) t) + (add-to-list 'LaTeX-label-alist '("listing" . "lst:") t) + (when (fboundp 'reftex-add-label-environments) + (reftex-add-label-environments + '(("listing" ?l "lst:" "~\\ref{%s}" caption nil nil)))))) ;; Add to the auto parser (TeX-auto-add-regexp LaTeX-minted-newminted-regexp) @@ -221,11 +359,17 @@ (when (and (fboundp 'font-latex-add-keywords) (fboundp 'font-latex-set-syntactic-keywords) (eq TeX-install-font-lock 'font-latex-setup)) - (font-latex-add-keywords '(;; FIXME: Those have the form \mint{lang}|code| + (font-latex-add-keywords '(("usemintedstyle" "[{") + ("newmintedfile" "[{{") + ("setminted" "[{") + ("setmintedinline" "[{") + ;; FIXME: Those have the form \mint{lang}|code| ;; so ideally the verbatim arg should be ;; recognized. "mint" "mintinline") 'function) + (font-latex-add-keywords '(("inputminted" "[{{")) + 'textual) ;; For syntactic fontification, e.g. verbatim constructs. (font-latex-set-syntactic-keywords) ;; Tell font-lock about the update. @@ -233,9 +377,12 @@ (font-lock-set-defaults))) LaTeX-dialect) -(defvar LaTeX-minted-package-options '("section" "chapter" "cache" - "outputdir" "cachedir" - "langlinenos") +(defvar LaTeX-minted-package-options '("chapter" "cache" + "cachedir" "finalizecache" + "frozencache" "draft" + "final" "kpsewhich" + "langlinenos" "newfloat" + "outputdir" "section") "Package options for the minted package.") ;;; minted.el ends here