Function: font-latex-match-command-with-arguments
font-latex-match-command-with-arguments is a byte-compiled function
defined in font-latex.el.
Signature
(font-latex-match-command-with-arguments REGEXP KEYWORDS FACE LIMIT)
Documentation
Search for regexp command KEYWORDS[opt]{arg} before LIMIT.
Returns nil if none of KEYWORDS is found.
Source Code
;; Defined in ~/.emacs.d/elpa/auctex-14.1.2/font-latex.el
(defun font-latex-match-command-with-arguments (regexp keywords face limit)
"Search for regexp command KEYWORDS[opt]{arg} before LIMIT.
Returns nil if none of KEYWORDS is found."
(setq font-latex-matched-faces nil)
(catch 'match
(while (re-search-forward regexp limit t)
(unless (font-latex-faces-present-p '(font-lock-comment-face
font-latex-verbatim-face)
(match-beginning 0))
(let* ((beg (match-beginning 0))
end ; Used for multiline text property.
(match-data (list beg))
match-beg syntax-error alternative spec
error-indicator-pos
(spec-list (string-to-list
(or (cadr (assoc (match-string 1) keywords))
font-latex-command-with-args-default-spec)))
(parse-sexp-ignore-comments t)) ; scan-sexps ignores comments
(goto-char (match-end 0))
;; Check for starred macro if first spec is an asterisk or a
;; plus sign in case of \defaultfontfeatures+ provided by
;; fontspec.sty
(when (memql (car spec-list) '(?* ?+))
(setq spec-list (cdr spec-list))
(skip-chars-forward "*+" (1+ (point))))
;; Add current point to match data and use keyword face for
;; region from start to point.
(nconc match-data (list (point)))
(add-to-list 'font-latex-matched-faces 'font-lock-keyword-face)
(setq end (point))
(catch 'break
;; Walk the list of specs.
(while spec-list
(setq spec (pop spec-list)
error-indicator-pos beg)
(while (and (not (eobp)) (font-latex-forward-comment)))
;; Alternative
(when (eq spec ?|)
(setq alternative t)
(setq spec (pop spec-list)))
(cond
;; Macros: \foo
((eq spec ?\\)
(if (eq (char-after) spec)
(progn
(nconc match-data
(list (point)
(progn
(forward-char)
(if (zerop (skip-syntax-forward "_w"))
(forward-char) ; Single-char macro.
(skip-chars-forward "*+"))
(point))))
(nconc font-latex-matched-faces (list face))
(setq end (max end (point)))
(when alternative (pop spec-list)))
(setq syntax-error t)
(throw 'break nil)))
;; Mandatory arguments: {...}
((eq spec ?{)
(if (and (eq (char-after) spec)
(setq match-beg (point))
(font-latex-find-matching-close ?{ ?}))
(progn
(nconc match-data (list (1+ match-beg) (1- (point))))
(nconc font-latex-matched-faces (list face))
(setq end (max end (1- (point))))
(when alternative (pop spec-list)))
(unless alternative
(setq syntax-error t)
(when (and match-beg (= match-beg (point)))
(setq error-indicator-pos match-beg))
(throw 'break nil))))
;; Asterisk or plus sign between arguments (sigh!):
((and (memql spec '(?* ?+))
(= (char-after) spec))
(setq match-beg (point))
(if (= (char-after) spec)
(progn
(nconc match-data
(list (point)
(progn
(skip-chars-forward "*+")
(point))))
(nconc font-latex-matched-faces
(list 'font-lock-keyword-face))
(setq end (max end (point))))
(throw 'break nil)))
;; Optional arguments: [...] and others
((eq (char-after) spec)
(setq match-beg (point))
(if (font-latex-find-matching-close
spec (cdr (assq
spec
font-latex-command-with-args-opt-arg-delims)))
(progn
(nconc match-data (list (1+ match-beg) (1- (point))))
(nconc font-latex-matched-faces
(list 'font-lock-variable-name-face))
(setq end (max end (1- (point)))))
(setq syntax-error t
error-indicator-pos match-beg)
(throw 'break nil))))
(setq alternative nil)))
(when (and syntax-error (memq major-mode
font-latex-syntax-error-modes))
;; Add the warning face at the front of the list because
;; the matcher uses 'append and the face would otherwise
;; be overridden by the keyword face.
(setq match-data (append (list error-indicator-pos
(1+ error-indicator-pos))
match-data))
(push 'font-latex-warning-face font-latex-matched-faces))
(store-match-data match-data)
(throw 'match t))))))