This will allow enums to be indented as in the GNU coding
standards without affecting brace lists.
* lisp/progmodes/cc-align.el
(c-lineup-arglist-intro-after-paren)
(c-lineup-arglist-close-under-paren)
(c-lineup-whitesmith-in-block)
(c-lineup-after-whitesmith-blocks): Amend doc strings to
indicate they can be used for enum-* syntactic symbols too.
* lisp/progmodes/cc-engine.el (c-looking-at-decl-block)
(c-backward-typed-enum-colon, c-backward-over-enum-header):
Rename c-after-brace-list-key to c-after-enum-list-key and
c-brace-list-key to c-enum-list-key.
(c-at-enum-brace): New function.
(c-inside-bracelist-p): Don't check for enums any more.
(c-add-stmt-syntax): New cond arm for enums.
(c-guess-continued-construct CASE B.6) New code for enum-open.
(c-guess-basic-syntax CASE 5A.3, CASE 7B, CASE 9, CASE 9B)
(CASE 9C, CASE 9D): Use the new function c-at-enum-brace, and
use enum-* syntactic symbols rather than brace-list-* ones
where appropriate.
(c-used-syntactic-symbols): New dynamic variable.
(c-evaluate-offset): Add handling for a different syntactic
symbol as the cdr of a c-offsets-alist element.
* lisp/progmodes/cc-fonts.el (c-get-fontification-context):
Add a call to c-at-enum-brace since c-inside-bracelist-p no
longer handles enums.
(c-font-lock-enum-body, c-font-lock-enum-tail): Condense calls
to c-backward-over-enum-header to c-at-enum-brace.
(c-basic-matchers-after): Replace a c-brace-list-decl-kwds with
c-enum-list-kwds.
* lisp/progmodes/cc-langs.el (c-enum-list-kwds)
(c-enum-list-key): New names for c-brace-list-decl-kwds and
c-brace-list-key.
(c-after-enum-list-kwds, c-after-enum-list-key): New names for
c-after-brace-list-decl-kwds and c-after-brace-list-key.
(c-enum-list-key, c-after-enum-list-key): Add code to
use a value of an old name, should a derived mode still use
that.
(c-defun-type-name-decl-kwds, c-typedef-decl-kwds)
(c-typeless-decl-kwds, c-prefix-spec-kwds)
(c-brace-id-list-kwds, c-enum-clause-introduction-re): Use
c-enum-list-kwds rather than c-brace-list-decl-kwds.
* lisp/progmodes/cc-styles.el (c-read-offset): Add "a
syntactic symbol" into an error message text.
* lisp/progmodes/cc-vars.el (c-valid-offset): Allow for a
syntactic symbol as the parameter.
(c-offsets-alist): Add new syntactic symbols enum-open,
enum-close, enum-intro, and enum-entry.
* doc/misc/cc-mode.texi (Syntactic Symbols): Add a note that
anchor points are briefly documented in cc-vars.el. Correct
the suffix "-block-intro" to "-intro". Remove "an enum or"
from the descriptions of the brace-list-* syntactic symbols.
Add in new descriptions for the enum-* syntactic symbols.
(Brace List Symbols): Remove references to enums. Add a note
that enums are no longer brace-lists.
(Enum Symbols): A new subsection documenting the new enum-*
syntactic symbols.
(c-offsets-alist): Document the new possibility, syntactic
symbol, for the cdr of an alist entry.
(Brace/Paren Line-Up, List Line-Up): Note that the new enum
syntactic symbols can be handled by these lineup functions.
(cherry picked from commit
c2d6f191d489de8349847b5c18acec8462b66247)
* Conditional Construct Symbols::
* Switch Statement Symbols::
* Brace List Symbols::
+* Enum Symbols::
* External Scope Symbols::
* Paren List Symbols::
* Literal Symbols::
source code to which they apply, appear in the examples in the
subsections below. Note that, in the interests of brevity, the anchor
position associated with most syntactic symbols is @emph{not}
-specified. In cases of doubt, type @kbd{C-c C-s} on a pertinent
-line---this highlights the anchor position.
+specified@footnote{These are briefly specified in comments in
+@code{(defvar c-offsets-alist ...)} in the source file
+@file{cc-vars.el}}. In cases of doubt, type @kbd{C-c C-s} on a
+pertinent line---this highlights the anchor position.
@ssindex -open symbols
@ssindex -close symbols
-@ssindex -block-intro symbols
+@ssindex -intro symbols
The syntactic symbols which indicate brace constructs follow a general
naming convention. When a line begins with an open or close brace,
its syntactic symbol will contain the suffix @code{-open} or
@code{-close} respectively. The first line within the brace block
-construct will contain the suffix @code{-block-intro}.
+construct will contain the suffix @code{-intro}.
@ssindex -intro symbols
@ssindex -cont symbols
@item block-close
Statement block close brace. @ref{Conditional Construct Symbols}.
@item brace-list-open
-Open brace of an enum or static array list. @ref{Brace List Symbols}.
+Open brace of a static array list. @ref{Brace List Symbols}.
@item brace-list-close
-Close brace of an enum or static array list. @ref{Brace List Symbols}.
+Close brace of a static array list. @ref{Brace List Symbols}.
@item brace-list-intro
-First line after the opening @samp{@{} in an enum or static array
-list. @ref{Brace List Symbols}.
+First line after the opening @samp{@{} in a static array list.
+@ref{Brace List Symbols}.
@item brace-list-entry
-Subsequent lines in an enum or static array list. @ref{Brace List
-Symbols}.
+Subsequent lines in a static array list. @ref{Brace List Symbols}.
@item brace-entry-open
-Subsequent lines in an enum or static array list where the line begins
-with an open brace. @ref{Brace List Symbols}.
+Subsequent lines in a static array list where the line begins with an
+open brace. @ref{Brace List Symbols}.
+@item enum-open
+Open brace of an enum list. @ref{Brace List Symbols}.
+@item enum-close
+Close brace of an enum list. @ref{Brace List Symbols}.
+@item enum-intro
+First line after the opening @samp{@{} in an enum list. @ref{Brace
+List Symbols}.
+@item enum-entry
+Subsequent lines in an enum ilst. @ref{Brace List Symbols}.
@item statement
A statement. @ref{Function Symbols}.
@item statement-cont
* Conditional Construct Symbols::
* Switch Statement Symbols::
* Brace List Symbols::
+* Enum Symbols::
* External Scope Symbols::
* Paren List Symbols::
* Literal Symbols::
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@cindex brace lists
-There are a set of syntactic symbols that are used to recognize
+There is a set of syntactic symbols that is used to recognize
constructs inside of brace lists. A brace list is defined as an
-@code{enum} or aggregate initializer list, such as might statically
-initialize an array of structs. The three special aggregate constructs
-in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are treated as
-brace lists too. An example:
+aggregate initializer list, such as might statically initialize an
+array of structs. Note that an @code{enum} construct is (since
+2024-09) no longer parsed as a brace list. Instead it now has its own
+syntactic symbols. @ref{Enum Symbols}. The three special aggregate
+constructs in Pike, @code{(@{ @})}, @code{([ ])} and @code{(< >)}, are
+treated as brace lists too. An example:
@example
1: static char* ingredients[] =
@code{c-lineup-under-anchor} (@pxref{Misc Line-Up}).}, and
@code{brace-list-entry} anchored on the @samp{1} of line 8.
+@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+@node Enum Symbols
+@subsection Enum Symbols
+@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+@cindex enum symbols
+There is a set of syntactic symbols that characterize the components
+of @code{enum} constructs. These are very like the brace list
+symbols@footnote{Indeed an @code{enum} used to be parsed with these
+other symbols. The two types of construct were separated in 2024-09
+to make it easier to give an @code{enum} indentation like that of a
+@code{class}.} (@pxref{Brace List Symbols}).
+
+@example
+ 1: enum test
+ 2: @{
+ 3: GOOD,
+ 4: BETTER,
+ 5: BEST
+ 6: @};
+@end example
+
+@ssindex enum-open
+@ssindex enum-intro
+@ssindex enum-close
+@ssindex enum-entry
+Line 2 is assigned @code{enum-open} sytax, and line 6
+@code{enum-close}. The first enum element on line 3 is assigned
+@code{enum-intro} sytax, and the remaining elements, on lines 4 and 5
+are assigned @code{enum-entry}.
+
+When the first enum element follows the @samp{@{} of the @code{enum},
+all on the opening line of the construct, the parsing is a little more
+involved.
+
+@example
+ 1: enum test @{ GOOD,
+ 2: BETTER,
+ 3: BEST
+ 4: @};
+@end example
+
+Here, line 2 is assigned a syntactic context with two elements:
+@code{enum-intro} anchored on the beginning of indentation of line 1,
+and @code{enum-entry} anchored on the first element @code{GOOD} on
+line 1. Line 3 is @code{enum-entry} and line 4 @code{enum-close} as
+you'd expect.
+
@comment !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
@node External Scope Symbols
@subsection External Scope Symbols
The offset specification associated with any particular syntactic
symbol can be an integer, a variable name, a vector, a function or
-lambda expression, a list, or one of the following special symbols:
-@code{+}, @code{-}, @code{++}, @code{--}, @code{*}, or @code{/}. The
-meanings of these values are described in detail below.
+lambda expression, another syntactic symbol, a list, or one of the
+following special symbols: @code{+}, @code{-}, @code{++}, @code{--},
+@code{*}, or @code{/}. The meanings of these values are described in
+detail below.
Here is an example fragment of a @code{c-offsets-alist}, showing some
of these kinds of offsets:
indentation. @xref{Line-Up Functions}, and @ref{Custom Line-Up}, for
details about them.
+@item Another syntactic symbol
+The offset of that other syntactic symbol will be used. This is
+useful for making sure that two distinct syntactic symbols cause the
+same indentation. By default, @code{enum-open} has the value
+@code{class-open}.
+
@item A symbol with a variable binding
If the symbol also has a function binding, the function takes
precedence over the variable. Otherwise the value of the variable is
discussion of this ``DWIM'' measure.
@workswith Almost all symbols, but are typically most useful on
-@code{arglist-close}, @code{brace-list-close}, @code{arglist-cont} and
+@code{arglist-close}, @code{brace-list-close},
+@code{enum-close}, @code{arglist-cont} and
@code{arglist-cont-nonempty}.
@end defun
@code{c-lineup-whitesmith-in-block}.
@workswith @code{brace-list-entry}, @code{brace-entry-open},
-@code{statement}, @code{arglist-cont}.
+@code{enum-entry}, @code{statement}, @code{arglist-cont}.
@end defun
@comment ------------------------------------------------------------
@workswith @code{defun-close}, @code{defun-block-intro},
@code{inline-close}, @code{block-close}, @code{brace-list-close},
-@code{brace-list-intro}, @code{statement-block-intro},
+@code{brace-list-intro},
+@code{enum-close}, @code{enum-intro}, @code{statement-block-intro},
@code{arglist-intro}, @code{arglist-cont-nonempty},
@code{arglist-close}, and all @code{in*} symbols, e.g., @code{inclass}
and @code{inextern-lang}.
brace block.
@workswith @code{defun-block-intro}, @code{brace-list-intro},
-@code{statement-block-intro}, @code{statement-case-intro},
-@code{arglist-intro}.
+@code{enum-intro}, @code{statement-block-intro},
+@code{statement-case-intro}, @code{arglist-intro}.
@end defun
@comment ------------------------------------------------------------
"Line up a line to just after the open paren of the surrounding paren
or brace block.
-Works with: defun-block-intro, brace-list-intro,
+Works with: defun-block-intro, brace-list-intro, enum-intro
statement-block-intro, statement-case-intro, arglist-intro."
(save-excursion
(beginning-of-line)
of this \"DWIM\" measure.
Works with: Almost all symbols, but are typically most useful on
-arglist-close, brace-list-close, arglist-cont and arglist-cont-nonempty."
+arglist-close, brace-list-close, enum-close, arglist-cont and
+arglist-cont-nonempty."
(save-excursion
(if (memq (c-langelem-sym langelem)
'(arglist-cont-nonempty arglist-close))
second `c-basic-offset' is added.
Works with: defun-close, defun-block-intro, inline-close, block-close,
-brace-list-close, brace-list-intro, statement-block-intro,
-arglist-intro, arglist-cont-nonempty, arglist-close, and all in*
-symbols, e.g. inclass and inextern-lang."
+brace-list-close, brace-list-intro, enum-close, enum-intro,
+statement-block-intro, arglist-intro, arglist-cont-nonempty,
+arglist-close, and all in* symbols, e.g. inclass and inextern-lang."
(save-excursion
(beginning-of-line)
(if (and (c-go-up-list-backward)
instead indents relative to the surrounding block just like
`c-lineup-whitesmith-in-block'.
-Works with: brace-list-entry, brace-entry-open, statement,
-arglist-cont."
+Works with: brace-list-entry, brace-entry-open, enum-entry,
+statement, arglist-cont."
(save-excursion
(goto-char (c-langelem-pos langelem))
(when (looking-at "\\s(")
(goto-char (setq kwd-start (match-beginning 0)))
(and
;; Exclude cases where we matched what would ordinarily
- ;; be a block declaration keyword, except where it's not
+ ;; be an enum declaration keyword, except where it's not
;; legal because it's part of a "compound keyword" like
- ;; "enum class". Of course, if c-after-brace-list-key
+ ;; "enum class". Of course, if c-after-enum-list-key
;; is nil, we can skip the test.
- (or (equal c-after-brace-list-key regexp-unmatchable)
+ (or (equal c-after-enum-list-key regexp-unmatchable)
(save-match-data
(save-excursion
(not
(and
- (looking-at c-after-brace-list-key)
+ (looking-at c-after-enum-list-key)
(= (c-backward-token-2 1 t) 0)
- (looking-at c-brace-list-key))))))
+ (looking-at c-enum-list-key))))))
(or
;; Found a keyword that can't be a type?
(match-beginning 1)
(or (c-on-identifier)
(progn
(c-backward-token-2)
- (looking-at c-brace-list-key)))))
+ (looking-at c-enum-list-key)))))
(setq colon-pos (point))
(forward-char)
(c-forward-syntactic-ws)
(looking-at c-postfix-decl-spec-key)))
(setq before-identifier nil)
t)
- ((looking-at c-after-brace-list-key) t)
- ((looking-at c-brace-list-key) nil)
+ ((looking-at c-after-enum-list-key) t)
+ ((looking-at c-enum-list-key) nil)
((eq (char-after) ?\()
(and (eq (c-backward-token-2) 0)
(or (looking-at c-decl-hangon-key)
(looking-at "\\s("))
t)
(t nil))))
- (or (looking-at c-brace-list-key)
+ (or (looking-at c-enum-list-key)
(progn (goto-char here) nil))))
+(defun c-at-enum-brace (&optional pos)
+ ;; Return the position of the enum-like keyword introducing the brace at POS
+ ;; (default point), or nil if we're not at such a construct.
+ (save-excursion
+ (if pos
+ (goto-char pos)
+ (setq pos (point)))
+ (and (c-backward-over-enum-header)
+ (point))))
+
(defun c-laomib-loop (lim)
;; The "expensive" loop from `c-looking-at-or-maybe-in-bracelist'. Move
;; backwards over comma separated sexps as far as possible, but no further
;; speed.
;;
;; This function might do hidden buffer changes.
- (or
- ;; This will pick up brace list declarations.
- (save-excursion
- (goto-char containing-sexp)
- (and (c-backward-over-enum-header)
- (point)))
- ;; this will pick up array/aggregate init lists, even if they are nested.
+ ;; this will pick up array/aggregate init lists, even if they are nested.
(save-excursion
(let ((bufpos t)
next-containing)
next-containing nil)))))
(and (consp bufpos)
(or accept-in-paren (not (eq (cdr bufpos) 'in-paren)))
- (car bufpos))))))
+ (car bufpos)))))
(defun c-looking-at-special-brace-list ()
;; If we're looking at the start of a pike-style list, i.e., `({ })',
(cdr (assoc (match-string 1)
c-other-decl-block-key-in-symbols-alist))
(max (c-point 'boi paren-pos) (point))))
+ ((c-at-enum-brace paren-pos)
+ (c-add-syntax 'enum-intro nil))
((c-inside-bracelist-p paren-pos paren-state nil)
(if (save-excursion
(goto-char paren-pos)
(cond
;; (CASE A removed.)
- ;; CASE B: open braces for class or brace-lists
+ ;; CASE B: open braces for class, enum or brace-lists
((setq special-brace-list
(or (and c-special-brace-lists
(c-looking-at-special-brace-list))
(c-add-syntax 'class-open beg-of-same-or-containing-stmt
(c-point 'boi placeholder)))
+ ;; CASE B.6: enum-open.
+ ((setq placeholder (c-at-enum-brace))
+ (c-add-syntax 'enum-open placeholder))
+
;; CASE B.2: brace-list-open
((or (consp special-brace-list)
(c-inside-bracelist-p (point)
literal char-before-ip before-ws-ip char-after-ip macro-start
in-macro-expr c-syntactic-context placeholder
step-type tmpsymbol keyword injava-inher special-brace-list tmp-pos
- tmp-pos2 containing-< tmp constraint-detail
+ tmp-pos2 containing-< tmp constraint-detail enum-pos
;; The following record some positions for the containing
;; declaration block if we're directly within one:
;; `containing-decl-open' is the position of the open
(c-add-syntax 'class-open placeholder
(c-point 'boi tmp-pos)))
- ;; CASE 5A.3: brace list open
+ ;; CASE 5A.3: brace-list/enum open
((save-excursion
(goto-char indent-point)
(skip-chars-forward " \t")
(cond
- ((c-backward-over-enum-header)
- (setq placeholder (c-point 'boi)))
+ ((setq enum-pos (c-at-enum-brace))
+ (setq placeholder (c-point 'boi enum-pos)))
((consp (setq placeholder
(c-looking-at-or-maybe-in-bracelist
containing-sexp lim)))
(progn
(c-beginning-of-statement-1 lim)
(c-add-syntax 'topmost-intro-cont (c-point 'boi)))
- (c-add-syntax 'brace-list-open placeholder)))
+ (c-add-syntax (if enum-pos 'enum-open 'brace-list-open)
+ placeholder)))
;; CASE 5A.4: inline defun open
((and containing-decl-open
(eq (c-beginning-of-statement-1 lim t nil t) 'same)
(looking-at c-opt-inexpr-brace-list-key))))
(progn
- (setq placeholder (c-inside-bracelist-p (point)
- paren-state
- nil))
+ (setq placeholder
+ (or (setq enum-pos (c-at-enum-brace))
+ (c-inside-bracelist-p (point)
+ paren-state
+ nil)))
(if placeholder
- (setq tmpsymbol '(brace-list-open . inexpr-class))
+ (setq tmpsymbol
+ `(,(if enum-pos 'enum-open 'brace-list-open)
+ . inexpr-class)
+ )
(setq tmpsymbol '(block-open . inexpr-statement)
placeholder
(cdr-safe (c-looking-at-inexpr-block
(c-add-syntax 'inher-cont (point))
)))
- ;; CASE 9: we are inside a brace-list
+ ;; CASE 9: we are inside a brace-list or enum.
((and (not (c-major-mode-is 'awk-mode)) ; Maybe this isn't needed (ACM, 2002/3/29)
(setq special-brace-list
(or (and c-special-brace-lists ;;;; ALWAYS NIL FOR AWK!!
(save-excursion
(goto-char containing-sexp)
(c-looking-at-special-brace-list)))
+ (setq enum-pos (c-at-enum-brace containing-sexp))
(c-inside-bracelist-p containing-sexp paren-state t))))
(cond
-
;; CASE 9A: In the middle of a special brace list opener.
((and (consp special-brace-list)
(save-excursion
(c-forward-noise-clause))))
(c-add-syntax 'brace-list-open (c-point 'boi))))
- ;; CASE 9B: brace-list-close brace
+ ;; CASE 9B: brace-list-close/enum-close brace
((if (consp special-brace-list)
;; Check special brace list closer.
(progn
(c-safe (goto-char (c-up-list-backward (point))) t)
(= (point) containing-sexp)))
(if (eq (point) (c-point 'boi))
- (c-add-syntax 'brace-list-close (point))
+ (c-add-syntax (if enum-pos 'enum-close 'brace-list-close)
+ (point))
(setq lim (or (save-excursion
(and
(c-back-over-member-initializers
(point)))
(c-most-enclosing-brace state-cache (point))))
(c-beginning-of-statement-1 lim nil nil t)
- (c-add-stmt-syntax 'brace-list-close nil t lim paren-state)))
+ (c-add-stmt-syntax (if enum-pos 'enum-close 'brace-list-close)
+ nil t lim paren-state)))
(t
;; Prepare for the rest of the cases below by going back to the
(c-skip-ws-forward indent-point)))
(cond
- ;; CASE 9C: we're looking at the first line in a brace-list
+ ;; CASE 9C: we're looking at the first line in a brace-list/enum
((= (point) indent-point)
(if (consp special-brace-list)
(goto-char (car (car special-brace-list)))
(goto-char containing-sexp))
(if (eq (point) (c-point 'boi))
- (c-add-syntax 'brace-list-intro (point))
+ (c-add-syntax (if enum-pos 'enum-intro 'brace-list-intro)
+ (point))
(setq lim (or (save-excursion
(and
(c-back-over-member-initializers
(point)))
(c-most-enclosing-brace state-cache (point))))
(c-beginning-of-statement-1 lim nil nil t)
- (c-add-stmt-syntax 'brace-list-intro nil t lim paren-state)))
+ (c-add-stmt-syntax (if enum-pos 'enum-intro 'brace-list-intro)
+ nil t lim paren-state)))
- ;; CASE 9D: this is just a later brace-list-entry or
+ ;; CASE 9D: this is just a later brace-list-entry/enum-entry or
;; brace-entry-open
(t (if (or (eq char-after-ip ?{)
(and c-special-brace-lists
(c-forward-syntactic-ws (c-point 'eol))
(c-looking-at-special-brace-list))))
(c-add-syntax 'brace-entry-open (point))
- (c-add-stmt-syntax 'brace-list-entry nil t containing-sexp
- paren-state (point))
- ))
- ))))
+ (c-add-stmt-syntax (if enum-pos 'enum-entry 'brace-list-entry)
+ nil t containing-sexp
+ paren-state (point))))))))
;; CASE 10: A continued statement or top level construct.
((and (not (memq char-before-ip '(?\; ?:)))
\f
;; Indentation calculation.
+(defvar c-used-syntactic-symbols nil)
+;; The syntactic symbols so far used in a chain of them.
+;; It is used to prevent infinite loops when the OFFSET in `c-evaluate-offset'
+;; is itself a syntactic symbol.
+
(defun c-evaluate-offset (offset langelem symbol)
- ;; offset can be a number, a function, a variable, a list, or one of
- ;; the symbols + or -
+ ;; Evaluate the offset for OFFSET, returning it either as a number,
+ ;; a vector, a symbol (whose value gets used), or nil.
+ ;; OFFSET is a number, a function, a syntactic symbol, a variable, a list,
+ ;; or a symbol such as +, -, etc.
+ ;; LANGELEM is the original language element for which this function is
+ ;; being called.
+ ;; SYMBOL is the syntactic symbol, used mainly for error messages.
;;
;; This function might do hidden buffer changes.
- (let ((res
+ (let*
+ (offset1
+ (res
(cond
((numberp offset) offset)
((vectorp offset) offset)
(c-langelem-pos langelem)))
langelem symbol))
+ ((setq offset1 (assq offset c-offsets-alist))
+ (when (memq offset c-used-syntactic-symbols)
+ (error "Error evaluating offset %S for %s: \
+Infinite loop of syntactic symbols: %S."
+ offset symbol c-used-syntactic-symbols))
+ (let ((c-used-syntactic-symbols
+ (cons symbol c-used-syntactic-symbols)))
+ (c-evaluate-offset (cdr-safe offset1) langelem offset)))
+
((listp offset)
(cond
((eq (car offset) 'quote)
(c-put-char-property (1- match-pos) 'c-type
'c-decl-arg-start)
(cons 'decl nil))
- ;; We're inside a brace list.
+ ;; We're inside a brace list/enum list.
((and (eq (char-before match-pos) ?{)
- (c-inside-bracelist-p (1- match-pos)
- (cdr (c-parse-state))
- nil))
+ (or (c-at-enum-brace (1- match-pos))
+ (c-inside-bracelist-p (1- match-pos)
+ (cdr (c-parse-state))
+ nil)))
(c-put-char-property (1- match-pos) 'c-type
'c-not-decl)
(cons 'not-decl nil))
;; Fontification".
(while (and (< (point) limit)
(search-forward-regexp c-enum-clause-introduction-re limit t))
- (when (save-excursion
- (backward-char)
- (c-backward-over-enum-header))
+ (when (c-at-enum-brace (1- (point)))
(c-forward-syntactic-ws)
(c-font-lock-declarators limit t nil t)))
nil)
(when (and
encl-pos
(eq (char-after encl-pos) ?\{)
- (save-excursion
- (goto-char encl-pos)
- (c-backward-over-enum-header)))
+ (c-at-enum-brace encl-pos))
(c-syntactic-skip-backward "^{," nil t)
(c-put-char-property (1- (point)) 'c-type 'c-decl-id-start)
generic casts and declarations are fontified. Used on level 2 and
higher."
- t `(,@(when (c-lang-const c-brace-list-decl-kwds)
+ t `(,@(when (c-lang-const c-enum-list-kwds)
;; Fontify the remaining identifiers inside an enum list when we start
;; inside it.
'(c-font-lock-enum-tail
t (c-make-keywords-re t (c-lang-const c-class-decl-kwds)))
(c-lang-defvar c-class-key (c-lang-const c-class-key))
-(c-lang-defconst c-brace-list-decl-kwds
+(c-lang-defconst c-enum-list-kwds
"Keywords introducing declarations where the following block (if
-any) is a brace list.
+any) is an enum list.
If any of these also are on `c-type-list-kwds', `c-ref-list-kwds',
`c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
t '("enum")
(awk) nil)
-(c-lang-defconst c-brace-list-key
+(c-lang-defconst c-enum-list-key
;; Regexp matching the start of declarations where the following
;; block is a brace list.
- t (c-make-keywords-re t (c-lang-const c-brace-list-decl-kwds)))
-(c-lang-defvar c-brace-list-key (c-lang-const c-brace-list-key))
-
-(c-lang-defconst c-after-brace-list-decl-kwds
- "Keywords that might follow keywords in `c-brace-list-decl-kwds'
+ t (let ((liszt
+ (condition-case nil
+ ;; (prog1
+ (c-lang-const c-brace-list-decl-kwds)
+ ;; (message "`c-brace-list-decl-kwds' has been renamed \
+ ;; to `c-enum-list-kwds'. Please amend your derived mode"))
+ ;; After a few CC Mode versions, output a message here,
+ ;; prompting the derived mode's maintainer to update the source.
+ ;; 2024-09.
+ (error (c-lang-const c-enum-list-kwds)))))
+ (c-make-keywords-re t liszt)))
+(c-lang-defvar c-enum-list-key (c-lang-const c-enum-list-key))
+
+(c-lang-defconst c-after-enum-list-kwds
+ "Keywords that might follow keywords in `c-enum-list-kwds'
and precede the opening brace."
t nil
c++ '("class" "struct"))
-(c-lang-defconst c-after-brace-list-key
- ;; Regexp matching keywords that can fall between a brace-list
+(c-lang-defconst c-after-enum-list-key
+ ;; Regexp matching keywords that can fall between an enum-list
;; keyword and the associated brace list.
- t (c-make-keywords-re t (c-lang-const c-after-brace-list-decl-kwds)))
-(c-lang-defvar c-after-brace-list-key (c-lang-const c-after-brace-list-key))
+ t (let ((liszt
+ (condition-case nil
+ ;; (prog1
+ (c-lang-const c-after-brace-list-decl-kwds)
+ ;; (message "`c-after-brace-list-decl-kwds' has been renamed \
+ ;; to `c-after-enum-list-kwds'. Please amend your derived mode"))
+ ;; After a few CC Mode versions, output a message here,
+ ;; prompting the derived mode's maintainer to update the source.
+ ;; 2024-09.
+ (error (c-lang-const c-after-enum-list-kwds)))))
+ (c-make-keywords-re t liszt)))
+(c-lang-defvar c-after-enum-list-key (c-lang-const c-after-enum-list-key))
(c-lang-defconst c-recognize-post-brace-list-type-p
"Set to t when we recognize a colon and then a type after an enum,
"Keywords introducing a named block, where the name is a \"defun\"
name."
t (append (c-lang-const c-class-decl-kwds)
- (c-lang-const c-brace-list-decl-kwds)))
+ (c-lang-const c-enum-list-kwds)))
(c-lang-defconst c-defun-type-name-decl-key
;; Regexp matching a keyword in `c-defun-type-name-decl-kwds'.
`c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
`c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
will be handled."
- ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
+ ;; Default to `c-class-decl-kwds' and `c-enum-list-kwds'
;; (since e.g. "Foo" is a type that's being defined in "class Foo
;; {...}").
t (append (c-lang-const c-class-decl-kwds)
- (c-lang-const c-brace-list-decl-kwds))
+ (c-lang-const c-enum-list-kwds))
;; Languages that have a "typedef" construct.
(c c++ objc idl pike) (append (c-lang-const c-typedef-decl-kwds)
'("typedef"))
`c-colon-type-list-kwds', `c-paren-nontype-kwds', `c-paren-type-kwds',
`c-<>-type-kwds', or `c-<>-arglist-kwds' then the associated clauses
will be handled."
- ;; Default to `c-class-decl-kwds' and `c-brace-list-decl-kwds'
+ ;; Default to `c-class-decl-kwds' and `c-enum-list-kwds'
;; (since e.g. "Foo" is the identifier being defined in "class Foo
;; {...}").
t (append (c-lang-const c-class-decl-kwds)
- (c-lang-const c-brace-list-decl-kwds))
+ (c-lang-const c-enum-list-kwds))
c nil
;; Note: "manages" for CORBA CIDL clashes with its presence on
;; `c-type-list-kwds' for IDL.
(c-lang-defconst c-other-decl-kwds
"Keywords that can start or prefix any declaration level construct,
-besides those on `c-class-decl-kwds', `c-brace-list-decl-kwds',
+besides those on `c-class-decl-kwds', `c-enum-list-kwds',
`c-other-block-decl-kwds', `c-typedef-decl-kwds',
`c-typeless-decl-kwds' and `c-modifier-kwds'.
;; declaration. They might be ambiguous with types or type
;; prefixes.
t (c--delete-duplicates (append (c-lang-const c-class-decl-kwds)
- (c-lang-const c-brace-list-decl-kwds)
+ (c-lang-const c-enum-list-kwds)
(c-lang-const c-other-block-decl-kwds)
(c-lang-const c-typedef-decl-kwds)
(c-lang-const c-typeless-decl-kwds)
"Keywords that may be followed by a brace block containing a comma
separated list of identifier definitions, i.e. like the list of
identifiers that follows the type in a normal declaration."
- t (c-lang-const c-brace-list-decl-kwds))
+ t (c-lang-const c-enum-list-kwds))
(c-lang-defconst c-block-stmt-1-kwds
"Statement keywords followed directly by a substatement."
;; keyword itself, and extending up to the "{". It may match text which
;; isn't such a construct; more accurate tests will rule these out when
;; needed.
- t (if (c-lang-const c-brace-list-decl-kwds)
+ t (if (c-lang-const c-enum-list-kwds)
(concat
"\\<\\("
- (c-make-keywords-re nil (c-lang-const c-brace-list-decl-kwds))
+ (c-make-keywords-re nil (c-lang-const c-enum-list-kwds))
"\\)\\>"
;; Disallow various common punctuation chars that can't come
;; before the '{' of the enum list, to avoid searching too far.
(symname (symbol-name langelem))
(defstr (format "(default %s): " oldoff))
(errmsg (concat "Offset must be int, func, var, vector, list, "
- "or [+,-,++,--,*,/] "
+ "a syntactic symbol, or [+,-,++,--,*,/] "
defstr))
(prompt (concat symname " offset " defstr))
(keymap (make-sparse-keymap))
(eq offset '/)
(integerp offset)
(functionp offset)
- (and (symbolp offset) (boundp offset))
+ (and (symbolp offset)
+ (or (boundp offset)
+ (assq offset c-offsets-alist)))
(and (vectorp offset)
(= (length offset) 1)
(integerp (elt offset 0)))
;; token.
(brace-entry-open . 0)
;; Anchor pos: Same as brace-list-entry.
+ (enum-open . class-open)
+ ;; Anchor pos: At the statement(*) at boi of the start of the
+ ;; enum construct.
+ (enum-close . 0)
+ ;; Anchor pos: At the enum block open.
+ (enum-intro . +)
+ ;; Anchor pos: The opening brace position when at boi, or boi
+ ;; at the enum decl start(*).
+ (enum-entry . 0)
+ ;; Anchor pos: Normally, boi of the line containing the
+ ;; previous token, but if that line also contains the opening
+ ;; brace, then the first token after that brace.
(statement . 0)
;; Anchor pos: After a `;' in the condition clause of a for
;; statement: At the first token after the starting paren.