emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/auctex 72a6943 54/95: Add fallback for indentation when


From: Tassilo Horn
Subject: [elpa] externals/auctex 72a6943 54/95: Add fallback for indentation when & is omitted
Date: Sun, 16 Apr 2017 01:26:54 -0400 (EDT)

branch: externals/auctex
commit 72a694360771d15393939b904d39a2054c34788c
Author: Arash Esbati <address@hidden>
Commit: Arash Esbati <address@hidden>

    Add fallback for indentation when & is omitted
    
    * latex.el (LaTeX-hanging-ampersand-position): Add fallback for
    indentation if the row searched does not contain a column
    separator &.
    
    * tests/latex/tabular-in.tex:
    * tests/latex/tabular-out.tex: Add filling test for missing & in
    row.
---
 latex.el                    | 27 +++++++++++++++++----------
 tests/latex/latex-test.el   |  2 ++
 tests/latex/tabular-in.tex  | 14 ++++++++++++++
 tests/latex/tabular-out.tex | 14 ++++++++++++++
 4 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/latex.el b/latex.el
index f034207..d91d9c9 100644
--- a/latex.el
+++ b/latex.el
@@ -6627,16 +6627,23 @@ function would return non-nil and `(match-string 1)' 
would return
 
 (defun LaTeX-hanging-ampersand-position ()
   "Return indent column for a hanging ampersand (i.e. ^\\s-*&)."
-  (destructuring-bind (beg-pos . beg-col)
-      (LaTeX-env-beginning-pos-col)
-    (let* ((cur-pos (point)))
-      (save-excursion
-        (if (re-search-backward "\\\\\\\\" beg-pos t)
-            (let ((cur-idx (TeX-how-many "[^\\]&" (point) cur-pos)))
-              (goto-char beg-pos)
-              (re-search-forward "[^\\]&" cur-pos t (+ 1 cur-idx))
-              (- (current-column) 1))
-          (+ 2 beg-col))))))
+  (destructuring-bind
+   (beg-pos . beg-col)
+   (LaTeX-env-beginning-pos-col)
+   (let* ((cur-pos (point)))
+     (save-excursion
+       (if (re-search-backward "\\\\\\\\" beg-pos t)
+          (let ((cur-idx (TeX-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 check the result first with `natnump' and return
+            ;; (+ 2 beg-col) as fallback.
+            (if (natnump (- (current-column) 1))
+                (- (current-column) 1)
+              (+ 2 beg-col)))
+        (+ 2 beg-col))))))
 
 (defun LaTeX-indent-tabular ()
   "Return indent column for the current tabular-like line."
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
index e6e70eb..69939cf 100644
--- a/tests/latex/latex-test.el
+++ b/tests/latex/latex-test.el
@@ -63,6 +63,8 @@ line and from another directory."
 
 ;; Test for detecting \& in a table cell added; see
 ;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26010
+;; Test for missing & in row added; see
+;; https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
 (ert-deftest LaTeX-indent-tabular ()
   (should (string=
            (with-temp-buffer
diff --git a/tests/latex/tabular-in.tex b/tests/latex/tabular-in.tex
index 61c0a92..a0b9bf0 100644
--- a/tests/latex/tabular-in.tex
+++ b/tests/latex/tabular-in.tex
@@ -53,4 +53,18 @@ prompta           & disputando & ne mel, ne
 vel.            & No petentium
 \end{tabular}
 
+% Next table tests filling when & (column separator) character is
+% missing in a row; the function `LaTeX-hanging-ampersand-position' now
+% (March 2017) detects this and has a fallback, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
+\begin{tabular}{llll}
+\multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei}\\
+& paulo tation honestatis,
+intellegam accommodare ne vim, ut \\
+& mel solum putant atomorum. Posse & dolores has ut, \\
+prompta & disputando & ne mel, ne
+\& viderer ceteros vel. \\
+& No petentium
+\end{tabular}
+
 \end{document}
diff --git a/tests/latex/tabular-out.tex b/tests/latex/tabular-out.tex
index 9310b0a..316ee99 100644
--- a/tests/latex/tabular-out.tex
+++ b/tests/latex/tabular-out.tex
@@ -53,4 +53,18 @@
                                    vel.            & No petentium
 \end{tabular}
 
+% Next table tests filling when & (column separator) character is
+% missing in a row; the function `LaTeX-hanging-ampersand-position' now
+% (March 2017) detects this and has a fallback, see:
+% https://debbugs.gnu.org/cgi/bugreport.cgi?bug=26032
+\begin{tabular}{llll}
+  \multicolumn{4}{c}{Lorem ipsum dolor sit amet, ei mei}\\
+  & paulo tation honestatis,
+    intellegam accommodare ne vim, ut \\
+  & mel solum putant atomorum. Posse & dolores has ut, \\
+  prompta & disputando & ne mel, ne
+                         \& viderer ceteros vel. \\
+  & No petentium
+\end{tabular}
+
 \end{document}



reply via email to

[Prev in Thread] Current Thread [Next in Thread]