emacs-bug-tracker
[Top][All Lists]
Advanced

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

bug#65824: closed (Indent after open delimiters in verb constructs)


From: GNU bug Tracking System
Subject: bug#65824: closed (Indent after open delimiters in verb constructs)
Date: Fri, 15 Sep 2023 08:19:02 +0000

Your message dated Fri, 15 Sep 2023 10:17:43 +0200
with message-id <86led7j1eg.fsf@gnu.org>
and subject line Re: bug#65824: Indent after open delimiters in verb constructs
has caused the debbugs.gnu.org bug report #65824,
regarding Indent after open delimiters in verb constructs
to be marked as done.

(If you believe you have received this mail in error, please contact
help-debbugs@gnu.org.)


-- 
65824: https://debbugs.gnu.org/cgi/bugreport.cgi?bug=65824
GNU Bug Tracking System
Contact help-debbugs@gnu.org with problems
--- Begin Message --- Subject: Indent after open delimiters in verb constructs Date: Fri, 08 Sep 2023 17:44:26 +0200 User-agent: Gnus/5.13 (Gnus v5.13)
Hi all,

please consider this small file:

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

\begin{document}

\verb|foo{bar|
foo
bar
baz
\end{document}
--8<---------------cut here---------------end--------------->8---

Now do 'M-x mark-whole-buffer RET M-x indent-region RET' and you get:

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

\begin{document}

\verb|foo{bar|
  foo
  bar
  baz
\end{document}
--8<---------------cut here---------------end--------------->8---

I think the issue is within `TeX-brace-count-line' which doesn't look
for opening/closing delimiters in verbatim text.  My simple minded
solution looks like this:

--8<---------------cut here---------------start------------->8---
diff --git a/tex.el b/tex.el
index a85b8ef9..30118384 100644
--- a/tex.el
+++ b/tex.el
@@ -5485,21 +5485,22 @@ additional characters."
                                           '(?\{ ?\} ?\\))
                                     (TeX-in-comment))))
                  (forward-char)
-                 (cond ((memq char (append
-                                    TeX-indent-open-delimiters
-                                    '(?\{)))
-                        (setq count (+ count TeX-brace-indent-level)))
-                       ((memq char (append
-                                    TeX-indent-close-delimiters
-                                    '(?\})))
-                        (setq count (- count TeX-brace-indent-level)))
-                       ((eq char ?\\)
-                        (when (< (point) limit)
-                          ;; ?\\ in verbatim constructs doesn't escape
-                          ;; the next char
-                          (unless (TeX-verbatim-p)
-                            (forward-char))
-                          t))))))
+                 ;; If inside a verbatim construct, just return t and
+                 ;; proceed, otherwise start counting:
+                 (if (TeX-verbatim-p)
+                     t
+                   (cond ((memq char (append
+                                      TeX-indent-open-delimiters
+                                      '(?\{)))
+                          (setq count (+ count TeX-brace-indent-level)))
+                         ((memq char (append
+                                      TeX-indent-close-delimiters
+                                      '(?\})))
+                          (setq count (- count TeX-brace-indent-level)))
+                         ((eq char ?\\)
+                          (when (< (point) limit)
+                            (forward-char)
+                            t)))))))
       count)))

 ;;; Navigation
--8<---------------cut here---------------end--------------->8---

Any better ideas how to do this?  My only concern is that
`LaTeX-verbatim-p' (which is used by `TeX-verbatim-p') uses
`save-match-data' which is known to be expensive.  I don't have any
benchmarks, but there might be performance hit when indenting/filling
large portions of text.

Best, Arash



--- End Message ---
--- Begin Message --- Subject: Re: bug#65824: Indent after open delimiters in verb constructs Date: Fri, 15 Sep 2023 10:17:43 +0200 User-agent: Gnus/5.13 (Gnus v5.13)
Hi Keita,

Ikumi Keita <ikumi@ikumi.que.jp> writes:

> Hmm, it really matters, I think there are two actions that we can take:
> 1. Remove `save-match-data' from `LaTeX-verbatim-p' and announce the
>    removal in changes.texi. Grepping over the current source briefly,
>    the only usage of (La)TeX-verbatim-p that needs to preserve the match
>    data is `LaTeX-search-forward-comment-start'. So wrapping it with
>    `save-match-data' in that function is easy. (In addition,
>    `LaTeX-search-forward-comment-start' is only used as a value of
>    `TeX-search-forward-comment-start-function', which is only used in
>    `TeX-search-forward-comment-start', which isn't used at all now.)
> 2. Implement LaTeX mode function for `indent-region'. Now AUCTeX has
>    "line-by-line" indent function only, but there are apparent overheads
>    when AUCTeX indents a region. We could implement region-oriented
>    indent function which works with less overheads.

Thanks for your response.  I pushed that change (a228137f66).  I'd say
let's wait and see if users complain about any performance regressions,
we can then implement one of your suggestions above.

For now, I'm closing this report.

Best, Arash


--- End Message ---

reply via email to

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