1 ;;; environ.el --- AUCTeX style for `environ.sty' version v0.3
3 ;; Copyright (C) 2015, 2016 Free Software Foundation, Inc.
5 ;; Author: Arash Esbati <arash@gnu.org>
6 ;; Maintainer: auctex-devel@gnu.org
10 ;; This file is part of AUCTeX.
12 ;; AUCTeX is free software; you can redistribute it and/or modify it
13 ;; under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; AUCTeX is distributed in the hope that it will be useful, but
18 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 ;; General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with AUCTeX; see the file COPYING. If not, write to the Free
24 ;; Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
29 ;; This file adds support for `environ.sty' version v0.3 from
30 ;; 2014/05/04. `environ.sty' is part of TeXLive.
32 ;; Name of new env's defined with `\NewEnviron' are automatically
33 ;; added to list of known env's, e.g.:
35 ;; \NewEnviron{test}{<macro code>}
37 ;; `test' will be in completion list upon `C-c C-e'.
39 ;; More sophisticated definions must go through AUCTeX's parser, e.g.:
41 ;; \NewEnviron{test}[2][]{<macro code>}
43 ;; After a definition like this, you have to invoke `C-c C-n' to get
44 ;; the correct completion.
48 (defvar LaTeX-auto-environ-NewEnviron nil
49 "Temporary for parsing the arguments of `\\NewEnviron'
50 from `environ' package.")
52 (defvar LaTeX-environ-NewEnviron-regexp
53 `(,(concat "\\\\\\(?:Ren\\|N\\)ewEnviron"
54 "[ \t\n\r]*{\\([A-Za-z0-9]+\\)}%?"
55 "[ \t\n\r]*\\[?\\([0-9]?\\)\\]?%?"
56 "[ \t\n\r]*\\(\\[\\)?")
57 (1 2 3) LaTeX-auto-environ-NewEnviron)
58 "Matches the argument of `\\NewEnviron' and `\\RenewEnviron'
61 (defun LaTeX-environ-auto-prepare ()
62 "Clear temporary variable from `environ.sty' before parsing."
63 (setq LaTeX-auto-environ-NewEnviron nil))
65 (defun LaTeX-environ-auto-cleanup ()
66 "Process the parsed results of `\\NewEnviron'."
67 (dolist (env-args LaTeX-auto-environ-NewEnviron)
68 (let ((env (car env-args))
69 (args (cadr env-args))
70 (opt (nth 2 env-args)))
71 (cond (;; opt. 1st argument and mandatory argument(s)
72 (and args (not (string-equal args ""))
73 opt (not (string-equal opt "")))
74 (add-to-list 'LaTeX-auto-environment
75 (list env 'LaTeX-env-args (vector "argument")
76 (1- (string-to-number args)))))
77 (;; mandatory argument(s) only
78 (and args (not (string-equal args ""))
79 (string-equal opt ""))
80 (add-to-list 'LaTeX-auto-environment
81 (list env (string-to-number args))))
83 (add-to-list 'LaTeX-auto-environment (list env)))))))
85 (add-hook 'TeX-auto-prepare-hook #'LaTeX-environ-auto-prepare t)
86 (add-hook 'TeX-auto-cleanup-hook #'LaTeX-environ-auto-cleanup t)
87 (add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
89 (defun TeX-arg-environ-final-code (_optional)
90 "Query for the presence of optional `final code' as argument to
91 `\\NewEnviron' and insert the appropriate brackets."
92 (let ((fincode (y-or-n-p "With optional final code? ")))
100 ;; Add it to the parser
101 (TeX-auto-add-regexp LaTeX-environ-NewEnviron-regexp)
105 ;; \NewEnviron{<name>}[<No.args>][<Opt.arg.>]{<Macro code>}[<Final code>]
107 (TeX-arg-define-environment "Environment")
108 [ "Number of arguments" ] [ "argument" ] t TeX-arg-environ-final-code)
111 (TeX-arg-environment "Environment")
112 [ "Number of arguments" ] [ "argument" ] t TeX-arg-environ-final-code)
114 ;; Insert a pair of braces and we're done
115 '("environfinalcode" t)
120 ;; Define another macro instead of \BODY
121 '("environbodyname" TeX-arg-define-macro))
124 (when (and (featurep 'font-latex)
125 (eq TeX-install-font-lock 'font-latex-setup))
126 (font-latex-add-keywords '(("NewEnviron" "{[[{[")
127 ("RenewEnviron" "{[[{[")
128 ("environbodyname" "|{\\"))
132 (defvar LaTeX-environ-package-options nil
133 "Package options for the environ package.")
135 ;;; environ.el ends here