emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex d27e773 21/28: Add new style environ.el.


From: Tassilo Horn
Subject: [elpa] externals/auctex d27e773 21/28: Add new style environ.el.
Date: Fri, 07 Aug 2015 15:59:25 +0000

branch: externals/auctex
commit d27e77316a03c8f1fab9ad403ad349724c2d7b6c
Author: Arash Esbati <address@hidden>
Commit: Mosè Giordano <address@hidden>

    Add new style environ.el.
    
    Signed-off-by: Mosè Giordano <address@hidden>
---
 ChangeLog        |    4 ++
 Makefile.in      |    2 +-
 style/environ.el |  127 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 132 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6eca23d..13d1120 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2015-07-18  Arash Esbati  <address@hidden>
 
+       * Makefile.in (STYLESRC): Add new style.
+
+       * style/environ.el: New file.
+
        * style/tabulary.el ("tabulary"): Add `LCRJ' to
        `LaTeX-array-column-letters'.
 
diff --git a/Makefile.in b/Makefile.in
index 290462c..0552e52 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -149,7 +149,7 @@ STYLESRC = style/prosper.el \
           style/geometry.el  style/ltablex.el   style/ltxtable.el \
           style/mn2e.el      style/colortbl.el  style/attachfile.el \
           style/newpxtext.el style/newpxmath.el style/pdfpages.el \
-          style/mnras.el
+          style/mnras.el     style/environ.el
 
 STYLEELC = $(STYLESRC:.el=.elc)
 
diff --git a/style/environ.el b/style/environ.el
new file mode 100644
index 0000000..bac82fc
--- /dev/null
+++ b/style/environ.el
@@ -0,0 +1,127 @@
+;;; environ.el --- AUCTeX style for `environ.sty' version v0.3
+
+;; Copyright (C) 2015 Free Software Foundation, Inc.
+
+;; Author: Arash Esbati <esbati'at'gmx.de>
+;; Maintainer: address@hidden
+;; Created: 2015-07-04
+;; 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 `environ.sty' version v0.3 from
+;; 2014/05/04.  `environ.sty' is part of TeXLive.
+
+;; Name of new env's defined with `\NewEnviron' are automatically
+;; added to list of known env's, e.g.:
+;;
+;;     \NewEnviron{test}{<macro code>}
+;;
+;; `test' will be in completion list upon `C-c C-e'.
+
+;; More sophisticated definions must go through AUCTeX's parser, e.g.:
+;;
+;;     \NewEnviron{test}[2][]{<macro code>}
+;;
+;; After a definition like this, you have to invoke `C-c C-n' to get
+;; the correct completion.
+
+;;; Code:
+
+(defvar LaTeX-auto-environ-NewEnviron nil
+  "Temporary for parsing the arguments of `\\NewEnviron'
+from `environ' package.")
+
+(defvar LaTeX-environ-NewEnviron-regexp
+  `(,(concat "\\\\\\(?:Ren\\|N\\)ewEnviron"
+            "[ \t\n\r]*{\\([A-Za-z0-9]+\\)}%?"
+            "[ \t\n\r]*\\[?\\([0-9]?\\)\\]?%?"
+            "[ \t\n\r]*\\(\\[\\)?")
+    (1 2 3) LaTeX-auto-environ-NewEnviron)
+  "Matches the argument of `\\NewEnviron' and `\\RenewEnviron'
+from `environ.sty'.")
+
+(defun LaTeX-environ-auto-prepare ()
+  "Clear temporary variable from `environ.sty' before parsing."
+  (setq LaTeX-auto-environ-NewEnviron nil))
+
+(defun LaTeX-environ-auto-cleanup ()
+  "Process the parsed results of `\\NewEnviron'."
+  (dolist (env-args LaTeX-auto-environ-NewEnviron)
+    (let ((env  (car   env-args))
+         (args (cadr  env-args))
+         (opt  (nth 2 env-args)))
+      (cond (;; opt. 1st argument and mandatory argument(s)
+            (and args (not (string-equal args ""))
+                 opt  (not (string-equal opt  "")))
+            (add-to-list 'LaTeX-auto-environment
+                         (list env 'LaTeX-env-args (vector "argument")
+                               (1- (string-to-number args)))))
+           (;; mandatory argument(s) only
+            (and args (not (string-equal args ""))
+                 (string-equal opt ""))
+            (add-to-list 'LaTeX-auto-environment
+                         (list env (string-to-number args))))
+           (t ; No args
+            (add-to-list 'LaTeX-auto-environment (list env)))))))
+
+(add-hook 'TeX-auto-prepare-hook #'LaTeX-environ-auto-prepare t)
+(add-hook 'TeX-auto-cleanup-hook #'LaTeX-environ-auto-cleanup t)
+(add-hook 'TeX-update-style-hook #'TeX-auto-parse t)
+
+(defun TeX-arg-environ-final-code (_optional)
+  "Query for the presence of optional `final code' as argument to
+`\\NewEnviron' and insert the appropriate brackets."
+  (let ((fincode (y-or-n-p "With optional final code?")))
+    (when fincode
+       (insert "[]"))))
+
+(TeX-add-style-hook
+ "environ"
+ (lambda ()
+
+   ;; Add it to the parser
+   (TeX-auto-add-regexp LaTeX-environ-NewEnviron-regexp)
+
+   (TeX-add-symbols
+
+    ;; \NewEnviron{<name>}[<No.args>][<Opt.arg.>]{<Macro code>}[<Final code>]
+    '("NewEnviron"
+      (TeX-arg-define-environment "Environment")
+      [ "Number of arguments" ] [ "argument" ] t TeX-arg-environ-final-code)
+
+    '("RenewEnviron"
+      (TeX-arg-environment "Environment")
+      [ "Number of arguments" ] [ "argument" ] t TeX-arg-environ-final-code)
+
+    ;; Insert a pair of braces and we're done
+    '("environfinalcode" t)
+
+    ;; Pre-defined
+    '("BODY")
+
+    ;; Define another macro instead of \BODY
+    '("environbodyname" TeX-arg-define-macro)))
+  LaTeX-dialect)
+
+(defvar LaTeX-environ-package-options nil
+  "Package options for the environ package.")
+
+;;; environ.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]