Re: [AUCTeX-devel] Extending `LaTeX-array-count-columns'

2016-12-17 Thread Arash Esbati
Hi Ikumi,

Ikumi Keita  writes:

>> 2 thing occurred to me when hitting `M-RET' in tabular environments:
>> Current code in `LaTeX-array-count-columns' cannot handle multi column
>> specs like `*{num}{spec}' and optional args to column specs S and s from
>> siunitx.el.  I have a patch to handle both issues.  Can people please
>> test this code against their tabular's and see if it does the right
>> thing?
>
> I found two cases that the code does not work as expected.
> (1) When the second argument of *-operator contains more than 1
> columns.
>
> \begin{tabular}[t]{*{3}{|cr}l}
>   1 & 2 & 3 & 4 & 5 & 6 & 7 \\
> &&&
> \end{tabular}
>
> (2) When *-operator is nested.
> \begin{tabular}[t]{*{3}{c*{2}{r}}l}
>   1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 & 9 & 0 \\
> &&&
> \end{tabular}

Thanks for looking at this.  Indeed, I totally ignored these cases!  I
admit that I've never seen case (2), but it works and your code supports
it.

> Apparently recursive call of LaTeX-array-count-columns is needed do the
> task.  How about this one?
>
> (defun LaTeX-array-count-columns (start end)
>   "Count number of ampersands to be inserted.
> The columns are specified by the letters found in the string
> `LaTeX-array-column-letters' and the number of those letters within the
> text between START and END is basically considered to be the number of
> columns.  The arguments surrounded between braces such as p{30pt} do not
> interfere the count of columns.
>
> Return one less number than the columns, or nil on failing to count the
> right number."
>   (save-excursion
> (let (p (cols 0))
>   (goto-char start)
>   (while (< (setq p (point)) end)
>
>   ;; The below block accounts for one unit of move for
>   ;; one column.
> (setq cols (+ cols
> ;; treat *-operator specially.
>   (if (eq (following-char) ?*)
> ;; *-operator is there.
>   (progn
>   ;; pick up repetition number and count
>   ;; how many columns are repeated.
> (re-search-forward
>  "\\*[ \t\r\n%]*{[ \t\r\n%]*\\([0-9]+\\)[ 
> \t\r\n%]*}" end)
>   (let ((n (string-to-number
>   (match-string-no-properties 1)))
> ;; get start and end of repeated spec.
> (s (progn (down-list 1) (point)))
> (e (progn (up-list 1) (1- (point)
> (* n (1+ (LaTeX-array-count-columns s e)
>   ;; not *-operator.
> (skip-chars-forward
>  LaTeX-array-column-letters end
>   (skip-chars-forward (concat
>"^" LaTeX-array-column-letters "*"
>TeX-grop LaTeX-optop) end)
> (when (or (eq (following-char) ?\{)
>   (eq (following-char) ?\[))
>   (forward-list 1))
>
>   ;; Not sure whether this is really necessary or not, but
>   ;; prepare for possible infinite loop anyway.
>   (when (eq p (point))
> (setq cols nil)
> (goto-char end)))
>   ;; The number of ampersands is one less than column.
>   (if cols (1- cols)
>
> The above version also changes the construct
>   (if (looking-at-p "\\*[ \t\r\n%]*{[ \t\r\n%0-9]+}")
>   (progn
> (re-search-forward
>  "\\*[ \t\r\n%]*{[ \t\r\n%]*\\([0-9]+\\)[ \t\r\n%]*}" end t)
> to
>   (if (eq (following-char) ?*)
>   (progn
> (re-search-forward
>  "\\*[ \t\r\n%]*{[ \t\r\n%]*\\([0-9]+\\)[ \t\r\n%]*}" end)
> based on the following two reasons.
> [a] Simple check of `the next char is * or not?' seems sufficient for
> the purpose.  (In addition, looking-at-p is not available in older
> emacsen.)
> [b] The noerror argument of re-search-forward is dropped.  If that
> re-search-forward fails, the string-to-number on the next line does not
> make sense.  Even if the error is raised here, it is captured by
> ignore-erros in LaTeX-insert-ampersands so the users are not bothered by
> the error.

Thanks!  I'm fine with your suggestions.  I have already pushed some
patches to git for other styles.  Once we have this function sorted out,
I would add some additional tests (see my other message to Mosè) and
update latex.el.  Then `M-RET' should work for all tabular env's.

Best, Arash

___
auctex-devel mailing list
auctex-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-devel


[AUCTeX-diffs] GNU AUCTeX branch, master, updated. a833afff74bb3534a5bce265e2478296f8152526

2016-12-17 Thread Arash Esbati
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
   via  a833afff74bb3534a5bce265e2478296f8152526 (commit)
   via  026579322e0d3327717841f50c1f8814e2909af1 (commit)
   via  945035c9c12a9930cb84491f3b6e0d30e1672798 (commit)
  from  1aa46c3e193ac4c9d23586b59e2256841d02c413 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
commit a833afff74bb3534a5bce265e2478296f8152526
Author: Arash Esbati 
Date:   Sat Dec 17 09:06:09 2016 +0100

Use `LaTeX-item-longtable' while inserting longtable's

* style/longtable.el (LaTeX-longtable-skipping-regexp): New variable.
(LaTeX-item-longtable): New function.  This function is a
variation of `LaTeX-item-array' which uses
`LaTeX-longtable-skipping-regexp' when inserting ampersands.
("longtable"): Append longtable to `LaTeX-item-list'.

diff --git a/style/longtable.el b/style/longtable.el
index 76c397b..aeb275e 100644
--- a/style/longtable.el
+++ b/style/longtable.el
@@ -29,6 +29,23 @@
 
 ;;; Code:
 
+(defvar LaTeX-longtable-skipping-regexp
+  (regexp-opt '("[l]" "[r]" "[c]" ""))
+  "Regexp matching between \\begin{longtable} and column specification.
+For longtable environments only.")
+
+(defun LaTeX-item-longtable ( suppress)
+  "Insert line break macro on the last line and suitable number of &'s.
+For longtable environments.  If SUPPRESS is non-nil, do not
+insert line break macro."
+  (unless suppress
+(save-excursion
+  (end-of-line 0)
+  (just-one-space)
+  (TeX-insert-macro "\\")))
+  (LaTeX-insert-ampersands
+   LaTeX-longtable-skipping-regexp #'LaTeX-array-count-columns))
+
 (TeX-add-style-hook
  "longtable"
  (lambda ()
@@ -64,7 +81,9 @@
(LaTeX-fill-paragraph)
;; Insert a new line and indent
(LaTeX-newline)
-   (indent-according-to-mode))
+   (indent-according-to-mode))
+ ;; Insert suitable number of &'s, suppress line break
+ (LaTeX-item-longtable t)
 
(TeX-add-symbols
 ;; Commands to end table rows
@@ -91,6 +110,9 @@
;; custome values.
(add-to-list 'LaTeX-label-alist '("longtable" . LaTeX-table-label) t)
 
+   ;; Append longtable to `LaTeX-item-list' with `LaTeX-item-longtable'
+   (add-to-list 'LaTeX-item-list '("longtable" . LaTeX-item-longtable) t)
+
;; Fontification
(when (and (featurep 'font-latex)
  (eq TeX-install-font-lock 'font-latex-setup))

commit 026579322e0d3327717841f50c1f8814e2909af1
Author: Arash Esbati 
Date:   Sat Dec 17 08:59:01 2016 +0100

Add "s" and "S" to `LaTeX-array-column-letters'

* style/siunitx.el ("siunitx"): Add column specification letters
"s" and "S" to `LaTeX-array-column-letters'.

diff --git a/style/siunitx.el b/style/siunitx.el
index a5890f5..9fad553 100644
--- a/style/siunitx.el
+++ b/style/siunitx.el
@@ -590,11 +590,17 @@ string."
   "ab"
   "zb"
   "yb"))
+
+   ;; `siunitx.sty' adds new column specification letters
+   (set (make-local-variable 'LaTeX-array-column-letters)
+   (concat LaTeX-array-column-letters "s" "S"))
+
(TeX-run-style-hooks "l3keys2e"
"array"
"amstext"
"xparse"
"expl3")
+
;; Fontification
(when (and (featurep 'font-latex)
  (eq TeX-install-font-lock 'font-latex-setup))

commit 945035c9c12a9930cb84491f3b6e0d30e1672798
Author: Arash Esbati 
Date:   Sat Dec 17 08:46:27 2016 +0100

Append tabular[xy] to `LaTeX-item-list'

* style/tabulary.el ("tabulary"):
* style/tabularx.el ("tabularx"): Append tabularx and tabulary to
`LaTeX-item-list'.

diff --git a/style/tabularx.el b/style/tabularx.el
index 63a1272..2d484db 100644
--- a/style/tabularx.el
+++ b/style/tabularx.el
@@ -43,6 +43,10 @@
;; `LaTeX-indent-environment-list' in order not to override custom settings.
(add-to-list (make-local-variable 'LaTeX-indent-environment-list)
'("tabularx" LaTeX-indent-tabular) t)
+
+   ;; Append tabularx to `LaTeX-item-list' with `LaTeX-item-tabular*'
+   (add-to-list 'LaTeX-item-list '("tabularx" . LaTeX-item-tabular*) t)
+
;; New symbols
(TeX-add-symbols
 "tracingtabularx"
diff --git a/style/tabulary.el b/style/tabulary.el
index 289401e..aa0fcf5 100644
--- a/style/tabulary.el
+++ b/style/tabulary.el
@@ -43,6 +43,10 @@
;; `LaTeX-indent-environment-list' in order not to override custom settings.
(add-to-list (make-local-variable 

[AUCTeX-commit] GNU AUCTeX branch, master, updated. a833afff74bb3534a5bce265e2478296f8152526

2016-12-17 Thread Arash Esbati
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU AUCTeX".

The branch, master has been updated
   via  a833afff74bb3534a5bce265e2478296f8152526 (commit)
   via  026579322e0d3327717841f50c1f8814e2909af1 (commit)
   via  945035c9c12a9930cb84491f3b6e0d30e1672798 (commit)
  from  1aa46c3e193ac4c9d23586b59e2256841d02c413 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -
commit a833afff74bb3534a5bce265e2478296f8152526
Author: Arash Esbati 
Date:   Sat Dec 17 09:06:09 2016 +0100

Use `LaTeX-item-longtable' while inserting longtable's

* style/longtable.el (LaTeX-longtable-skipping-regexp): New variable.
(LaTeX-item-longtable): New function.  This function is a
variation of `LaTeX-item-array' which uses
`LaTeX-longtable-skipping-regexp' when inserting ampersands.
("longtable"): Append longtable to `LaTeX-item-list'.

commit 026579322e0d3327717841f50c1f8814e2909af1
Author: Arash Esbati 
Date:   Sat Dec 17 08:59:01 2016 +0100

Add "s" and "S" to `LaTeX-array-column-letters'

* style/siunitx.el ("siunitx"): Add column specification letters
"s" and "S" to `LaTeX-array-column-letters'.

commit 945035c9c12a9930cb84491f3b6e0d30e1672798
Author: Arash Esbati 
Date:   Sat Dec 17 08:46:27 2016 +0100

Append tabular[xy] to `LaTeX-item-list'

* style/tabulary.el ("tabulary"):
* style/tabularx.el ("tabularx"): Append tabularx and tabulary to
`LaTeX-item-list'.

---

Summary of changes:
 style/longtable.el |   24 +++-
 style/siunitx.el   |6 ++
 style/tabularx.el  |4 
 style/tabulary.el  |4 
 4 files changed, 37 insertions(+), 1 deletion(-)


hooks/post-receive
-- 
GNU AUCTeX

___
auctex-commit mailing list
auctex-com...@gnu.org
https://lists.gnu.org/mailman/listinfo/auctex-commit