Function: TeX-find-macro-boundaries
TeX-find-macro-boundaries is a byte-compiled function defined in
tex.el.
Signature
(TeX-find-macro-boundaries &optional LOWER-BOUND SIGNATURE)
Documentation
Return a cons containing the start and end of a macro.
If LOWER-BOUND is given, do not search backward further than this point in buffer. Arguments enclosed in brackets or braces are considered part of the macro.
If SIGNATURE is given, restrict the total number of arguments. If SIGNATURE is an integer N, allow at most N total arguments. If SIGNATURE is a cons cell (P . Q), allow at most P optional and Q mandatory arguments.
Finally, SIGNATURE may be a function, called before each new argument is
consumed with a single list argument consisting of the argument blocks
encountered thus far. For example, with point before
"\\begin{equation}", it is called first with the empty list () and
then with the single element list ("{equation}"). If SIGNATURE
returns non-nil, then no further macro arguments are consumed.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/tex.el
(defun TeX-find-macro-boundaries (&optional lower-bound signature)
"Return a cons containing the start and end of a macro.
If LOWER-BOUND is given, do not search backward further than this
point in buffer. Arguments enclosed in brackets or braces are
considered part of the macro.
If SIGNATURE is given, restrict the total number of arguments. If
SIGNATURE is an integer N, allow at most N total arguments. If
SIGNATURE is a cons cell (P . Q), allow at most P optional and Q
mandatory arguments.
Finally, SIGNATURE may be a function, called before each new argument is
consumed with a single list argument consisting of the argument blocks
encountered thus far. For example, with point before
\"\\begin{equation}\", it is called first with the empty list () and
then with the single element list (\"{equation}\"). If SIGNATURE
returns non-nil, then no further macro arguments are consumed."
;; FIXME: Pay attention to `texmathp-allow-detached-args' and
;; `reftex-allow-detached-macro-args'.
;; Should we handle cases like \"{o} and \\[3mm] (that is, a macro
;; whose name is a symbol and takes some arguments) as well? Note
;; that amsmath package arranges the macro \\ so that white spaces
;; between \\ and [something] prevents the latter to be interpreted
;; as an optional argument. mathtools package arranges some
;; environments including gathered similarly.
(save-restriction
(when lower-bound
(narrow-to-region lower-bound (point-max)))
(let ((orig-point (point))
start-point)
;; Point is located directly at the start of a macro. (-!-\foo{bar})
(when (and (eq (char-after) (aref TeX-esc 0))
(not (TeX-escaped-p)))
(setq start-point (point)))
;; Point is located on a macro. (\fo-!-o{bar})
(unless start-point
(save-excursion
(skip-chars-backward "A-Za-z@*")
(when (and (eq (char-before) (aref TeX-esc 0))
(not (TeX-escaped-p (1- (point)))))
(setq start-point (1- (point))))))
;; Point is located in the argument of a macro. (\foo{ba-!-r})
(unless start-point
(save-excursion
(catch 'abort
(let ((parse-sexp-ignore-comments t))
(when (condition-case nil (progn (up-list) t) (error nil))
(while (progn
(condition-case nil (backward-sexp)
(error (throw 'abort nil)))
(forward-comment -1)
(skip-chars-backward " \t")
(and (memq (char-before) '(?\] ?\}))
(not (TeX-escaped-p (1- (point)))))))
(skip-chars-backward "A-Za-z@*")
(when (and (eq (char-before) (aref TeX-esc 0))
(not (TeX-escaped-p (1- (point)))))
(setq start-point (1- (point)))))))))
;; Search forward for the end of the macro.
(when start-point
(save-excursion
(goto-char (TeX-find-macro-end-helper start-point signature))
(if (< orig-point (point))
(cons start-point (point))
nil))))))