auctex-devel
[Top][All Lists]
Advanced

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

Indenting conditionals


From: Arash Esbati
Subject: Indenting conditionals
Date: Tue, 15 Mar 2022 17:44:30 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Hi all,

I had a closer look at my proposal in this message[1] and I think I have
a working setup for indenting conditionals in AUCTeX.  I've patched the
functions `LaTeX-indent-calculate', `LaTeX-indent-calculate-last' and
`LaTeX-indent-level-count' and hitting TAB in the following snippet
works as expected:

\iffalse
  foo
  \ifx\foo\bar
    \foo{%
      bar
    }
  \else
    foo
  \fi
\else
  \if@foo
    x
  \else
    y
  \fi
\fi

I also wanted to generalize this approch for other styles like
algpseudocode.el to get this example pseudo code also indented
correctly:

\IF{$n$ is odd}
  \RETURN \TRUE
\ELSE
  \RETURN \FALSE
\ENDIF

The proof of concept is attached in the lisp file.  The idea is that
style files add their keywords like this:

(add-to-list 'LaTeX-indent-begin-regexp-list "IF")
(add-to-list 'LaTeX-indent-mid-regexp-list "ELSE")
(add-to-list 'LaTeX-indent-end-regexp-list "ENDIF")

and then call the function `LaTeX-indent-commmands-regexp-make' which
updates the interal regexps used in the 3 functions mentioned above.
Before adding the code to latex.el and sending a patch for further
discussion, I'd be grateful for any comments reg. this feature being
useful and the interface being usable.

Best, Arash

Footnotes:
[1]  https://lists.gnu.org/archive/html/auctex/2022-03/msg00033.html

Attachment: latex-indent.el
Description: application/emacs-lisp


reply via email to

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