Function: LaTeX-array-count-columns
LaTeX-array-count-columns is a byte-compiled function defined in
latex.el.
Signature
(LaTeX-array-count-columns START END)
Documentation
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.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(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))))
;; Do not skip over `*' (see above) and `[' (siunitx has `S[key=val]':):
(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)))))