@@ -3233,7 +3233,7 @@ This function should be added to the `before-change-functions'
3233
3233
hook by major modes that use CC Mode's filling functionality
3234
3234
without initializing CC Mode. Currently (2020-06) these are
3235
3235
`js-mode' and `mhtml-mode'."
3236
- (c-truncate-lit-pos-cache beg))
3236
+ (c-truncate-lit-pos/state -cache beg))
3237
3237
3238
3238
(defun c-foreign-init-lit-pos-cache ()
3239
3239
"Initialize CC Mode's literal cache.
@@ -3242,7 +3242,7 @@ This function should be called from the mode functions of major
3242
3242
modes which use CC Mode's filling functionality without
3243
3243
initializing CC Mode. Currently (2020-06) these are `js-mode' and
3244
3244
`mhtml-mode'."
3245
- (c-truncate-lit-pos-cache 1))
3245
+ (c-truncate-lit-pos/state -cache 1))
3246
3246
3247
3247
3248
3248
;; A system for finding noteworthy parens before the point.
@@ -13365,12 +13365,21 @@ comment at the start of cc-engine.el for more info."
13365
13365
(t t)))) ;; The caller can go up one level.
13366
13366
))))
13367
13367
13368
- ;; A list of the form returned by `c-parse-state'. Each opening brace in it
13369
- ;; is not the brace of a brace list. Any cons items in it are ignored, and
13370
- ;; are also unreliable.
13368
+ ;; A list of the form returned by `c-parse-state', but without conses. Each
13369
+ ;; opening brace in it is not the brace of a brace list.
13371
13370
(defvar c-no-bracelist-cache nil)
13372
13371
(make-variable-buffer-local 'c-no-bracelist-cache)
13373
13372
13373
+ (defun c-strip-conses (liszt)
13374
+ ;; Make a copy of the list LISZT, removing conses from the copy. Return the
13375
+ ;; result.
13376
+ (let ((ptr liszt) new)
13377
+ (while ptr
13378
+ (if (atom (car ptr))
13379
+ (push (car ptr) new))
13380
+ (setq ptr (cdr ptr)))
13381
+ (nreverse new)))
13382
+
13374
13383
(defun c-inside-bracelist-p (containing-sexp paren-state accept-in-paren)
13375
13384
;; Return the buffer position of the beginning of the brace list statement
13376
13385
;; if CONTAINING-SEXP is inside a brace list, otherwise return nil.
@@ -13433,13 +13442,13 @@ comment at the start of cc-engine.el for more info."
13433
13442
(not (memq next-containing c-no-bracelist-cache)))
13434
13443
(setq next-containing (c-pull-open-brace paren-state)))
13435
13444
(setq c-no-bracelist-cache
13436
- (nconc whole-paren-state
13445
+ (nconc (c-strip-conses whole-paren-state)
13437
13446
(and next-containing (list next-containing))
13438
13447
paren-state))
13439
13448
nil)
13440
13449
((not (memq containing-sexp c-no-bracelist-cache))
13441
13450
;; Update `c-no-bracelist-cache'
13442
- (setq c-no-bracelist-cache (copy-tree whole-paren-state))
13451
+ (setq c-no-bracelist-cache (c-strip-conses whole-paren-state))
13443
13452
nil)))))
13444
13453
13445
13454
(defun c-looking-at-special-brace-list ()
@@ -14067,6 +14076,7 @@ comment at the start of cc-engine.el for more info."
14067
14076
(let ((syntax-last c-syntactic-context)
14068
14077
(boi (c-point 'boi))
14069
14078
(anchor-boi (c-point 'boi))
14079
+ (anchor-point-2 containing-sexp)
14070
14080
;; Set when we're on a label, so that we don't stop there.
14071
14081
;; FIXME: To be complete we should check if we're on a label
14072
14082
;; now at the start.
@@ -14078,17 +14088,24 @@ comment at the start of cc-engine.el for more info."
14078
14088
(point) nil)
14079
14089
syntax-extra-args)
14080
14090
14081
- ;; Loop while we have to back out of containing blocks.
14091
+ ;; Each time round the following loop, back out of the containing block.
14092
+ ;; Do this unless `fixed-anchor' is non-nil and `containing-sexp' is at
14093
+ ;; or before the BOI of the anchor position. Carry on until the inner
14094
+ ;; `while' loop fails to back up to `containing-sexp', or we reach the
14095
+ ;; top level, or `containing-sexp' is before the initial anchor point.
14082
14096
(while
14083
14097
(and
14084
14098
(catch 'back-up-block
14085
14099
14086
- ;; Loop while we have to back up statements.
14100
+ ;; Each time round the following loop, back up a single
14101
+ ;; statement until we reach a BOS at BOI, or `containing-sexp',
14102
+ ;; or any previous statement when `stop-at-boi-only' is nil.
14103
+ ;; More or less. Read the source for full details. ;-(
14087
14104
(while (or (/= (point) boi)
14088
14105
on-label
14089
14106
(looking-at c-comment-start-regexp))
14090
14107
14091
- ;; Skip past any comments that stands between the
14108
+ ;; Skip past any comments that stand between the
14092
14109
;; statement start and boi.
14093
14110
(let ((savepos (point)))
14094
14111
(while (and (/= savepos boi)
@@ -14146,7 +14163,11 @@ comment at the start of cc-engine.el for more info."
14146
14163
14147
14164
containing-sexp
14148
14165
(or (null fixed-anchor)
14149
- (> containing-sexp anchor-boi)))
14166
+ (> containing-sexp anchor-boi)
14167
+ (save-excursion
14168
+ (goto-char (1+ containing-sexp))
14169
+ (c-forward-syntactic-ws (c-point 'eol))
14170
+ (< (point) (c-point 'eol)))))
14150
14171
14151
14172
;; Now we have to go out of this block.
14152
14173
(goto-char containing-sexp)
@@ -14168,7 +14189,7 @@ comment at the start of cc-engine.el for more info."
14168
14189
;; from and add the right syntactic element for it.
14169
14190
(let ((paren-pos (point))
14170
14191
(paren-char (char-after))
14171
- step-type)
14192
+ step-type anchor-point )
14172
14193
14173
14194
(if (eq paren-char ?\()
14174
14195
;; Stepped out of a parenthesis block, so we're in an
@@ -14199,45 +14220,62 @@ comment at the start of cc-engine.el for more info."
14199
14220
on-label nil))
14200
14221
14201
14222
;; Stepped out of a brace block.
14223
+ (save-excursion
14224
+ (if (and (zerop (c-backward-token-2))
14225
+ (looking-at "=\\([^=]\\|$\\)")
14226
+ (zerop (c-backward-token-2))
14227
+ (looking-at c-symbol-key)
14228
+ (not (looking-at c-keywords-regexp)))
14229
+ (setq anchor-point (point))))
14230
+ (if anchor-point
14231
+ (progn (goto-char anchor-point)
14232
+ (setq step-type 'same
14233
+ on-label nil))
14234
+
14202
14235
(setq step-type (c-beginning-of-statement-1 containing-sexp)
14203
- on-label (eq step-type 'label))
14236
+ on-label (eq step-type 'label)))
14204
14237
14205
- (if (and (eq step-type 'same)
14206
- (/= paren-pos (point)))
14207
- (let (inexpr bspec)
14208
- (cond
14209
- ((save-excursion
14210
- (goto-char paren-pos)
14211
- (setq inexpr (c-looking-at-inexpr-block
14212
- (c-safe-position containing-sexp paren-state)
14213
- containing-sexp)))
14214
- (c-add-syntax (if (eq (car inexpr) 'inlambda)
14215
- 'defun-block-intro
14216
- 'statement-block-intro)
14217
- nil))
14218
- ((looking-at c-other-decl-block-key)
14219
- (c-add-syntax
14220
- (cdr (assoc (match-string 1)
14221
- c-other-decl-block-key-in-symbols-alist))
14222
- (max (c-point 'boi paren-pos) (point))))
14223
- ((c-at-enum-brace paren-pos)
14224
- (c-add-syntax 'enum-intro nil))
14225
- ((c-inside-bracelist-p paren-pos paren-state nil)
14226
- (if (save-excursion
14227
- (goto-char paren-pos)
14228
- (c-looking-at-statement-block))
14229
- (c-add-syntax 'defun-block-intro nil)
14230
- (c-add-syntax 'brace-list-intro nil)))
14231
- ((save-excursion
14238
+ (let (inexpr bspec)
14239
+ (cond
14240
+ ((or (not (eq step-type 'same))
14241
+ (eq paren-pos (point)))
14242
+ (if (and (eq paren-pos (point))
14243
+ (c-inside-bracelist-p paren-pos paren-state nil))
14244
+ (c-add-syntax 'brace-list-intro nil anchor-point-2)
14245
+ (c-add-syntax 'statement-block-intro nil)))
14246
+ ((save-excursion
14247
+ (goto-char paren-pos)
14248
+ (setq inexpr (c-looking-at-inexpr-block
14249
+ (c-safe-position containing-sexp paren-state)
14250
+ containing-sexp)))
14251
+ (c-add-syntax (if (eq (car inexpr) 'inlambda)
14252
+ 'defun-block-intro
14253
+ 'statement-block-intro)
14254
+ nil))
14255
+ ((looking-at c-other-decl-block-key)
14256
+ (c-add-syntax
14257
+ (cdr (assoc (match-string 1)
14258
+ c-other-decl-block-key-in-symbols-alist))
14259
+ (max (c-point 'boi paren-pos) (point))))
14260
+ ((c-at-enum-brace paren-pos)
14261
+ (c-add-syntax 'enum-intro nil anchor-point-2))
14262
+ ((c-inside-bracelist-p paren-pos paren-state nil)
14263
+ (if (save-excursion
14232
14264
(goto-char paren-pos)
14233
- (setq bspec (c-looking-at-or-maybe-in-bracelist
14234
- containing-sexp containing-sexp))
14235
- (and (consp bspec)
14236
- (eq (cdr bspec) 'in-paren)))
14237
- (c-add-syntax 'brace-list-intro (car bspec)))
14238
- (t (c-add-syntax 'defun-block-intro nil))))
14265
+ (c-looking-at-statement-block))
14266
+ (c-add-syntax 'defun-block-intro nil)
14267
+ (c-add-syntax 'brace-list-intro nil anchor-point-2)))
14268
+ ((save-excursion
14269
+ (goto-char paren-pos)
14270
+ (setq bspec (c-looking-at-or-maybe-in-bracelist
14271
+ containing-sexp containing-sexp))
14272
+ (and (consp bspec)
14273
+ (eq (cdr bspec) 'in-paren)))
14274
+ (c-add-syntax 'brace-list-intro (car bspec)
14275
+ anchor-point-2))
14276
+ (t (c-add-syntax 'defun-block-intro nil))))
14239
14277
14240
- (c-add-syntax 'statement-block-intro nil) ))
14278
+ (setq anchor-point-2 containing-sexp ))
14241
14279
14242
14280
(if (= paren-pos boi)
14243
14281
;; Always done if the open brace was at boi. The
@@ -15489,9 +15527,13 @@ comment at the start of cc-engine.el for more info."
15489
15527
(not (eq (cdr tmp) 'expression))
15490
15528
(setq placeholder (car tmp)))
15491
15529
(c-add-syntax
15492
- (if (eq char-after-ip ?{)
15493
- 'substatement-open
15494
- 'substatement)
15530
+ (cond
15531
+ ((and (eq (char-after containing-sexp) ?\()
15532
+ (> containing-sexp placeholder))
15533
+ 'constraint-cont)
15534
+ ((eq char-after-ip ?{)
15535
+ 'substatement-open)
15536
+ (t 'substatement))
15495
15537
(c-point 'boi placeholder)))
15496
15538
15497
15539
;; ((Old) CASE 6 has been removed.)
@@ -15761,7 +15803,17 @@ comment at the start of cc-engine.el for more info."
15761
15803
(c-determine-limit 1000))
15762
15804
(point)))
15763
15805
(c-most-enclosing-brace state-cache (point))))
15764
- (c-beginning-of-statement-1 lim nil nil t)
15806
+ (save-excursion
15807
+ (setq placeholder
15808
+ (and (zerop (c-backward-token-2))
15809
+ (looking-at "=\\([^=]\\|$\\)")
15810
+ (zerop (c-backward-token-2))
15811
+ (looking-at c-symbol-key)
15812
+ (not (looking-at c-keywords-regexp))
15813
+ (point))))
15814
+ (if placeholder
15815
+ (goto-char placeholder)
15816
+ (c-beginning-of-statement-1 lim nil nil t))
15765
15817
(c-add-stmt-syntax (if enum-pos 'enum-close 'brace-list-close)
15766
15818
nil t lim paren-state)))
15767
15819
@@ -15790,7 +15842,7 @@ comment at the start of cc-engine.el for more info."
15790
15842
(goto-char containing-sexp))
15791
15843
(if (eq (point) (c-point 'boi))
15792
15844
(c-add-syntax (if enum-pos 'enum-intro 'brace-list-intro)
15793
- (point))
15845
+ (point) containing-sexp )
15794
15846
(setq lim (or (save-excursion
15795
15847
(and
15796
15848
(c-back-over-member-initializers
@@ -15799,20 +15851,25 @@ comment at the start of cc-engine.el for more info."
15799
15851
(c-most-enclosing-brace state-cache (point))))
15800
15852
(c-beginning-of-statement-1 lim nil nil t)
15801
15853
(c-add-stmt-syntax (if enum-pos 'enum-intro 'brace-list-intro)
15802
- nil t lim paren-state)))
15854
+ (list containing-sexp)
15855
+ t lim paren-state)))
15803
15856
15804
15857
;; CASE 9D: this is just a later brace-list-entry/enum-entry or
15805
15858
;; brace-entry-open
15806
- (t (if (or (eq char-after-ip ?{)
15807
- (and c-special-brace-lists
15808
- (save-excursion
15809
- (goto-char indent-point)
15810
- (c-forward-syntactic-ws (c-point 'eol))
15811
- (c-looking-at-special-brace-list))))
15812
- (c-add-syntax 'brace-entry-open (point))
15859
+ (t (cond
15860
+ ((or (eq char-after-ip ?{)
15861
+ (and c-special-brace-lists
15862
+ (save-excursion
15863
+ (goto-char indent-point)
15864
+ (c-forward-syntactic-ws (c-point 'eol))
15865
+ (c-looking-at-special-brace-list))))
15866
+ (c-add-syntax 'brace-entry-open (point)))
15867
+ ((eq (c-point 'eol) (1- indent-point))
15813
15868
(c-add-stmt-syntax (if enum-pos 'enum-entry 'brace-list-entry)
15814
15869
nil t containing-sexp
15815
- paren-state (point))))))))
15870
+ paren-state (point)))
15871
+ (t (c-add-syntax (if enum-pos 'enum-entry 'brace-list-entry)
15872
+ (point)))))))))
15816
15873
15817
15874
;; CASE 10: A continued statement or top level construct.
15818
15875
((and (not (memq char-before-ip '(?\; ?:)))
0 commit comments