>From f464242eab092e610dda6b654e6fd197ef649d3e Mon Sep 17 00:00:00 2001 From: Ikumi Keita 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