branch: externals/auctex commit 6e94ea0227aae5959b820b5021ef08973c2403eb Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Add (start of an) minted style. * style/minted.el: New style. * Makefile.in (STYLESRC): Add style/minted.el. --- ChangeLog | 4 + Makefile.in | 2 +- style/minted.el | 212 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 217 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 735d8d0..402416e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2014-12-19 Tassilo Horn <t...@gnu.org> + * style/minted.el: New style. + + * Makefile.in (STYLESRC): Add style/minted.el. + * latex.el (LaTeX-env-args): Bind exit-mark if its not bound already. (LaTeX-verbatim-regexp): Make variable obsolete. diff --git a/Makefile.in b/Makefile.in index a132c1c..998e730 100644 --- a/Makefile.in +++ b/Makefile.in @@ -142,7 +142,7 @@ STYLESRC = style/prosper.el \ style/XCharter.el style/zlmtt.el style/ifluatex.el \ style/luatextra.el style/erewhon.el style/baskervaldx.el \ style/fbb.el style/newtxmath.el style/newtxsf.el \ - style/newtxtext.el style/newtxttt.el + style/newtxtext.el style/newtxttt.el style/minted.el STYLEELC = $(STYLESRC:.el=.elc) ifeq (@preview_enabled@,yes) diff --git a/style/minted.el b/style/minted.el new file mode 100644 index 0000000..b5733c3 --- /dev/null +++ b/style/minted.el @@ -0,0 +1,212 @@ +;;; minted.el --- AUCTeX style for `minted.sty' + +;; Copyright (C) 2014 Free Software Foundation, Inc. + +;; Author: Tassilo Horn <t...@gnu.org> +;; Maintainer: auctex-de...@gnu.org +;; Created: 2014-12-19 +;; Keywords: tex + +;; This file is part of AUCTeX. + +;; AUCTeX is free software; you can redistribute it and/or modify it +;; under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; AUCTeX is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with AUCTeX; see the file COPYING. If not, write to the Free +;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA +;; 02110-1301, USA. + +;;; Commentary: + +;; This file adds support for `minted.sty'. + +;;; Code: + +(require 'tex) + +(defvar LaTeX-minted-key-val-options + '(("autogobble" ("true" "false")) + ("baselinestretch" ("auto")) + ("bgcolor") + ("codetagify") + ("encoding") + ("outencoding") + ("firstline") + ("firstnumber" ("auto")) + ("fontfamily" ("tt" "courier" "helvetica")) + ("fontseries" ("auto")) + ("fontsize" ("auto" "\\tiny" "\\large" "\\scriptsize" "\\Large" + "\\footnotesize" "\\LARGE" "\\small" "\\huge" + "\\normalsize" "\\Huge")) + ("fontshape" ("auto")) + ("formatcom") + ("frame" ("none" "leftline" "topline" "bottomline" "lines" "single")) + ("framerule") + ("framesep") + ("funcnamehighlighting" ("true" "false")) + ("gobble") + ("keywordcase" ("lower" "upper" "capitalize")) + ("label") + ("labelposition" ("none" "topline" "bottomline" "all")) + ("lastline") + ("linenos" ("true" "false")) + ("numbers" ("left" "right")) + ("mathescape" ("true" "false")) + ("numberblanklines" ("true" "false")) + ("numbersep") + ("obeytabs" ("true" "false")) + ("python3" ("true" "false")) + ("resetmargins" ("true" "false")) + ("rulecolor") + ("samepage" ("true" "false")) + ("showspaces" ("true" "false")) + ("showtabs" ("true" "false")) + ("startinline" ("true" "false")) + ("style") + ("stepnumber") + ("stripnl") + ("tabsize") + ("texcl" ("true" "false")) + ("texcomments" ("true" "false")) + ("xleftmargin") + ("xrightmargin")) + "Key=value options for minted macros and environments.") + +(defvar LaTeX-minted-pygmentize-program (executable-find "pygmentize")) + +(defvar LaTeX-minted-language-list nil) + +(defun LaTeX-minted-language-list (&rest _ignored) + (or LaTeX-minted-language-list + (when LaTeX-minted-pygmentize-program + (with-temp-buffer + (shell-command (concat LaTeX-minted-pygmentize-program " -L lexers") + (current-buffer)) + (goto-char (point-min)) + (let (languages) + (while (re-search-forward "^\\*[[:space:]]\\([^:]+\\):" nil t) + (dolist (lang (split-string (match-string 1) "[[:space:],]" t)) + (push lang languages))) + languages))))) + +(defun LaTeX-arg-minted-language (optional &optional prompt) + (TeX-argument-insert + (completing-read (TeX-argument-prompt optional prompt "Language") + (LaTeX-minted-language-list)) + optional)) + +;; FIXME: All the \newmint-macros allow to specify the env/macro name as +;; optional 1st arg, e.g., with \newminted[fifi]{cpp}{opts} the resulting +;; environments are fifi and fifi* rather than cppcode and cppcode*. +(defvar LaTeX-minted-auto-newminted nil) +(defvar LaTeX-minted-newminted-regexp + '("\\\\newminted{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newminted)) + +(defvar LaTeX-minted-auto-newmint nil) +(defvar LaTeX-minted-newmint-regexp + '("\\\\newmint{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmint)) + +(defvar LaTeX-minted-auto-newmintinline nil) +(defvar LaTeX-minted-newmintinline-regexp + '("\\\\newmintinline{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmintinline)) + +(defvar LaTeX-minted-auto-newmintedfile nil) +(defvar LaTeX-minted-newmintedfile-regexp + '("\\\\newmintedfile{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmintedfile)) + +(defun LaTeX-minted-auto-prepare () + (setq LaTeX-minted-auto-newminted nil + LaTeX-minted-auto-newmint nil + LaTeX-minted-auto-newmintinline nil + LaTeX-minted-auto-newmintedfile nil)) + +(defun LaTeX-minted-auto-cleanup () + ;; (message "1: %s\n2: %s\n3: %s\n4: %s" + ;; LaTeX-minted-auto-newminted + ;; LaTeX-minted-auto-newmint + ;; LaTeX-minted-auto-newmintinline + ;; LaTeX-minted-auto-newmintedfile) + ;; Every \newminted{lang}{opts} defines a new langcode and a new langcode* + ;; env. The starred version has mandatory args. + (dolist (lang LaTeX-minted-auto-newminted) + (let* ((env (concat lang "code")) + (env* (concat env "*"))) + (add-to-list 'LaTeX-auto-environment (list env)) + (add-to-list 'LaTeX-auto-environment + (list env* 'LaTeX-env-args + '(TeX-arg-key-val LaTeX-minted-key-val-options))) + (add-to-list 'LaTeX-indent-environment-list `(,env current-indentation)) + (add-to-list 'LaTeX-indent-environment-list `(,env* current-indentation)) + (add-to-list 'LaTeX-verbatim-environments-local env) + (add-to-list 'LaTeX-verbatim-environments-local env*))) + (when (and (fboundp 'font-latex-add-keywords) + (fboundp 'font-latex-set-syntactic-keywords) + (eq TeX-install-font-lock 'font-latex-setup)) + ;; 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))) + +(add-hook 'TeX-auto-prepare-hook #'LaTeX-minted-auto-prepare t) +(add-hook 'TeX-auto-cleanup-hook #'LaTeX-minted-auto-cleanup t) + +(TeX-add-style-hook + "minted" + (lambda () + ;; New symbols + (TeX-add-symbols + '("mint" LaTeX-arg-minted-language TeX-arg-verb) + '("mintinline" LaTeX-arg-minted-language TeX-arg-verb) + '("listoflistings")) + + ;; 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"])) + + ;; Add to the auto parser + (TeX-auto-add-regexp LaTeX-minted-newminted-regexp) + (TeX-auto-add-regexp LaTeX-minted-newmint-regexp) + (TeX-auto-add-regexp LaTeX-minted-newmintinline-regexp) + (TeX-auto-add-regexp LaTeX-minted-newmintedfile-regexp) + + ;; Filling + (make-local-variable 'LaTeX-indent-environment-list) + (add-to-list 'LaTeX-indent-environment-list + '("minted" current-indentation)) + (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) + (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| + ;; so ideally the verbatim arg should be + ;; recognized. + "mint" "mintinline") + 'function) + ;; For syntactic fontification, e.g. verbatim constructs. + (font-latex-set-syntactic-keywords) + ;; Tell font-lock about the update. + (setq font-lock-set-defaults nil) + (font-lock-set-defaults))) + LaTeX-dialect) + +(defvar LaTeX-minted-package-options '("section" "chapter" "cache" + "outputdir" "cachedir" + "langlinenos") + "Package options for the minted package.") + +;;; minted.el ends here