[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 182/299: Add indentation for tabular environment.
From: |
Stefan Monnier |
Subject: |
[elpa] 182/299: Add indentation for tabular environment. |
Date: |
Sun, 02 Nov 2014 03:11:18 +0000 |
monnier pushed a commit to branch externals/auctex
in repository elpa.
commit f8c1d44c62f958e19d924deeb51c54f2413e1ef6
Author: Oleh Krehel <address@hidden>
Date: Sat Oct 12 12:16:16 2013 +0200
Add indentation for tabular environment.
* latex.el: `LaTeX-indent-tabular' now indents tabular-like environments.
(LaTeX--tabular-like-end): new variable.
(LaTeX-indent-environment-list): added `LaTeX-indent-tabular' as
indenter for "tabular" and "align", added a setter that recomputes
`LaTeX--tabular-like-end'
(LaTeX-env-beginning-pos-col): new function.
(LaTeX-hanging-ampersand-position): new function.
(LaTeX-indent-tabular): new function.
* tests/latex/latex-test.el : added an ERT test for `LaTeX-indent-tabular'
(LaTeX-indent-tabular-test/in): input filename variable
(LaTeX-indent-tabular-test/out): output filename variable
* tests/latex/tabular-in.tex: input to latex-test.el
* tests/latex/tabular-out.tex: input to latex-test.el
* tex.el (TeX-how-many): added for compatibility with XEmacs.
Signed-off-by: Tassilo Horn <address@hidden>
---
ChangeLog | 23 +++++++++++++++
latex.el | 67 +++++++++++++++++++++++++++++++++++++++++--
tests/latex/latex-test.el | 13 ++++++++
tests/latex/tabular-in.tex | 41 ++++++++++++++++++++++++++
tests/latex/tabular-out.tex | 41 ++++++++++++++++++++++++++
tex.el | 9 ++++++
6 files changed, 191 insertions(+), 3 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index e5c8100..b8ff631 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2013-10-14 Oleh Krehel <address@hidden>
+
+ * latex.el: `LaTeX-indent-tabular' now indents tabular-like
+ environments.
+ (LaTeX--tabular-like-end): new variable.
+ (LaTeX-indent-environment-list): added `LaTeX-indent-tabular' as
+ indenter for "tabular" and "align", added a setter that recomputes
+ `LaTeX--tabular-like-end'
+ (LaTeX-env-beginning-pos-col): new function.
+ (LaTeX-hanging-ampersand-position): new function.
+ (LaTeX-indent-tabular): new function.
+
+ * tests/latex/latex-test.el : added an ERT test for
+ `LaTeX-indent-tabular'
+ (LaTeX-indent-tabular-test/in): input filename variable
+ (LaTeX-indent-tabular-test/out): output filename variable
+
+ * tests/latex/tabular-in.tex: input to latex-test.el
+
+ * tests/latex/tabular-out.tex: input to latex-test.el
+
+ * tex.el (TeX-how-many): added for compatibility with XEmacs.
+
2013-10-11 Mos� Giordano <address@hidden>
* doc/auctex.texi (Quotes): Fix typo.
diff --git a/latex.el b/latex.el
index f59168f..8488966 100644
--- a/latex.el
+++ b/latex.el
@@ -2633,14 +2633,34 @@ consideration just as is in the non-commented source
code."
("tabbing")
("table")
("table*")
- ("tabular")
- ("tabular*"))
+ ("tabular" LaTeX-indent-tabular)
+ ("tabular*" LaTeX-indent-tabular)
+ ("align" LaTeX-indent-tabular)
+ ("align*" LaTeX-indent-tabular))
"Alist of environments with special indentation.
The second element in each entry is the function to calculate the
indentation level in columns."
:group 'LaTeX-indentation
:type '(repeat (list (string :tag "Environment")
- (option function))))
+ (option function)))
+ :set (lambda (symbol value)
+ (setq LaTeX--tabular-like-end
+ (format "\\\\end{%s}"
+ (regexp-opt
+ (let (out)
+ (mapc (lambda (x)
+ (when (eq (cadr x) 'LaTeX-indent-tabular)
+ (push (car x) out)))
+ value)
+ out))))
+ (set-default symbol value)))
+
+(defvar LaTeX--tabular-like-end nil
+ "A regexp matching tabular-like environment ends.
+Those will be aligned with `LaTeX-indent-tabular'.
+
+Do not set this variable. This variable is auto-set
+by customizing `LaTeX-indent-environment-list'.")
(defcustom LaTeX-indent-environment-check t
"*If non-nil, check for any special environments."
@@ -5996,6 +6016,47 @@ i.e. you do _not_ have to cater for this yourself by
adding \\\\' or $."
(replace-match "\\\\input{" nil nil)))))
(TeX-normal-mode nil))
+(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))))
+
+(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))))))
+
+(defun LaTeX-indent-tabular ()
+ "Return indent column for the current tabular-like line."
+ (destructuring-bind (beg-pos . beg-col)
+ (LaTeX-env-beginning-pos-col)
+ (cond ((looking-at LaTeX--tabular-like-end)
+ beg-col)
+
+ ((looking-at "\\\\\\\\")
+ (+ 2 beg-col))
+
+ ((looking-at "&")
+ (LaTeX-hanging-ampersand-position))
+
+ (t
+ (+ 2
+ (let ((any-col (save-excursion
+ (when (re-search-backward "\\\\\\\\\\|&"
beg-pos t)
+ (current-column)))))
+ (if (and any-col (string= "&" (match-string 0)))
+ any-col
+ beg-col)))))))
+
(provide 'latex)
;;; latex.el ends here
diff --git a/tests/latex/latex-test.el b/tests/latex/latex-test.el
new file mode 100644
index 0000000..a2d71e4
--- /dev/null
+++ b/tests/latex/latex-test.el
@@ -0,0 +1,13 @@
+(defvar LaTeX-indent-tabular-test/in (expand-file-name "tabular-in.tex"))
+(defvar LaTeX-indent-tabular-test/out (expand-file-name "tabular-out.tex"))
+
+(ert-deftest LaTeX-indent-tabular ()
+ (should (string=
+ (with-temp-buffer
+ (insert-file-contents LaTeX-indent-tabular-test/in)
+ (LaTeX-mode)
+ (indent-region (point-min) (point-max))
+ (buffer-string))
+ (with-temp-buffer
+ (insert-file-contents LaTeX-indent-tabular-test/out)
+ (buffer-string)))))
diff --git a/tests/latex/tabular-in.tex b/tests/latex/tabular-in.tex
new file mode 100644
index 0000000..a8be333
--- /dev/null
+++ b/tests/latex/tabular-in.tex
@@ -0,0 +1,41 @@
+\documentclass{article}
+\begin{document}
+\begin{tabular}{llll}
+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
+\\
+
+reformidans mel. & Quo no sale
+natum, cu
+pericula & deterruisset
+usu. Nec & bonorum detracto\\
+detraxit & no. & Ne sea doming & deserunt.
+\end{tabular}
+
+\begin{tabular}{ll}
+1 & 2 & 3
+\\
+& 4 & 5
+\\
+6 & 7
+& 8\\
+9 &
+10
+& 11
+\end{tabular}
+\begin{align}
+1 & 2
+3 & 4
+5\\
+6 &
+7
+8 &
+9
+\end{align}
+\end{document}
diff --git a/tests/latex/tabular-out.tex b/tests/latex/tabular-out.tex
new file mode 100644
index 0000000..cd5b708
--- /dev/null
+++ b/tests/latex/tabular-out.tex
@@ -0,0 +1,41 @@
+\documentclass{article}
+\begin{document}
+\begin{tabular}{llll}
+ 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
+ \\
+
+ reformidans mel. & Quo no sale
+ natum, cu
+ pericula & deterruisset
+ usu. Nec & bonorum detracto\\
+ detraxit & no. & Ne sea doming & deserunt.
+\end{tabular}
+
+\begin{tabular}{ll}
+ 1 & 2 & 3
+ \\
+ & 4 & 5
+ \\
+ 6 & 7
+ & 8\\
+ 9 &
+ 10
+ & 11
+\end{tabular}
+\begin{align}
+ 1 & 2
+ 3 & 4
+ 5\\
+ 6 &
+ 7
+ 8 &
+ 9
+\end{align}
+\end{document}
diff --git a/tex.el b/tex.el
index 0541acf..443cf25 100644
--- a/tex.el
+++ b/tex.el
@@ -5776,6 +5776,15 @@ NAME may be a package, a command, or a document."
(put 'TeX-insert-quote 'delete-selection t)
(put 'TeX-insert-backslash 'delete-selection t)
+(defun TeX-how-many (regexp &optional rstart rend)
+ "Compatibily function for `how-many'.
+Supports restriction to a region where the XEmacs version doesn't."
+ (save-excursion
+ (save-restriction
+ (narrow-to-region rstart rend)
+ (goto-char (point-min))
+ (how-many regexp))))
+
(provide 'tex)
;; Local Variables:
- [elpa] 163/299: Don't prompt for reference format when RefTeX is active., (continued)
- [elpa] 163/299: Don't prompt for reference format when RefTeX is active., Stefan Monnier, 2014/11/01
- [elpa] 173/299: Fix unit name in siunitx style file., Stefan Monnier, 2014/11/01
- [elpa] 180/299: fix author in ChangeLog, Stefan Monnier, 2014/11/01
- [elpa] 175/299: Detect a couple of hyperref rerun messages., Stefan Monnier, 2014/11/01
- [elpa] 174/299: Enhance brace pairing feature., Stefan Monnier, 2014/11/01
- [elpa] 176/299: Fix in TeX-arg-insert-braces. Again., Stefan Monnier, 2014/11/01
- [elpa] 181/299: Fix typos., Stefan Monnier, 2014/11/01
- [elpa] 179/299: Docs for paired braces feature., Stefan Monnier, 2014/11/01
- [elpa] 178/299: Add new possible value for `TeX-insert-macro-default-style'., Stefan Monnier, 2014/11/01
- [elpa] 177/299: Add new customizable variable TeX-insert-braces-alist., Stefan Monnier, 2014/11/01
- [elpa] 182/299: Add indentation for tabular environment.,
Stefan Monnier <=
- [elpa] 183/299: Use enhanced tabular indentation for more envs., Stefan Monnier, 2014/11/01
- [elpa] 187/299: Fix in biblatex style file., Stefan Monnier, 2014/11/01
- [elpa] 188/299: Really fix bug in biblatex style file., Stefan Monnier, 2014/11/01
- [elpa] 189/299: Run style files of the bibliography files when inserting bibliography macros., Stefan Monnier, 2014/11/01
- [elpa] 186/299: Add narrowing commands., Stefan Monnier, 2014/11/01
- [elpa] 190/299: Document missing folding variables., Stefan Monnier, 2014/11/01
- [elpa] 193/299: void-function error fix., Stefan Monnier, 2014/11/01
- [elpa] 184/299: Mention new tabular indentation in changes.texi., Stefan Monnier, 2014/11/01
- [elpa] 185/299: Add completion for ProvidesPackage, ProvidesClass, and ProvidesFile., Stefan Monnier, 2014/11/01
- [elpa] 198/299: Declare expert macros and envs in biblatex style file., Stefan Monnier, 2014/11/01