;; pair element into an open paren element. Doing that would mean that the
;; new open paren wouldn't have the required preceding paren pair element.
;;
- ;; This function is called from c-after-change.
+ ;; This function is called from c-before-change.
;; The caches of non-literals:
;; Note that we use "<=" for the possibility of the second char of a two-char
;; below `here'. To maintain its consistency, we may need to insert a new
;; brace pair.
(let ((here-bol (c-point 'bol here))
- too-high-pa ; recorded {/(/[ next above here, or nil.
+ too-high-pa ; recorded {/(/[ next above or just below here, or nil.
dropped-cons ; was the last removed element a brace pair?
pa)
;; The easy bit - knock over-the-top bits off `c-state-cache'.
;; Do we need to add in an earlier brace pair, having lopped one off?
(if (and dropped-cons
- (< too-high-pa (+ here c-state-cache-too-far)))
+ (<= too-high-pa here))
(c-append-lower-brace-pair-to-state-cache too-high-pa here here-bol))
(setq c-state-cache-good-pos (or (c-state-cache-after-top-paren)
(c-state-get-min-scan-pos)))))
(make-variable-buffer-local 'c-parse-state-state)
(defun c-record-parse-state-state ()
(setq c-parse-state-point (point))
+ (when (markerp (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)))
+ (move-marker (cdr (assq 'c-state-old-cpp-beg c-parse-state-state)) nil)
+ (move-marker (cdr (assq 'c-state-old-cpp-end c-parse-state-state)) nil))
(setq c-parse-state-state
(mapcar
(lambda (arg)
(setq safe-pos-list (cdr safe-pos-list)))
(unless (setq safe-pos (car-safe safe-pos-list))
(setq safe-pos (max (or (c-safe-position
- (point) (or c-state-cache
- (c-parse-state)))
+ (point) (c-parse-state))
0)
(point-min))
safe-pos-list (list safe-pos)))
Note that this function might do hidden buffer changes. See the
comment at the start of cc-engine.el for more info."
- (let ((start (point))
- state-2
- ;; A list of syntactically relevant positions in descending
- ;; order. It's used to avoid scanning repeatedly over
- ;; potentially large regions with `parse-partial-sexp' to verify
- ;; each position. Used in `c-ssb-lit-begin'
- safe-pos-list
- ;; The result from `c-beginning-of-macro' at the start position or the
- ;; start position itself if it isn't within a macro. Evaluated on
- ;; demand.
- start-macro-beg
- ;; The earliest position after the current one with the same paren
- ;; level. Used only when `paren-level' is set.
- lit-beg
- (paren-level-pos (point)))
-
- (while
- (progn
- ;; The next loop "tries" to find the end point each time round,
- ;; loops when it hasn't succeeded.
- (while
- (and
- (let ((pos (point)))
- (while (and
- (< (skip-chars-backward skip-chars limit) 0)
- ;; Don't stop inside a literal.
- (when (setq lit-beg (c-ssb-lit-begin))
- (goto-char lit-beg)
- t)))
- (< (point) pos))
+ (c-self-bind-state-cache
+ (let ((start (point))
+ state-2
+ ;; A list of syntactically relevant positions in descending
+ ;; order. It's used to avoid scanning repeatedly over
+ ;; potentially large regions with `parse-partial-sexp' to verify
+ ;; each position. Used in `c-ssb-lit-begin'
+ safe-pos-list
+ ;; The result from `c-beginning-of-macro' at the start position or the
+ ;; start position itself if it isn't within a macro. Evaluated on
+ ;; demand.
+ start-macro-beg
+ ;; The earliest position after the current one with the same paren
+ ;; level. Used only when `paren-level' is set.
+ lit-beg
+ (paren-level-pos (point)))
+
+ (while
+ (progn
+ ;; The next loop "tries" to find the end point each time round,
+ ;; loops when it hasn't succeeded.
+ (while
+ (and
+ (let ((pos (point)))
+ (while (and
+ (< (skip-chars-backward skip-chars limit) 0)
+ ;; Don't stop inside a literal.
+ (when (setq lit-beg (c-ssb-lit-begin))
+ (goto-char lit-beg)
+ t)))
+ (< (point) pos))
+
+ (let ((pos (point)) state-2 pps-end-pos)
- (let ((pos (point)) state-2 pps-end-pos)
+ (cond
+ ((and paren-level
+ (save-excursion
+ (setq state-2 (parse-partial-sexp
+ pos paren-level-pos -1)
+ pps-end-pos (point))
+ (/= (car state-2) 0)))
+ ;; Not at the right level.
+
+ (if (and (< (car state-2) 0)
+ ;; We stop above if we go out of a paren.
+ ;; Now check whether it precedes or is
+ ;; nested in the starting sexp.
+ (save-excursion
+ (setq state-2
+ (parse-partial-sexp
+ pps-end-pos paren-level-pos
+ nil nil state-2))
+ (< (car state-2) 0)))
+
+ ;; We've stopped short of the starting position
+ ;; so the hit was inside a nested list. Go up
+ ;; until we are at the right level.
+ (condition-case nil
+ (progn
+ (goto-char (scan-lists pos -1
+ (- (car state-2))))
+ (setq paren-level-pos (point))
+ (if (and limit (>= limit paren-level-pos))
+ (progn
+ (goto-char limit)
+ nil)
+ t))
+ (error
+ (goto-char (or limit (point-min)))
+ nil))
+
+ ;; The hit was outside the list at the start
+ ;; position. Go to the start of the list and exit.
+ (goto-char (1+ (elt state-2 1)))
+ nil))
+
+ ((c-beginning-of-macro limit)
+ ;; Inside a macro.
+ (if (< (point)
+ (or start-macro-beg
+ (setq start-macro-beg
+ (save-excursion
+ (goto-char start)
+ (c-beginning-of-macro limit)
+ (point)))))
+ t
+
+ ;; It's inside the same macro we started in so it's
+ ;; a relevant match.
+ (goto-char pos)
+ nil))))))
- (cond
- ((and paren-level
- (save-excursion
- (setq state-2 (parse-partial-sexp
- pos paren-level-pos -1)
- pps-end-pos (point))
- (/= (car state-2) 0)))
- ;; Not at the right level.
-
- (if (and (< (car state-2) 0)
- ;; We stop above if we go out of a paren.
- ;; Now check whether it precedes or is
- ;; nested in the starting sexp.
- (save-excursion
- (setq state-2
- (parse-partial-sexp
- pps-end-pos paren-level-pos
- nil nil state-2))
- (< (car state-2) 0)))
-
- ;; We've stopped short of the starting position
- ;; so the hit was inside a nested list. Go up
- ;; until we are at the right level.
- (condition-case nil
- (progn
- (goto-char (scan-lists pos -1
- (- (car state-2))))
- (setq paren-level-pos (point))
- (if (and limit (>= limit paren-level-pos))
- (progn
- (goto-char limit)
- nil)
- t))
- (error
- (goto-char (or limit (point-min)))
- nil))
-
- ;; The hit was outside the list at the start
- ;; position. Go to the start of the list and exit.
- (goto-char (1+ (elt state-2 1)))
- nil))
-
- ((c-beginning-of-macro limit)
- ;; Inside a macro.
- (if (< (point)
- (or start-macro-beg
- (setq start-macro-beg
- (save-excursion
- (goto-char start)
- (c-beginning-of-macro limit)
- (point)))))
- t
-
- ;; It's inside the same macro we started in so it's
- ;; a relevant match.
- (goto-char pos)
- nil))))))
-
- (> (point)
- (progn
- ;; Skip syntactic ws afterwards so that we don't stop at the
- ;; end of a comment if `skip-chars' is something like "^/".
- (c-backward-syntactic-ws)
- (point)))))
+ (> (point)
+ (progn
+ ;; Skip syntactic ws afterwards so that we don't stop at the
+ ;; end of a comment if `skip-chars' is something like "^/".
+ (c-backward-syntactic-ws)
+ (point)))))
- ;; We might want to extend this with more useful return values in
- ;; the future.
- (/= (point) start)))
+ ;; We might want to extend this with more useful return values in
+ ;; the future.
+ (/= (point) start))))
;; The following is an alternative implementation of
;; `c-syntactic-skip-backward' that uses backward movement to keep
(when (or (looking-at "extends")
(looking-at "super"))
- (forward-word)
+ (forward-word-strictly)
(c-forward-syntactic-ws)
(let ((c-promote-possible-types t)
(c-record-found-types t))
;; Stop on ',', '|', '&', '+' and '-' to catch
;; common binary operators that could be between
;; two comparison expressions "a<b" and "c>d".
- "[<;{},|+&-]\\|[>)]"
+ ;; 2016-02-11: C++11 templates can now contain arithmetic
+ ;; expressions, so template detection in C++ is now less
+ ;; robust than it was.
+ c-<>-notable-chars-re
nil t t))
(cond
;; Either an operator starting with '>' or the end of
;; the angle bracket arglist.
- (if (looking-at c->-op-without->-cont-regexp)
+ (if (save-excursion
+ (c-backward-token-2)
+ (looking-at c-multichar->-op-not->>-regexp))
(progn
(goto-char (match-end 0))
t) ; Continue the loop.
)))
t) ; carry on looping.
+ ((and
+ (eq (char-before) ?\()
+ (c-go-up-list-forward)
+ (eq (char-before) ?\))))
+
((and (not c-restricted-<>-arglists)
(or (and (eq (char-before) ?&)
(not (eq (char-after) ?&)))
;; This identifier is bound only in the inner let.
'(setq start id-start))))
-(defun c-forward-declarator (&optional limit)
+(defun c-forward-declarator (&optional limit accept-anon)
;; Assuming point is at the start of a declarator, move forward over it,
;; leaving point at the next token after it (e.g. a ) or a ; or a ,).
;;
;; BRACKETS-AFTER-ID is non-nil if a [...] pair is present after the id.
;; GOT-INIT is non-nil when the declarator is followed by "=" or "(".
;;
+ ;; If ACCEPT-ANON is non-nil, move forward over any "anonymous declarator",
+ ;; i.e. something like the (*) in int (*), such as might be found in a
+ ;; declaration. In such a case ID-START and ID-END in the return value are
+ ;; both set to nil. A "null" "anonymous declarator" gives a non-nil result.
+ ;;
;; If no declarator is found, leave point unmoved and return nil. LIMIT is
;; an optional limit for forward searching.
;;
;; If we haven't passed the identifier already, do it now.
(unless got-identifier
- (setq id-start (point))
- (c-forward-name))
- (prog1
- (/= (point) here)
+ (setq id-start (point)))
+ (cond
+ ((or got-identifier
+ (c-forward-name))
(save-excursion
(c-backward-syntactic-ws)
- (setq id-end (point)))))
+ (setq id-end (point))))
+ (accept-anon
+ (setq id-start nil id-end nil)
+ t)
+ (t (/= (point) here))))
;; Skip out of the parens surrounding the identifier. If closing
;; parens are missing, this form returns nil.
(goto-char id-start)
;; Skip over type decl prefix operators. (Note similar code in
- ;; `c-font-lock-declarators'.)
+ ;; `c-forward-declarator'.)
(if (and c-recognize-typeless-decls
(equal c-type-decl-prefix-key "\\<\\>"))
(when (eq (char-after) ?\()
before-lparen after-rparen
(here (point))
(pp-count-out 20) ; Max number of paren/brace constructs before
- ; we give up
- ids ; List of identifiers in the parenthesised list.
+ ; we give up.
+ ids ; List of identifiers in the parenthesized list.
id-start after-prec-token decl-or-cast decl-res
c-last-identifier-range identifier-ok)
(narrow-to-region low-lim (or macro-end (point-max)))
;; {
;;
;; Additionally, for a knr list to be recognized:
- ;; o - The identifier of each deeclarator up to and including the
+ ;; o - The identifier of each declarator up to and including the
;; one "near" point must be contained in the arg list.
(catch 'knr
paren-state)))
;; CASE 14: A case or default label
- ((looking-at c-label-kwds-regexp)
+ ((save-excursion
+ (and (looking-at c-label-kwds-regexp)
+ (or (c-major-mode-is 'idl-mode)
+ (and
+ containing-sexp
+ (goto-char containing-sexp)
+ (eq (char-after) ?{)
+ (progn (c-backward-syntactic-ws) t)
+ (eq (char-before) ?\))
+ (c-go-list-backward)
+ (progn (c-backward-syntactic-ws) t)
+ (c-simple-skip-symbol-backward)
+ (looking-at c-block-stmt-2-key)))))
(if containing-sexp
(progn
(goto-char containing-sexp)
((save-excursion
(back-to-indentation)
(and (not (looking-at c-syntactic-ws-start))
+ (not (looking-at c-label-kwds-regexp))
(c-forward-label)))
(cond (containing-decl-open
(setq placeholder (c-add-class-syntax 'inclass