[Top][All Lists]

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

Re: [AUCTeX-devel] Adjusting filecontents env to new LaTeX

From: jfbu
Subject: Re: [AUCTeX-devel] Adjusting filecontents env to new LaTeX
Date: Wed, 16 Oct 2019 10:27:16 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:60.0) Gecko/20100101 Thunderbird/60.9.0

Le 15/10/2019 à 22:08, Arash Esbati a écrit :
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?
Hi Arash,
simply to approve that indeed the contents should not get indented
as spaces at start of lines will be obeyed in written-to-disk file
(spaces at end of lines disappear because TeX discards them
when tokenizing the line)

reply via email to

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