Re: Indenting conditionals

2022-03-17 Thread Arash Esbati
Ikumi Keita  writes:

> This time it doesn't seem to show abnormal behavior. :-)

Thanks for checking.  Attached is also a diff against latex.el.  If
there are no other comments I will try to commit it tomorrow incl. a
test and announcement etc.

Best, Arash
diff --git a/latex.el b/latex.el
index 142d075c..78451932 100644
--- a/latex.el
+++ b/latex.el
@@ -3751,9 +3751,11 @@ value."
 
 (defvar docTeX-indent-inner-fixed
   `((,(concat (regexp-quote TeX-esc)
- "\\(begin\\|end\\)[ \t]*{macrocode\\*?}") 4 t)
+  "\\(begin\\|end\\)[ \t]*{macrocode\\*?}")
+ 4 t)
 (,(concat (regexp-quote TeX-esc)
- "\\(begin\\|end\\)[ \t]*{\\(macro\\|environment\\)\\*?}") 0 nil))
+  "\\(begin\\|end\\)[ \t]*{\\(macro\\|environment\\)\\*?}")
+ 0 nil))
   "List of items which should have a fixed inner indentation.
 The items consist of three parts.  The first is a regular
 expression which should match the respective string.  The second
@@ -3762,6 +3764,110 @@ toggles if comment padding is relevant or not.  If t padding is
 part of the amount given, if nil the amount of spaces will be
 inserted after potential padding.")
 
+(defvar-local LaTeX-indent-begin-list nil
+  "List of macros increasing indentation.
+Each item in this list is a string with the name of the macro
+without a backslash.  The final regexp will be calculated by the
+function `LaTeX-indent-commmands-regexp-make'.  A regexp for the
+\\if contructs is added by the function as well.  AUCTeX styles
+should add their macros to this variable and then run
+`LaTeX-indent-commmands-regexp-make'.")
+
+(defvar-local LaTeX-indent-begin-exceptions-list nil
+  "List of macros which shouldn't increase the indentation.
+Each item in this list is a string without a backslash and will
+mostly start with 'if'.  These macros should not increase
+indentation although they start with 'if', for example the
+'ifthenelse' macro provided by the ifthen package.  AUCTeX styles
+should add their macros to this variable and then run
+`LaTeX-indent-commmands-regexp-make'.")
+
+(defvar-local LaTeX-indent-mid-list nil
+  "List of macros which backindent the line where they appear.
+Each item in this list is a string with the name of the macro
+without a backslash.  The final regexp will be calculated by the
+function `LaTeX-indent-commmands-regexp-make' which takes care of
+\\else and \\or.  AUCTeX styles should add their macros to this
+variable and then run `LaTeX-indent-commmands-regexp-make'.")
+
+(defvar-local LaTeX-indent-end-list nil
+  "List of macros decreasing indentation.
+Each item in this list is a string with the name of the macro
+without a backslash.  The final regexp will be calculated by the
+function `LaTeX-indent-commmands-regexp-make' which takes care of
+\\fi.  AUCTeX styles should add their macros to this variable and
+then run `LaTeX-indent-commmands-regexp-make'.")
+
+(defvar-local LaTeX-indent-begin-regexp-local nil
+  "Regexp calculated from `LaTeX-indent-begin-list'.
+The value is calculated and set by the function
+`LaTeX-indent-commmands-regexp-make' which already takes care of
+\\if constructs.")
+
+(defvar-local LaTeX-indent-begin-regexp-exceptions-local nil
+  "Regexp calculated from `LaTeX-indent-begin-exceptions-list'.
+The value is calculated and set by the function
+`LaTeX-indent-commmands-regexp-make' which already takes care of
+\\ifthenelse.")
+
+(defvar-local LaTeX-indent-mid-regexp-local nil
+  "Regexp calculated from `LaTeX-indent-mid-list'.
+The value is calculated and set by the function
+`LaTeX-indent-commmands-regexp-make' which already takes care of
+\\else and \\or.")
+
+(defvar-local LaTeX-indent-end-regexp-local nil
+  "Regexp calculated from `LaTeX-indent-end-list'.
+The value is calculated and set by the function
+`LaTeX-indent-commmands-regexp-make' which already takes care of
+\\fi.")
+
+(defun LaTeX-indent-commmands-regexp-make ()
+  "Calculate final regexp for adjusting indentation.
+This function takes the elements provided in
+`LaTeX-indent-begin-list', `LaTeX-indent-begin-exceptions-list',
+`LaTeX-indent-mid-list' and `LaTeX-indent-end-list' and generates
+the regexp's which are stored in
+`LaTeX-indent-begin-regexp-local',
+`LaTeX-indent-begin-regexp-exceptions-local',
+`LaTeX-indent-mid-regexp-local' and
+`LaTeX-indent-end-regexp-local' accordingly.  Some standard
+macros are added to the regexp's.  This function is called in
+`LaTeX-common-initialization' to set the regexp's."
+  (let* (cmds
+ symbs
+ (func (lambda (in regexp out)
+ (setq cmds nil
+   symbs nil)
+ (dolist (elt in)
+   (if (string-match "[^a-zA-Z@]" elt)
+   (push elt symbs)
+ (push elt cmds)))
+ (set out (concat regexp
+  (when cmds
+(concat "\\|"
+(regexp-opt 

Re: Indenting conditionals

2022-03-16 Thread Ikumi Keita
> Arash Esbati  writes:
> Thanks for catching this.  The reason was sitting in front of the
> keyboard here.

Oh.

> Please try it again with the file attached.

This time it doesn't seem to show abnormal behavior. :-)

Bye,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: Indenting conditionals

2022-03-16 Thread Arash Esbati
Hi Keita,

Ikumi Keita  writes:

> This code introduces spurious indent but I haven't figured out the
> reason.

Thanks for catching this.  The reason was sitting in front of the
keyboard here.  Please try it again with the file attached.

Best, Arash


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


Re: Indenting conditionals

2022-03-16 Thread Ikumi Keita
Hi Arash,

> Arash Esbati  writes:
> Arash Esbati  writes:
>> The proof of concept is attached in the lisp file.

> Following up myself, please find attached an updated version of this
> idea.

This code introduces spurious indent but I haven't figured out the
reason. Examine the following example.

\documentclass{article}
\begin{document}

\begin{foo}
  After evaluating (LaTeX-indent-commmands-regexp-make), 
\end{foo}
<- type TAB here.

\begin{bar}
  abcdefghi
\end{bar}

<- Or here.

\begin{verbatim}
However, that behavior is suppressed after verbatim env.
\end{verbatim}
<-

\end{document}

Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine



Re: Indenting conditionals

2022-03-16 Thread Sašo Živanović
Yes, LaTeX-indent-begin-regexp-exceptions-list is a must! Many thanks 
for working on this. (And my apologies for the late replies!)

Best,
Sašo

Arash Esbati je 16. 03. 22 ob 13:21 napisal:

Arash Esbati  writes:


The proof of concept is attached in the lisp file.


Following up myself, please find attached an updated version of this
idea.

Best, Arash




Re: Indenting conditionals

2022-03-16 Thread Arash Esbati
Arash Esbati  writes:

> The proof of concept is attached in the lisp file.

Following up myself, please find attached an updated version of this
idea.

Best, Arash


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