-
-\f
-(defconst c-offsets-alist
- '((string . -1000)
- (c . c-lineup-C-comments)
- (defun-open . 0)
- (defun-close . 0)
- (defun-block-intro . +)
- (class-open . 0)
- (class-close . 0)
- (inline-open . +)
- (inline-close . 0)
- (func-decl-cont . +)
- (knr-argdecl-intro . +)
- (knr-argdecl . 0)
- (topmost-intro . 0)
- (topmost-intro-cont . 0)
- (member-init-intro . +)
- (member-init-cont . 0)
- (inher-intro . +)
- (inher-cont . c-lineup-multi-inher)
- (block-open . 0)
- (block-close . 0)
- (brace-list-open . 0)
- (brace-list-close . 0)
- (brace-list-intro . +)
- (brace-list-entry . 0)
- (statement . 0)
- ;; some people might prefer
- ;;(statement . c-lineup-runin-statements)
- (statement-cont . +)
- ;; some people might prefer
- ;;(statement-cont . c-lineup-math)
- (statement-block-intro . +)
- (statement-case-intro . +)
- (statement-case-open . 0)
- (substatement . +)
- (substatement-open . +)
- (case-label . 0)
- (access-label . -)
- (label . 2)
- (do-while-closure . 0)
- (else-clause . 0)
- (comment-intro . c-lineup-comment)
- (arglist-intro . +)
- (arglist-cont . 0)
- (arglist-cont-nonempty . c-lineup-arglist)
- (arglist-close . +)
- (stream-op . c-lineup-streamop)
- (inclass . +)
- (cpp-macro . -1000)
- (cpp-macro-cont . c-lineup-dont-change)
- (friend . 0)
- (objc-method-intro . -1000)
- (objc-method-args-cont . c-lineup-ObjC-method-args)
- (objc-method-call-cont . c-lineup-ObjC-method-call)
- (extern-lang-open . 0)
- (extern-lang-close . 0)
- (inextern-lang . +)
- (namespace-open . 0)
- (namespace-close . 0)
- (innamespace . +)
- (template-args-cont . +)
- )
- "Association list of syntactic element symbols and indentation offsets.
-As described below, each cons cell in this list has the form:
-
- (SYNTACTIC-SYMBOL . OFFSET)
-
-When a line is indented, CC Mode first determines the syntactic
-context of the line by generating a list of symbols called syntactic
-elements. This list can contain more than one syntactic element and
-the global variable `c-syntactic-context' contains the context list
-for the line being indented. Each element in this list is actually a
-cons cell of the syntactic symbol and a buffer position. This buffer
-position is called the relative indent point for the line. Some
-syntactic symbols may not have a relative indent point associated with
-them.
-
-After the syntactic context list for a line is generated, CC Mode
-calculates the absolute indentation for the line by looking at each
-syntactic element in the list. First, it compares the syntactic
-element against the SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it
-finds a match, it adds the OFFSET to the column of the relative indent
-point. The sum of this calculation for each element in the syntactic
-list is the absolute offset for line being indented.
-
-If the syntactic element does not match any in the `c-offsets-alist',
-an error is generated if `c-strict-syntax-p' is non-nil, otherwise the
-element is ignored.
-
-Actually, OFFSET can be an integer, a function, a variable, or one of
-the following symbols: `+', `-', `++', `--', `*', or `/'. These
-latter designate positive or negative multiples of `c-basic-offset',
-respectively: 1, -1, 2, -2, 0.5, and -0.5. If OFFSET is a function, it
-is called with a single argument containing the cons of the syntactic
-element symbol and the relative indent point. The function should
-return an integer offset.
-
-Here is the current list of valid syntactic element symbols:
-
- string -- inside multi-line string
- c -- inside a multi-line C style block comment
- defun-open -- brace that opens a function definition
- defun-close -- brace that closes a function definition
- defun-block-intro -- the first line in a top-level defun
- class-open -- brace that opens a class definition
- class-close -- brace that closes a class definition
- inline-open -- brace that opens an in-class inline method
- inline-close -- brace that closes an in-class inline method
- func-decl-cont -- the region between a function definition's
- argument list and the function opening brace
- (excluding K&R argument declarations). In C, you
- cannot put anything but whitespace and comments
- between them; in C++ and Java, throws declarations
- and other things can appear in this context.
- knr-argdecl-intro -- first line of a K&R C argument declaration
- knr-argdecl -- subsequent lines in a K&R C argument declaration
- topmost-intro -- the first line in a topmost construct definition
- topmost-intro-cont -- topmost definition continuation lines
- member-init-intro -- first line in a member initialization list
- member-init-cont -- subsequent member initialization list lines
- inher-intro -- first line of a multiple inheritance list
- inher-cont -- subsequent multiple inheritance lines
- block-open -- statement block open brace
- block-close -- statement block close brace
- brace-list-open -- open brace of an enum or static array list
- brace-list-close -- close brace of an enum or static array list
- brace-list-intro -- first line in an enum or static array list
- brace-list-entry -- subsequent lines in an enum or static array list
- statement -- a C (or like) statement
- statement-cont -- a continuation of a C (or like) statement
- statement-block-intro -- the first line in a new statement block
- statement-case-intro -- the first line in a case \"block\"
- statement-case-open -- the first line in a case block starting with brace
- substatement -- the first line after an if/while/for/do/else
- substatement-open -- the brace that opens a substatement block
- case-label -- a `case' or `default' label
- access-label -- C++ private/protected/public access label
- label -- any ordinary label
- do-while-closure -- the `while' that ends a do/while construct
- else-clause -- the `else' of an if/else construct
- comment-intro -- a line containing only a comment introduction
- arglist-intro -- the first line in an argument list
- arglist-cont -- subsequent argument list lines when no
- arguments follow on the same line as the
- arglist opening paren
- arglist-cont-nonempty -- subsequent argument list lines when at
- least one argument follows on the same
- line as the arglist opening paren
- arglist-close -- the solo close paren of an argument list
- stream-op -- lines continuing a stream operator construct
- inclass -- the construct is nested inside a class definition
- cpp-macro -- the start of a C preprocessor macro definition
- cpp-macro-cont -- the second and subsequent lines in a
- multi-line C preprocessor macro definition
- friend -- a C++ friend declaration
- objc-method-intro -- the first line of an Objective-C method definition
- objc-method-args-cont -- lines continuing an Objective-C method definition
- objc-method-call-cont -- lines continuing an Objective-C method call
- extern-lang-open -- brace that opens an external language block
- extern-lang-close -- brace that closes an external language block
- inextern-lang -- analogous to `inclass' syntactic symbol,
- but used inside, e.g. extern \"C\" constructs
- namespace-open -- brace that opens a C++ namespace block
- namespace-close -- brace that closes a C++ namespace block
- innamespace -- analogous to `inextern-lang' syntactic
- symbol, but used inside C++ namespace constructs
- template-args-cont -- C++ template argument list continuations
-")
-
-(defun c-get-offset (langelem)
- ;; Get offset from LANGELEM which is a cons cell of the form:
- ;; (SYMBOL . RELPOS). The symbol is matched against
- ;; c-offsets-alist and the offset found there is either returned,
- ;; or added to the indentation at RELPOS. If RELPOS is nil, then
- ;; the offset is simply returned.
- (let* ((symbol (car langelem))
- (relpos (cdr langelem))
- (match (assq symbol c-offsets-alist))
- (offset (cdr-safe match)))
- ;; offset can be a number, a function, a variable, or one of the
- ;; symbols + or -
- (cond
- ((not match)
- (if c-strict-syntax-p
- (error "don't know how to indent a %s" symbol)
- (setq offset 0
- relpos 0)))
- ((eq offset '+) (setq offset c-basic-offset))
- ((eq offset '-) (setq offset (- c-basic-offset)))
- ((eq offset '++) (setq offset (* 2 c-basic-offset)))
- ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
- ((eq offset '*) (setq offset (/ c-basic-offset 2)))
- ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
- ((functionp offset) (setq offset (funcall offset langelem)))
- ((not (numberp offset)) (setq offset (symbol-value offset)))
- )
- (+ (if (and relpos
- (< relpos (c-point 'bol)))
- (save-excursion
- (goto-char relpos)
- (current-column))
- 0)
- offset)))
-