auctex-devel
[Top][All Lists]
Advanced

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

Re: LaTeX-current-environment in macrocode environment


From: Arash Esbati
Subject: Re: LaTeX-current-environment in macrocode environment
Date: Sat, 12 Mar 2022 20:41:14 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Arash Esbati <arash@gnu.org> writes:

> Thanks for the feedback.  My current suggestion to fix this is the
> following change:

Following up myself, another issue occurred to me.  Please consider this
valid LaTeX code:

--8<---------------cut here---------------start------------->8---
\documentclass[a4paper]{article}

\newenvironment{ foo3 }{\bfseries}{}

\begin{document}

\noindent
Some text and%
\begin{ foo3 }
  (LaTeX-current-environment) returns
\end{ foo3 }
\verb|document|

\end{document}

%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---

Our current implementation for `LaTeX-current-environment' doesn't
recognize the env ' foo3 ' -- note that spaces and other non-letter
characters are allowed in env names.  Hence, my suggestion for the
change looks like this:

--8<---------------cut here---------------start------------->8---
diff --git a/latex.el b/latex.el
index d48522fe..71d27889 100644
--- a/latex.el
+++ b/latex.el
@@ -917,7 +917,7 @@ work analogously."
     (save-excursion
       (while (and (/= arg 0)
                   (re-search-backward
-                   "\\\\\\(begin\\|end\\) *{ *\\([A-Za-z*]+\\) *}" nil t))
+                   "\\\\\\(begin\\|end\\) *{\\([^}]+\\)}" nil t))
         (when (or (and LaTeX-syntactic-comments
                        (eq in-comment (TeX-in-commented-line))
                        (or (not in-comment)
@@ -925,7 +925,15 @@ work analogously."
                            ;; commented case.
                            (string= comment-prefix (TeX-comment-prefix))))
                   (and (not LaTeX-syntactic-comments)
-                       (not (TeX-in-commented-line))))
+                       (not (TeX-in-commented-line)))
+                  ;; macrocode*? in docTeX-mode is special since we
+                  ;; have also regular code lines not starting with a
+                  ;; comment-prefix.  Hence the next check just looks
+                  ;; if we're inside such a group and returns t to
+                  ;; recognize such a situation.
+                  (and (eq major-mode 'doctex-mode)
+                       (member (match-string-no-properties 2)
+                               '("macrocode" "macrocode*"))))
           (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg)))))
       (if (/= arg 0)
           "document"
--8<---------------cut here---------------end--------------->8---

Any comments welcome.

Best, Arash



reply via email to

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