[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[AUCTeX-diffs] [elpa] externals/auctex 844e758a47 07/60: Improve indent
From: |
Tassilo Horn |
Subject: |
[AUCTeX-diffs] [elpa] externals/auctex 844e758a47 07/60: Improve indent in tabular-like environments |
Date: |
Fri, 8 Apr 2022 11:52:46 -0400 (EDT) |
branch: externals/auctex
commit 844e758a475860addc94ac6f73b2c0ac2e598eaa
Author: Ikumi Keita <ikumi@ikumi.que.jp>
Commit: Ikumi Keita <ikumi@ikumi.que.jp>
Improve indent in tabular-like environments
* latex.el (LaTeX-hanging-ampersand-position): Fall back to default
value if encountered "\\" in an inner env.
Attach optional arguments for efficiency.
(LaTeX-indent-tabular): Skip inner env which also is tabular-like.
Call `LaTeX-hanging-ampersand-position' with new optional arguments.
---
latex.el | 76 +++++++++++++++++++++++++++++++++++++++++++++++++---------------
1 file changed, 58 insertions(+), 18 deletions(-)
diff --git a/latex.el b/latex.el
index a5e57b0929..8c8f8040e7 100644
--- a/latex.el
+++ b/latex.el
@@ -7761,22 +7761,40 @@ function would return non-nil and `(match-string 1)'
would return
(LaTeX-find-matching-begin)
(cons (point) (current-column))))
-(defun LaTeX-hanging-ampersand-position ()
- "Return indent column for a hanging ampersand (that is, ^\\s-*&)."
+(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."
(cl-destructuring-bind
(beg-pos . beg-col)
- (LaTeX-env-beginning-pos-col)
- (let* ((cur-pos (point)))
+ (if pos
+ (cons pos col)
+ (LaTeX-env-beginning-pos-col))
+ (let ((cur-pos (point)))
(save-excursion
- (if (re-search-backward "\\\\\\\\" beg-pos t)
+ (if (and (search-backward "\\\\" beg-pos t)
+ ;; Give up if the found "\\" belongs to an inner env.
+ (= beg-pos
+ (save-excursion
+ (LaTeX-find-matching-begin)
+ (point))))
+ ;; FIXME: This `how-many' fails to count correctly if
+ ;; there is an inner env with "&" but without "\\", e.g.
+ ;; \begin{pmatrix}
+ ;; a & b
+ ;; \end{pmatrix}
(let ((cur-idx (how-many "[^\\]&" (point) cur-pos)))
(goto-char beg-pos)
- (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
- ;; If the above searchs fails, i.e. no "&" found,
- ;; (- (current-column) 1) returns -1, which is wrong. So
- ;; we use a fallback (+ 2 beg-col) whenever this happens:
- (max (- (current-column) 1)
- (+ 2 beg-col)))
+ ;; FIXME: This regex search fails if there is an inner
+ ;; env with "&" in it.
+ (if (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
+ (- (current-column) 1)
+ ;; If the above searchs fails, i.e. no "&" found,
+ ;; (- (current-column) 1) returns -1, which is wrong.
+ ;; So we use a fallback (+ 2 beg-col) whenever this
+ ;; happens:
+ (+ 2 beg-col)))
(+ 2 beg-col))))))
(defun LaTeX-indent-tabular ()
@@ -7800,16 +7818,38 @@ function would return non-nil and `(match-string 1)'
would return
(+ 2 beg-col))
((looking-at "&")
- (LaTeX-hanging-ampersand-position))
+ (LaTeX-hanging-ampersand-position beg-pos beg-col))
(t
(+ 2
- (let ((any-col (save-excursion
- (when (re-search-backward "\\\\\\\\\\|[^\\]&"
beg-pos t)
- (current-column)))))
- (if (and any-col (= ?& (char-before (match-end 0))))
- (1+ any-col)
- beg-col))))))))
+ (let ((any-col
+ (save-excursion
+ (when
+ (catch 'found
+ ;; Search "\\" or "&" which belongs to
+ ;; the current env, not an inner env.
+ (while (re-search-backward
+ "\\\\\\\\\\|[^\\]&" beg-pos t)
+ (let ((p (point)))
+ (when (= beg-pos
+ (progn
+ (LaTeX-find-matching-begin)
+ (point)))
+ ;; It belongs to the current env.
+ ;; Go to target position and exit
+ ;; the loop.
+ (goto-char (1+ p))
+ (throw 'found t)
+ ;; Otherwise it belongs to an
+ ;; inner env, so continue the
+ ;; loop.
+ ))))
+ ;; If we found "&", then use its column as
+ ;; `any-col'. Else, `any-col' will be nil.
+ (if (= ?& (char-after))
+ (current-column))))))
+ (or any-col
+ beg-col))))))))
;; Utilities:
- [AUCTeX-diffs] [elpa] externals/auctex updated (8ff369bd92 -> 03ed9004cd), Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 90b1803b02 10/60: Use DEFAULT argument in latex.el where appropriate, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex e625dc05ea 01/60: Improve keymap handling, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 0847db39c9 03/60: Improve file query in style/ltxtable.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 7119e9b58c 14/60: ; Fix tests relying on font-lock has put syntax properties already, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 3e95554c27 19/60: Reduce code duplication in style/sidecap.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 163dcb75bd 02/60: Fix label insertion at env. insertion with active region (bug#28382), Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex f464242eab 29/60: Enable indent by square bracket, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex f686fbca6d 16/60: Add new test, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex e37c7a8b39 31/60: Revise documentation about simultaneous process, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 844e758a47 07/60: Improve indent in tabular-like environments,
Tassilo Horn <=
- [AUCTeX-diffs] [elpa] externals/auctex 0e0551126d 17/60: * doc/changes.texi: Document switch from initial input to default., Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex ab3bfaf103 13/60: Don't use obsolete font-lock-syntactic-keywords, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 2be733a3e3 28/60: Add new style/l3doc.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex dff1592319 09/60: Adjust argument list of `TeX-arg-length', Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex c43d21326d 42/60: Follow similar update of latex.el in context.el, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex b2cea20056 53/60: ; Delete unnecessary quoting in docstrings, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 4e4c48556b 08/60: ; Trivial cleanup, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex b3d4a509d0 39/60: ; * doc/auctex.texi (Indenting): Fix wording., Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 4bcda2d50c 35/60: Improve indentation in env from algpseudocode package, Tassilo Horn, 2022/04/08
- [AUCTeX-diffs] [elpa] externals/auctex 1823017839 55/60: Wrap the 'function' environment better with %, Tassilo Horn, 2022/04/08