Update CC Mode to release 5.31.

This commit is contained in:
Alan Mackenzie 2005-12-02 12:30:36 +00:00
parent d60d4cd6ef
commit 0386b551af
14 changed files with 9673 additions and 6111 deletions

View file

@ -45,19 +45,10 @@
(cc-require 'cc-engine)
;; Standard indentation line-ups
;; Calling convention:
;; Standard line-up functions
;;
;; The single argument is a cons cell containing the syntactic symbol
;; in the car, and the relpos (a.k.a. anchor position) in the cdr.
;; The cdr may be nil for syntactic symbols which doesn't have an
;; associated relpos.
;;
;; Some syntactic symbols provide more information, usually more
;; interesting positions. The complete list for the syntactic element
;; (beginning with the symbol itself) is available in
;; `c-syntactic-element'.
;; See the section "Custom Indentation Functions" in the manual for
;; details on the calling convention.
(defun c-lineup-topmost-intro-cont (langelem)
"Line up declaration continuation lines zero or one indentation step.
@ -91,17 +82,67 @@ statement-cont.)
Works with: topmost-intro-cont."
(save-excursion
(beginning-of-line)
(c-backward-syntactic-ws (cdr langelem))
(if (memq (char-before) '(?} ?,))
(c-backward-syntactic-ws (c-langelem-pos langelem))
(if (and (memq (char-before) '(?} ?,))
(not (and c-overloadable-operators-regexp
(c-after-special-operator-id))))
c-basic-offset)))
(defun c-block-in-arglist-dwim (arglist-start)
;; This function implements the DWIM to avoid far indentation of
;; brace block constructs in arguments in `c-lineup-arglist' etc.
;; Return non-nil if a brace block construct is detected within the
;; arglist starting at ARGLIST-START.
(or
;; Check if the syntactic context contains any of the symbols for
;; in-expression constructs. This can both save the work that we
;; have to do below, and it also detect the brace list constructs
;; that `c-looking-at-inexpr-block' currently misses (they are
;; recognized by `c-inside-bracelist-p' instead).
(assq 'inexpr-class c-syntactic-context)
(assq 'inexpr-statement c-syntactic-context)
(assq 'inlambda c-syntactic-context)
(save-restriction
;; Search for open braces from the arglist start to the end of the
;; line.
(narrow-to-region arglist-start (c-point 'eol arglist-start))
(goto-char arglist-start)
(while (and (c-syntactic-re-search-forward "{" nil t)
(progn
(backward-char)
(or
;; Ignore starts of special brace lists.
(and c-special-brace-lists
(save-restriction
(widen)
(c-looking-at-special-brace-list)))
;; Ignore complete blocks.
(c-safe (c-forward-sexp) t))))
(forward-char))
(looking-at "{"))
(let (containing-sexp)
(goto-char arglist-start)
;; `c-syntactic-eol' always matches somewhere on the line.
(re-search-forward c-syntactic-eol)
(goto-char (match-beginning 0))
(c-forward-syntactic-ws)
(setq containing-sexp (c-most-enclosing-brace (c-parse-state)))
(c-looking-at-inexpr-block
(c-safe-position (or containing-sexp (point)) c-state-cache)
containing-sexp))))
(defun c-lineup-arglist (langelem)
"Line up the current argument line under the first argument.
As a special case, if an argument on the same line as the open
parenthesis starts with a brace block opener, the indentation is
`c-basic-offset' only. This is intended as a \"DWIM\" measure in
cases like macros that contains statement blocks, e.g:
As a special case, if the indented line is inside a brace block
construct, the indentation is `c-basic-offset' only. This is intended
as a \"DWIM\" measure in cases like macros that contains statement
blocks, e.g:
A_VERY_LONG_MACRO_NAME ({
some (code, with + long, lines * in[it]);
@ -115,38 +156,25 @@ indent such cases this way.
Works with: arglist-cont-nonempty, arglist-close."
(save-excursion
(goto-char (1+ (elt c-syntactic-element 2)))
(let ((indent-pos (point)))
;; Don't stop in the middle of a special brace list opener
;; like "({".
(when c-special-brace-lists
(let ((special-list (c-looking-at-special-brace-list)))
(when (and special-list (< (car (car special-list)) (point)))
(goto-char (+ (car (car special-list)) 2)))))
(let ((savepos (point))
(eol (c-point 'eol)))
;; Find out if an argument on the same line starts with an
;; unclosed open brace paren. Note similar code in
;; `c-lineup-close-paren' and
;; `c-lineup-arglist-close-under-paren'.
(if (and (c-syntactic-re-search-forward "{" eol t t)
(looking-at c-syntactic-eol)
(progn (backward-char)
(not (c-looking-at-special-brace-list)))
(progn (c-backward-syntactic-ws)
(or (= (point) savepos)
(eq (char-before) ?,))))
c-basic-offset
(if (c-block-in-arglist-dwim (c-langelem-2nd-pos c-syntactic-element))
c-basic-offset ; DWIM case.
;; Normal case. Indent to the token after the arglist open paren.
(goto-char savepos)
(c-forward-syntactic-ws)
(when (< (point) eol)
(goto-char savepos)
(skip-chars-forward " \t"))
(vector (current-column))))))
(goto-char (c-langelem-2nd-pos c-syntactic-element))
(if (and c-special-brace-lists
(c-looking-at-special-brace-list))
;; Skip a special brace list opener like "({".
(progn (c-forward-token-2)
(forward-char))
(forward-char))
(let ((arglist-content-start (point)))
(c-forward-syntactic-ws)
(when (< (point) indent-pos)
(goto-char arglist-content-start)
(skip-chars-forward " \t"))
(vector (current-column)))))))
;; Contributed by Kevin Ryde <user42@zip.com.au>.
(defun c-lineup-argcont (elem)
@ -172,7 +200,7 @@ Works with: arglist-cont, arglist-cont-nonempty."
;; isn't, go back to the last position in it. We do this by
;; stepping back over open parens until we get to the open paren
;; of our argument list.
(let ((open-paren (elt c-syntactic-element 2))
(let ((open-paren (c-langelem-2nd-pos c-syntactic-element))
(paren-state (c-parse-state)))
(while (not (eq (car paren-state) open-paren))
(unless (consp (car paren-state)) ;; ignore matched braces
@ -233,51 +261,36 @@ corresponding open paren, but can also be used with arglist-cont and
arglist-cont-nonempty to line up all lines inside a parenthesis under
the open paren.
As a special case, if a brace block is opened at the same line as the
open parenthesis of the argument list, the indentation is
As a special case, if a brace block construct starts at the same line
as the open parenthesis of the argument list, the indentation is
`c-basic-offset' only. See `c-lineup-arglist' for further discussion
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."
(save-excursion
(let (special-list paren-start savepos)
(if (memq (car langelem) '(arglist-cont-nonempty arglist-close))
(goto-char (elt c-syntactic-element 2))
(beginning-of-line)
(c-go-up-list-backward))
(if (memq (c-langelem-sym langelem)
'(arglist-cont-nonempty arglist-close))
(goto-char (c-langelem-2nd-pos c-syntactic-element))
(beginning-of-line)
(c-go-up-list-backward))
(if (and c-special-brace-lists
(setq special-list (c-looking-at-special-brace-list)))
;; Don't stop in the middle of a special brace list opener
;; like "({".
(progn
(setq paren-start (car (car special-list)))
(goto-char (+ paren-start 2)))
(setq paren-start (point))
(forward-char 1))
(if (save-excursion (c-block-in-arglist-dwim (point)))
c-basic-offset ; DWIM case.
(setq savepos (point))
;; Find out if an argument on the same line starts with an
;; unclosed open brace paren. Note similar code in
;; `c-lineup-arglist' and `c-lineup-close-paren'.
(if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t)
(looking-at c-syntactic-eol)
(progn (backward-char)
(not (c-looking-at-special-brace-list)))
(progn (c-backward-syntactic-ws)
(or (= (point) savepos)
(eq (char-before) ?,))))
c-basic-offset
;; Normal case. Indent to the arglist open paren.
(goto-char paren-start)
;; Normal case. Indent to the arglist open paren.
(let (special-list)
(if (and c-special-brace-lists
(setq special-list (c-looking-at-special-brace-list)))
;; Cope if we're in the middle of a special brace list
;; opener like "({".
(goto-char (car (car special-list))))
(vector (current-column))))))
(defun c-lineup-arglist-operators (langelem)
"Line up lines starting with an infix operator under the open paren.
Return nil on lines that don't start with an operator, to leave those
cases to other lineup functions. Example:
cases to other line-up functions. Example:
if ( x < 10
|| at_limit (x, <- c-lineup-arglist-operators
@ -285,7 +298,7 @@ if ( x < 10
)
Since this function doesn't do anything for lines without an infix
operator you typically want to use it together with some other lineup
operator you typically want to use it together with some other line-up
settings, e.g. as follows \(the arglist-close setting is just a
suggestion to get a consistent style):
@ -310,52 +323,48 @@ main (int, main (
char ** int, char **
) <-> ) <- c-lineup-close-paren
As a special case, if a brace block is opened at the same line as the
open parenthesis of the argument list, the indentation is
As a special case, if a brace block construct starts at the same line
as the open parenthesis of the argument list, the indentation is
`c-basic-offset' instead of the open paren column. See
`c-lineup-arglist' for further discussion of this \"DWIM\" measure.
Works with: All *-close symbols."
(save-excursion
(beginning-of-line)
(c-go-up-list-backward)
(if (memq (c-langelem-sym langelem)
'(arglist-cont-nonempty arglist-close))
(goto-char (c-langelem-2nd-pos c-syntactic-element))
(beginning-of-line)
(c-go-up-list-backward))
(let ((spec (c-looking-at-special-brace-list)) savepos argstart)
(if spec (goto-char (car (car spec))))
(setq savepos (point))
(forward-char 1)
(when spec
(c-forward-syntactic-ws)
(forward-char 1))
(let (special-list arglist-start)
(if (and c-special-brace-lists
(setq special-list (c-looking-at-special-brace-list)))
;; Cope if we're in the middle of a special brace list
;; opener like "({".
(progn
(goto-char (setq arglist-start (car (car special-list))))
(c-forward-token-2)
(forward-char))
(setq arglist-start (point))
(forward-char))
(if (looking-at c-syntactic-eol)
;; The arglist is "empty".
0
(cond ((looking-at c-syntactic-eol)
0) ; The arglist is "empty".
;; Find out if an argument on the same line starts with an
;; unclosed open brace paren. Note similar code in
;; `c-lineup-arglist' and
;; `c-lineup-arglist-close-under-paren'.
(setq argstart (point))
(if (and (c-syntactic-re-search-forward "{" (c-point 'eol) t t)
(looking-at c-syntactic-eol)
(progn (backward-char)
(not (c-looking-at-special-brace-list)))
(progn (c-backward-syntactic-ws)
(or (= (point) argstart)
(eq (char-before) ?,))))
c-basic-offset
((c-block-in-arglist-dwim (point))
c-basic-offset) ; DWIM case.
;; Normal case. Indent to the arglist open paren.
(goto-char savepos)
(vector (current-column)))))))
(t
;; Normal case. Indent to the arglist open paren.
(goto-char arglist-start)
(vector (current-column)))))))
(defun c-lineup-streamop (langelem)
"Line up C++ stream operators under each other.
Works with: stream-op."
(save-excursion
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(re-search-forward "<<\\|>>" (c-point 'eol) 'move)
(goto-char (match-beginning 0))
(vector (current-column))))
@ -382,7 +391,8 @@ Works with: inher-cont, member-init-cont."
(let* ((eol (c-point 'eol))
(here (point))
(char-after-ip (char-after)))
(if (cdr langelem) (goto-char (cdr langelem)))
(if (c-langelem-pos langelem)
(goto-char (c-langelem-pos langelem)))
;; This kludge is necessary to support both inher-cont and
;; member-init-cont, since they have different anchor positions.
@ -415,7 +425,7 @@ class Foo class Foo
Works with: inher-cont."
(save-excursion
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(forward-word 1)
(if (looking-at "[ \t]*$")
c-basic-offset
@ -439,7 +449,7 @@ Works with: func-decl-cont."
(save-excursion
(let* ((lim (1- (c-point 'bol)))
(throws (catch 'done
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(while (zerop (c-forward-token-2 1 t lim))
(if (looking-at "throws\\>[^_]")
(throw 'done t))))))
@ -537,13 +547,13 @@ Works with: The `c' syntactic symbol."
;; matches comment-start-skip, and choose whichever is
;; longest.
(max (save-excursion
(goto-char (1+ (cdr langelem)))
(goto-char (1+ (c-langelem-pos langelem)))
(if (and (match-string 0)
(looking-at (regexp-quote (match-string 0))))
(- (match-end 0) (match-beginning 0))
0))
(save-excursion
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(looking-at comment-start-skip)
(- (or (match-end 1)
(save-excursion
@ -557,14 +567,20 @@ Works with: The `c' syntactic symbol."
;; a nonempty comment prefix. Treat it as free form text
;; and don't change the indentation.
(vector (current-column))
(forward-line -1)
(back-to-indentation)
(if (>= (cdr langelem) (point))
;; On the second line in the comment.
;; Go back to the previous non-blank line, if any.
(while
(progn
(forward-line -1)
(back-to-indentation)
(and (> (point) (c-langelem-pos langelem))
(looking-at "[ \t]*$"))))
;; Is the starting line the first continuation line with content?
(if (>= (c-langelem-pos langelem) (point))
(if (zerop prefixlen)
;; No nonempty comment prefix. Align after comment
;; starter.
(progn
(looking-at comment-start-skip)
(goto-char (match-end 0))
;; The following should not be necessary, since
;; comment-start-skip should match everything (i.e.
@ -580,27 +596,27 @@ Works with: The `c' syntactic symbol."
;; Javadoc style comments.
(if (> starterlen prefixlen)
(progn
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(vector (1+ (current-column))))
(goto-char (+ (cdr langelem) starterlen 1))
(goto-char (+ (c-langelem-pos langelem) starterlen 1))
(vector (- (current-column) prefixlen))))
;; Not on the second line in the comment. If the previous
;; line has a nonempty comment prefix, align with it.
;; Otherwise, align with the previous nonempty line, but
;; align the comment ender with the starter.
;; We didn't start on the first non-blank continuation line. If the
;; previous line has a nonempty comment prefix, align with it.
;; Otherwise, align with the previous nonempty line, but align the
;; comment ender with the starter.
(when (or (not (looking-at c-current-comment-prefix))
(eq (match-beginning 0) (match-end 0)))
(goto-char here)
(back-to-indentation)
(if (looking-at (concat "\\(" c-current-comment-prefix "\\)\\*/"))
(goto-char (cdr langelem))
(goto-char (c-langelem-pos langelem))
(while (and (zerop (forward-line -1))
(looking-at "^[ \t]*$")))
(back-to-indentation)
(if (< (point) (cdr langelem))
(if (< (point) (c-langelem-pos langelem))
;; Align with the comment starter rather than
;; with the code before it.
(goto-char (cdr langelem)))))
(goto-char (c-langelem-pos langelem)))))
(vector (current-column)))))))
(defun c-lineup-comment (langelem)
@ -665,38 +681,39 @@ If there is no statement after the opening brace to align with, nil is
returned. This makes the function usable in list expressions.
Works with: The `statement' syntactic symbol."
(if (eq (char-after (cdr langelem)) ?{)
(if (eq (char-after (c-langelem-pos langelem)) ?{)
(save-excursion
(if (cdr langelem) (goto-char (cdr langelem)))
(if (c-langelem-pos langelem)
(goto-char (c-langelem-pos langelem)))
(forward-char 1)
(skip-chars-forward " \t")
(unless (eolp)
(vector (current-column))))))
(defun c-lineup-math (langelem)
"Line up the current line after the equal sign on the first line in
the statement. If there isn't any, indent with `c-basic-offset'. If
the current line contains an equal sign too, try to align it with the
first one.
(defun c-lineup-assignments (langelem)
"Line up the current line after the assignment operator on the first
line in the statement. If there isn't any, return nil to allow
stacking with other line-up functions. If the current line contains
an assignment operator too, try to align it with the first one.
Works with: topmost-intro-cont, statement-cont, arglist-cont,
arglist-cont-nonempty."
(let (startpos endpos equalp)
(if (eq (car langelem) 'arglist-cont-nonempty)
(if (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
;; If it's an arglist-cont-nonempty then we're only interested
;; in equal signs outside it. We don't search for a "=" on
;; the current line since that'd have a different nesting
;; compared to the one we should align with.
(save-excursion
(save-restriction
(setq endpos (nth 2 c-syntactic-element))
(narrow-to-region (cdr langelem) endpos)
(setq endpos (c-langelem-2nd-pos c-syntactic-element))
(narrow-to-region (c-langelem-pos langelem) endpos)
(if (setq startpos (c-up-list-backward endpos))
(setq startpos (1+ startpos))
(setq startpos (cdr langelem)))))
(setq startpos (c-langelem-pos langelem)))))
(setq startpos (cdr langelem)
(setq startpos (c-langelem-pos langelem)
endpos (point))
;; Find a syntactically relevant and unnested "=" token on the
@ -727,7 +744,7 @@ arglist-cont-nonempty."
(eolp)))
;; There's no equal sign on the line, or there is one but
;; nothing follows it.
c-basic-offset
nil
;; calculate indentation column after equals and ws, unless
;; our line contains an equals sign
@ -739,6 +756,17 @@ arglist-cont-nonempty."
(vector (- (current-column) equalp)))
)))
(defun c-lineup-math (langelem)
"Like `c-lineup-assignments' but indent with `c-basic-offset' if no
assignment operator was found on the first line. I.e. this function
is the same as specifying a list (c-lineup-assignments +). It's
provided for compatibility with old configurations.
Works with: topmost-intro-cont, statement-cont, arglist-cont,
arglist-cont-nonempty."
(or (c-lineup-assignments langelem)
c-basic-offset))
(defun c-lineup-cascaded-calls (langelem)
"Line up \"cascaded calls\" under each other.
If the line begins with \"->\" or \".\" and the preceding line ends
@ -755,8 +783,8 @@ expressions.
Works with: topmost-intro-cont, statement-cont, arglist-cont,
arglist-cont-nonempty."
(if (and (eq (car langelem) 'arglist-cont-nonempty)
(not (eq (nth 2 c-syntactic-element)
(if (and (eq (c-langelem-sym langelem) 'arglist-cont-nonempty)
(not (eq (c-langelem-2nd-pos c-syntactic-element)
(c-most-enclosing-brace (c-parse-state)))))
;; The innermost open paren is not our one, so don't do
;; anything. This can occur for arglist-cont-nonempty with
@ -767,7 +795,7 @@ arglist-cont-nonempty."
(back-to-indentation)
(let ((operator (and (looking-at "->\\|\\.")
(regexp-quote (match-string 0))))
(stmt-start (cdr langelem)) col)
(stmt-start (c-langelem-pos langelem)) col)
(when (and operator
(looking-at operator)
@ -794,7 +822,7 @@ result = prefix + \"A message \"
\"string.\"; <- c-lineup-string-cont
Nil is returned in other situations, to allow stacking with other
lineup functions.
line-up functions.
Works with: topmost-intro-cont, statement-cont, arglist-cont,
arglist-cont-nonempty."
@ -829,18 +857,18 @@ Works with: template-args-cont."
Go to the position right after the message receiver, and if you are at
the end of the line, indent the current line c-basic-offset columns
from the opening bracket; otherwise you are looking at the first
character of the first method call argument, so lineup the current
character of the first method call argument, so line up the current
line with it.
Works with: objc-method-call-cont."
(save-excursion
(let* ((extra (save-excursion
(back-to-indentation)
(c-backward-syntactic-ws (cdr langelem))
(c-backward-syntactic-ws (c-langelem-pos langelem))
(if (eq (char-before) ?:)
(- c-basic-offset)
0)))
(open-bracket-pos (cdr langelem))
(open-bracket-pos (c-langelem-pos langelem))
(open-bracket-col (progn
(goto-char open-bracket-pos)
(current-column)))
@ -864,7 +892,7 @@ Works with: objc-method-args-cont."
(let* ((here (c-point 'boi))
(curcol (progn (goto-char here) (current-column)))
(eol (c-point 'eol))
(relpos (cdr langelem))
(relpos (c-langelem-pos langelem))
(first-col-column (progn
(goto-char relpos)
(skip-chars-forward "^:" eol)
@ -888,7 +916,7 @@ Works with: objc-method-args-cont."
(let* ((here (c-point 'boi))
(curcol (progn (goto-char here) (current-column)))
(eol (c-point 'eol))
(relpos (cdr langelem))
(relpos (c-langelem-pos langelem))
(prev-col-column (progn
(skip-chars-backward "^:" relpos)
(and (eq (char-before) ?:)
@ -927,13 +955,10 @@ Works with: inlambda, inexpr-statement, inexpr-class."
containing-sexp))))))
(when res
(goto-char (cdr res))
(- (current-column)
(progn
(back-to-indentation)
(current-column)))))))
(vector (current-column))))))
(defun c-lineup-whitesmith-in-block (langelem)
"Line up lines inside a block in whitesmith style.
"Line up lines inside a block in Whitesmith style.
It's done in a way that works both when the opening brace hangs and
when it doesn't. E.g:
@ -946,21 +971,54 @@ something
In the first case the indentation is kept unchanged, in the
second `c-basic-offset' is added.
Works with: defun-close, defun-block-intro, block-close,
brace-list-close, brace-list-intro, statement-block-intro and all in*
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."
(save-excursion
(+ (progn
(back-to-indentation)
(if (eq (char-syntax (char-after)) ?\()
c-basic-offset
0))
(progn
(goto-char (cdr langelem))
(back-to-indentation)
(if (eq (char-syntax (char-after)) ?\()
0
c-basic-offset)))))
(if (and (c-go-up-list-backward)
(= (point) (c-point 'boi)))
nil
c-basic-offset)))
(defun c-lineup-after-whitesmith-blocks (langelem)
"Compensate for Whitesmith style indentation of blocks.
Due to the way CC Mode calculates anchor positions for normal lines
inside blocks, this function is necessary for those lines to get
correct Whitesmith style indentation. Consider the following
examples:
int foo()
{
int foo() {
{ a;
a; }
x; <-> x; <- c-lineup-after-whitesmith-blocks
The fact that the line with \"x\" is preceded by a Whitesmith style
indented block in one case and not the other should not affect its
indentation. But since CC Mode in cases like this uses the
indentation of the preceding statement as anchor position, the \"x\"
would in the rightmost case be indented too much if the offset for
`statement' was set simply to zero.
This lineup function corrects for this situation by detecting if the
anchor position is at an open paren character. In that case, it
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."
(save-excursion
(goto-char (c-langelem-pos langelem))
(when (looking-at "\\s\(")
(if (c-go-up-list-backward)
(let ((pos (point)))
(back-to-indentation)
(if (= pos (point))
(vector (current-column))
(vector (+ (current-column) c-basic-offset))))
(vector 0)))))
(defun c-lineup-cpp-define (langelem)
"Line up macro continuation lines according to the indentation of
@ -1058,9 +1116,10 @@ Works with: cpp-define-intro."
The \"x\" line is aligned to the text after the \":\" on the \"w\" line, and
similarly \"z\" under \"y\".
This is done only in an \"asm\" or \"__asm__\" block, and only to those
lines mentioned. Anywhere else nil is returned. The usual arrangement is
to have this routine as an extra feature at the start of arglist lineups, e.g.
This is done only in an \"asm\" or \"__asm__\" block, and only to
those lines mentioned. Anywhere else nil is returned. The usual
arrangement is to have this routine as an extra feature at the start
of arglist line-ups, e.g.
(c-lineup-gcc-asm-reg c-lineup-arglist)
@ -1076,7 +1135,7 @@ Works with: arglist-cont, arglist-cont-nonempty."
;; This can occur for arglist-cont-nonempty with nested arglist
;; starts on the same line.
(or (not (eq (car elem) 'arglist-cont-nonempty))
(eq (elt c-syntactic-element 2)
(eq (c-langelem-2nd-pos c-syntactic-element)
(c-most-enclosing-brace (c-parse-state))))
;; Find the ":" to align to. Look for this first so as to quickly
@ -1117,13 +1176,24 @@ ACTION associated with `block-close' syntax."
(let (langelem)
(if (and (eq syntax 'block-close)
(setq langelem (assq 'block-close c-syntactic-context))
(progn (goto-char (elt langelem 1))
(progn (goto-char (c-langelem-pos langelem))
(if (eq (char-after) ?{)
(c-safe (c-forward-sexp -1)))
(looking-at "\\<do\\>[^_]")))
'(before)
'(before after)))))
(defun c-snug-1line-defun-close (syntax pos)
"Determine the brace hanginess for an AWK defun-close.
If the action/function being closed is a one-liner, keep it so. Otherwise put
the closing brace on its own line."
(save-excursion
(goto-char pos)
(if (> (c-point 'bol)
(progn (up-list -1) (point)))
'(before after)
'(after))))
(defun c-gnu-impose-minimum ()
"Imposes a minimum indentation for lines inside code blocks.
The variable `c-label-minimum-indentation' specifies the minimum

File diff suppressed because it is too large Load diff

View file

@ -1,7 +1,7 @@
;;; cc-bytecomp.el --- compile time setup for proper compilation
;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005
;; Free Software Foundation, Inc.
;; Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation,
;; Inc.
;; Author: Martin Stjernholm
;; Maintainer: bug-cc-mode@gnu.org
@ -22,7 +22,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation,
;; Inc.
;; Authors: 1998- Martin Stjernholm
;; 1994-1999 Barry A. Warsaw
@ -22,7 +23,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
;;; cc-menus.el --- imenu support for CC Mode
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation,
;; Inc.
;; Authors: 1998- Martin Stjernholm
;; 1992-1999 Barry A. Warsaw
@ -24,7 +25,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
@ -240,7 +241,6 @@ Example:
- perform: (SEL)aSelector withObject: object1 withObject: object2; /* METHOD */
=>
-perform:withObject:withObject:withObject: /* selector */"
;; This function does not do any hidden buffer changes.
(let ((return "") ; String to be returned
(p 0) ; Current scanning position in METHOD
(pmax (length method)) ;
@ -281,7 +281,6 @@ Example:
(defun cc-imenu-objc-remove-white-space (str)
"Remove all spaces and tabs from STR."
;; This function does not do any hidden buffer changes.
(let ((return "")
(p 0)
(max (length str))
@ -296,7 +295,6 @@ Example:
(defun cc-imenu-objc-function ()
"imenu supports for objc-mode."
;; This function does not do any hidden buffer changes.
(let (methodlist
clist
;;
@ -415,7 +413,6 @@ Example:
(defun cc-imenu-init (mode-generic-expression
&optional mode-create-index-function)
;; This function does not do any hidden buffer changes.
(setq imenu-generic-expression mode-generic-expression
imenu-case-fold-search nil)
(when mode-create-index-function

View file

@ -1,6 +1,7 @@
;;; cc-mode.el --- major mode for editing C and similar languages
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation,
;; Inc.
;; Authors: 2003- Alan Mackenzie
;; 1998- Martin Stjernholm
@ -92,10 +93,9 @@
(cc-require 'cc-menus)
;; Silence the compiler.
(cc-bytecomp-defvar comment-line-break-function) ; (X)Emacs 20+
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs 20+
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
(cc-bytecomp-defun set-keymap-parents) ; XEmacs
(cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1+
(cc-bytecomp-defun run-mode-hooks) ; Emacs 21.1
(cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
;; We set these variables during mode init, yet we don't require
@ -107,6 +107,11 @@
;; with your version of Emacs, you are incompatible!
(cc-external-require 'easymenu)
;; Autoload directive for emacsen that doesn't have an older CC Mode
;; version in the dist.
(autoload 'c-subword-mode "cc-subword"
"Mode enabling subword movement and editing keys." t)
;; Load cc-fonts first after font-lock is loaded, since it isn't
;; necessary until font locking is requested.
(eval-after-load "font-lock"
@ -153,7 +158,6 @@ directly supported by CC Mode. This can be used instead of the
`c-init-language-vars' macro if the language you want to use is one of
those, rather than a derived language defined through the language
variable system (see \"cc-langs.el\")."
;; This function does not do any hidden buffer changes.
(cond ((eq mode 'c-mode) (c-init-language-vars c-mode))
((eq mode 'c++-mode) (c-init-language-vars c++-mode))
((eq mode 'objc-mode) (c-init-language-vars objc-mode))
@ -171,8 +175,6 @@ initialization to run CC Mode for the C language is done. Otherwise
only some basic setup is done, and a call to `c-init-language-vars' or
`c-init-language-vars-for' is necessary too (which gives more
control). See \"cc-mode.el\" for more info."
;;
;; This function does not do any hidden buffer changes.
(setq c-buffer-is-cc-mode t)
@ -220,7 +222,7 @@ control). See \"cc-mode.el\" for more info."
(defun c-define-abbrev-table (name defs)
;; Compatibility wrapper for `define-abbrev' which passes a non-nil
;; sixth argument for SYSTEM-FLAG in emacsen that support it
;; (currently only Emacs 21.2).
;; (currently only Emacs >= 21.2).
(let ((table (or (symbol-value name)
(progn (define-abbrev-table name nil)
(symbol-value name)))))
@ -232,20 +234,25 @@ control). See \"cc-mode.el\" for more info."
(setq defs (cdr defs)))))
(put 'c-define-abbrev-table 'lisp-indent-function 1)
(defun c-bind-special-erase-keys ()
;; Only used in Emacs to bind C-c C-<delete> and C-c C-<backspace>
;; to the proper keys depending on `normal-erase-is-backspace'.
(if normal-erase-is-backspace
(progn
(define-key c-mode-base-map (kbd "C-c C-<delete>")
'c-hungry-delete-forward)
(define-key c-mode-base-map (kbd "C-c C-<backspace>")
'c-hungry-backspace))
(define-key c-mode-base-map (kbd "C-c C-<delete>")
'c-hungry-backspace)
(define-key c-mode-base-map (kbd "C-c C-<backspace>")
'c-hungry-delete-forward)))
(if c-mode-base-map
nil
;; TBD: should we even worry about naming this keymap. My vote: no,
;; because Emacs and XEmacs do it differently.
(setq c-mode-base-map (make-sparse-keymap))
;; put standard keybindings into MAP
;; the following mappings correspond more or less directly to BOCM
(define-key c-mode-base-map "{" 'c-electric-brace)
(define-key c-mode-base-map "}" 'c-electric-brace)
(define-key c-mode-base-map ";" 'c-electric-semi&comma)
(define-key c-mode-base-map "#" 'c-electric-pound)
(define-key c-mode-base-map ":" 'c-electric-colon)
(define-key c-mode-base-map "(" 'c-electric-paren)
(define-key c-mode-base-map ")" 'c-electric-paren)
;; Separate M-BS from C-M-h. The former should remain
;; backward-kill-word.
(define-key c-mode-base-map [(control meta h)] 'c-mark-function)
@ -259,21 +266,23 @@ control). See \"cc-mode.el\" for more info."
(substitute-key-definition 'indent-new-comment-line
'c-indent-new-comment-line
c-mode-base-map global-map)
(substitute-key-definition 'indent-for-tab-command
'c-indent-command
c-mode-base-map global-map)
(when (fboundp 'comment-indent-new-line)
;; indent-new-comment-line has changed name to
;; comment-indent-new-line in Emacs 21.
(substitute-key-definition 'comment-indent-new-line
'c-indent-new-comment-line
c-mode-base-map global-map))
;; RMS says don't make these the default.
;; (define-key c-mode-base-map "\e\C-a" 'c-beginning-of-defun)
;; (define-key c-mode-base-map "\e\C-e" 'c-end-of-defun)
(define-key c-mode-base-map "\C-c\C-n" 'c-forward-conditional)
(define-key c-mode-base-map "\C-c\C-p" 'c-backward-conditional)
(define-key c-mode-base-map "\C-c\C-u" 'c-up-conditional)
(substitute-key-definition 'indent-for-tab-command
'c-indent-command
c-mode-base-map global-map)
;; It doesn't suffice to put `c-fill-paragraph' on
;; `fill-paragraph-function' since `c-fill-paragraph' must be called
@ -290,34 +299,74 @@ control). See \"cc-mode.el\" for more info."
(substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
c-mode-base-map global-map)
;; We bind the forward deletion key and (implicitly) C-d to
;; `c-electric-delete-forward', and the backward deletion key to
;; `c-electric-backspace'. The hungry variants are bound to the
;; same keys but prefixed with C-c. This implies that C-c C-d is
;; `c-hungry-delete-forward'. For consistency, we bind not only C-c
;; <backspace> to `c-hungry-backspace' but also C-c C-<backspace>,
;; so that the Ctrl key can be held down during the whole sequence
;; regardless of the direction. This in turn implies that we bind
;; C-c C-<delete> to `c-hungry-delete-forward', for the same reason.
;; Bind the electric deletion functions to C-d and DEL. Emacs 21
;; automatically maps the [delete] and [backspace] keys to these two
;; depending on window system and user preferences. (In earlier
;; versions it's possible to do the same by using `function-key-map'.)
(define-key c-mode-base-map "\C-d" 'c-electric-delete-forward)
(define-key c-mode-base-map "\177" 'c-electric-backspace)
(when (boundp 'delete-key-deletes-forward)
;; In XEmacs 20 and later we fix the forward and backward deletion
;; behavior by binding the keysyms for the [delete] and
;; [backspace] keys directly, and use `delete-forward-p' or
;; `delete-key-deletes-forward' to decide what [delete] should do.
(define-key c-mode-base-map "\C-c\C-d" 'c-hungry-delete-forward)
(define-key c-mode-base-map [?\C-c ?\d] 'c-hungry-backspace)
(define-key c-mode-base-map [?\C-c ?\C-\d] 'c-hungry-backspace)
(define-key c-mode-base-map [?\C-c deletechar] 'c-hungry-delete-forward) ; C-c <delete> on a tty.
(define-key c-mode-base-map [?\C-c (control deletechar)] ; C-c C-<delete> on a tty.
'c-hungry-delete-forward)
(when (boundp 'normal-erase-is-backspace)
;; The automatic C-d and DEL mapping functionality doesn't extend
;; to special combinations like C-c C-<delete>, so we have to hook
;; into the `normal-erase-is-backspace' system to bind it directly
;; as appropriate.
(add-hook 'normal-erase-is-backspace-hook 'c-bind-special-erase-keys)
(c-bind-special-erase-keys))
(when (fboundp 'delete-forward-p)
;; In XEmacs we fix the forward and backward deletion behavior by
;; binding the keysyms for the [delete] and [backspace] keys
;; directly, and use `delete-forward-p' to decide what [delete]
;; should do. That's done in the XEmacs specific
;; `c-electric-delete' and `c-hungry-delete' functions.
(define-key c-mode-base-map [delete] 'c-electric-delete)
(define-key c-mode-base-map [backspace] 'c-electric-backspace))
(define-key c-mode-base-map "," 'c-electric-semi&comma)
(define-key c-mode-base-map "*" 'c-electric-star)
(define-key c-mode-base-map [backspace] 'c-electric-backspace)
(define-key c-mode-base-map (kbd "C-c <delete>") 'c-hungry-delete)
(define-key c-mode-base-map (kbd "C-c C-<delete>") 'c-hungry-delete)
(define-key c-mode-base-map (kbd "C-c <backspace>") 'c-hungry-backspace)
(define-key c-mode-base-map (kbd "C-c C-<backspace>") 'c-hungry-backspace))
(define-key c-mode-base-map "#" 'c-electric-pound)
(define-key c-mode-base-map "{" 'c-electric-brace)
(define-key c-mode-base-map "}" 'c-electric-brace)
(define-key c-mode-base-map "/" 'c-electric-slash)
(define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
(define-key c-mode-base-map "*" 'c-electric-star)
(define-key c-mode-base-map ";" 'c-electric-semi&comma)
(define-key c-mode-base-map "," 'c-electric-semi&comma)
(define-key c-mode-base-map ":" 'c-electric-colon)
(define-key c-mode-base-map "(" 'c-electric-paren)
(define-key c-mode-base-map ")" 'c-electric-paren)
(define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
(define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
(define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-newline)
(define-key c-mode-base-map "\C-c\C-b" 'c-submit-bug-report)
(define-key c-mode-base-map "\C-c\C-c" 'comment-region)
(define-key c-mode-base-map "\C-c\C-d" 'c-toggle-hungry-state)
(define-key c-mode-base-map "\C-c\C-l" 'c-toggle-electric-state)
(define-key c-mode-base-map "\C-c\C-o" 'c-set-offset)
(define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
(define-key c-mode-base-map "\C-c\C-s" 'c-show-syntactic-information)
(define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state)
;; (define-key c-mode-base-map "\C-c\C-t" 'c-toggle-auto-hungry-state) Commented out by ACM, 2005-03-05.
(define-key c-mode-base-map "\C-c." 'c-set-style)
;; conflicts with OOBR
;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
;; (define-key c-mode-base-map "\C-c\C-y" 'c-toggle-hungry-state) Commented out by ACM, 2005-11-22.
(define-key c-mode-base-map "\C-c\C-w" 'c-subword-mode)
)
;; We don't require the outline package, but we configure it a bit anyway.
@ -341,32 +390,47 @@ preferably use the `c-mode-menu' language constant directly."
(let ((f (symbol-function 'c-populate-syntax-table)))
(if (byte-code-function-p f) f (byte-compile f)))))
;; CAUTION: Try to avoid installing things on
;; `before-change-functions'. The macro `combine-after-change-calls'
;; is used and it doesn't work if there are things on that hook. That
;; can cause font lock functions to run in inconvenient places during
;; temporary changes in some font lock support modes, causing extra
;; unnecessary work and font lock glitches due to interactions between
;; various text properties.
(defun c-after-change (beg end len)
;; Function put on `after-change-functions' to adjust various
;; caches. Prefer speed to finesse here, since there will be an
;; order of magnitude more calls to this function than any of the
;; Function put on `after-change-functions' to adjust various caches
;; etc. Prefer speed to finesse here, since there will be an order
;; of magnitude more calls to this function than any of the
;; functions that use the caches.
;;
;; Note that care must be taken so that this is called before any
;; font-lock callbacks since we might get calls to functions using
;; these caches from inside them, and we must thus be sure that this
;; has already been executed.
;;
;; This function does not do any hidden buffer changes.
(c-save-buffer-state ()
(when (> end (point-max))
;; Some emacsen might return positions past the end. This has been
;; observed in Emacs 20.7 when rereading a buffer changed on disk
;; (haven't been able to minimize it, but Emacs 21.3 appears to
;; work).
(setq end (point-max))
(when (> beg end)
(setq beg end)))
;; When `combine-after-change-calls' is used we might get calls
;; with regions outside the current narrowing. This has been
;; observed in Emacs 20.7.
(save-restriction
(widen)
(c-invalidate-sws-region-after beg end)
(c-invalidate-state-cache beg)
(c-invalidate-find-decl-cache beg)))
(when (> end (point-max))
;; Some emacsen might return positions past the end. This has been
;; observed in Emacs 20.7 when rereading a buffer changed on disk
;; (haven't been able to minimize it, but Emacs 21.3 appears to
;; work).
(setq end (point-max))
(when (> beg end)
(setq beg end)))
(c-invalidate-sws-region-after beg end)
(c-invalidate-state-cache beg)
(c-invalidate-find-decl-cache beg)
(when c-recognize-<>-arglists
(c-after-change-check-<>-operators beg end)))))
(defun c-basic-common-init (mode default-style)
"Do the necessary initialization for the syntax handling routines
@ -380,8 +444,6 @@ same format as `c-default-style'.
Note that `c-init-language-vars' must be called before this function.
This function cannot do that since `c-init-language-vars' is a macro
that requires a literal mode spec at compile time."
;;
;; This function does not do any hidden buffer changes.
(setq c-buffer-is-cc-mode mode)
@ -395,13 +457,20 @@ that requires a literal mode spec at compile time."
(make-local-variable 'comment-end)
(make-local-variable 'comment-start-skip)
(make-local-variable 'comment-multi-line)
(make-local-variable 'comment-line-break-function)
(make-local-variable 'paragraph-start)
(make-local-variable 'paragraph-separate)
(make-local-variable 'paragraph-ignore-fill-prefix)
(make-local-variable 'adaptive-fill-mode)
(make-local-variable 'adaptive-fill-regexp)
;; now set their values
(setq parse-sexp-ignore-comments t
indent-line-function 'c-indent-line
indent-region-function 'c-indent-region
normal-auto-fill-function 'c-do-auto-fill
comment-multi-line t)
comment-multi-line t
comment-line-break-function 'c-indent-new-comment-line)
;; Install `c-fill-paragraph' on `fill-paragraph-function' so that a
;; direct call to `fill-paragraph' behaves better. This still
@ -409,21 +478,25 @@ that requires a literal mode spec at compile time."
(make-local-variable 'fill-paragraph-function)
(setq fill-paragraph-function 'c-fill-paragraph)
;; (X)Emacs 20 and later.
(when (boundp 'comment-line-break-function)
(make-local-variable 'comment-line-break-function)
(setq comment-line-break-function
'c-indent-new-comment-line))
(when (or c-recognize-<>-arglists
(c-major-mode-is 'awk-mode))
;; We'll use the syntax-table text property to change the syntax
;; of some chars for this language, so do the necessary setup for
;; that.
;;
;; Note to other package developers: It's ok to turn this on in CC
;; Mode buffers when CC Mode doesn't, but it's not ok to turn it
;; off if CC Mode has turned it on.
;; Emacs 20 and later.
(when (boundp 'parse-sexp-lookup-properties)
(make-local-variable 'parse-sexp-lookup-properties)
(setq parse-sexp-lookup-properties t))
;; Emacs.
(when (boundp 'parse-sexp-lookup-properties)
(make-local-variable 'parse-sexp-lookup-properties)
(setq parse-sexp-lookup-properties t))
;; Same as above for XEmacs 21 (although currently undocumented).
(when (boundp 'lookup-syntax-properties)
(make-local-variable 'lookup-syntax-properties)
(setq lookup-syntax-properties t))
;; Same as above for XEmacs.
(when (boundp 'lookup-syntax-properties)
(make-local-variable 'lookup-syntax-properties)
(setq lookup-syntax-properties t)))
;; Use this in Emacs 21 to avoid meddling with the rear-nonsticky
;; property on each character.
@ -441,18 +514,12 @@ that requires a literal mode spec at compile time."
;; In Emacs 21 and later it's possible to turn off the ad-hoc
;; heuristic that open parens in column 0 are defun starters. Since
;; we have c-state-cache that isn't useful and only causes trouble
;; so turn it off.
;; we have c-state-cache, that heuristic isn't useful and only causes
;; trouble, so turn it off.
(when (memq 'col-0-paren c-emacs-features)
(make-local-variable 'open-paren-in-column-0-is-defun-start)
(setq open-paren-in-column-0-is-defun-start nil))
;; The `c-type' text property with `c-decl-end' is used to mark the
;; ends of access keys to make interactive refontification work
;; better.
(when c-opt-access-key
(setq c-type-decl-end-used t))
(c-clear-found-types)
;; now set the mode style based on default-style
@ -483,14 +550,15 @@ that requires a literal mode spec at compile time."
(make-local-variable 'comment-indent-function)
(setq comment-indent-function 'c-comment-indent)
;; put auto-hungry designators onto minor-mode-alist, but only once
(or (assq 'c-auto-hungry-string minor-mode-alist)
;; Put submode indicators onto minor-mode-alist, but only once.
(or (assq 'c-submode-indicators minor-mode-alist)
(setq minor-mode-alist
(cons '(c-auto-hungry-string c-auto-hungry-string)
(cons '(c-submode-indicators c-submode-indicators)
minor-mode-alist)))
;; Install the functions that ensure that various internal caches
;; don't become invalid due to buffer changes.
(make-local-hook 'after-change-functions)
(add-hook 'after-change-functions 'c-after-change nil t))
(defun c-after-font-lock-init ()
@ -505,7 +573,7 @@ This does not load the font-lock package. Use after
(make-local-variable 'font-lock-defaults)
(setq font-lock-defaults
`(,(if (c-mode-is-new-awk-p)
`(,(if (c-major-mode-is 'awk-mode)
;; awk-mode currently has only one font lock level.
'awk-font-lock-keywords
(mapcar 'c-mode-symbol
@ -517,6 +585,8 @@ This does not load the font-lock package. Use after
(font-lock-lines-before . 1)
(font-lock-mark-block-function
. c-mark-function)))
(make-local-hook 'font-lock-mode-hook)
(add-hook 'font-lock-mode-hook 'c-after-font-lock-init nil t))
(defun c-setup-doc-comment-style ()
@ -536,9 +606,7 @@ Mode to operate correctly.
MODE is the symbol for the mode to initialize, like 'c-mode. See
`c-basic-common-init' for details. It's only optional to be
compatible with old code; callers should always specify it.
This function does not do any hidden buffer changes."
compatible with old code; callers should always specify it."
(unless mode
;; Called from an old third party package. The fallback is to
@ -569,8 +637,6 @@ setting found in `c-file-style', then it applies any offset settings
it finds in `c-file-offsets'.
Note that the style variables are always made local to the buffer."
;;
;; This function does not do any hidden buffer changes.
;; apply file styles and offsets
(when c-buffer-is-cc-mode
@ -584,7 +650,18 @@ Note that the style variables are always made local to the buffer."
(let ((langelem (car langentry))
(offset (cdr langentry)))
(c-set-offset langelem offset)))
c-file-offsets))))
c-file-offsets))
;; Problem: The file local variable block might have explicitly set a
;; style variable. The `c-set-style' or `mapcar' call might have
;; overwritten this. So we run `hack-local-variables' again to remedy
;; this. There are no guarantees this will work properly, particularly as
;; we have no control over what the other hook functions on
;; `hack-local-variables-hook' would have done, or what any "eval"
;; expression will do when evaluated again. C'est la vie! ACM,
;; 2005/11/2.
(if (or c-file-style c-file-offsets)
(let ((hack-local-variables-hook nil))
(hack-local-variables)))))
(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
@ -794,9 +871,6 @@ Key bindings:
mode-name "ObjC"
local-abbrev-table objc-mode-abbrev-table
abbrev-mode t)
;; The `c-type' text property with `c-decl-end' is used to mark the
;; end of the @-style directives.
(setq c-type-decl-end-used t)
(use-local-map objc-mode-map)
(c-init-language-vars-for 'objc-mode)
(c-common-init 'objc-mode)
@ -996,8 +1070,7 @@ Key bindings:
(c-update-modeline))
;; Support for awk. This is purposely disabled for older (X)Emacsen which
;; don't support syntax-table properties.
;; Support for AWK
;;;###autoload (add-to-list 'auto-mode-alist '("\\.awk\\'" . awk-mode))
;;;###autoload (add-to-list 'interpreter-mode-alist '("awk" . awk-mode))
@ -1009,37 +1082,34 @@ Key bindings:
;;; autoload form instead.
;;;###autoload (autoload 'awk-mode "cc-mode" "Major mode for editing AWK code." t)
(if (not (memq 'syntax-properties c-emacs-features))
(autoload 'awk-mode "awk-mode" "Major mode for editing AWK code." t)
(defvar awk-mode-abbrev-table nil
"Abbreviation table used in awk-mode buffers.")
(c-define-abbrev-table 'awk-mode-abbrev-table
'(("else" "else" c-electric-continued-statement 0)
("while" "while" c-electric-continued-statement 0)))
(defvar awk-mode-abbrev-table nil
"Abbreviation table used in awk-mode buffers.")
(c-define-abbrev-table 'awk-mode-abbrev-table
'(("else" "else" c-electric-continued-statement 0)
("while" "while" c-electric-continued-statement 0)))
(defvar awk-mode-map ()
"Keymap used in awk-mode buffers.")
(if awk-mode-map
nil
(setq awk-mode-map (c-make-inherited-keymap))
;; add bindings which are only useful for awk.
(define-key awk-mode-map "#" 'self-insert-command)
(define-key awk-mode-map "/" 'self-insert-command)
(define-key awk-mode-map "*" 'self-insert-command)
(define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
(define-key awk-mode-map "\C-c\C-p" 'undefined)
(define-key awk-mode-map "\C-c\C-u" 'undefined)
(define-key awk-mode-map "\M-a" 'c-beginning-of-statement) ; 2003/10/7
(define-key awk-mode-map "\M-e" 'c-end-of-statement) ; 2003/10/7
(define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
(define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
(defvar awk-mode-map ()
"Keymap used in awk-mode buffers.")
(if awk-mode-map
nil
(setq awk-mode-map (c-make-inherited-keymap))
;; add bindings which are only useful for awk.
(define-key awk-mode-map "#" 'self-insert-command)
(define-key awk-mode-map "/" 'self-insert-command)
(define-key awk-mode-map "*" 'self-insert-command)
(define-key awk-mode-map "\C-c\C-n" 'undefined) ; #if doesn't exist in awk.
(define-key awk-mode-map "\C-c\C-p" 'undefined)
(define-key awk-mode-map "\C-c\C-u" 'undefined)
(define-key awk-mode-map "\M-a" 'undefined) ; c-awk-beginning-of-statement isn't yet implemented.
(define-key awk-mode-map "\M-e" 'undefined) ; c-awk-end-of-statement isn't yet implemented.
(define-key awk-mode-map "\C-\M-a" 'c-awk-beginning-of-defun)
(define-key awk-mode-map "\C-\M-e" 'c-awk-end-of-defun))
(easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
(cons "AWK" (c-lang-const c-mode-menu awk)))
(easy-menu-define c-awk-menu awk-mode-map "AWK Mode Commands"
(cons "AWK" (c-lang-const c-mode-menu awk)))
(defun awk-mode ()
"Major mode for editing AWK code.
(defun awk-mode ()
"Major mode for editing AWK code.
To submit a problem report, enter `\\[c-submit-bug-report]' from an
awk-mode buffer. This automatically sets up a mail buffer with version
information already added. You just need to add a description of the
@ -1052,41 +1122,40 @@ initialization, then `awk-mode-hook'.
Key bindings:
\\{awk-mode-map}"
(interactive)
(require 'cc-awk) ; Added 2003/6/10.
(kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table awk-mode-syntax-table)
(setq major-mode 'awk-mode
mode-name "AWK"
local-abbrev-table awk-mode-abbrev-table
abbrev-mode t)
(use-local-map awk-mode-map)
(c-init-language-vars-for 'awk-mode)
(c-common-init 'awk-mode)
;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
;; so it's not set by `c-font-lock-init'.
(make-local-variable 'font-lock-syntactic-keywords)
(setq font-lock-syntactic-keywords
'((c-awk-set-syntax-table-properties
0 (0) ; Everything on this line is a dummy.
nil t)))
(c-awk-unstick-NL-prop)
(add-hook 'before-change-functions 'c-awk-before-change nil t)
(add-hook 'after-change-functions 'c-awk-after-change nil t)
(c-save-buffer-state nil
(save-restriction
(widen)
(c-awk-clear-NL-props (point-min) (point-max))
(c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
(interactive)
(require 'cc-awk) ; Added 2003/6/10.
(kill-all-local-variables)
(c-initialize-cc-mode t)
(set-syntax-table awk-mode-syntax-table)
(setq major-mode 'awk-mode
mode-name "AWK"
local-abbrev-table awk-mode-abbrev-table
abbrev-mode t)
(use-local-map awk-mode-map)
(c-init-language-vars-for 'awk-mode)
(c-common-init 'awk-mode)
;; The rest of CC Mode does not (yet) use `font-lock-syntactic-keywords',
;; so it's not set by `c-font-lock-init'.
(make-local-variable 'font-lock-syntactic-keywords)
(setq font-lock-syntactic-keywords
'((c-awk-set-syntax-table-properties
0 (0) ; Everything on this line is a dummy.
nil t)))
(c-awk-unstick-NL-prop)
(add-hook 'before-change-functions 'c-awk-before-change nil t)
(add-hook 'after-change-functions 'c-awk-after-change nil t)
(c-save-buffer-state nil
(save-restriction
(widen)
(c-awk-clear-NL-props (point-min) (point-max))
(c-awk-after-change (point-min) (point-max) 0))) ; Set syntax-table props.
;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
;; in cc-engine.el, just before (defun c-fast-in-literal ...
(defalias 'c-in-literal 'c-slow-in-literal)
;; Prevent Xemacs's buffer-syntactic-context being used. See the comment
;; in cc-engine.el, just before (defun c-fast-in-literal ...
(defalias 'c-in-literal 'c-slow-in-literal)
(c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
(c-update-modeline))
) ;; closes the (if (not (memq 'syntax-properties c-emacs-features))
(c-run-mode-hooks 'c-mode-common-hook 'awk-mode-hook)
(c-update-modeline))
;; bug reporting
@ -1175,5 +1244,5 @@ Key bindings:
(cc-provide 'cc-mode)
;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
;;; arch-tag: 7825e5c4-fd09-439f-a04d-4c13208ba3d7
;;; cc-mode.el ends here

View file

@ -1,6 +1,7 @@
;;; cc-styles.el --- support for styles in CC Mode
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation,
;; Inc.
;; Authors: 1998- Martin Stjernholm
;; 1992-1999 Barry A. Warsaw
@ -24,7 +25,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
@ -55,6 +56,7 @@
'(("gnu"
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
(c-hanging-braces-alist . ((substatement-open before after)))
(c-offsets-alist . ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . +)
@ -65,11 +67,10 @@
(arglist-intro . c-lineup-arglist-intro-after-paren)
(arglist-close . c-lineup-arglist)
(inline-open . 0)
(brace-list-open . +)
))
(brace-list-open . +)))
(c-special-indent-hook . c-gnu-impose-minimum)
(c-block-comment-prefix . "")
)
(c-block-comment-prefix . ""))
("k&r"
(c-basic-offset . 5)
(c-comment-only-line-offset . 0)
@ -78,9 +79,8 @@
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(statement-cont . +)
))
)
(statement-cont . +))))
("bsd"
(c-basic-offset . 8)
(c-comment-only-line-offset . 0)
@ -91,9 +91,8 @@
(label . 0)
(statement-cont . +)
(inline-open . 0)
(inexpr-class . 0)
))
)
(inexpr-class . 0))))
("stroustrup"
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
@ -101,46 +100,61 @@
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(statement-cont . +)
))
)
(statement-cont . +))))
("whitesmith"
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
(c-offsets-alist . ((knr-argdecl-intro . +)
(label . 0)
(statement-cont . +)
;; It's obvious that the CC Mode way of choosing anchor positions
;; doesn't fit this style at all. :P
(c-offsets-alist . ((defun-open . +)
(defun-close . c-lineup-whitesmith-in-block)
(defun-block-intro . (add c-lineup-whitesmith-in-block
c-indent-multi-line-block))
(class-open . +)
(class-close . +)
(inline-open . +)
(inline-close . c-lineup-whitesmith-in-block)
(knr-argdecl-intro . +)
(block-open . 0) ; Get indentation from `statement' instead.
(block-close . c-lineup-whitesmith-in-block)
(brace-list-open . +)
(brace-list-close . c-lineup-whitesmith-in-block)
(brace-list-intro . (add c-lineup-whitesmith-in-block
c-indent-multi-line-block))
(brace-list-entry . (add c-lineup-after-whitesmith-blocks
c-indent-multi-line-block))
(brace-entry-open . (add c-lineup-after-whitesmith-blocks
c-indent-multi-line-block))
(statement . (add c-lineup-after-whitesmith-blocks
c-indent-multi-line-block))
(statement-block-intro . (add c-lineup-whitesmith-in-block
c-indent-multi-line-block))
(substatement-open . +)
(substatement-label . +)
(block-open . +)
(statement-block-intro . c-lineup-whitesmith-in-block)
(block-close . c-lineup-whitesmith-in-block)
(inline-open . +)
(defun-open . +)
(defun-block-intro . c-lineup-whitesmith-in-block)
(defun-close . c-lineup-whitesmith-in-block)
(brace-list-open . +)
(brace-list-intro . c-lineup-whitesmith-in-block)
(brace-entry-open . c-indent-multi-line-block)
(brace-list-close . c-lineup-whitesmith-in-block)
(class-open . +)
(label . 0)
(arglist-intro . (add c-lineup-whitesmith-in-block
c-indent-multi-line-block))
(arglist-cont . (add c-lineup-after-whitesmith-blocks
c-indent-multi-line-block))
(arglist-cont-nonempty . (add c-lineup-whitesmith-in-block
c-indent-multi-line-block))
(arglist-close . c-lineup-whitesmith-in-block)
(inclass . c-lineup-whitesmith-in-block)
(class-close . +)
(inexpr-class . 0)
(extern-lang-open . +)
(inextern-lang . c-lineup-whitesmith-in-block)
(extern-lang-close . +)
(namespace-open . +)
(innamespace . c-lineup-whitesmith-in-block)
(namespace-close . +)
(module-open . +)
(inmodule . c-lineup-whitesmith-in-block)
(module-close . +)
(composition-open . +)
(incomposition . c-lineup-whitesmith-in-block)
(extern-lang-close . +)
(namespace-close . +)
(module-close . +)
(composition-close . +)
))
)
(inextern-lang . c-lineup-whitesmith-in-block)
(innamespace . c-lineup-whitesmith-in-block)
(inmodule . c-lineup-whitesmith-in-block)
(incomposition . c-lineup-whitesmith-in-block)
(inexpr-class . 0))))
("ellemtel"
(c-basic-offset . 3)
(c-comment-only-line-offset . 0)
@ -151,9 +165,8 @@
(case-label . +)
(access-label . -)
(inclass . ++)
(inline-open . 0)
))
)
(inline-open . 0))))
("linux"
(c-basic-offset . 8)
(c-comment-only-line-offset . 0)
@ -167,9 +180,8 @@
(substatement-open . 0)
(substatement-label . 0)
(label . 0)
(statement-cont . +)
))
)
(statement-cont . +))))
("python"
(indent-tabs-mode . t)
(fill-column . 78)
@ -177,17 +189,15 @@
(c-offsets-alist . ((substatement-open . 0)
(inextern-lang . 0)
(arglist-intro . +)
(knr-argdecl-intro . +)
))
(knr-argdecl-intro . +)))
(c-hanging-braces-alist . ((brace-list-open)
(brace-list-intro)
(brace-list-close)
(brace-entry-open)
(substatement-open after)
(block-close . c-snug-do-while)
))
(c-block-comment-prefix . "")
)
(block-close . c-snug-do-while)))
(c-block-comment-prefix . ""))
("java"
(c-basic-offset . 4)
(c-comment-only-line-offset . (0 . 0))
@ -205,9 +215,23 @@
(arglist-close . c-lineup-arglist)
(access-label . 0)
(inher-cont . c-lineup-java-inher)
(func-decl-cont . c-lineup-java-throws)
))
)
(func-decl-cont . c-lineup-java-throws))))
;; awk style exists primarily for auto-newline settings. Otherwise it's
;; pretty much like k&r.
("awk"
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((defun-open after)
(defun-close . c-snug-1line-defun-close)
(substatement-open after)
(block-close . c-snug-do-while)))
(c-hanging-semi&comma-criteria . nil)
(c-cleanup-list . nil) ; You might want one-liner-defun here.
(c-offsets-alist . ((statement-block-intro . +)
(substatement-open . 0)
(statement-cont . +))))
)
"Styles of indentation.
Elements of this alist are of the form:
@ -246,8 +270,6 @@ the existing style.")
;; Functions that manipulate styles
(defun c-set-style-1 (conscell dont-override)
;; Set the style for one variable
;;
;; This function does not do any hidden buffer changes.
(let ((attr (car conscell))
(val (cdr conscell)))
(cond
@ -291,8 +313,6 @@ the existing style.")
(defun c-get-style-variables (style basestyles)
;; Return all variables in a style by resolving inheritances.
;;
;; This function does not do any hidden buffer changes.
(if (not style)
(copy-alist c-fallback-style)
(let ((vars (cdr (or (assoc (downcase style) c-style-alist)
@ -314,48 +334,36 @@ the existing style.")
;;;###autoload
(defun c-set-style (stylename &optional dont-override)
"Set CC Mode variables to use one of several different indentation styles.
STYLENAME is a string representing the desired style from the list of
styles described in the variable `c-style-alist'. See that variable
for details of setting up styles.
"Set the current buffer to use the style STYLENAME.
STYLENAME, a string, must be an existing CC Mode style - These are contained
in the variable `c-style-alist'.
The variable `c-indentation-style' always contains the buffer's current
style name.
The variable `c-indentation-style' will get set to STYLENAME.
If the optional argument DONT-OVERRIDE is t, no style variables that
already have values will be overridden. I.e. in the case of
`c-offsets-alist', syntactic symbols will only be added, and in the
case of all other style variables, only those set to `set-from-style'
will be reassigned.
\"Setting the style\" is done by setting CC Mode's \"style variables\" to the
values indicated by the pertinent entry in `c-style-alist'. Other variables
might get set too.
If DONT-OVERRIDE is neither nil nor t, only those style variables that
have default (i.e. non-buffer local) values will keep their settings
while the rest will be overridden. This is useful to avoid overriding
global settings done in ~/.emacs when setting a style from a mode hook
\(providing the style variables are buffer local, which is the
default).
If DONT-OVERRIDE is neither nil nor t, style variables whose default values
have been set (more precisely, whose default values are not the symbol
`set-from-style') will not be changed. This avoids overriding global settings
done in ~/.emacs. It is useful to call c-set-style from a mode hook in this
way.
Obviously, setting DONT-OVERRIDE to t is useful mainly when the
initial style is chosen for a CC Mode buffer by a major mode. Since
that is done internally by CC Mode, it typically won't have any effect
when used elsewhere."
If DONT-OVERRIDE is t, style variables that already have values (i.e., whose
values are not the symbol `set-from-style') will not be overridden. CC Mode
calls c-set-style internally in this way whilst initializing a buffer; if
cc-set-style is called like this from anywhere else, it will usually behave as
a null operation."
(interactive
(list (let ((completion-ignore-case t)
(prompt (format "Which %s indentation style? "
mode-name)))
(condition-case nil
;; The default argument is preferred over
;; initial-contents, but it only exists in Emacs >= 20
;; and XEmacs >= 21.
(completing-read prompt c-style-alist nil t nil
'c-set-style-history
c-indentation-style)
(wrong-number-of-arguments
;; If the call above failed, we fall back to the old way
;; of specifying the default value.
(completing-read prompt c-style-alist nil t
(cons c-indentation-style 0)
'c-set-style-history))))))
(completing-read prompt c-style-alist nil t nil
'c-set-style-history
c-indentation-style))))
(or c-buffer-is-cc-mode
(error "Buffer %s is not a CC Mode buffer (c-set-style)" (buffer-name)))
(or (stringp stylename)
(error "Argument to c-set-style was not a string"))
(c-initialize-builtin-style)
@ -406,8 +414,6 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
(defun c-read-offset (langelem)
;; read new offset value for LANGELEM from minibuffer. return a
;; legal value only
;;
;; This function does not do any hidden buffer changes.
(let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist)
(assq langelem (get 'c-offsets-alist
'c-stylevar-fallback)))))
@ -475,20 +481,22 @@ and exists only for compatibility reasons."
(setq c-offsets-alist (cons (cons symbol offset)
c-offsets-alist))
(c-benign-error "%s is not a valid syntactic symbol" symbol))))
(c-benign-error "Invalid indentation setting for symbol %s: %s"
(c-benign-error "Invalid indentation setting for symbol %s: %S"
symbol offset))
(c-keep-region-active))
(defun c-setup-paragraph-variables ()
"Fix things up for paragraph recognition and filling inside comments by
incorporating the value of `c-comment-prefix-regexp' in the relevant
"Fix things up for paragraph recognition and filling inside comments and
strings by incorporating the values of `c-comment-prefix-regexp',
`sentence-end', `paragraph-start' and `paragraph-separate' in the relevant
variables."
;;
;; This function does not do any hidden buffer changes.
(interactive)
(or c-buffer-is-cc-mode
(error "Buffer %s is not a CC Mode buffer (c-setup-paragraph-variables)"
(buffer-name)))
;; Set up the values for use in comments.
(setq c-current-comment-prefix
(if (listp c-comment-prefix-regexp)
(cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
@ -498,34 +506,48 @@ variables."
(let ((comment-line-prefix
(concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*")))
(set (make-local-variable 'paragraph-start)
(concat comment-line-prefix
c-paragraph-start
"\\|"
page-delimiter))
(set (make-local-variable 'paragraph-separate)
(concat comment-line-prefix
c-paragraph-separate
"\\|"
page-delimiter))
(set (make-local-variable 'paragraph-ignore-fill-prefix) t)
(set (make-local-variable 'adaptive-fill-mode) t)
(set (make-local-variable 'adaptive-fill-regexp)
(concat comment-line-prefix
(if (default-value 'adaptive-fill-regexp)
(concat "\\("
(default-value 'adaptive-fill-regexp)
"\\)")
"")))
(setq paragraph-start (concat comment-line-prefix
c-paragraph-start
"\\|"
page-delimiter)
paragraph-separate (concat comment-line-prefix
c-paragraph-separate
"\\|"
page-delimiter)
paragraph-ignore-fill-prefix t
adaptive-fill-mode t
adaptive-fill-regexp
(concat comment-line-prefix
(if (default-value 'adaptive-fill-regexp)
(concat "\\("
(default-value 'adaptive-fill-regexp)
"\\)")
"")))
(when (boundp 'adaptive-fill-first-line-regexp)
;; XEmacs (20.x) adaptive fill mode doesn't have this.
(set (make-local-variable 'adaptive-fill-first-line-regexp)
(concat "\\`" comment-line-prefix
;; Maybe we should incorporate the old value here,
;; but then we have to do all sorts of kludges to
;; deal with the \` and \' it probably contains.
"\\'")))))
;; XEmacs adaptive fill mode doesn't have this.
(make-local-variable 'adaptive-fill-first-line-regexp)
(setq adaptive-fill-first-line-regexp
(concat "\\`" comment-line-prefix
;; Maybe we should incorporate the old value here,
;; but then we have to do all sorts of kludges to
;; deal with the \` and \' it probably contains.
"\\'"))))
;; Set up the values for use in strings. These are the default
;; paragraph-start/separate values, enhanced to accept escaped EOLs as
;; whitespace. Used in c-beginning/end-of-sentence-in-string in cc-cmds.
(setq c-string-par-start
;;(concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$"))
"\f\\|[ \t]*\\\\?$")
(setq c-string-par-separate
;;(concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$"))
"[ \t\f]*\\\\?$")
(setq c-sentence-end-with-esc-eol
(concat "\\(\\(" (c-default-value-sentence-end) "\\)"
;; N.B.: "$" would be illegal when not enclosed like "\\($\\)".
"\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
"\\)")))
;; Helper for setting up Filladapt mode. It's not used by CC Mode itself.
@ -542,8 +564,6 @@ CC Mode by making sure the proper entries are present on
`c-mode-common-hook' or similar."
;; This function is intended to be used explicitly by the end user
;; only.
;;
;; This function does not do any hidden buffer changes.
;; The default configuration already handles C++ comments, but we
;; need to add handling of C block comments. A new filladapt token
@ -573,8 +593,6 @@ CC Mode by making sure the proper entries are present on
;; crucial because future c-set-style calls will always reset the
;; variables first to the `cc-mode' style before instituting the new
;; style. Only do this once!
;;
;; This function does not do any hidden buffer changes.
(unless (get 'c-initialize-builtin-style 'is-run)
(put 'c-initialize-builtin-style 'is-run t)
;;(c-initialize-cc-mode)
@ -601,13 +619,11 @@ CC Mode by making sure the proper entries are present on
"Make all CC Mode style variables buffer local.
If `this-buf-only-p' is non-nil, the style variables will be made
buffer local only in the current buffer. Otherwise they'll be made
permanently buffer local in any buffer that change their values.
permanently buffer local in any buffer that changes their values.
The buffer localness of the style variables are normally controlled
with the variable `c-style-variables-are-local-p', so there's seldom
any reason to call this function directly."
;;
;; This function does not do any hidden buffer changes.
;; style variables
(let ((func (if this-buf-only-p
@ -619,7 +635,7 @@ any reason to call this function directly."
;; Hooks must be handled specially
(if this-buf-only-p
(make-local-hook 'c-special-indent-hook)
(make-variable-buffer-local 'c-special-indent-hook)
(with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
(setq c-style-variables-are-local-p t))
))
@ -627,5 +643,5 @@ any reason to call this function directly."
(cc-provide 'cc-styles)
;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c
;;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c
;;; cc-styles.el ends here

View file

@ -0,0 +1,312 @@
;;; cc-subword.el --- Handling capitalized subwords in a nomenclature
;; Copyright (C) 2004, 2005 Free Software Foundation, Inc.
;; Author: Masatake YAMATO
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2, or (at your option)
;; any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
;;; Commentary:
;; This package provides `subword' oriented commands and a minor mode
;; (`c-subword-mode') that substitutes the common word handling
;; functions with them.
;; In spite of GNU Coding Standards, it is popular to name a symbol by
;; mixing uppercase and lowercase letters, e.g. "GtkWidget",
;; "EmacsFrameClass", "NSGraphicsContext", etc. Here we call these
;; mixed case symbols `nomenclatures'. Also, each capitalized (or
;; completely uppercase) part of a nomenclature is called a `subword'.
;; Here are some examples:
;; Nomenclature Subwords
;; ===========================================================
;; GtkWindow => "Gtk" and "Window"
;; EmacsFrameClass => "Emacs", "Frame" and "Class"
;; NSGraphicsContext => "NS", "Graphics" and "Context"
;; The subword oriented commands defined in this package recognize
;; subwords in a nomenclature to move between them and to edit them as
;; words.
;; In the minor mode, all common key bindings for word oriented
;; commands are overridden by the subword oriented commands:
;; Key Word oriented command Subword oriented command
;; ============================================================
;; M-f `forward-word' `c-forward-subword'
;; M-b `backward-word' `c-backward-subword'
;; M-@ `mark-word' `c-mark-subword'
;; M-d `kill-word' `c-kill-subword'
;; M-DEL `backward-kill-word' `c-backward-kill-subword'
;; M-t `transpose-words' `c-transpose-subwords'
;; M-c `capitalize-word' `c-capitalize-subword'
;; M-u `upcase-word' `c-upcase-subword'
;; M-l `downcase-word' `c-downcase-subword'
;;
;; Note: If you have changed the key bindings for the word oriented
;; commands in your .emacs or a similar place, the keys you've changed
;; to are also used for the corresponding subword oriented commands.
;; To make the mode turn on automatically, put the following code in
;; your .emacs:
;;
;; (add-hook 'c-mode-common-hook
;; (lambda () (c-subword-mode 1)))
;;
;; Acknowledgment:
;; The regular expressions to detect subwords are mostly based on
;; the old `c-forward-into-nomenclature' originally contributed by
;; Terry_Glanfield dot Southern at rxuk dot xerox dot com.
;; TODO: ispell-word and subword oriented C-w in isearch.
;;; Code:
(eval-when-compile
(let ((load-path
(if (and (boundp 'byte-compile-dest-file)
(stringp byte-compile-dest-file))
(cons (file-name-directory byte-compile-dest-file) load-path)
load-path)))
(load "cc-bytecomp" nil t)))
(cc-require 'cc-defs)
(cc-require 'cc-cmds)
;; Don't complain about the `define-minor-mode' form if it isn't defined.
(cc-bytecomp-defvar c-subword-mode)
;;; Autoload directives must be on the top level, so we construct an
;;; autoload form instead.
;;;###autoload (autoload 'c-subword-mode "cc-subword" "Mode enabling subword movement and editing keys." t)
(if (not (fboundp 'define-minor-mode))
(defun c-subword-mode ()
"(Missing) mode enabling subword movement and editing keys.
This mode is not (yet) available in this version of (X)Emacs. Sorry! If
you really want it, please send a request to <bug-gnu-emacs@gnu.org>,
telling us which (X)Emacs version you're using."
(interactive)
(error
"c-subword-mode is not (yet) available in this version of (X)Emacs. Sorry!"))
(defvar c-subword-mode-map
(let ((map (make-sparse-keymap)))
(substitute-key-definition 'forward-word
'c-forward-subword
map global-map)
(substitute-key-definition 'backward-word
'c-backward-subword
map global-map)
(substitute-key-definition 'mark-word
'c-mark-subword
map global-map)
(substitute-key-definition 'kill-word
'c-kill-subword
map global-map)
(substitute-key-definition 'backward-kill-word
'c-backward-kill-subword
map global-map)
(substitute-key-definition 'transpose-words
'c-transpose-subwords
map global-map)
(substitute-key-definition 'capitalize-word
'c-capitalize-subword
map global-map)
(substitute-key-definition 'upcase-word
'c-upcase-subword
map global-map)
(substitute-key-definition 'downcase-word
'c-downcase-subword
map global-map)
map)
"Keymap used in command `c-subword-mode' minor mode.")
(define-minor-mode c-subword-mode
"Mode enabling subword movement and editing keys.
In spite of GNU Coding Standards, it is popular to name a symbol by
mixing uppercase and lowercase letters, e.g. \"GtkWidget\",
\"EmacsFrameClass\", \"NSGraphicsContext\", etc. Here we call these
mixed case symbols `nomenclatures'. Also, each capitalized (or
completely uppercase) part of a nomenclature is called a `subword'.
Here are some examples:
Nomenclature Subwords
===========================================================
GtkWindow => \"Gtk\" and \"Window\"
EmacsFrameClass => \"Emacs\", \"Frame\" and \"Class\"
NSGraphicsContext => \"NS\", \"Graphics\" and \"Context\"
The subword oriented commands activated in this minor mode recognize
subwords in a nomenclature to move between subwords and to edit them
as words.
\\{c-subword-mode-map}"
nil
nil
c-subword-mode-map
(c-update-modeline))
)
(defun c-forward-subword (&optional arg)
"Do the same as `forward-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `forward-word'."
(interactive "p")
(unless arg (setq arg 1))
(c-keep-region-active)
(cond
((< 0 arg)
(dotimes (i arg (point))
(c-forward-subword-internal)))
((> 0 arg)
(dotimes (i (- arg) (point))
(c-backward-subword-internal)))
(t
(point))))
(defun c-backward-subword (&optional arg)
"Do the same as `backward-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `backward-word'."
(interactive "p")
(c-forward-subword (- (or arg 1))))
(defun c-mark-subword (arg)
"Do the same as `mark-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `mark-word'."
;; This code is almost copied from `mark-word' in GNU Emacs.
(interactive "p")
(cond ((and (eq last-command this-command) (mark t))
(set-mark
(save-excursion
(goto-char (mark))
(c-forward-subword arg)
(point))))
(t
(push-mark
(save-excursion
(c-forward-subword arg)
(point))
nil t))))
(defun c-kill-subword (arg)
"Do the same as `kill-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `kill-word'."
(interactive "p")
(kill-region (point) (c-forward-subword arg)))
(defun c-backward-kill-subword (arg)
"Do the same as `backward-kill-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `backward-kill-word'."
(interactive "p")
(c-kill-subword (- arg)))
(defun c-transpose-subwords (arg)
"Do the same as `transpose-words' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `transpose-words'."
(interactive "*p")
(transpose-subr 'c-forward-subword arg))
(defun c-capitalize-subword (arg)
"Do the same as `capitalize-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `capitalize-word'."
(interactive "p")
(let ((count (abs arg))
(direction (if (< 0 arg) 1 -1)))
(dotimes (i count)
(when (re-search-forward
(concat "[" c-alpha "]")
nil t)
(goto-char (match-beginning 0)))
(let* ((p (point))
(pp (1+ p))
(np (c-forward-subword direction)))
(upcase-region p pp)
(downcase-region pp np)
(goto-char np)))))
(defun c-downcase-subword (arg)
"Do the same as `downcase-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `downcase-word'."
(interactive "p")
(downcase-region (point) (c-forward-subword arg)))
(defun c-upcase-subword (arg)
"Do the same as `upcase-word' but on subwords.
See the command `c-subword-mode' for a description of subwords.
Optional argument ARG is the same as for `upcase-word'."
(interactive "p")
(upcase-region (point) (c-forward-subword arg)))
;;
;; Internal functions
;;
(defun c-forward-subword-internal ()
(if (and
(save-excursion
(let ((case-fold-search nil))
(re-search-forward
(concat "\\W*\\(\\([" c-upper "]*\\W?\\)[" c-lower c-digit "]*\\)")
nil t)))
(> (match-end 0) (point))) ; So we don't get stuck at a
; "word-constituent" which isn't c-upper,
; c-lower or c-digit
(goto-char
(cond
((< 1 (- (match-end 2) (match-beginning 2)))
(1- (match-end 2)))
(t
(match-end 0))))
(forward-word 1)))
(defun c-backward-subword-internal ()
(if (save-excursion
(let ((case-fold-search nil))
(re-search-backward
(concat
"\\(\\(\\W\\|[" c-lower c-digit "]\\)\\([" c-upper "]+\\W*\\)"
"\\|\\W\\w+\\)")
nil t)))
(goto-char
(cond
((and (match-end 3)
(< 1 (- (match-end 3) (match-beginning 3)))
(not (eq (point) (match-end 3))))
(1- (match-end 3)))
(t
(1+ (match-beginning 0)))))
(backward-word 1)))
(cc-provide 'cc-subword)
;;; arch-tag: 2be9d294-7f30-4626-95e6-9964bb93c7a3
;;; cc-subword.el ends here

View file

@ -1,6 +1,7 @@
;;; cc-vars.el --- user customization variables for CC Mode
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software Foundation, Inc.
;; Copyright (C) 1985,1987,1992-2003, 2004, 2005 Free Software
;; Foundation, Inc.
;; Authors: 1998- Martin Stjernholm
;; 1992-1999 Barry A. Warsaw
@ -24,7 +25,7 @@
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to
;; along with this program; see the file COPYING. If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
;; Boston, MA 02110-1301, USA.
@ -43,33 +44,11 @@
(cc-require 'cc-defs)
;; Silence the compiler.
(cc-bytecomp-defun get-char-table) ; XEmacs 20+
(cc-bytecomp-defun char-table-range) ; Emacs 19+
(cc-bytecomp-defun char-table-p) ; Emacs 19+, XEmacs 20+
(cc-bytecomp-defun get-char-table) ; XEmacs
;; Pull in custom if it exists and is recent enough (the one in Emacs
;; 19.34 isn't).
(eval
(cc-eval-when-compile
(condition-case nil
(progn
(require 'custom)
(or (fboundp 'defcustom) (error ""))
(require 'widget)
'(progn ; Compile in the require's.
(require 'custom)
(require 'widget)))
(error
(message "Warning: Compiling without Customize support \
since a (good enough) custom library wasn't found")
(cc-bytecomp-defmacro define-widget (name class doc &rest args))
(cc-bytecomp-defmacro defgroup (symbol members doc &rest args))
(cc-bytecomp-defmacro defcustom (symbol value doc &rest args)
`(defvar ,symbol ,value ,doc))
(cc-bytecomp-defmacro custom-declare-variable (symbol value doc
&rest args)
`(defvar ,(eval symbol) ,(eval value) ,doc))
nil))))
(cc-eval-when-compile
(require 'custom)
(require 'widget))
(cc-eval-when-compile
;; Need the function form of `backquote', which isn't standardized
@ -207,7 +186,6 @@ the value set here overrides the style system (there is a variable
(defun c-valid-offset (offset)
"Return non-nil iff OFFSET is a valid offset for a syntactic symbol.
See `c-offsets-alist'."
;; This function does not do any hidden buffer changes.
(or (eq offset '+)
(eq offset '-)
(eq offset '++)
@ -216,17 +194,19 @@ See `c-offsets-alist'."
(eq offset '/)
(integerp offset)
(functionp offset)
(and (symbolp offset)
(or (boundp offset)
(fboundp offset)))
(and (symbolp offset) (boundp offset))
(and (vectorp offset)
(= (length offset) 1)
(integerp (elt offset 0)))
(progn
(while (and (consp offset)
(c-valid-offset (car offset)))
(setq offset (cdr offset)))
(null offset))))
(and (consp offset)
(not (eq (car offset) 'quote)) ; Detect misquoted lists.
(progn
(when (memq (car offset) '(first min max add))
(setq offset (cdr offset)))
(while (and (consp offset)
(c-valid-offset (car offset)))
(setq offset (cdr offset)))
(null offset)))))
@ -311,6 +291,7 @@ effect in this mode, nor any of the indentation associated variables,
e.g. `c-special-indent-hook'."
:type 'boolean
:group 'c)
(make-variable-buffer-local 'c-syntactic-indentation)
(defcustom c-syntactic-indentation-in-macros t
"*Enable syntactic analysis inside macros.
@ -470,6 +451,7 @@ style comments."
(defcustom-c-stylevar c-comment-prefix-regexp
'((pike-mode . "//+!?\\|\\**")
(awk-mode . "#+")
(other . "//+\\|\\**"))
"*Regexp to match the line prefix inside comments.
This regexp is used to recognize the fill prefix inside comments for
@ -517,14 +499,17 @@ variable in a mode hook."
(cons :format "%v"
(const :format "IDL " idl-mode) (regexp :format "%v"))
(cons :format "%v"
(const :format "Pike " pike-mode) (regexp :format "%v")))
(const :format "Pike " pike-mode) (regexp :format "%v"))
(cons :format "%v"
(const :format "AWK " awk-mode) (regexp :format "%v")))
(cons :format " %v"
(const :format "Other " other) (regexp :format "%v"))))
:group 'c)
(defcustom-c-stylevar c-doc-comment-style
'((java-mode . javadoc)
(pike-mode . autodoc))
(pike-mode . autodoc)
(c-mode . gtkdoc))
"*Specifies documentation comment style(s) to recognize.
This is primarily used to fontify doc comments and the markup within
them, e.g. Javadoc comments.
@ -534,6 +519,7 @@ comment styles:
javadoc -- Javadoc style for \"/** ... */\" comments (default in Java mode).
autodoc -- Pike autodoc style for \"//! ...\" comments (default in Pike mode).
gtkdoc -- GtkDoc style for \"/** ... **/\" comments (default in C mode).
The value may also be a list of doc comment styles, in which case all
of them are recognized simultaneously (presumably with markup cues
@ -585,6 +571,9 @@ afterwards to redo that work."
(cons :format "%v"
(const :format "Pike " pike-mode)
(c-symbol-list :format "%v"))
(cons :format "%v"
(const :format "AWK " awk-mode)
(c-symbol-list :format "%v"))
(cons :format "%v"
(const :format "Other " other)
(c-symbol-list :format "%v")))))
@ -613,8 +602,8 @@ contexts are:
(defcustom-c-stylevar c-cleanup-list '(scope-operator)
"*List of various C/C++/ObjC constructs to \"clean up\".
The following clean ups only take place when the auto-newline feature
is turned on, as evidenced by the `/a' or `/ah' appearing next to the
mode name:
is turned on, as evidenced by the `/la' appearing next to the mode
name:
brace-else-brace -- Clean up \"} else {\" constructs by placing
entire construct on a single line. This clean
@ -630,21 +619,28 @@ mode name:
\"} catch (...) {\" constructs.
empty-defun-braces -- Clean up empty defun braces by placing the
braces on the same line. Clean up occurs when
the defun closing brace is typed.
the defun closing brace is typed.
one-liner-defun -- If the code inside a function body is a single
line then remove any newlines between that
line and the defun braces so that the whole
body becomes a single line.
`c-max-one-liner-length' gives the maximum
length allowed for the resulting line. Clean
up occurs when the closing brace is typed.
defun-close-semi -- Clean up the terminating semi-colon on defuns
by placing the semi-colon on the same line as
the closing brace. Clean up occurs when the
semi-colon is typed.
by placing the semi-colon on the same line as
the closing brace. Clean up occurs when the
semi-colon is typed.
list-close-comma -- Clean up commas following braces in array
and aggregate initializers. Clean up occurs
when the comma is typed.
when the comma is typed.
scope-operator -- Clean up double colons which may designate
a C++ scope operator split across multiple
lines. Note that certain C++ constructs can
generate ambiguous situations. This clean up
only takes place when there is nothing but
whitespace between colons. Clean up occurs
when the second colon is typed.
a C++ scope operator split across multiple
lines. Note that certain C++ constructs can
generate ambiguous situations. This clean up
only takes place when there is nothing but
whitespace between colons. Clean up occurs
when the second colon is typed.
The following clean ups always take place when they are on this list,
regardless of the auto-newline feature, since they typically don't
@ -654,31 +650,39 @@ involve auto-newline inserted newlines:
parenthesis of a function call. Clean up
occurs when the opening parenthesis is typed.
compact-empty-funcall -- Clean up any space before the function call
opening parenthesis if and only if the
opening parenthesis if and only if the
argument list is empty. This is typically
useful together with `space-before-funcall' to
get the style \"foo (bar)\" and \"foo()\".
Clean up occurs when the closing parenthesis
is typed."
is typed.
comment-close-slash -- When a slash is typed after the comment prefix
on a bare line in a c-style comment, the comment
is closed by cleaning up preceding space and
inserting a star if needed."
:type '(set
(const :tag "Put \"} else {\" on one line"
(const :tag "Put \"} else {\" on one line (brace-else-brace)"
brace-else-brace)
(const :tag "Put \"} else if (...) {\" on one line"
(const :tag "Put \"} else if (...) {\" on one line (brace-elseif-brace)"
brace-elseif-brace)
(const :tag "Put \"} catch (...) {\" on one line"
(const :tag "Put \"} catch (...) {\" on one line (brace-catch-brace)"
brace-catch-brace)
(const :tag "Put empty defun braces on one line"
(const :tag "Put empty defun braces on one line (empty-defun-braces)"
empty-defun-braces)
(const :tag "Put \"};\" ending defuns on one line"
(const :tag "Put short function bodies on one line (one-liner-defun)"
one-liner-defun)
(const :tag "Put \"};\" ending defuns on one line (defun-close-semi)"
defun-close-semi)
(const :tag "Put \"},\" in aggregates on one line"
(const :tag "Put \"},\" in aggregates on one line (list-close-comma)"
list-close-comma)
(const :tag "Put C++ style \"::\" on one line"
(const :tag "Put C++ style \"::\" on one line (scope-operator)"
scope-operator)
(const :tag "Put a space before funcall parens, e.g. \"foo (bar)\""
(const :tag "Put a space before funcall parens, e.g. \"foo (bar)\" (space-before-funcall)"
space-before-funcall)
(const :tag "Remove space before empty funcalls, e.g. \"foo()\""
compact-empty-funcall))
(const :tag "Remove space before empty funcalls, e.g. \"foo()\" (compact-empty-funcall)"
compact-empty-funcall)
(const :tag "Make / on a bare line of a C-style comment close it (comment-close-slash)"
comment-close-slash))
:group 'c)
(defcustom-c-stylevar c-hanging-braces-alist '((brace-list-open)
@ -751,6 +755,12 @@ syntactic context for the brace line."
inexpr-class-open inexpr-class-close)))
:group 'c)
(defcustom c-max-one-liner-length 80
"Maximum length of line that clean-up \"one-liner-defun\" will compact to.
Zero or nil means no limit."
:type 'integer
:group 'c)
(defcustom-c-stylevar c-hanging-colons-alist nil
"*Controls the insertion of newlines before and after certain colons.
This variable contains an association list with elements of the
@ -832,35 +842,40 @@ space."
:group 'c)
(defcustom c-require-final-newline
;; C and C++ mandates that all nonempty files should end with a
;; C and C++ mandate that all nonempty files should end with a
;; newline. Objective-C refers to C for all things it doesn't
;; specify, so the same holds there. The other languages does not
;; specify, so the same holds there. The other languages do not
;; require it (at least not explicitly in a normative text).
'((c-mode . t)
(c++-mode . t)
(objc-mode . t))
"*Controls `require-final-newline' in C-related major modes.
The value is an association list specifying, for each specific mode,
whether to override `require-final-newline'. If the cdr of the element
is non-nil, that means to use `mode-require-final-newline' instead."
"*Controls whether a final newline is ensured when the file is saved.
The value is an association list that for each language mode specifies
the value to give to `require-final-newline' at mode initialization;
see that variable for details about the value. If a language isn't
present on the association list, CC Mode won't touch
`require-final-newline' in buffers for that language."
:type `(set (cons :format "%v"
(const :format "C " c-mode)
(const t))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "C++ " c++-mode)
(const t))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "ObjC " objc-mode)
(const t))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "Java " java-mode)
(const t))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "IDL " idl-mode)
(const t))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "Pike " pike-mode)
(const t)))
(symbol :format "%v" :value ,require-final-newline))
(cons :format "%v"
(const :format "AWK " awk-mode)
(symbol :format "%v" :value ,require-final-newline)))
:group 'c)
(defcustom c-electric-pound-behavior nil
@ -892,7 +907,8 @@ this variable to nil."
:type 'integer
:group 'c)
(defcustom c-default-style '((java-mode . "java") (other . "gnu"))
(defcustom c-default-style '((java-mode . "java") (awk-mode . "awk")
(other . "gnu"))
"*Style which gets installed by default when a file is visited.
The value of this variable can be any style defined in
@ -926,6 +942,8 @@ can always override the use of `c-default-style' by making calls to
(const :format "IDL " idl-mode) (string :format "%v"))
(cons :format "%v"
(const :format "Pike " pike-mode) (string :format "%v"))
(cons :format "%v"
(const :format "AWK " awk-mode) (string :format "%v"))
(cons :format "%v"
(const :format "Other " other) (string :format "%v"))))
:group 'c)
@ -939,170 +957,170 @@ can always override the use of `c-default-style' by making calls to
;; symbol and continue searching.
(c-set-stylevar-fallback 'c-offsets-alist
'((string . c-lineup-dont-change)
;; Relpos: Beg of previous line.
;; Anchor pos: Beg of previous line.
(c . c-lineup-C-comments)
;; Relpos: Beg of the comment.
;; Anchor pos: Beg of the comment.
(defun-open . 0)
;; Relpos: When inside a class: Boi at the func decl start.
;; Anchor pos: When inside a class: Boi at the func decl start.
;; When at top level: Bol at the func decl start. When inside
;; a code block (only possible in Pike): At the func decl
;; start(*).
(defun-close . 0)
;; Relpos: At the defun block open if it's at boi, otherwise
;; boi at the func decl start.
;; Anchor pos: At the defun block open if it's at boi,
;; otherwise boi at the func decl start.
(defun-block-intro . +)
;; Relpos: At the block open(*).
;; Anchor pos: At the block open(*).
(class-open . 0)
;; Relpos: Boi at the class decl start.
;; Anchor pos: Boi at the class decl start.
(class-close . 0)
;; Relpos: Boi at the class decl start.
;; Anchor pos: Boi at the class decl start.
(inline-open . +)
;; Relpos: None for functions (inclass got the relpos then),
;; boi at the lambda start for lambdas.
;; Anchor pos: None for functions (inclass got the relpos
;; then), boi at the lambda start for lambdas.
(inline-close . 0)
;; Relpos: Inexpr functions: At the lambda block open if it's
;; at boi, else at the statement(*) at boi of the start of the
;; lambda construct. Otherwise: At the inline block open if
;; it's at boi, otherwise boi at the func decl start.
;; Anchor pos: Inexpr functions: At the lambda block open if
;; it's at boi, else at the statement(*) at boi of the start of
;; the lambda construct. Otherwise: At the inline block open
;; if it's at boi, otherwise boi at the func decl start.
(func-decl-cont . +)
;; Relpos: Boi at the func decl start.
;; Anchor pos: Boi at the func decl start.
(knr-argdecl-intro . +)
;; Relpos: Boi at the topmost intro line.
;; Anchor pos: Boi at the topmost intro line.
(knr-argdecl . 0)
;; Relpos: At the beginning of the first K&R argdecl.
;; Anchor pos: At the beginning of the first K&R argdecl.
(topmost-intro . 0)
;; Relpos: Bol at the last line of previous construct.
;; Anchor pos: Bol at the last line of previous construct.
(topmost-intro-cont . c-lineup-topmost-intro-cont)
;; Relpos: Boi at the topmost intro line.
;; Anchor pos: Boi at the topmost intro line.
(member-init-intro . +)
;; Relpos: Boi at the func decl arglist open.
;; Anchor pos: Boi at the func decl arglist open.
(member-init-cont . c-lineup-multi-inher)
;; Relpos: Beg of the first member init.
;; Anchor pos: Beg of the first member init.
(inher-intro . +)
;; Relpos: Boi at the class decl start.
;; Anchor pos: Boi at the class decl start.
(inher-cont . c-lineup-multi-inher)
;; Relpos: Java: At the implements/extends keyword start.
;; Anchor pos: Java: At the implements/extends keyword start.
;; Otherwise: At the inher start colon, or boi at the class
;; decl start if the first inherit clause hangs and it's not a
;; func-local inherit clause (when does that occur?).
(block-open . 0)
;; Relpos: Inexpr statement: At the statement(*) at boi of the
;; start of the inexpr construct. Otherwise: None.
;; Anchor pos: Inexpr statement: At the statement(*) at boi of
;; the start of the inexpr construct. Otherwise: None.
(block-close . 0)
;; Relpos: Inexpr statement: At the inexpr block open if it's
;; at boi, else at the statement(*) at boi of the start of the
;; inexpr construct. Block hanging on a case/default label: At
;; the closest preceding label that starts at boi. Otherwise:
;; At the block open(*).
;; Anchor pos: Inexpr statement: At the inexpr block open if
;; it's at boi, else at the statement(*) at boi of the start of
;; the inexpr construct. Block hanging on a case/default
;; label: At the closest preceding label that starts at boi.
;; Otherwise: At the block open(*).
(brace-list-open . 0)
;; Relpos: Boi at the brace list decl start, but a starting
;; Anchor pos: Boi at the brace list decl start, but a starting
;; "typedef" token is ignored.
(brace-list-close . 0)
;; Relpos: At the brace list decl start(*).
;; Anchor pos: At the brace list decl start(*).
(brace-list-intro . +)
;; Relpos: At the brace list decl start(*).
;; Anchor pos: At the brace list decl start(*).
(brace-list-entry . 0)
;; Relpos: At the first non-ws char after the open paren if the
;; first token is on the same line, otherwise boi at that
;; Anchor pos: At the first non-ws char after the open paren if
;; the first token is on the same line, otherwise boi at that
;; token.
(brace-entry-open . 0)
;; Relpos: Same as brace-list-entry.
;; Anchor pos: Same as brace-list-entry.
(statement . 0)
;; Relpos: After a `;' in the condition clause of a for
;; Anchor pos: After a `;' in the condition clause of a for
;; statement: At the first token after the starting paren.
;; Otherwise: At the preceding statement(*).
(statement-cont . +)
;; Relpos: After the first token in the condition clause of a
;; for statement: At the first token after the starting paren.
;; Otherwise: At the containing statement(*).
;; Anchor pos: After the first token in the condition clause of
;; a for statement: At the first token after the starting
;; paren. Otherwise: At the containing statement(*).
(statement-block-intro . +)
;; Relpos: In inexpr statement block: At the inexpr block open
;; if it's at boi, else at the statement(*) at boi of the start
;; of the inexpr construct. In a block hanging on a
;; Anchor pos: In inexpr statement block: At the inexpr block
;; open if it's at boi, else at the statement(*) at boi of the
;; start of the inexpr construct. In a block hanging on a
;; case/default label: At the closest preceding label that
;; starts at boi. Otherwise: At the start of the containing
;; block(*).
(statement-case-intro . +)
;; Relpos: At the case/default label(*).
;; Anchor pos: At the case/default label(*).
(statement-case-open . 0)
;; Relpos: At the case/default label(*).
;; Anchor pos: At the case/default label(*).
(substatement . +)
;; Relpos: At the containing statement(*).
;; Anchor pos: At the containing statement(*).
(substatement-open . +)
;; Relpos: At the containing statement(*).
;; Anchor pos: At the containing statement(*).
(substatement-label . 2)
;; Relpos: At the containing statement(*).
;; Anchor pos: At the containing statement(*).
(case-label . 0)
;; Relpos: At the start of the switch block(*).
;; Anchor pos: At the start of the switch block(*).
(access-label . -)
;; Relpos: Same as inclass.
;; Anchor pos: Same as inclass.
(label . 2)
;; Relpos: At the start of the containing block(*).
;; Anchor pos: At the start of the containing block(*).
(do-while-closure . 0)
;; Relpos: At the corresponding while statement(*).
;; Anchor pos: At the corresponding while statement(*).
(else-clause . 0)
;; Relpos: At the corresponding if statement(*).
;; Anchor pos: At the corresponding if statement(*).
(catch-clause . 0)
;; Relpos: At the previous try or catch statement clause(*).
;; Anchor pos: At the previous try or catch statement clause(*).
(comment-intro . (c-lineup-knr-region-comment c-lineup-comment))
;; Relpos: None.
;; Anchor pos: None.
(arglist-intro . +)
;; Relpos: Boi at the open paren, or at the first non-ws after
;; the open paren of the surrounding sexp, whichever is later.
;; Anchor pos: At the containing statement(*).
;; 2nd pos: At the open paren.
(arglist-cont . (c-lineup-gcc-asm-reg 0))
;; Relpos: At the first token after the open paren.
;; Anchor pos: At the first token after the open paren.
(arglist-cont-nonempty . (c-lineup-gcc-asm-reg c-lineup-arglist))
;; Relpos: At the containing statement(*).
;; Anchor pos: At the containing statement(*).
;; 2nd pos: At the open paren.
(arglist-close . +)
;; Relpos: At the containing statement(*).
;; Anchor pos: At the containing statement(*).
;; 2nd pos: At the open paren.
(stream-op . c-lineup-streamop)
;; Relpos: Boi at the first stream op in the statement.
;; Anchor pos: Boi at the first stream op in the statement.
(inclass . +)
;; Relpos: At the class open brace if it's at boi, otherwise
;; boi at the class decl start.
;; Anchor pos: At the class open brace if it's at boi,
;; otherwise boi at the class decl start.
(cpp-macro . [0])
;; Relpos: None.
;; Anchor pos: None.
(cpp-macro-cont . +)
;; Relpos: At the macro start (always at boi).
;; Anchor pos: At the macro start (always at boi).
(cpp-define-intro . (c-lineup-cpp-define +))
;; Relpos: None.
;; Anchor pos: None.
(friend . 0)
;; Relpos: None.
;; Anchor pos: None.
(objc-method-intro . [0])
;; Relpos: Boi.
;; Anchor pos: Boi.
(objc-method-args-cont . c-lineup-ObjC-method-args)
;; Relpos: At the method start (always at boi).
;; Anchor pos: At the method start (always at boi).
(objc-method-call-cont . c-lineup-ObjC-method-call)
;; Relpos: At the open bracket.
;; Anchor pos: At the open bracket.
(extern-lang-open . 0)
(namespace-open . 0)
(module-open . 0)
(composition-open . 0)
;; Relpos: Boi at the extern/namespace/etc keyword.
;; Anchor pos: Boi at the extern/namespace/etc keyword.
(extern-lang-close . 0)
(namespace-close . 0)
(module-close . 0)
(composition-close . 0)
;; Relpos: Boi at the corresponding extern/namespace/etc keyword.
;; Anchor pos: Boi at the corresponding extern/namespace/etc keyword.
(inextern-lang . +)
(innamespace . +)
(inmodule . +)
(incomposition . +)
;; Relpos: At the extern/namespace/etc block open brace if it's
;; at boi, otherwise boi at the keyword.
;; Anchor pos: At the extern/namespace/etc block open brace if
;; it's at boi, otherwise boi at the keyword.
(template-args-cont . (c-lineup-template-args +))
;; Relpos: Boi at the decl start. This might be changed; the
;; logical position is clearly the opening '<'.
;; Anchor pos: Boi at the decl start. This might be changed;
;; the logical position is clearly the opening '<'.
(inlambda . c-lineup-inexpr-block)
;; Relpos: None.
;; Anchor pos: None.
(lambda-intro-cont . +)
;; Relpos: Boi at the lambda start.
;; Anchor pos: Boi at the lambda start.
(inexpr-statement . +)
;; Relpos: None.
;; Anchor pos: None.
(inexpr-class . +)
;; Relpos: None.
;; Anchor pos: None.
))
(defcustom c-offsets-alist nil
"Association list of syntactic element symbols and indentation offsets.
@ -1112,50 +1130,66 @@ As described below, each cons cell in this list has the form:
When a line is indented, CC Mode first determines the syntactic
context of it 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.
elements. The global variable `c-syntactic-context' is bound to the
that list. Each element in the list is in turn a list where the first
element is a syntactic symbol which tells what kind of construct the
indentation point is located within. More elements in the syntactic
element lists are optional. If there is one more and it isn't nil,
then it's the anchor position for that construct.
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. 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
After generating the syntactic context for the line, CC Mode
calculates the absolute indentation: First the base indentation is
found by using the anchor position for the first syntactic element
that provides one. If none does, zero is used as base indentation.
Then CC Mode looks at each syntactic element in the context in turn.
It compares the car of the syntactic element against the
SYNTACTIC-SYMBOL's in `c-offsets-alist'. When it finds a match, it
adds OFFSET to the base indentation. The sum of this calculation is
the absolute offset for line being indented.
If the syntactic element does not match any in the `c-offsets-alist',
the element is ignored.
If OFFSET is nil, the syntactic element is ignored in the offset
calculation.
OFFSET can specify an offset in several different ways:
If OFFSET is an integer, it's added to the relative indent.
If OFFSET is nil then it's ignored.
If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/', a
positive or negative multiple of `c-basic-offset' is added; 1, -1, 2,
-2, 0.5, and -0.5, respectively.
If OFFSET is an integer then it's used as relative offset, i.e. it's
added to the base indentation.
If OFFSET is a vector, it's first element, which must be an integer,
is used as an absolute indentation column. This overrides all
relative offsets. If there are several syntactic elements which
evaluates to absolute indentation columns, the first one takes
precedence. You can see in which order CC Mode combines the syntactic
elements in a certain context by using \\[c-show-syntactic-information] on the line.
If OFFSET is one of the symbols `+', `-', `++', `--', `*', or `/'
then a positive or negative multiple of `c-basic-offset' is added to
the base indentation; 1, -1, 2, -2, 0.5, and -0.5, respectively.
If OFFSET is a function, it's called with a single argument
containing the cons of the syntactic element symbol and the relative
indent point. The return value from the function is then
reinterpreted as an OFFSET value.
If OFFSET is a symbol with a value binding then that value, which
must be an integer, is used as relative offset.
If OFFSET is a list, it's recursively evaluated using the semantics
described above. The first element of the list to return a non-nil
value succeeds. If none of the elements returns a non-nil value, the
syntactic element is ignored.
If OFFSET is a vector then it's first element, which must be an
integer, is used as an absolute indentation column. This overrides
the previous base indentation and the relative offsets applied to
it, and it becomes the new base indentation.
If OFFSET is a function or a lambda expression then it's called with
a single argument containing the cons of the syntactic symbol and
the anchor position (or nil if there is none). The return value
from the function is then reinterpreted as an offset specification.
If OFFSET is a list then its elements are evaluated recursively as
offset specifications. If the first element is any of the symbols
below then it isn't evaluated but instead specifies how the
remaining offsets in the list should be combined. If it's something
else then the list is combined according the method `first'. The
valid combination methods are:
`first' -- Use the first offset (that doesn't evaluate to nil).
`min' -- Use the minimum of all the offsets. All must be either
relative or absolute - they can't be mixed.
`max' -- Use the maximum of all the offsets. All must be either
relative or absolute - they can't be mixed.
`add' -- Add all the evaluated offsets together. Exactly one of
them may be absolute, in which case the result is
absolute. Any relative offsets that preceded the
absolute one in the list will be ignored in that case.
`c-offsets-alist' is a style variable. This means that the offsets on
this variable are normally taken from the style system in CC Mode
@ -1336,6 +1370,11 @@ The list of variables to buffer localize are:
:type 'hook
:group 'c)
(defcustom awk-mode-hook nil
"*Hook called by `awk-mode'."
:type 'hook
:group 'c)
(defcustom c-mode-common-hook nil
"*Hook called by all CC Mode modes for common initializations."
:type 'hook
@ -1380,16 +1419,17 @@ working due to this change.")
:args '((const :tag "none" nil)
(repeat :tag "types" regexp)))
(eval-and-compile
;; XEmacs 19 evaluates this at compile time below, while most other
;; versions delays the evaluation until the package is loaded.
(defun c-make-font-lock-extra-types-blurb (mode1 mode2 example)
(concat "\
(defun c-make-font-lock-extra-types-blurb (mode1 mode2 example)
(concat "\
*List of extra types (aside from the type keywords) to recognize in "
mode1 " mode.
Each list item should be a regexp matching a single identifier.
" example "
Note that items on this list that don't include any regexp special
characters are automatically optimized using `regexp-opt', so you
should not use `regexp-opt' explicitly to build regexps here.
On decoration level 3 (and higher, where applicable), a method is used
that finds most types and declarations by syntax alone. This variable
is still used as a first step, but other types are recognized
@ -1401,43 +1441,58 @@ initialized. If you change it later you have to reinitialize CC Mode
by doing \\[" mode2 "].
Despite the name, this variable is not only used for font locking but
also elsewhere in CC Mode to tell types from other identifiers.")))
also elsewhere in CC Mode to tell types from other identifiers."))
;; Note: Most of the variables below are also defined in font-lock.el
;; in older versions in Emacs, so depending on the load order we might
;; in older versions of Emacs, so depending on the load order we might
;; not install the values below. There's no kludge to cope with this
;; (as opposed to the *-font-lock-keywords-* variables) since the old
;; values work fairly well anyway.
(defcustom c-font-lock-extra-types
'("FILE" "\\sw+_t"
"bool" "complex" "imaginary" ; Defined in C99.
'("\\sw+_t"
;; Defined in C99:
"bool" "complex" "imaginary"
;; Standard library types (except those matched by the _t pattern):
"FILE" "lconv" "tm" "va_list" "jmp_buf"
;; I do not appreciate the following very Emacs-specific luggage
;; in the default value, but otoh it can hardly get in the way for
;; other users, and removing it would cause unnecessary grief for
;; the old timers that are used to it. /mast
"Lisp_Object")
(c-make-font-lock-extra-types-blurb "C" "c-mode"
"For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word FILE
and words ending in _t are treated as type names.")
"For example, a value of (\"FILE\" \"\\\\sw+_t\") means the word \"FILE\"
and words ending in \"_t\" are treated as type names.")
:type 'c-extra-types-widget
:group 'c)
(defcustom c++-font-lock-extra-types
'("\\sw+_t"
"\\([iof]\\|str\\)+stream\\(buf\\)?" "ios"
;; C library types (except those matched by the _t pattern):
"FILE" "lconv" "tm" "va_list" "jmp_buf"
;; Some standard C++ types that came from font-lock.el.
;; Experienced C++ users says there's no clear benefit in
;; extending this to all the types in the standard library, at
;; least not when they'll be recognized without "std::" too.
"istream" "istreambuf"
"ostream" "ostreambuf"
"ifstream" "ofstream" "fstream"
"strstream" "strstreambuf" "istrstream" "ostrstream"
"ios"
"string" "rope"
"list" "slist"
"deque" "vector" "bit_vector"
"set" "multiset"
"map" "multimap"
"hash\\(_\\(m\\(ap\\|ulti\\(map\\|set\\)\\)\\|set\\)\\)?"
"hash"
"hash_set" "hash_multiset"
"hash_map" "hash_multimap"
"stack" "queue" "priority_queue"
"type_info"
"iterator" "const_iterator" "reverse_iterator" "const_reverse_iterator"
"reference" "const_reference")
(c-make-font-lock-extra-types-blurb "C++" "c++-mode"
"For example, a value of (\"string\") means the word string is treated
"For example, a value of (\"string\") means the word \"string\" is treated
as a type name.")
:type 'c-extra-types-widget
:group 'c)
@ -1499,40 +1554,49 @@ Note that file offset settings are applied after file style settings
as designated in the variable `c-file-style'.")
(make-variable-buffer-local 'c-file-offsets)
;; It isn't possible to specify a docstring without specifying an
;; initial value with `defvar', so the following two variables have
;; only doc comments even though they are part of the API. It's
;; really good not to have an initial value for variables like these
;; that always should be dynamically bound, so it's worth the
;; inconvenience.
;; It isn't possible to specify a doc-string without specifying an
;; initial value with `defvar', so the following two variables have been
;; given doc-strings by setting the property `variable-documentation'
;; directly. C-h v will read this documentation only for versions of GNU
;; Emacs from 22.1. It's really good not to have an initial value for
;; variables like these that always should be dynamically bound, so it's
;; worth the inconvenience.
(cc-bytecomp-defvar c-syntactic-context)
(defvar c-syntactic-context)
;; Variable containing the syntactic analysis list during indentation.
;; It is a list with one element for each found syntactic symbol. See
;; `c-syntactic-element' for further info.
;;
;; This is always bound dynamically. It should never be set
;; statically (e.g. with `setq').
(put 'c-syntactic-context 'variable-documentation
"Variable containing the syntactic analysis list for a line of code.
It is a list with one element for each syntactic symbol pertinent to the
line, for example \"((defun-block-intro 1) (comment-intro))\".
It is dynamically bound when calling \(i) a brace hanging \"action
function\"; \(ii) a semicolon/comma hanging \"criteria function\"; \(iii) a
\"line-up function\"; \(iv) a c-special-indent-hook function. It is also
used internally by CC Mode.
c-syntactic-context is always bound dynamically. It must NEVER be set
statically (e.g. with `setq').")
(cc-bytecomp-defvar c-syntactic-element)
(defvar c-syntactic-element)
;; Variable containing the info regarding the current syntactic
;; element during calls to the lineup functions. The value is one of
;; the elements in the list in `c-syntactic-context' and is a list
;; with the symbol name in the first position, followed by zero or
;; more elements containing any additional info associated with the
;; syntactic symbol. There are accessor functions `c-langelem-sym',
;; `c-langelem-pos', `c-langelem-col', and `c-langelem-2nd-pos' to
;; access the list.
;;
;; Specifically, the element returned by `c-langelem-pos' is the
;; relpos (a.k.a. anchor position), or nil if there isn't any. See
;; the comments in the `c-offsets-alist' variable for more detailed
;; info about the data each syntactic symbol provides.
;;
;; This is always bound dynamically. It should never be set
;; statically (e.g. with `setq').
(put 'c-syntactic-element 'variable-documentation
"Variable containing the current syntactic element during calls to
the lineup functions. The value is one of the elements in the list in
`c-syntactic-context' and is a list with the symbol name in the first
position, followed by zero or more elements containing any additional
info associated with the syntactic symbol. There are accessor functions
`c-langelem-sym', `c-langelem-pos', `c-langelem-col', and
`c-langelem-2nd-pos' to access the list.
Specifically, the element returned by `c-langelem-pos' is the anchor
position, or nil if there isn't any. See the comments in the
`c-offsets-alist' variable and the CC Mode manual for more detailed info
about the data each syntactic symbol provides.
This is always bound dynamically. It should never be set
statically (e.g. with `setq').")
(defvar c-indentation-style nil
"Name of the currently installed style.
@ -1543,6 +1607,29 @@ Don't change this directly; call `c-set-style' instead.")
Set from `c-comment-prefix-regexp' at mode initialization.")
(make-variable-buffer-local 'c-current-comment-prefix)
;; N.B. The next three variables are initialized in
;; c-setup-paragraph-variables. Their initializations here are "just in
;; case". ACM, 2004/2/15. They are NOT buffer local (yet?).
(defvar c-string-par-start
;; (concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$")
"\f\\|[ \t]*\\\\?$"
"Value of paragraph-start used when scanning strings.
It treats escaped EOLs as whitespace.")
(defvar c-string-par-separate
;; (concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$")
"[ \t\f]*\\\\?$"
"Value of paragraph-separate used when scanning strings.
It treats escaped EOLs as whitespace.")
(defvar c-sentence-end-with-esc-eol
(concat "\\(\\(" (c-default-value-sentence-end) "\\)"
;; N.B.: "$" would be illegal when not enclosed like "\\($\\)".
"\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
"\\)")
"Value used like sentence-end used when scanning strings.
It treats escaped EOLs as whitespace.")
(cc-provide 'cc-vars)