Function: LaTeX-insert-ampersands
LaTeX-insert-ampersands is a byte-compiled function defined in
latex.el.
Signature
(LaTeX-insert-ampersands REGEXP FUNC)
Documentation
Insert suitable number of ampersands for the current environment.
The number is calculated from REGEXP and FUNC.
Example 1:
Consider the case that the current environment begins with
\begin{array}[t]{|lcr|}
. REGEXP must be chosen to match "[t]", that is, the text between just
after "\\begin{array}" and just before "{|lcr|}", which encloses
the column specification. FUNC must return the number of ampersands to
be inserted, which is 2 since this example specifies three columns.
FUNC is called with two arguments START and END, which spans the column
specification (without enclosing braces.) REGEXP is used to determine
these START and END.
Example 2:
This time the environment begins with
\begin{tabular*}{1.0\linewidth}[b]{c@{,}p{5ex}}
. REGEXP must match "{1.0\\linewidth}[b]" and FUNC must return 1 from
the text "c@{,}p{5ex}" between START and END specified two columns.
FUNC should return nil if it cannot determine the number of ampersands.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/latex.el
(defun LaTeX-insert-ampersands (regexp func)
"Insert suitable number of ampersands for the current environment.
The number is calculated from REGEXP and FUNC.
Example 1:
Consider the case that the current environment begins with
\\begin{array}[t]{|lcr|}
. REGEXP must be chosen to match \"[t]\", that is, the text between just
after \"\\begin{array}\" and just before \"{|lcr|}\", which encloses
the column specification. FUNC must return the number of ampersands to
be inserted, which is 2 since this example specifies three columns.
FUNC is called with two arguments START and END, which spans the column
specification (without enclosing braces.) REGEXP is used to determine
these START and END.
Example 2:
This time the environment begins with
\\begin{tabular*}{1.0\\linewidth}[b]{c@{,}p{5ex}}
. REGEXP must match \"{1.0\\linewidth}[b]\" and FUNC must return 1 from
the text \"c@{,}p{5ex}\" between START and END specified two columns.
FUNC should return nil if it cannot determine the number of ampersands."
(let* ((cur (point))
(num
(save-excursion
(ignore-errors
(LaTeX-find-matching-begin)
;; Skip over "\begin{xxx}" and possible whitespaces.
(forward-list 1)
(skip-chars-forward " \t")
;; Skip over the text specified by REGEXP and whitespaces.
(when (let ((case-fold-search nil))
(re-search-forward regexp cur))
(skip-chars-forward " \t")
(when (eq (following-char) ?{)
;; We have reached the target "{yyy}" part.
(forward-char 1)
;; The next line doesn't move point, so point
;; is left just after the opening brace.
(let ((pos (TeX-find-closing-brace)))
(if pos
;; Calculate number of ampersands to be inserted.
(funcall func (point) (1- pos))))))))))
(if (natnump num)
(save-excursion (insert (make-string num ?&))))))