--- latex.el 22 Jun 2005 17:33:01 +0200 5.376 +++ latex.el 02 Jul 2005 12:36:19 +0200 @@ -600,17 +600,21 @@ "Insert LaTeX ENVIRONMENT with optional argument EXTRA." (let ((active-mark (and (TeX-active-mark) (not (eq (mark) (point))))) - comment-flag prefix) + comment-flag prefix point-at-end case-fold-search + (macrocode-p (string-match "\\`macrocode\\*?\\'" environment))) (when active-mark - (if (< (mark) (point)) + (if (setq point-at-end (< (mark) (point))) (exchange-point-and-mark))) (unless (TeX-looking-at-backward (if (and LaTeX-insert-into-comments - (TeX-in-commented-line) + (or macrocode-p (TeX-in-commented-line)) (not (bolp))) (concat "^[ \t]*" TeX-comment-start-regexp "+[ \t]*") "^[ \t]*")) - (LaTeX-newline)) + (if (and macrocode-p + (not (TeX-in-commented-line))) + (insert "\n%") + (LaTeX-newline))) ;; Insert a linebreak at the end of the marked region if necessary. ;; Do this before we insert anything which might alter the prefix. (when active-mark @@ -619,9 +623,12 @@ (unless (progn (skip-chars-forward " \t") (eolp)) ;; Use `(insert "\n")' instead of `(newline)' because in contrast ;; to Emacs, XEmacs moves the mark if `newline' is used. - (if (bolp) (insert "\n") (LaTeX-newline)) + (if macrocode-p + (insert "\n") + (LaTeX-newline)) (indent-according-to-mode)))) (when (and LaTeX-insert-into-comments + (not macrocode-p) (looking-at (concat "[ \t]*\\(" TeX-comment-start-regexp "+\\)"))) (setq comment-flag t) @@ -629,10 +636,12 @@ (insert TeX-esc "begin" TeX-grop environment TeX-grcl) (indent-according-to-mode) (if extra (insert extra)) - (LaTeX-newline) + (if macrocode-p + (insert "\n") + (LaTeX-newline)) (if active-mark (progn - (goto-char (mark)) + (exchange-point-and-mark) (unless (TeX-looking-at-backward (if (and LaTeX-insert-into-comments (TeX-in-commented-line) @@ -647,8 +656,11 @@ (indent-according-to-mode) (end-of-line 0) (if active-mark - (or (assoc environment LaTeX-indent-environment-list) - (LaTeX-fill-environment nil)) + (progn + (or (assoc environment LaTeX-indent-environment-list) + (LaTeX-fill-region (mark) (point) nil environment)) + (unless point-at-end + (exchange-point-and-mark))) (indent-according-to-mode))) (TeX-math-input-method-off))