Function: c-looking-at-inexpr-block
c-looking-at-inexpr-block is a byte-compiled function defined in
cc-engine.el.gz.
Signature
(c-looking-at-inexpr-block LIM CONTAINING-SEXP &optional CHECK-AT-END)
Documentation
This function has :around advice: csharp-looking-at-inexpr-block.
Source Code
;; Defined in /usr/src/emacs/lisp/progmodes/cc-engine.el.gz
(defun c-looking-at-inexpr-block (lim containing-sexp &optional check-at-end)
;; Return non-nil if we're looking at the beginning of a block
;; inside an expression. The value returned is actually a cons of
;; either 'inlambda, 'inexpr-statement or 'inexpr-class and the
;; position of the beginning of the construct.
;;
;; LIM limits the backward search. CONTAINING-SEXP is the start
;; position of the closest containing list. If it's nil, the
;; containing paren isn't used to decide whether we're inside an
;; expression or not. If both LIM and CONTAINING-SEXP are used, LIM
;; needs to be farther back.
;;
;; If CHECK-AT-END is non-nil then extra checks at the end of the
;; brace block might be done. It should only be used when the
;; construct can be assumed to be complete, i.e. when the original
;; starting position was further down than that.
;;
;; This function might do hidden buffer changes.
(save-excursion
(let ((res 'maybe) (passed-bracket-pairs 0) bracket-pos passed-paren
haskell-op-pos
(closest-lim (or containing-sexp lim (point-min)))
;; Look at the character after point only as a last resort
;; when we can't disambiguate.
(block-follows (and (eq (char-after) ?{) (point))))
;; Search for a C++11 "->" which suggests a lambda declaration.
(when (and (c-major-mode-is 'c++-mode)
(setq haskell-op-pos
(save-excursion
(while
(progn
(c-syntactic-skip-backward "^;=,}>" closest-lim t)
(and (eq (char-before) ?>)
(c-backward-token-2)
(not (looking-at c-haskell-op-re)))))
(and (looking-at c-haskell-op-re)
(point)))))
(goto-char haskell-op-pos))
(while (and (eq res 'maybe)
(progn (c-backward-syntactic-ws lim)
(> (point) closest-lim))
(not (bobp))
(progn (backward-char)
(looking-at "[]).]\\|\\w\\|\\s_"))
(c-safe (forward-char)
(goto-char (scan-sexps (point) -1))))
(setq res
(if (looking-at c-keywords-regexp)
(let ((kw-sym (c-keyword-sym (match-string 1))))
(cond
((and block-follows
(c-keyword-member kw-sym 'c-inexpr-class-kwds))
(and (not (eq passed-paren ?\[))
(or (not (looking-at c-class-key))
;; If the class definition is at the start of
;; a statement, we don't consider it an
;; in-expression class.
(let ((prev (point)))
(while (and
(= (c-backward-token-2 1 nil closest-lim) 0)
(eq (char-syntax (char-after)) ?w))
(setq prev (point)))
(goto-char prev)
(not (c-at-statement-start-p)))
;; Also, in Pike we treat it as an
;; in-expression class if it's used in an
;; object clone expression.
(save-excursion
(and check-at-end
(c-major-mode-is 'pike-mode)
(progn (goto-char block-follows)
(zerop (c-forward-token-2 1 t)))
(eq (char-after) ?\())))
(cons 'inexpr-class (point))))
((c-keyword-member kw-sym 'c-paren-any-kwds) ; e.g. C++11 "throw" or "noexcept"
(setq passed-paren nil)
(setq passed-bracket-pairs 0)
(setq bracket-pos nil)
'maybe)
((c-keyword-member kw-sym 'c-inexpr-block-kwds)
(when (not passed-paren)
(cons 'inexpr-statement (point))))
((c-keyword-member kw-sym 'c-lambda-kwds)
(when (or (not passed-paren)
(eq passed-paren ?\())
(cons 'inlambda (point))))
((c-keyword-member kw-sym 'c-block-stmt-kwds)
nil)
(t
'maybe)))
(if (looking-at "\\s(")
(if passed-paren
(cond
((and (eq passed-paren ?\[)
(eq (char-after) ?\[)
(not (eq (char-after (1+ (point))) ?\[))) ; C++ attribute.
;; Accept several square bracket sexps for
;; Java array initializations.
(setq passed-bracket-pairs (1+ passed-bracket-pairs))
'maybe)
((and (eq passed-paren ?\()
(eq (char-after) ?\[)
(not (eq (char-after (1+ (point))) ?\[))
(eq passed-bracket-pairs 0))
;; C++11 lambda function declaration
(setq passed-bracket-pairs 1)
(setq bracket-pos (point))
'maybe)
(t nil))
(when (not (looking-at "\\[\\["))
(setq passed-paren (char-after))
(when (eq passed-paren ?\[)
(setq passed-bracket-pairs 1)
(setq bracket-pos (point))))
'maybe)
'maybe))))
(if (eq res 'maybe)
(cond
((and (c-major-mode-is 'c++-mode)
block-follows
(eq passed-bracket-pairs 1)
(save-excursion
(goto-char bracket-pos)
(or (<= (point) (or lim (point-min)))
(progn
(c-backward-token-2 1 nil lim)
(and
(not (and (c-on-identifier)
(looking-at c-symbol-char-key)))
(not (looking-at c-opt-op-identifier-prefix)))))))
(cons 'inlambda bracket-pos))
((and c-recognize-paren-inexpr-blocks
block-follows
containing-sexp
(eq (char-after containing-sexp) ?\())
(goto-char containing-sexp)
(if (or (save-excursion
(c-backward-syntactic-ws lim)
(while (and (eq (char-before) ?>)
(c-get-char-property (1- (point))
'syntax-table)
(c-go-list-backward nil lim))
(c-backward-syntactic-ws lim))
(and (> (point) (or lim (point-min)))
(c-on-identifier)))
(and c-special-brace-lists
(c-looking-at-special-brace-list))
(and c-has-compound-literals
(save-excursion
(goto-char block-follows)
(not (c-looking-at-statement-block)))))
nil
(cons 'inexpr-statement (point)))))
res))))