branch: externals/auctex commit df97f94f70fc159ba8f5de774e1e29062aaac9a1 Author: Tassilo Horn <t...@gnu.org> Commit: Tassilo Horn <t...@gnu.org>
Improve minted style. * tex.el (TeX-parse-macro): Enclose arg in LaTeX-default-verb-delimiter if macro is in LaTeX-verbatim-macros-with-delims and there's only one argument. (TeX-auto-store): Check if LaTeX-verbatim-environments, LaTeX-verbatim-macros-with-delims, and LaTeX-verbatim-macros-with-braces are bound before using them. * style/minted.el (LaTeX-minted-newminted-regexp) (LaTeX-minted-newmint-regexp, LaTeX-minted-newmintinline-regexp) (LaTeX-minted-newmintedfile-regexp, LaTeX-minted-auto-cleanup): Extend to recognize optional env/macro name. ("minted"): Add \newminted, \newmint, \newmintinline, and \newmintedfile macros. --- ChangeLog | 16 ++++++++++ style/minted.el | 57 +++++++++++++++++++++++++++--------- tex.el | 86 +++++++++++++++++++++++++++++++----------------------- 3 files changed, 107 insertions(+), 52 deletions(-) diff --git a/ChangeLog b/ChangeLog index 641764b..429c6af 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2014-12-21 Tassilo Horn <t...@gnu.org> + + * tex.el (TeX-parse-macro): Enclose arg in + LaTeX-default-verb-delimiter if macro is in + LaTeX-verbatim-macros-with-delims and there's only one argument. + (TeX-auto-store): Check if LaTeX-verbatim-environments, + LaTeX-verbatim-macros-with-delims, and + LaTeX-verbatim-macros-with-braces are bound before using them. + + * style/minted.el (LaTeX-minted-newminted-regexp) + (LaTeX-minted-newmint-regexp, LaTeX-minted-newmintinline-regexp) + (LaTeX-minted-newmintedfile-regexp, LaTeX-minted-auto-cleanup): + Extend to recognize optional env/macro name. + ("minted"): Add \newminted, \newmint, \newmintinline, and + \newmintedfile macros. + 2014-12-20 Tassilo Horn <t...@gnu.org> * tex.el (TeX-auto-store): Write LaTeX-verbatim-*-local variables diff --git a/style/minted.el b/style/minted.el index dce725b..83d4764 100644 --- a/style/minted.el +++ b/style/minted.el @@ -108,19 +108,23 @@ ;; 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)) + '("\\\\newminted\\(?:\\[\\([^]]+\\)\\]\\)?{\\([^}]+\\)}{[^}]*}" + (1 2) LaTeX-minted-auto-newminted)) (defvar LaTeX-minted-auto-newmint nil) (defvar LaTeX-minted-newmint-regexp - '("\\\\newmint{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmint)) + '("\\\\newmint\\(?:\\[\\([^]]+\\)\\]\\)?{\\([^}]+\\)}{[^}]*}" + (1 2) LaTeX-minted-auto-newmint)) (defvar LaTeX-minted-auto-newmintinline nil) (defvar LaTeX-minted-newmintinline-regexp - '("\\\\newmintinline{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmintinline)) + '("\\\\newmintinline\\(?:\\[\\([^]]+\\)\\]\\)?{\\([^}]+\\)}{[^}]*}" + (1 2) LaTeX-minted-auto-newmintinline)) (defvar LaTeX-minted-auto-newmintedfile nil) (defvar LaTeX-minted-newmintedfile-regexp - '("\\\\newmintedfile{\\([^}]+\\)}{[^}]*}" 1 LaTeX-minted-auto-newmintedfile)) + '("\\\\newmintedfile\\(?:\\[\\([^]]+\\)\\]\\)?{\\([^}]+\\)}{[^}]*}" + (1 2) LaTeX-minted-auto-newmintedfile)) (defun LaTeX-minted-auto-prepare () (setq LaTeX-minted-auto-newminted nil @@ -130,8 +134,11 @@ (defun LaTeX-minted-auto-cleanup () ;; \newminted{lang}{opts} => new langcode and langcode* envs. - (dolist (lang LaTeX-minted-auto-newminted) - (let* ((env (concat lang "code")) + ;; \newminted[envname]{lang}{opts} => new envname/envname* envs. + (dolist (name-lang LaTeX-minted-auto-newminted) + (let* ((env (if (> (length (car name-lang)) 0) + (car name-lang) + (cadr name-lang))) (env* (concat env "*"))) (add-to-list 'LaTeX-auto-environment (list env)) (add-to-list 'LaTeX-auto-environment @@ -142,16 +149,28 @@ (add-to-list 'LaTeX-verbatim-environments-local env) (add-to-list 'LaTeX-verbatim-environments-local env*))) ;; \newmint{foo}{opts} => \foo|code| - (dolist (lang LaTeX-minted-auto-newmint) - (add-to-list 'TeX-auto-symbol lang) - (add-to-list 'LaTeX-verbatim-macros-with-delims-local lang)) + ;; \newmint[macname]{foo}{opts} => \macname|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 'LaTeX-verbatim-macros-with-delims-local lang))) ;; \newmintinline{foo}{opts} => \fooinline|code| - (dolist (lang LaTeX-minted-auto-newmintinline) - (add-to-list 'TeX-auto-symbol lang) - (add-to-list 'LaTeX-verbatim-macros-with-delims-local (concat lang "inline"))) + ;; \newmintinline[macname]{foo}{opts} => \macname|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} - (dolist (lang LaTeX-minted-auto-newmintedfile) - (add-to-list 'TeX-auto-symbol (list lang 'TeX-arg-file))) + ;; \newmintedfile[macname]{foo}{opts} => \macname{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)))) (when (and (fboundp 'font-latex-add-keywords) (fboundp 'font-latex-set-syntactic-keywords) (eq TeX-install-font-lock 'font-latex-setup)) @@ -170,7 +189,15 @@ (TeX-add-symbols '("mint" LaTeX-arg-minted-language TeX-arg-verb) '("mintinline" LaTeX-arg-minted-language TeX-arg-verb) - '("listoflistings")) + '("listoflistings") + '("newminted" ["Environment Name"] LaTeX-arg-minted-language + (TeX-arg-key-val LaTeX-minted-key-val-options)) + '("newmint" ["Macro Name"] LaTeX-arg-minted-language + (TeX-arg-key-val LaTeX-minted-key-val-options)) + '("newmintinline" ["Macro Name"] LaTeX-arg-minted-language + (TeX-arg-key-val LaTeX-minted-key-val-options)) + '("newmintedfile" ["Macro Name"] LaTeX-arg-minted-language + (TeX-arg-key-val LaTeX-minted-key-val-options))) ;; New environments (LaTeX-add-environments diff --git a/tex.el b/tex.el index 713a476..ac404e0 100644 --- a/tex.el +++ b/tex.el @@ -3031,42 +3031,51 @@ type of ARGS: parse it as a list, otherwise parse the only element as above. Use square brackets instead of curly braces, and is not inserted on empty user input." - - (if (and (TeX-active-mark) - (> (point) (mark))) - (exchange-point-and-mark)) - (insert TeX-esc symbol) - (let ((exit-mark (make-marker)) - (position (point))) - (TeX-parse-arguments args) - (cond ((marker-position exit-mark) - (goto-char (marker-position exit-mark)) - (set-marker exit-mark nil)) - ((let ((element (assoc symbol TeX-insert-braces-alist))) - ;; If in `TeX-insert-braces-alist' there is an element associated - ;; to the current macro, use its value to decide whether inserting - ;; a pair of braces, otherwise use the standard criterion. - (if element - (cdr element) - (and TeX-insert-braces - ;; Do not add braces if the argument is 0 or -1. - (not (and (= (safe-length args) 1) - (numberp (car args)) - (<= (car args) 0))) - (equal position (point)) - (string-match "[a-zA-Z]+" symbol)))) - (if (texmathp) - (when (TeX-active-mark) - (insert TeX-grop) - (exchange-point-and-mark) - (insert TeX-grcl)) - (insert TeX-grop) - (if (TeX-active-mark) - (progn + (let ((TeX-grop (if (and (or (atom args) (= (length args) 1)) + (fboundp 'LaTeX-verbatim-macros-with-delims) + (member symbol (LaTeX-verbatim-macros-with-delims))) + LaTeX-default-verb-delimiter + TeX-grop)) + (TeX-grcl (if (and (or (atom args) (= (length args) 1)) + (fboundp 'LaTeX-verbatim-macros-with-delims) + (member symbol (LaTeX-verbatim-macros-with-delims))) + LaTeX-default-verb-delimiter + TeX-grcl))) + (if (and (TeX-active-mark) + (> (point) (mark))) + (exchange-point-and-mark)) + (insert TeX-esc symbol) + (let ((exit-mark (make-marker)) + (position (point))) + (TeX-parse-arguments args) + (cond ((marker-position exit-mark) + (goto-char (marker-position exit-mark)) + (set-marker exit-mark nil)) + ((let ((element (assoc symbol TeX-insert-braces-alist))) + ;; If in `TeX-insert-braces-alist' there is an element associated + ;; to the current macro, use its value to decide whether inserting + ;; a pair of braces, otherwise use the standard criterion. + (if element + (cdr element) + (and TeX-insert-braces + ;; Do not add braces if the argument is 0 or -1. + (not (and (= (safe-length args) 1) + (numberp (car args)) + (<= (car args) 0))) + (equal position (point)) + (string-match "[a-zA-Z]+" symbol)))) + (if (texmathp) + (when (TeX-active-mark) + (insert TeX-grop) (exchange-point-and-mark) (insert TeX-grcl)) - (insert TeX-grcl) - (backward-char))))))) + (insert TeX-grop) + (if (TeX-active-mark) + (progn + (exchange-point-and-mark) + (insert TeX-grcl)) + (insert TeX-grcl) + (backward-char)))))))) (defun TeX-arg-string (optional &optional prompt initial-input) "Prompt for a string. @@ -3700,9 +3709,12 @@ If TEX is a directory, generate style files for all files in the directory." LaTeX-provided-class-options)) (pkg-opts (if (boundp 'LaTeX-provided-package-options) LaTeX-provided-package-options)) - (verb-envs LaTeX-verbatim-environments-local) - (verb-macros-delims LaTeX-verbatim-macros-with-delims-local) - (verb-macros-braces LaTeX-verbatim-macros-with-braces-local)) + (verb-envs (when (boundp 'LaTeX-verbatim-environments-local) + LaTeX-verbatim-environments-local)) + (verb-macros-delims (when (boundp 'LaTeX-verbatim-macros-with-delims-local) + LaTeX-verbatim-macros-with-delims-local)) + (verb-macros-braces (when (boundp 'LaTeX-verbatim-macros-with-braces-local) + LaTeX-verbatim-macros-with-braces-local))) (TeX-unload-style style) (with-current-buffer (generate-new-buffer file) (erase-buffer)