GNU bug report logs - #69346
13.2; newcommand arguments affecting indentation

Previous Next

Package: auctex;

Reported by: Paul Nelson <ultrono <at> gmail.com>

Date: Sat, 24 Feb 2024 08:44:01 UTC

Severity: normal

Tags: notabug

Found in version 13.2

Done: Arash Esbati <arash <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 69346 in the body.
You can then email your comments to 69346 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-auctex <at> gnu.org:
bug#69346; Package auctex. (Sat, 24 Feb 2024 08:44:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Paul Nelson <ultrono <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-auctex <at> gnu.org. (Sat, 24 Feb 2024 08:44:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: bug-auctex <at> gnu.org
Subject: 13.2; newcommand arguments affecting indentation
Date: Sat, 24 Feb 2024 09:42:52 +0100
[Message part 1 (text/plain, inline)]
Create a tex file with the following contents:

\newcommand{\ifs}{\text{if }}
\newcommand{\foo}{\text{foo}}

M-x mark-whole-buffer, M-x indent-region yields the following:

\newcommand{\ifs}{\text{if }}
  \newcommand{\foo}{\text{foo}}

The issue is that LaTeX-indent-level-count returns 2 for the first
line, while it should return 0.  This is ultimately because
LaTeX-indent-begin-regexp-local matches the "'\ifs" newcommand
argument, which LaTeX-indent-level-count views as belonging to the
family of \if* tex commands that would normally result in an
indentation.

It seems to me that one could fix this by skipping over the first
argument of \newcommand in LaTeX-indent-level-count.  The attached
patch is my best attempt at implementing this.

There may be a more robust solution, e.g., involving more
constructions than just "\newcommand", but I haven't thought about
that.



Emacs  : GNU Emacs 30.0.50 (build 4, aarch64-apple-darwin23.2.0, NS
appkit-2487.30 Version 14.2.1 (Build 23C71))
 of 2024-02-06
Package: 13.2

current state:
==============
(setq
 AUCTeX-date "2023-10-10"
 window-system 'ns
 LaTeX-version "2e"
 TeX-style-path '("/usr/local/var/auctex"
                  "/Users/au710211/.emacs.d/elpaca/builds/auctex/auctex/style"
                  "/Users/au710211/.emacs.d/auctex/auto"
                  "/Users/au710211/.emacs.d/auctex/style" "auto" "style")
 TeX-auto-save t
 TeX-parse-self t
 TeX-master "~/doit/preview-master.tex"
 TeX-command-list '(("TeX"
                     "%(PDF)%(tex) %(file-line-error) %`%(extraopts)
