Hi all,
>>>>> Ikumi Keita <[email protected]> writes:
>>>>> Sašo Živanović <[email protected]> writes:
>> Summing up: while I find []-indenting indispensable for Forest trees,
>> and TikZ in general, I would definitely want to have an way to
>> override it for specific cases, and counting stuff in comments seems
>> the simplest way to implement the override.
>> On the other hand, I have a hard time imagining a situation where I
>> would want to override a {}-based indent via a comment, so I would say
>> that the AuCTeX's current behaviour to ignore these in comments makes
>> perfect sense and should be kept (even without the historical
>> reasons). So I would propose that the extended indenting mechanism
>> would ignore {} in comments but count all other delimiters.
> That seems reasonable direction: In comments, ignore {} while count []
> (and other symbols?).
> And it seems that AUCTeX should consider to indent inside [] only
> optionally; by default it should indent inside {} only.
I think the attached patch works as expected. My approach is to include
only additional delimiters in new user options, since braces "{" and "}"
should always be considered to pull in indentation.
To try indent inside square brackets, include
(setq TeX-indent-open-delimiters "[")
(setq TeX-indent-close-delimiters "]")
somewhere in your init.el.
If this proposal is acceptable, I can commit it the git repo and I'd
appreciate if someone could write suitable paragraphs to include in
.texi documentation ;-) .
Regards,
Ikumi Keita
#StandWithUkraine #StopWarInUkraine
>From f464242eab092e610dda6b654e6fd197ef649d3e Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email protected]>
Date: Sat, 5 Mar 2022 00:29:08 +0900
Subject: [PATCH] Enable indent by square bracket
* tex.el (TeX-indent-open-delimiters):
(TeX-indent-close-delimiters): New options regarded as additional
open/close delimiters at indentation.
* tex.el (TeX-brace-count-line): Increase indentation inside those
options in addition to "{", "}". In comments, don't ignore those
additional characters.
* latex.el (LaTeX-indent-calculate):
(LaTeX-indent-calculate-last):
Treat chars in `TeX-indent-close-delimiters' in the same way as "}".
---
latex.el | 7 +++++--
tex.el | 41 +++++++++++++++++++++++++++++++++++------
2 files changed, 40 insertions(+), 8 deletions(-)
diff --git a/latex.el b/latex.el
index 4de97600..142d075c 100644
--- a/latex.el
+++ b/latex.el
@@ -3899,7 +3899,8 @@ outer indentation in case of a commented line. The symbols
"\\)"))
;; Items.
(+ (LaTeX-indent-calculate-last force-type) LaTeX-item-indent))
- ((looking-at "}")
+ ((memq (char-after) (append
+ TeX-indent-close-delimiters '(?\})))
;; End brace in the start of the line.
(- (LaTeX-indent-calculate-last force-type)
TeX-brace-indent-level))
@@ -4041,7 +4042,9 @@ outer indentation in case of a commented line. The symbols
LaTeX-item-regexp
"\\)"))
(- LaTeX-item-indent))
- ((looking-at "}")
+ ((memq (char-after) (append
+ TeX-indent-close-delimiters
+ '(?\})))
TeX-brace-indent-level)
(t 0)))))))
diff --git a/tex.el b/tex.el
index 4876ae55..eb32a379 100644
--- a/tex.el
+++ b/tex.el
@@ -5410,6 +5410,20 @@ regardless of its data type."
:group 'TeX-indentation
:type 'integer)
+(defcustom TeX-indent-open-delimiters ""
+ "Additional open delimiters to increase indentation.
+Include \"[\" to indent inside square brackets.
+See `TeX-brace-count-line' and `TeX-indent-close-delimiters'."
+ :group 'TeX-indentation
+ :type '(string :tag "Open delimiters"))
+
+(defcustom TeX-indent-close-delimiters ""
+ "Additional close delimiters to increase indentation.
+Include \"]\" to indent inside square brackets.
+See `TeX-brace-count-line' and `TeX-indent-open-delimiters'."
+ :group 'TeX-indentation
+ :type '(string :tag "Close delimiters"))
+
(defun TeX-comment-indent ()
"Determine the indentation of a comment."
(if (looking-at "%%%")
@@ -5419,17 +5433,32 @@ regardless of its data type."
comment-column)))
(defun TeX-brace-count-line ()
- "Count number of open/closed braces."
+ "Count indent caused by open/closed braces.
+In addition to \"{\" and \"}\", characters in
+`TeX-indent-open-delimiters' and `TeX-indent-close-delimiters'
+are also taken into account. Ignore them when they are escaped
+by \"\\\". In comments, ignore \"{\" and \"}\" but don't ignore
+additional characters."
(save-excursion
(let ((count 0) (limit (line-end-position)) char)
(while (progn
- (skip-chars-forward "^{}\\\\" limit)
- (when (and (< (point) limit) (not (TeX-in-comment)))
- (setq char (char-after))
+ (skip-chars-forward
+ (concat "^{}\\\\"
+ TeX-indent-open-delimiters
+ TeX-indent-close-delimiters)
+ limit)
+ (when (and (< (point) limit)
+ (not (and (memq (setq char (char-after))
+ '(?\{ ?\} ?\\))
+ (TeX-in-comment))))
(forward-char)
- (cond ((eq char ?\{)
+ (cond ((memq char (append
+ TeX-indent-open-delimiters
+ '(?\{)))
(setq count (+ count TeX-brace-indent-level)))
- ((eq char ?\})
+ ((memq char (append
+ TeX-indent-close-delimiters
+ '(?\})))
(setq count (- count TeX-brace-indent-level)))
((eq char ?\\)
(when (< (point) limit)
--
2.34.1