[Top][All Lists]

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

[AUCTeX-devel] Adjusting filecontents env to new LaTeX

From: Arash Esbati
Subject: [AUCTeX-devel] Adjusting filecontents env to new LaTeX
Date: Tue, 15 Oct 2019 22:08:31 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/27.0.50

Hi all,

newest LaTeX has a change to filecontents environment:

    The filecontents environment now supports an optional argument in
    which you can specify that it is allowed to overwrite an already
    existing file; by default nothing is written if a file with the
    given name exists anywhere in the search tree. ...  Another change
    is that this environment is now allowed anywhere in the document,
    which means it provides everything (and more) of what the now
    obsolete filecontents package provided.

This means a change to `LaTeX-env-contents which can look like this:

diff --git a/latex.el b/latex.el
index 514ffbb1..0b64e1bd 100644
--- a/latex.el
+++ b/latex.el
@@ -1227,14 +1227,22 @@ Just like array and tabular."

 (defun LaTeX-env-contents (environment)
-  "Insert ENVIRONMENT with filename for contents."
-  (save-excursion
-    (when (re-search-backward LaTeX-header-end nil t)
-      (error "Put %s environment before \\begin{document}" environment)))
-  (LaTeX-insert-environment environment
-                           (concat TeX-grop
-                                   (TeX-read-string "File: ")
-                                   TeX-grcl))
+  "Insert ENVIRONMENT with optional argument and filename for contents."
+  (let* ((opt '("overwrite" "force" "nosearch"))
+        (arg (mapconcat #'identity
+                        (TeX-completing-read-multiple
+                         (TeX-argument-prompt t nil "Options")
+                         (if (string= environment "filecontents*")
+                             opt
+                           (cons "noheader" opt)))
+                        ",")))
+    (LaTeX-insert-environment environment
+                             (concat
+                              (when (and arg (not (string= arg "")))
+                                (concat LaTeX-optop arg LaTeX-optcl))
+                              TeX-grop
+                              (TeX-read-string "File: ")
+                              TeX-grcl)))

One last thing to clarify is how do we like to handle the content in the
environment?  I don't like to indent the content, so we could add
`filecontents' and `filecontents*' to `LaTeX-verbatim-environments'
which will also kill filling.  Other way is to add them to
`LaTeX-document-regexp' which would allow filling.

Any comments?

Best, Arash

reply via email to

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