%S%(PDFout)%(mode)%' %(output-dir) %t"
                     TeX-run-TeX nil (plain-tex-mode ams-tex-mode
texinfo-mode) :help
                     "Run plain TeX")
                    ("LaTeX" "%`%l%(mode)%' %T" TeX-run-TeX nil
(latex-mode doctex-mode)
                     :help "Run LaTeX")
                    ("Makeinfo" "makeinfo %(extraopts) %(o-dir) %t"
TeX-run-compile nil
                     (texinfo-mode) :help "Run Makeinfo with Info output")
                    ("Makeinfo HTML" "makeinfo %(extraopts) %(o-dir) --html %t"
                     TeX-run-compile nil (texinfo-mode) :help
                     "Run Makeinfo with HTML output")
                    ("AmSTeX" "amstex %(PDFout) %`%(extraopts)
%S%(mode)%' %(output-dir) %t"
                     TeX-run-TeX nil (ams-tex-mode) :help "Run AMSTeX")
                    ("ConTeXt" "%(cntxcom) --once --texutil
%(extraopts) %(execopts)%t"
                     TeX-run-TeX nil (context-mode) :help "Run ConTeXt once")
                    ("ConTeXt Full" "%(cntxcom) %(extraopts)
%(execopts)%t" TeX-run-TeX nil
                     (context-mode) :help "Run ConTeXt until completion")
                    ("BibTeX" "bibtex %(O?aux)" TeX-run-BibTeX nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode
                      context-mode)
                     :help "Run BibTeX")
                    ("Biber" "biber %(output-dir) %s" TeX-run-Biber nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run Biber")
                    ("Texindex" "texindex %s.??" TeX-run-command nil
(texinfo-mode) :help
                     "Run Texindex")
                    ("Texi2dvi" "%(PDF)texi2dvi %t" TeX-run-command
nil (texinfo-mode) :help
                     "Run Texi2dvi or Texi2pdf")
                    ("View" "%V" TeX-run-discard-or-function t t :help
"Run Viewer")
                    ("Print" "%p" TeX-run-command t t :help "Print the file")
                    ("Queue" "%q" TeX-run-background nil t :help "View
the printer queue"
                     :visible TeX-queue-command)
                    ("File" "%(o?)dvips %d -o %f " TeX-run-dvips t
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Generate PostScript file")
                    ("Dvips" "%(o?)dvips %d -o %f " TeX-run-dvips nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert DVI file to PostScript")
                    ("Dvipdfmx" "dvipdfmx -o %(O?pdf) %d" TeX-run-dvipdfmx nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert DVI file to PDF with dvipdfmx")
                    ("Ps2pdf" "ps2pdf %f %(O?pdf)" TeX-run-ps2pdf nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Convert PostScript file to PDF")
                    ("Glossaries" "makeglossaries %(d-dir) %s"
TeX-run-command nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run makeglossaries to create glossary file")
                    ("Index" "makeindex %(O?idx)" TeX-run-index nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run makeindex to create index file")
                    ("upMendex" "upmendex %(O?idx)" TeX-run-index t
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run upmendex to create index file")
                    ("Xindy" "texindy %s" TeX-run-command nil
                     (plain-tex-mode latex-mode doctex-mode
ams-tex-mode texinfo-mode) :help
                     "Run xindy to create index file")
                    ("Check" "lacheck %s" TeX-run-compile nil (latex-mode) :help
                     "Check LaTeX file for correctness")
                    ("ChkTeX" "chktex -v6 %s" TeX-run-compile nil
(latex-mode) :help
                     "Check LaTeX file for common mistakes")
                    ("Spell" "(TeX-ispell-document \"\")"
TeX-run-function nil t :help
                     "Spell-check the document")
                    ("Clean" "TeX-clean" TeX-run-function nil t :help
                     "Delete generated intermediate files")
                    ("Clean All" "(TeX-clean t)" TeX-run-function nil t :help
                     "Delete generated intermediate and output files")
                    ("Other" "" TeX-run-command t t :help "Run an
arbitrary command"))
 )
[0001-fix-indentation-issue-involving-newcommand.patch (application/octet-stream, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#69346; Package auctex. (Sat, 24 Feb 2024 09:56:02 GMT) Full text and rfc822 format available.

Message #8 received at 69346 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: 69346 <at> debbugs.gnu.org
Subject: bug#69346: 13.2; newcommand arguments affecting indentation
Date: Sat, 24 Feb 2024 10:40:41 +0100
[Message part 1 (text/plain, inline)]
It occurred to me that a better solution would be to constrain the
"if*" commands matched by the regexp produced by
LaTeX-indent-commands-regexp-make.  My earlier patch fixed the
preamble definition, which was all that mattered for the specific tex
file that I was editing, but it is more natural to simultaneously fix
any uses of such commands.  I've attached a patch which gives my best
attempt at doing this (no claim of optimality).
[0001-fix-indentation-issue-involving-user-defined-if-comm.patch (application/octet-stream, attachment)]

Information forwarded to bug-auctex <at> gnu.org:
bug#69346; Package auctex. (Sat, 24 Feb 2024 22:57:02 GMT) Full text and rfc822 format available.

Message #11 received at 69346 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 69346 <at> debbugs.gnu.org
Subject: Re: bug#69346: 13.2; newcommand arguments affecting indentation
Date: Sat, 24 Feb 2024 23:40:24 +0100
Paul Nelson <ultrono <at> gmail.com> writes:

> It occurred to me that a better solution would be to constrain the
> "if*" commands matched by the regexp produced by
> LaTeX-indent-commands-regexp-make.  My earlier patch fixed the
> preamble definition, which was all that mattered for the specific tex
> file that I was editing, but it is more natural to simultaneously fix
> any uses of such commands.  I've attached a patch which gives my best
> attempt at doing this (no claim of optimality).

Hi Paul,

the issue with your suggestion is that it is too rigid and doesn't work
for definitions like:

--8<---------------cut here---------------start------------->8---
\newif\iffoo <at> bar
\iffoo <at> bar
  do this
\else
  do that
\fi
--8<---------------cut here---------------end--------------->8---

AUCTeX already tries to provide a solution for your problem, namely, the
variable `LaTeX-indent-begin-exceptions-list'.  You can add your defined
macro on a per file basis with the local variables like this:

--8<---------------cut here---------------start------------->8---
%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% eval: (add-to-list 'LaTeX-indent-begin-exceptions-list "ifs")
%%% End:
--8<---------------cut here---------------end--------------->8---

Personally, I would define this one macro like this and avoid the
hassle:

--8<---------------cut here---------------start------------->8---
\expandafter\newcommand\csname ifs\endcsname{%
  \text{if }%
}
--8<---------------cut here---------------end--------------->8---

Or simply rename the macro to `\italicif' or something that doesn't
start if 'if'.

Best, Arash




Information forwarded to bug-auctex <at> gnu.org:
bug#69346; Package auctex. (Sun, 25 Feb 2024 08:26:01 GMT) Full text and rfc822 format available.

Message #14 received at 69346 <at> debbugs.gnu.org (full text, mbox):

From: Paul Nelson <ultrono <at> gmail.com>
To: Arash Esbati <arash <at> gnu.org>
Cc: 69346 <at> debbugs.gnu.org
Subject: Re: bug#69346: 13.2; newcommand arguments affecting indentation
Date: Sun, 25 Feb 2024 09:24:02 +0100
Hi Arash,

Thanks, that makes sense, and LaTeX-indent-begin-exceptions-list
indeed addresses the issue.

Paul




Information forwarded to bug-auctex <at> gnu.org:
bug#69346; Package auctex. (Sun, 25 Feb 2024 14:04:01 GMT) Full text and rfc822 format available.

Message #17 received at 69346 <at> debbugs.gnu.org (full text, mbox):

From: Arash Esbati <arash <at> gnu.org>
To: Paul Nelson <ultrono <at> gmail.com>
Cc: 69346 <at> debbugs.gnu.org
Subject: Re: bug#69346: 13.2; newcommand arguments affecting indentation
Date: Sun, 25 Feb 2024 15:00:50 +0100
tags 69346 notabug
close 69346
thanks

Paul Nelson <ultrono <at> gmail.com> writes:

> Thanks, that makes sense, and LaTeX-indent-begin-exceptions-list
> indeed addresses the issue.

Great, closing this report.

Best, Arash




Added tag(s) notabug. Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 25 Feb 2024 14:04:02 GMT) Full text and rfc822 format available.

bug closed, send any further explanations to 69346 <at> debbugs.gnu.org and Paul Nelson <ultrono <at> gmail.com> Request was from Arash Esbati <arash <at> gnu.org> to control <at> debbugs.gnu.org. (Sun, 25 Feb 2024 14:04:02 GMT) Full text and rfc822 format available.

bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Wed, 27 Mar 2024 11:24:14 GMT) Full text and rfc822 format available.

This bug report was last modified 1 year and 85 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.