[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master aabf144d: Arrange indent of tabular-like environments (bug#65648)
From: |
Ikumi Keita |
Subject: |
master aabf144d: Arrange indent of tabular-like environments (bug#65648) |
Date: |
Thu, 14 Sep 2023 01:33:06 -0400 (EDT) |
branch: master
commit aabf144dfb5c2ce4a2de37f45d88b0fadf77a57a
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Arrange indent of tabular-like environments (bug#65648)
This fixes bug#54949 as well.
* latex.el (LaTeX-env-beginning-pos-indent): New function to align "&"
and \end{foo} relative to the indent of the line where \begin{foo} is,
not the column of \begin{foo} itself.
(LaTeX-indent-tabular, LaTeX-hanging-ampersand-position): Use the new
function instead of `LaTeX-env-beginning-pos-col'. This makes
difference when \begin{foo} isn't on its own dedicated line.
(LaTeX-hanging-ampersand-position): Arrange the doc string.
* tests/latex/tabular-out.tex: Modify the expected result according to
the above change.
---
latex.el | 24 +++++++++++++++++++-----
tests/latex/tabular-out.tex | 8 ++++----
2 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/latex.el b/latex.el
index 548b18a9..3abb00f2 100644
--- a/latex.el
+++ b/latex.el
@@ -8911,22 +8911,36 @@ function would return non-nil and `(match-string 1)'
would return
(replace-match "\\\\input{" nil nil)))))
(TeX-normal-mode nil))
+;; This function is no longer used; We leave it for compatibility.
(defun LaTeX-env-beginning-pos-col ()
"Return a cons: (POINT . COLUMN) for current environment's beginning."
(save-excursion
(LaTeX-find-matching-begin)
(cons (point) (current-column))))
+;; This makes difference from `LaTeX-env-beginning-pos-col' when
+;; something non-whitespace sits before the \begin{foo}. (bug#65648)
+(defun LaTeX-env-beginning-pos-indent ()
+ "Return a cons: (POINT . INDENT) for current environment's beginning.
+INDENT is the indent of the line containing POINT."
+ (save-excursion
+ ;; FIXME: There should be some fallback mechanism in case that the
+ ;; next `backward-up' fails. (Such fail can occur in document
+ ;; with temporarily broken structure due to in-progress editing
+ ;; process.)
+ (LaTeX-backward-up-environment)
+ (cons (point) (LaTeX-current-indentation))))
+
(defun LaTeX-hanging-ampersand-position (&optional pos col)
"Return indent column for a hanging ampersand (that is, ^\\s-*&).
-When you know the position and column of the beginning of the
-current environment, supply them as optional arguments POS and
-COL for efficiency."
+When you know the position of the beginning of the current
+environment and indent of its line, supply them as optional
+arguments POS and COL for efficiency."
(cl-destructuring-bind
(beg-pos . beg-col)
(if pos
(cons pos col)
- (LaTeX-env-beginning-pos-col))
+ (LaTeX-env-beginning-pos-indent))
(let ((cur-pos (point)))
(save-excursion
(if (and (search-backward "\\\\" beg-pos t)
@@ -8957,7 +8971,7 @@ COL for efficiency."
"Return indent column for the current tabular-like line."
(cl-destructuring-bind
(beg-pos . beg-col)
- (LaTeX-env-beginning-pos-col)
+ (LaTeX-env-beginning-pos-indent)
(let ((tabular-like-end-regex
(format "\\\\end{%s}"
(regexp-opt
diff --git a/tests/latex/tabular-out.tex b/tests/latex/tabular-out.tex
index 66de0641..113c1d12 100644
--- a/tests/latex/tabular-out.tex
+++ b/tests/latex/tabular-out.tex
@@ -45,11 +45,11 @@
\begin{equation}
\begin{aligned}
&n u m=\left[\begin{array}{ll}
- 2 & 25
- \end{array}\right] \\
+ 2 & 25
+ \end{array}\right] \\
&d e n=\left[\begin{array}{lll}
- 1 & 4 & 25
- \end{array}\right]
+ 1 & 4 & 25
+ \end{array}\right]
\end{aligned}
\end{equation}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- master aabf144d: Arrange indent of tabular-like environments (bug#65648),
Ikumi Keita <=