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

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

[elpa] 23/299: * latex.el (LaTeX-env-document): Only insert \documentcla


From: Stefan Monnier
Subject: [elpa] 23/299: * latex.el (LaTeX-env-document): Only insert \documentclass in case the document does not already contain one.
Date: Sun, 02 Nov 2014 03:09:57 +0000

monnier pushed a commit to branch externals/auctex
in repository elpa.

commit 4dfd0f098c3dd015114d2596fe15ef5016c1f3cb
Author: Tassilo Horn <address@hidden>
Date:   Thu Jan 10 09:29:33 2013 +0000

    * latex.el (LaTeX-env-document): Only insert \documentclass in
    case the document does not already contain one.
---
 ChangeLog |    5 +++++
 latex.el  |   22 +++++++++++++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index fb2f088..5ce8d4b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2013-01-10  Mads Jensen  <address@hidden>
+
+       * latex.el (LaTeX-env-document): Only insert \documentclass in
+       case the document does not already contain one.
+
 2013-01-09  Ralf Angeli  <address@hidden>
 
        * style/epigraph.el ("epigraph"): Do not quote list entries for
diff --git a/latex.el b/latex.el
index 4f94cbf..fcff159 100644
--- a/latex.el
+++ b/latex.el
@@ -763,12 +763,24 @@ To insert a hook here, you must insert it in the 
appropiate style file.")
 
 (defun LaTeX-env-document (&optional ignore)
   "Create new LaTeX document.
+Also inserts a \\documentclass macro if there's none already
 The compatibility argument IGNORE is ignored."
-  (TeX-insert-macro "documentclass")
-  (LaTeX-newline)
-  (LaTeX-newline)
-  (LaTeX-newline)
-  (end-of-line 0)
+  ;; just assume a single valid \\documentclass, i.e., one not in a
+  ;; commented line
+  (let ((found nil))
+    (save-excursion
+      (while (and (not found)
+                 (re-search-backward
+                  
"\\\\documentclass\\(\\[[a-z0-9A-Z\-\_,]*\\]\\)?\\({[^}]+}\\)"
+                  nil t))
+       (and (not (TeX-in-commented-line))
+            (setq found t))))
+    (when (not found)
+      (TeX-insert-macro "documentclass")
+      (LaTeX-newline)
+      (LaTeX-newline)
+      (LaTeX-newline)
+      (end-of-line 0)))
   (LaTeX-insert-environment "document")
   (run-hooks 'LaTeX-document-style-hook)
   (setq LaTeX-document-style-hook nil))



reply via email to

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