Hi all,
I have some minor issues with respect to `LaTeX-find-matching-begin',
`LaTeX-find-matching-end' and `LaTeX-current-environment', which I'd
like to discuss.
1. I noticed that `LaTeX-find-matching-{begin,end}' doesn't work
correctly when the point is just after the asterisk of "\end{foo*}".
To confirm, put the point at "!" in the following example and
type M-: (LaTeX-find-matching-begin) RET or M-:
(LaTeX-find-matching-end) RET
----------------------------------------------------------------------
\documentclass{article}
\begin{document}
\begin{equation*}
abc = xyz
\end{equation*!}
\end{document}
----------------------------------------------------------------------
The attached patch fixes the starred variant case, but, as stated in
the FIXME comment, this simple fix doesn't yet work for the case
discussed in bug#19281[1]; When the point is after "\bar" of
"\end{\bar}", neither `LaTeX-find-matching-begin' nor
`LaTeX-find-matching-end' find the correct position. Should we handle
such exceptional cases, too?
2. `LaTeX-current-environment' has special support for macrocode*?
environments, but that support is absent in
`LaTeX-find-matching-{begin,end}':
----------------------------------------------------------------------
;; 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*"))))
----------------------------------------------------------------------
Is this intentional? Or should we add similar codes to
`LaTeX-find-matching-{begin,end}' as well? (I have little experience
with doctex mode, so am not sure what to do.)
3. The regexp used in `LaTeX-current-environment' is
----------------------------------------------------------------------
(re-search-backward
"\\\\\\(begin\\|end\\) *{\\([^}]+\\)}" nil t))
----------------------------------------------------------------------
so it doesn't handle the exceptional cases of bug#19281, namely
"\begin{\bar{xyz}}" and "\end{\bar{xyz}}". Should we cater for such
cases?
[1] https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19281
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
>From f33999550949549b4012e2d5e12be04e041bf4a3 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email protected]>
Date: Sun, 11 Dec 2022 16:08:50 +0900
Subject: [PATCH] Support starred variant name
* latex.el (LaTeX-find-matching-end):
(LaTeX-find-matching-begin):
Find correct begin or end when the point is just after the asterisk of
"\end{foo*}".
Remove spurious `regexp-quote' for `TeX-grop'.
---
latex.el | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/latex.el b/latex.el
index 04caaf53..24d285e4 100644
--- a/latex.el
+++ b/latex.el
@@ -5268,8 +5268,12 @@ environment in commented regions with the same comment prefix."
(in-comment (TeX-in-commented-line))
(comment-prefix (and in-comment (TeX-comment-prefix)))
(case-fold-search nil))
+ ;; FIXME: The following code until `while' handles exceptional
+ ;; cases that the point is on "\begin{foo}" or "\end{foo}".
+ ;; However, this assumes that environment names consist of a-zA-Z*
+ ;; and doesn't work for case discussed in bug#19281.
(let ((pt (point)))
- (skip-chars-backward (concat "a-zA-Z \t" (regexp-quote TeX-grop)))
+ (skip-chars-backward (concat "a-zA-Z* \t" TeX-grop))
(unless (bolp)
(backward-char 1)
(if (and (looking-at regexp)
@@ -5305,7 +5309,11 @@ environment in commented regions with the same comment prefix."
(in-comment (TeX-in-commented-line))
(comment-prefix (and in-comment (TeX-comment-prefix)))
(case-fold-search nil))
- (skip-chars-backward (concat "a-zA-Z \t" (regexp-quote TeX-grop)))
+ ;; FIXME: The following code until `while' handles exceptional
+ ;; cases that the point is on "\begin{foo}" or "\end{foo}".
+ ;; However, this assumes that environment names consist of a-zA-Z*
+ ;; and doesn't work for case discussed in bug#19281.
+ (skip-chars-backward (concat "a-zA-Z* \t" TeX-grop))
(unless (bolp)
(backward-char 1)
(and (looking-at regexp)
--
2.38.1