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: Fri, 11 Mar 2022 12:13:34 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Jan Braun <Jan.Braun@klein-gallien.org> writes:

>> Am 10.03.2022 um 15:30 schrieb Arash Esbati <arash@gnu.org>:
>
>> The `current-indentation' never happens inside macrocode environment
>> because it's not recognized.  I haven't looked into details (yet), but
>> can others confirm this behavior?
>
> I can confirm this behaviour.

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

--8<---------------cut here---------------start------------->8---
diff --git a/latex.el b/latex.el
index d48522fe..bc5276fe 100644
--- a/latex.el
+++ b/latex.el
@@ -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)
+                       (or (string= (match-string-no-properties 2) "macrocode")
+                           (string= (match-string-no-properties 2) 
"macrocode*"))))
           (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg)))))
       (if (/= arg 0)
           "document"
--8<---------------cut here---------------end--------------->8---

In case someone wants to test this without applying the change, here to
function:

--8<---------------cut here---------------start------------->8---
(defun LaTeX-current-environment (&optional arg)
  "Return the name (a string) of the enclosing LaTeX environment.
With optional ARG>=1, find that outer level.

If function is called inside a comment and
`LaTeX-syntactic-comments' is enabled, try to find the
environment in commented regions with the same comment prefix.

The functions `LaTeX-find-matching-begin' and `LaTeX-find-matching-end'
work analogously."
  (setq arg (if arg (if (< arg 1) 1 arg) 1))
  (let* ((in-comment (TeX-in-commented-line))
         (comment-prefix (and in-comment (TeX-comment-prefix)))
         (case-fold-search nil))
    (save-excursion
      (while (and (/= arg 0)
                  (re-search-backward
                   "\\\\\\(begin\\|end\\) *{ *\\([A-Za-z*]+\\) *}" nil t))
        (when (or (and LaTeX-syntactic-comments
                       (eq in-comment (TeX-in-commented-line))
                       (or (not in-comment)
                           ;; Consider only matching prefixes in the
                           ;; commented case.
                           (string= comment-prefix (TeX-comment-prefix))))
                  (and (not LaTeX-syntactic-comments)
                       (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)
                       (or (string= (match-string-no-properties 2) "macrocode")
                           (string= (match-string-no-properties 2) 
"macrocode*"))))
          (setq arg (if (string= (match-string 1) "end") (1+ arg) (1- arg)))))
      (if (/= arg 0)
          "document"
        (match-string-no-properties 2)))))
--8<---------------cut here---------------end--------------->8---

Any comments welcome.

Best, Arash



reply via email to

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