Function: c-font-lock-c++-lambda-captures

c-font-lock-c++-lambda-captures is a byte-compiled function defined in cc-fonts.el.gz.

Signature

(c-font-lock-c++-lambda-captures LIMIT)

Source Code

;; Defined in /usr/src/emacs/lisp/progmodes/cc-fonts.el.gz
(defun c-font-lock-c++-lambda-captures (limit)
  ;; Fontify the lambda capture component of C++ lambda declarations.
  ;;
  ;; This function will be called from font-lock for a region bounded by POINT
  ;; and LIMIT, as though it were to identify a keyword for
  ;; font-lock-keyword-face.  It always returns NIL to inhibit this and
  ;; prevent a repeat invocation.  See elisp/lispref page "Search-based
  ;; Fontification".
  (let (mode capture-default id-start id-end declaration sub-begin sub-end tem)
    (while (and (< (point) limit)
		(search-forward "[" limit t))
      (when (progn (backward-char)
		   (prog1
		       (c-looking-at-c++-lambda-capture-list)
		     (forward-char)))
	(c-forward-syntactic-ws)
	(setq mode (and (memq (char-after) '(?= ?&))
			(char-after)))
	;; Is the first element of the list a bare "=" or "&"?
	(when mode
	  (setq tem nil)
	  (save-excursion
	    (forward-char)
	    (c-forward-syntactic-ws)
	    (if (memq (char-after) '(?, ?\]))
		(progn
		  (setq capture-default mode)
		  (when (eq (char-after) ?,)
		    (forward-char)
		    (c-forward-syntactic-ws))
		  (setq tem (point)))))
	  (if tem (goto-char tem)))

	;; Go round the following loop once per captured item.  We use "\\s)"
	;; rather than "\\]" here to avoid infinite looping in this situation:
	;; "unsigned items [] { [ }".  The second "[" triggers this function,
	;; but if we don't match the "}" with an "\\s)", the
	;; `c-syntactic-re-search-forward' at the end of the loop fails to
	;; move forward over it, leaving point stuck at the "}".
	(while (and (not (looking-at "\\s)"))
		    (< (point) limit))
	  (if (eq (char-after) ?&)
	      (progn (setq mode ?&)
		     (forward-char)
		     (c-forward-syntactic-ws))
	    (setq mode ?=))
	  (if (c-on-identifier)
	      (progn
		(setq id-start (point))
		(forward-char)
		(c-end-of-current-token)
		(setq id-end (point))
		(c-forward-syntactic-ws)

		(setq declaration (eq (char-after) ?=))
		(when declaration
		  (forward-char)	; over "="
		  (c-forward-syntactic-ws)
		  (setq sub-begin (point)))
		(if (or (and (< (point) limit)
			     (c-syntactic-re-search-forward "," limit t t))
			(and (c-go-up-list-forward nil limit)
			     (eq (char-before) ?\])))
		    (backward-char)
		  (goto-char limit))
		(when declaration
		  (save-excursion
		    (setq sub-end (point))
		    (goto-char sub-begin)
		    (c-font-lock-c++-lambda-captures sub-end)))

		(c-put-font-lock-face id-start id-end
				      (cond
				       (declaration
					'font-lock-variable-name-face)
				       ((and capture-default
					     (eq mode capture-default))
					'font-lock-warning-face)
				       ((eq mode ?=) font-lock-constant-face)
				       (t 'font-lock-variable-name-face))))
	    (c-syntactic-re-search-forward "," limit 'bound t))

	  (c-forward-syntactic-ws)
	  (when (eq (char-after) ?,)
	    (forward-char)
	    (c-forward-syntactic-ws)))

	(setq capture-default nil)
	(if (< (point) limit)
	    (forward-char))))) ; over the terminating "]" or other close paren.
  nil)