Well, I have just written the following patch, and it is butt-ugly.
Anybody with a better proposal?  One thing to note is that it does not
make sense to insert an empty line after the reopening \begin{...}.
This should rather be done where point ends up.

On a different tack, when doing C-c C-e to insert a macrocode
environment, I end up with

%    \begin{macrocode}
% <-cursor
%    \end{macrocode}

This should rather be

%    \begin{macrocode}
<-cursor at appropriate indentation from last macrocode
%    \end{macrocode}

And an _another_ note, insertion of macrocode environments should
ignore whether I am already in outcommented lines or not and insert in
outcommented form.  Wait, it apparently already does that, except for
the inserted line in the middle, the one that ends up with the cursor
on it.  But it should do so there as well, I guess.

--- latex.el	13 Oct 2005 00:56:32 +0200	5.387
+++ latex.el	14 Oct 2005 04:55:52 +0200	
@@ -572,9 +572,10 @@
 	  (t
 	   (apply (nth 1 entry) environment (nthcdr 2 entry))))))
 
-(defun LaTeX-close-environment ()
-  "Create an \\end{...} to match the current environment."
-  (interactive "*")
+(defun LaTeX-close-environment (&optional reopen)
+  "Create an \\end{...} to match the current environment.
+With prefix-argument, reopen environment afterwards."
+  (interactive "*P")
   (if (> (point)
 	 (save-excursion
 	   (beginning-of-line)
@@ -584,17 +585,25 @@
 	   (skip-chars-forward " \t")
 	   (point)))
       (LaTeX-newline))
-  (insert "\\end{" (LaTeX-current-environment 1) "}")
-  (indent-according-to-mode)
-  (if (or (not (looking-at "[ \t]*$"))
-	  (and (TeX-in-commented-line)
-	       (save-excursion (beginning-of-line 2)
-			       (not (TeX-in-commented-line)))))
-      (LaTeX-newline)
-    (let ((next-line-add-newlines t))
-      (next-line 1)
-      (beginning-of-line)))
-  (indent-according-to-mode))
+  (let ((environment (LaTeX-current-environment 1)) marker)
+    (insert "\\end{" environment "}")
+    (indent-according-to-mode)
+    (if (or (not (looking-at "[ \t]*$"))
+	    (and (TeX-in-commented-line)
+		 (save-excursion (beginning-of-line 2)
+				 (not (TeX-in-commented-line)))))
+	(LaTeX-newline)
+      (let ((next-line-add-newlines t))
+	(next-line 1)
+	(beginning-of-line)))
+    (indent-according-to-mode)
+    (when reopen
+      (save-excursion
+	(setq marker (point-marker))
+	(set-marker-insertion-type marker t)
+	(LaTeX-environment-menu environment)
+	(delete-region (point) marker)
+	(move-marker marker nil)))))
 
 (defun LaTeX-insert-environment (environment &optional extra)
   "Insert LaTeX ENVIRONMENT with optional argument EXTRA."

-- 
David Kastrup, Kriemhildstr. 15, 44793 Bochum
_______________________________________________
auctex-devel mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/auctex-devel

Reply via email to