Initial commit
This commit is contained in:
commit
a491ef2093
813 changed files with 345031 additions and 0 deletions
727
site-lisp/cc-mode/zbrad-integrated/cc-align.el
Normal file
727
site-lisp/cc-mode/zbrad-integrated/cc-align.el
Normal file
|
|
@ -0,0 +1,727 @@
|
|||
;;; cc-align.el --- custom indentation functions for CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
(cc-require 'cc-defs)
|
||||
(cc-require 'cc-vars)
|
||||
(cc-require 'cc-langs)
|
||||
(cc-require 'cc-engine)
|
||||
|
||||
|
||||
;; Standard indentation line-ups
|
||||
|
||||
(defun c-lineup-arglist (langelem)
|
||||
"Line up the current argument line under the first argument.
|
||||
|
||||
Works with: arglist-cont-nonempty."
|
||||
(save-excursion
|
||||
(let* ((containing-sexp
|
||||
(save-excursion
|
||||
;; arglist-cont-nonempty gives relpos ==
|
||||
;; to boi of containing-sexp paren. This
|
||||
;; is good when offset is +, but bad
|
||||
;; when it is c-lineup-arglist, so we
|
||||
;; have to special case a kludge here.
|
||||
(if (memq (car langelem) '(arglist-intro arglist-cont-nonempty))
|
||||
(progn
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(skip-chars-forward " \t" (c-point 'eol)))
|
||||
(goto-char (cdr langelem)))
|
||||
(point)))
|
||||
(langelem-col (c-langelem-col langelem t)))
|
||||
(if (save-excursion
|
||||
(beginning-of-line)
|
||||
(looking-at "[ \t]*)"))
|
||||
(progn (goto-char (match-end 0))
|
||||
(c-forward-sexp -1)
|
||||
(forward-char 1)
|
||||
(c-forward-syntactic-ws)
|
||||
(- (current-column) langelem-col))
|
||||
(goto-char containing-sexp)
|
||||
(or (eolp)
|
||||
(not (memq (char-after) '(?{ ?\( ?\[)))
|
||||
(let ((eol (c-point 'eol))
|
||||
(here (progn
|
||||
(forward-char 1)
|
||||
(skip-chars-forward " \t")
|
||||
(point))))
|
||||
(c-forward-syntactic-ws)
|
||||
(if (< (point) eol)
|
||||
(goto-char here))))
|
||||
(- (current-column) langelem-col)
|
||||
))))
|
||||
|
||||
(defun c-lineup-arglist-intro-after-paren (langelem)
|
||||
"Line up a line just after the open paren of the surrounding paren or
|
||||
brace block.
|
||||
|
||||
Works with: defun-block-intro, brace-list-intro,
|
||||
statement-block-intro, statement-case-intro, arglist-intro."
|
||||
(save-excursion
|
||||
(let ((langelem-col (c-langelem-col langelem t))
|
||||
(ce-curcol (save-excursion
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(skip-chars-forward " \t" (c-point 'eol))
|
||||
(current-column))))
|
||||
(- ce-curcol langelem-col -1))))
|
||||
|
||||
(defun c-lineup-arglist-close-under-paren (langelem)
|
||||
"Line up a closing paren line under the corresponding open paren.
|
||||
|
||||
Works with: defun-close, class-close, inline-close, block-close,
|
||||
brace-list-close, arglist-close, extern-lang-close, namespace-close
|
||||
\(for most of these, a zero offset will normally produce the same
|
||||
result, though)."
|
||||
(save-excursion
|
||||
(let ((langelem-col (c-langelem-col langelem t))
|
||||
(ce-curcol (save-excursion
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(current-column))))
|
||||
(- ce-curcol langelem-col))))
|
||||
|
||||
(defun c-lineup-close-paren (langelem)
|
||||
"Line up the closing paren under its corresponding open paren if the
|
||||
open paren is followed by code. If the open paren ends its line, no
|
||||
indentation is added. E.g:
|
||||
|
||||
main (int, main (
|
||||
char ** int, char **
|
||||
) <-> ) <- c-lineup-close-paren
|
||||
|
||||
Works with: defun-close, class-close, inline-close, block-close,
|
||||
brace-list-close, arglist-close, extern-lang-close, namespace-close."
|
||||
(save-excursion
|
||||
(condition-case nil
|
||||
(let (opencol spec)
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(setq spec (c-looking-at-special-brace-list))
|
||||
(if spec (goto-char (car (car spec))))
|
||||
(setq opencol (current-column))
|
||||
(forward-char 1)
|
||||
(if spec (progn
|
||||
(c-forward-syntactic-ws)
|
||||
(forward-char 1)))
|
||||
(c-forward-syntactic-ws (c-point 'eol))
|
||||
(if (eolp)
|
||||
0
|
||||
(- opencol (c-langelem-col langelem t))))
|
||||
(error nil))))
|
||||
|
||||
(defun c-lineup-streamop (langelem)
|
||||
"Line up C++ stream operators under each other.
|
||||
|
||||
Works with: stream-op."
|
||||
(save-excursion
|
||||
(let ((langelem-col (c-langelem-col langelem)))
|
||||
(re-search-forward "<<\\|>>" (c-point 'eol) 'move)
|
||||
(goto-char (match-beginning 0))
|
||||
(- (current-column) langelem-col))))
|
||||
|
||||
(defun c-lineup-multi-inher (langelem)
|
||||
"Line up the classes in C++ multiple inheritance clauses and member
|
||||
initializers under each other. E.g:
|
||||
|
||||
class Foo: Foo::Foo (int a, int b):
|
||||
public Cyphr, Cyphr (a),
|
||||
public Bar <-> Bar (b) <- c-lineup-multi-inher
|
||||
|
||||
class Foo Foo::Foo (int a, int b)
|
||||
: public Cyphr, : Cyphr (a),
|
||||
public Bar <-> Bar (b) <- c-lineup-multi-inher
|
||||
|
||||
class Foo Foo::Foo (int a, int b)
|
||||
: public Cyphr : Cyphr (a)
|
||||
, public Bar <-> , Bar (b) <- c-lineup-multi-inher
|
||||
|
||||
Works with: inher-cont, member-init-cont."
|
||||
(save-excursion
|
||||
(let* ((eol (c-point 'eol))
|
||||
(here (point))
|
||||
(char-after-ip (progn
|
||||
(skip-chars-forward " \t")
|
||||
(char-after)))
|
||||
(langelem-col (c-langelem-col langelem)))
|
||||
|
||||
;; This kludge is necessary to support both inher-cont and
|
||||
;; member-init-cont, since they have different anchor positions.
|
||||
(c-backward-syntactic-ws)
|
||||
(when (eq (char-before) ?:)
|
||||
(backward-char)
|
||||
(c-backward-syntactic-ws))
|
||||
|
||||
(skip-chars-forward "^:" eol)
|
||||
(if (eq char-after-ip ?,)
|
||||
(skip-chars-forward " \t" eol)
|
||||
(skip-chars-forward " \t:" eol))
|
||||
(if (or (eolp)
|
||||
(looking-at c-comment-start-regexp))
|
||||
(c-forward-syntactic-ws here))
|
||||
(- (current-column) langelem-col)
|
||||
)))
|
||||
|
||||
(defun c-lineup-java-inher (langelem)
|
||||
"Line up Java implements and extends declarations.
|
||||
If class names follows on the same line as the implements/extends
|
||||
keyword, they are lined up under each other. Otherwise, they are
|
||||
indented by adding `c-basic-offset' to the column of the keyword.
|
||||
E.g:
|
||||
|
||||
class Foo class Foo
|
||||
extends extends Cyphr,
|
||||
Bar <-> Bar <- c-lineup-java-inher
|
||||
<--> c-basic-offset
|
||||
|
||||
Works with: inher-cont."
|
||||
(save-excursion
|
||||
(let ((langelem-col (c-langelem-col langelem)))
|
||||
(forward-word 1)
|
||||
(if (looking-at "[ \t]*$")
|
||||
c-basic-offset
|
||||
(c-forward-syntactic-ws)
|
||||
(- (current-column) langelem-col)))))
|
||||
|
||||
(defun c-lineup-java-throws (langelem)
|
||||
"Line up Java throws declarations.
|
||||
If exception names follows on the same line as the throws keyword,
|
||||
they are lined up under each other. Otherwise, they are indented by
|
||||
adding `c-basic-offset' to the column of the throws keyword. The
|
||||
throws keyword itself is also indented by `c-basic-offset' from the
|
||||
function declaration start if it doesn't hang. E.g:
|
||||
|
||||
int foo() int foo() throws Cyphr,
|
||||
throws <-> Bar, <- c-lineup-java-throws
|
||||
Bar <-> Vlod <- c-lineup-java-throws
|
||||
<--><--> c-basic-offset
|
||||
|
||||
Works with: func-decl-cont."
|
||||
(save-excursion
|
||||
(let* ((lim (1- (c-point 'bol)))
|
||||
(throws (catch 'done
|
||||
(goto-char (cdr langelem))
|
||||
(while (zerop (c-forward-token-1 1 t lim))
|
||||
(if (looking-at "throws\\>[^_]")
|
||||
(throw 'done t))))))
|
||||
(if throws
|
||||
(if (zerop (c-forward-token-1 1 nil (c-point 'eol)))
|
||||
(- (current-column) (c-langelem-col langelem))
|
||||
(back-to-indentation)
|
||||
(+ (- (current-column) (c-langelem-col langelem))
|
||||
c-basic-offset))
|
||||
c-basic-offset))))
|
||||
|
||||
(defun c-indent-one-line-block (langelem)
|
||||
"Indent a one line block `c-basic-offset' extra.
|
||||
E.g:
|
||||
|
||||
if (n > 0) if (n > 0)
|
||||
{m+=n; n=0;} <-> { <- c-indent-one-line-block
|
||||
<--> c-basic-offset m+=n; n=0;
|
||||
}
|
||||
|
||||
The block may use any kind of parenthesis character. nil is returned
|
||||
if the line doesn't start with a one line block, which makes the
|
||||
function usable in list expressions.
|
||||
|
||||
Work with: Almost all syntactic symbols, but most useful on *-open."
|
||||
(save-excursion
|
||||
(let ((eol (c-point 'eol)))
|
||||
(back-to-indentation)
|
||||
(if (and (eq (char-syntax (char-after)) ?\()
|
||||
(c-safe (progn (c-forward-sexp) t))
|
||||
(<= (point) eol))
|
||||
c-basic-offset
|
||||
nil))))
|
||||
|
||||
(defun c-indent-multi-line-block (langelem)
|
||||
"Indent a multi line block `c-basic-offset' extra.
|
||||
E.g:
|
||||
|
||||
int *foo[] = { int *foo[] = {
|
||||
NULL, NULL,
|
||||
{17}, <-> { <- c-indent-multi-line-block
|
||||
17
|
||||
}
|
||||
<--> c-basic-offset
|
||||
|
||||
The block may use any kind of parenthesis character. nil is returned
|
||||
if the line doesn't start with a multi line block, which makes the
|
||||
function usable in list expressions.
|
||||
|
||||
Work with: Almost all syntactic symbols, but most useful on *-open."
|
||||
(save-excursion
|
||||
(let ((eol (c-point 'eol)))
|
||||
(back-to-indentation)
|
||||
(if (and (eq (char-syntax (char-after)) ?\()
|
||||
(or (not (c-safe (progn (c-forward-sexp) t)))
|
||||
(> (point) eol)))
|
||||
c-basic-offset
|
||||
nil))))
|
||||
|
||||
(defun c-lineup-C-comments (langelem)
|
||||
"Line up C block comment continuation lines.
|
||||
Various heuristics are used to handle many of the common comment
|
||||
styles. Some examples:
|
||||
|
||||
/* /** /* /* text /* /**
|
||||
* text * text text text ** text ** text
|
||||
*/ */ */ */ */ */
|
||||
|
||||
/*********************************************************************
|
||||
* text
|
||||
********************************************************************/
|
||||
|
||||
/*********************************************************************
|
||||
Free form text comments:
|
||||
In comments with a long delimiter line at the start, the indentation
|
||||
is kept unchanged for lines that start with an empty comment line
|
||||
prefix. The delimiter line is whatever matches the
|
||||
`comment-start-skip' regexp.
|
||||
*********************************************************************/
|
||||
|
||||
The variable `c-comment-prefix-regexp' is used to recognize the
|
||||
comment line prefix, e.g. the `*' that usually starts every line
|
||||
inside a comment.
|
||||
|
||||
Works with: The `c' syntactic symbol."
|
||||
(save-excursion
|
||||
(let* ((here (point))
|
||||
(prefixlen (progn (back-to-indentation)
|
||||
(if (looking-at c-current-comment-prefix)
|
||||
(- (match-end 0) (point))
|
||||
0)))
|
||||
(starterlen (save-excursion
|
||||
(goto-char (cdr langelem))
|
||||
(looking-at comment-start-skip)
|
||||
(- (save-excursion
|
||||
(goto-char (match-end 0))
|
||||
(skip-chars-backward " \t")
|
||||
(point))
|
||||
(or (match-end 1) (point))
|
||||
1))) ; Don't count the first '/'.
|
||||
(langelem-col (save-excursion (c-langelem-col langelem))))
|
||||
(if (and (> starterlen 10) (zerop prefixlen))
|
||||
;; The comment has a long starter and the line doesn't have
|
||||
;; a nonempty comment prefix. Treat it as free form text
|
||||
;; and don't change the indentation.
|
||||
(- (current-column) langelem-col)
|
||||
(forward-line -1)
|
||||
(back-to-indentation)
|
||||
(if (>= (cdr langelem) (point))
|
||||
;; On the second line in the comment.
|
||||
(if (zerop prefixlen)
|
||||
;; No nonempty comment prefix. Align after comment
|
||||
;; starter.
|
||||
(progn
|
||||
(goto-char (match-end 0))
|
||||
(if (looking-at "\\([ \t]+\\).+$")
|
||||
;; Align with the text that hangs after the
|
||||
;; comment starter.
|
||||
(goto-char (match-end 1)))
|
||||
(- (current-column) langelem-col))
|
||||
;; How long is the comment starter? if greater than the
|
||||
;; length of the comment prefix, align left. if less
|
||||
;; than or equal, align right. this should also pick up
|
||||
;; Javadoc style comments.
|
||||
(if (> starterlen prefixlen)
|
||||
(progn
|
||||
(goto-char (cdr langelem))
|
||||
(- (current-column) -1 langelem-col))
|
||||
(goto-char (match-end 0))
|
||||
(skip-chars-backward " \t")
|
||||
(- (current-column) prefixlen langelem-col)))
|
||||
;; 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.
|
||||
(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))
|
||||
(while (and (zerop (forward-line -1))
|
||||
(looking-at "^[ \t]*$")))
|
||||
(back-to-indentation)
|
||||
(if (< (point) (cdr langelem))
|
||||
;; Align with the comment starter rather than
|
||||
;; with the code before it.
|
||||
(goto-char (cdr langelem)))))
|
||||
(- (current-column) langelem-col))))))
|
||||
|
||||
(defun c-lineup-comment (langelem)
|
||||
"Line up a comment start according to `c-comment-only-line-offset'.
|
||||
If the comment is lined up with a comment starter on the previous
|
||||
line, that alignment is preserved.
|
||||
|
||||
Works with: comment-intro."
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(let ((col (current-column)))
|
||||
(cond
|
||||
;; CASE 1: preserve aligned comments
|
||||
((save-excursion
|
||||
(and (c-forward-comment -1)
|
||||
(= col (current-column))))
|
||||
(vector col)) ; Return an absolute column.
|
||||
;; indent as specified by c-comment-only-line-offset
|
||||
((not (bolp))
|
||||
(or (car-safe c-comment-only-line-offset)
|
||||
c-comment-only-line-offset))
|
||||
(t
|
||||
(or (cdr-safe c-comment-only-line-offset)
|
||||
(car-safe c-comment-only-line-offset)
|
||||
-1000)) ;jam it against the left side
|
||||
))))
|
||||
|
||||
(defun c-lineup-runin-statements (langelem)
|
||||
"Line up statements when the first statement is on the same line as
|
||||
the block opening brace. E.g:
|
||||
|
||||
int main()
|
||||
{ puts (\"Hello world!\");
|
||||
return 0; <- c-lineup-runin-statements
|
||||
}
|
||||
|
||||
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)) ?{)
|
||||
(save-excursion
|
||||
(let ((langelem-col (c-langelem-col langelem)))
|
||||
(forward-char 1)
|
||||
(skip-chars-forward " \t")
|
||||
(unless (eolp)
|
||||
(- (current-column) langelem-col))))))
|
||||
|
||||
(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.
|
||||
|
||||
Works with: statement-cont."
|
||||
(save-excursion
|
||||
(let ((equalp (save-excursion
|
||||
(goto-char (c-point 'boi))
|
||||
(let ((eol (c-point 'eol)))
|
||||
(c-forward-token-1 0 t eol)
|
||||
(while (and (not (eq (char-after) ?=))
|
||||
(= (c-forward-token-1 1 t eol) 0))))
|
||||
(and (eq (char-after) ?=)
|
||||
(- (point) (c-point 'boi)))))
|
||||
(langelem-col (c-langelem-col langelem))
|
||||
donep)
|
||||
(while (and (not donep)
|
||||
(< (point) (c-point 'eol)))
|
||||
(skip-chars-forward "^=" (c-point 'eol))
|
||||
(if (c-in-literal (cdr langelem))
|
||||
(forward-char 1)
|
||||
(setq donep t)))
|
||||
(if (or (not (eq (char-after) ?=))
|
||||
(save-excursion
|
||||
(forward-char 1)
|
||||
(c-forward-syntactic-ws (c-point 'eol))
|
||||
(eolp)))
|
||||
;; there's no equal sign on the line
|
||||
c-basic-offset
|
||||
;; calculate indentation column after equals and ws, unless
|
||||
;; our line contains an equals sign
|
||||
(if (not equalp)
|
||||
(progn
|
||||
(forward-char 1)
|
||||
(skip-chars-forward " \t")
|
||||
(setq equalp 0)))
|
||||
(- (current-column) equalp langelem-col))
|
||||
)))
|
||||
|
||||
(defun c-lineup-template-args (langelem)
|
||||
"Line up template argument lines under the first argument.
|
||||
To allow this function to be used in a list expression, nil is
|
||||
returned if there's no template argument on the first line.
|
||||
|
||||
Works with: template-args-cont."
|
||||
(save-excursion
|
||||
(c-with-syntax-table c++-template-syntax-table
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(if (and (eq (char-after) ?<)
|
||||
(zerop (c-forward-token-1 1 nil (c-point 'eol))))
|
||||
(- (current-column) (c-langelem-col langelem))))))
|
||||
|
||||
(defun c-lineup-ObjC-method-call (langelem)
|
||||
"Line up selector args as elisp-mode does with function args:
|
||||
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
|
||||
line with it.
|
||||
|
||||
Works with: objc-method-call-cont."
|
||||
(save-excursion
|
||||
(let* ((extra (save-excursion
|
||||
(back-to-indentation)
|
||||
(c-backward-syntactic-ws (cdr langelem))
|
||||
(if (eq (char-before) ?:)
|
||||
(- c-basic-offset)
|
||||
0)))
|
||||
(open-bracket-pos (cdr langelem))
|
||||
(open-bracket-col (progn
|
||||
(goto-char open-bracket-pos)
|
||||
(current-column)))
|
||||
(target-col (progn
|
||||
(forward-char)
|
||||
(c-forward-sexp)
|
||||
(skip-chars-forward " \t")
|
||||
(if (eolp)
|
||||
(+ open-bracket-col c-basic-offset)
|
||||
(current-column))))
|
||||
)
|
||||
(- target-col open-bracket-col extra))))
|
||||
|
||||
(defun c-lineup-ObjC-method-args (langelem)
|
||||
"Line up the colons that separate args.
|
||||
The colon on the current line is aligned with the one on the first
|
||||
line.
|
||||
|
||||
Works with: objc-method-args-cont."
|
||||
(save-excursion
|
||||
(let* ((here (c-point 'boi))
|
||||
(curcol (progn (goto-char here) (current-column)))
|
||||
(eol (c-point 'eol))
|
||||
(relpos (cdr langelem))
|
||||
(first-col-column (progn
|
||||
(goto-char relpos)
|
||||
(skip-chars-forward "^:" eol)
|
||||
(and (eq (char-after) ?:)
|
||||
(current-column)))))
|
||||
(if (not first-col-column)
|
||||
c-basic-offset
|
||||
(goto-char here)
|
||||
(skip-chars-forward "^:" eol)
|
||||
(if (eq (char-after) ?:)
|
||||
(+ curcol (- first-col-column (current-column)))
|
||||
c-basic-offset)))))
|
||||
|
||||
(defun c-lineup-ObjC-method-args-2 (langelem)
|
||||
"Line up the colons that separate args.
|
||||
The colon on the current line is aligned with the one on the previous
|
||||
line.
|
||||
|
||||
Works with: objc-method-args-cont."
|
||||
(save-excursion
|
||||
(let* ((here (c-point 'boi))
|
||||
(curcol (progn (goto-char here) (current-column)))
|
||||
(eol (c-point 'eol))
|
||||
(relpos (cdr langelem))
|
||||
(prev-col-column (progn
|
||||
(skip-chars-backward "^:" relpos)
|
||||
(and (eq (char-before) ?:)
|
||||
(- (current-column) 1)))))
|
||||
(if (not prev-col-column)
|
||||
c-basic-offset
|
||||
(goto-char here)
|
||||
(skip-chars-forward "^:" eol)
|
||||
(if (eq (char-after) ?:)
|
||||
(+ curcol (- prev-col-column (current-column)))
|
||||
c-basic-offset)))))
|
||||
|
||||
(defun c-lineup-inexpr-block (langelem)
|
||||
"Line up the block for constructs that use a block inside an expression,
|
||||
e.g. anonymous classes in Java and lambda functions in Pike. The body
|
||||
is aligned with the start of the header, e.g. with the \"new\" or
|
||||
\"lambda\" keyword. Returns nil if the block isn't part of such a
|
||||
construct.
|
||||
|
||||
Works with: inlambda, inexpr-statement, inexpr-class."
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(let ((res (or (c-looking-at-inexpr-block)
|
||||
(if (c-safe (backward-up-list 1)
|
||||
(eq (char-after) ?{))
|
||||
(c-looking-at-inexpr-block)))))
|
||||
(when res
|
||||
(goto-char (cdr res))
|
||||
(- (current-column)
|
||||
(progn
|
||||
(back-to-indentation)
|
||||
(current-column)))))))
|
||||
|
||||
(defun c-lineup-whitesmith-in-block (langelem)
|
||||
"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:
|
||||
|
||||
something
|
||||
{ something {
|
||||
foo; <-> foo; <- c-lineup-whitesmith-in-block
|
||||
} }
|
||||
<--> c-basic-offset
|
||||
|
||||
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, inclass,
|
||||
inextern-lang, innamespace."
|
||||
(save-excursion
|
||||
(goto-char (cdr langelem))
|
||||
(back-to-indentation)
|
||||
(if (eq (char-syntax (char-after)) ?\()
|
||||
0
|
||||
c-basic-offset)))
|
||||
|
||||
(defun c-lineup-dont-change (langelem)
|
||||
"Do not change the indentation of the current line.
|
||||
|
||||
Works with: Any syntactic symbol."
|
||||
(save-excursion
|
||||
(back-to-indentation)
|
||||
(vector (current-column))))
|
||||
|
||||
|
||||
(defun c-snug-do-while (syntax pos)
|
||||
"Dynamically calculate brace hanginess for do-while statements.
|
||||
Using this function, `while' clauses that end a `do-while' block will
|
||||
remain on the same line as the brace that closes that block.
|
||||
|
||||
See `c-hanging-braces-alist' for how to utilize this function as an
|
||||
ACTION associated with `block-close' syntax."
|
||||
(save-excursion
|
||||
(let (langelem)
|
||||
(if (and (eq syntax 'block-close)
|
||||
(setq langelem (assq 'block-close c-syntactic-context))
|
||||
(progn (goto-char (cdr langelem))
|
||||
(if (eq (char-after) ?{)
|
||||
(c-safe (c-forward-sexp -1)))
|
||||
(looking-at "\\<do\\>[^_]")))
|
||||
'(before)
|
||||
'(before after)))))
|
||||
|
||||
(defun c-gnu-impose-minimum ()
|
||||
"Imposes a minimum indentation for lines inside a top-level construct.
|
||||
The variable `c-label-minimum-indentation' specifies the minimum
|
||||
indentation amount."
|
||||
(let ((non-top-levels '(defun-block-intro statement statement-cont
|
||||
statement-block-intro statement-case-intro
|
||||
statement-case-open substatement substatement-open
|
||||
case-label label do-while-closure else-clause
|
||||
))
|
||||
(syntax c-syntactic-context)
|
||||
langelem)
|
||||
(while syntax
|
||||
(setq langelem (car (car syntax))
|
||||
syntax (cdr syntax))
|
||||
;; don't adjust macro or comment-only lines
|
||||
(cond ((memq langelem '(cpp-macro comment-intro))
|
||||
(setq syntax nil))
|
||||
((memq langelem non-top-levels)
|
||||
(save-excursion
|
||||
(setq syntax nil)
|
||||
(back-to-indentation)
|
||||
(if (zerop (current-column))
|
||||
(insert (make-string c-label-minimum-indentation 32)))
|
||||
))
|
||||
))))
|
||||
|
||||
|
||||
;; Useful for c-hanging-semi&comma-criteria
|
||||
|
||||
(defun c-semi&comma-inside-parenlist ()
|
||||
"Controls newline insertion after semicolons in parenthesis lists.
|
||||
If a comma was inserted, no determination is made. If a semicolon was
|
||||
inserted inside a parenthesis list, no newline is added otherwise a
|
||||
newline is added. In either case, checking is stopped. This supports
|
||||
exactly the old newline insertion behavior."
|
||||
;; newline only after semicolon, but only if that semicolon is not
|
||||
;; inside a parenthesis list (e.g. a for loop statement)
|
||||
(if (not (eq last-command-char ?\;))
|
||||
nil ; continue checking
|
||||
(if (condition-case nil
|
||||
(save-excursion
|
||||
(up-list -1)
|
||||
(not (eq (char-after) ?\()))
|
||||
(error t))
|
||||
t
|
||||
'stop)))
|
||||
|
||||
;; Suppresses newlines before non-blank lines
|
||||
(defun c-semi&comma-no-newlines-before-nonblanks ()
|
||||
"Controls newline insertion after semicolons.
|
||||
If a comma was inserted, no determination is made. If a semicolon was
|
||||
inserted, and the following line is not blank, no newline is inserted.
|
||||
Otherwise, no determination is made."
|
||||
(save-excursion
|
||||
(if (and (= last-command-char ?\;)
|
||||
;;(/= (point-max)
|
||||
;; (save-excursion (skip-syntax-forward " ") (point))
|
||||
(zerop (forward-line 1))
|
||||
(not (looking-at "^[ \t]*$")))
|
||||
'stop
|
||||
nil)))
|
||||
|
||||
;; Suppresses new lines after semicolons in one-liners methods
|
||||
(defun c-semi&comma-no-newlines-for-oneline-inliners ()
|
||||
"Controls newline insertion after semicolons for some one-line methods.
|
||||
If a comma was inserted, no determination is made. Newlines are
|
||||
suppressed in one-liners, if the line is an in-class inline function.
|
||||
For other semicolon contexts, no determination is made."
|
||||
(let ((syntax (c-guess-basic-syntax))
|
||||
(bol (save-excursion
|
||||
(if (c-safe (up-list -1) t)
|
||||
(c-point 'bol)
|
||||
-1))))
|
||||
(if (and (eq last-command-char ?\;)
|
||||
(eq (car (car syntax)) 'inclass)
|
||||
(eq (car (car (cdr syntax))) 'topmost-intro)
|
||||
(= (c-point 'bol) bol))
|
||||
'stop
|
||||
nil)))
|
||||
|
||||
|
||||
(cc-provide 'cc-align)
|
||||
|
||||
;;; cc-align.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-align.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-align.elc
Normal file
Binary file not shown.
296
site-lisp/cc-mode/zbrad-integrated/cc-bytecomp.el
Normal file
296
site-lisp/cc-mode/zbrad-integrated/cc-bytecomp.el
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
;;; cc-bytecomp.el --- compile time setup for proper compilation
|
||||
|
||||
;; Copyright (C) 2000, 01 Free Software Foundation, Inc.
|
||||
|
||||
;; Author: Martin Stjernholm
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 15-Jul-2000
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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 GNU Emacs; see the file COPYING. If not, write to the
|
||||
;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This file is used to ensure that the CC Mode files are correctly
|
||||
;; compiled regardless the environment (e.g. if an older CC Mode with
|
||||
;; outdated macros are loaded during compilation). It also provides
|
||||
;; features to defeat the compiler warnings for selected symbols.
|
||||
|
||||
|
||||
;;; Code:
|
||||
|
||||
(defvar cc-bytecomp-unbound-variables nil)
|
||||
(defvar cc-bytecomp-original-functions nil)
|
||||
(defvar cc-bytecomp-original-properties nil)
|
||||
(defvar cc-bytecomp-load-depth 0)
|
||||
(defvar cc-bytecomp-loaded-files nil)
|
||||
(defvar cc-bytecomp-environment-set nil)
|
||||
|
||||
(put 'cc-eval-when-compile 'lisp-indent-hook 0)
|
||||
(defmacro cc-eval-when-compile (&rest body)
|
||||
"Like `progn', but evaluates the body at compile time.
|
||||
The result of the body appears to the compiler as a quoted constant.
|
||||
|
||||
This variant works around what looks like a bug in
|
||||
`eval-when-compile': During byte compilation it byte compiles its
|
||||
contents before evaluating it. That can cause forms to be compiled in
|
||||
situations they aren't intended to be compiled. See cc-bytecomp.el
|
||||
for further discussion."
|
||||
;;
|
||||
;; Example: It's not possible to defsubst a primitive, e.g. the
|
||||
;; following will produce an error (in any emacs flavor), since
|
||||
;; `nthcdr' is a primitive function that's handled specially by the
|
||||
;; byte compiler and thus can't be redefined:
|
||||
;;
|
||||
;; (defsubst nthcdr (val) val)
|
||||
;;
|
||||
;; `defsubst', like `defmacro', needs to be evaluated at compile
|
||||
;; time, so this will produce an error during byte compilation.
|
||||
;;
|
||||
;; CC Mode occasionally needs to do things like this for cross-emacs
|
||||
;; compatibility (although we try to avoid it since it results in
|
||||
;; byte code that isn't compatible between emacsen). It therefore
|
||||
;; uses the following to conditionally do a `defsubst':
|
||||
;;
|
||||
;; (eval-when-compile
|
||||
;; (if (not (fboundp 'foo))
|
||||
;; (defsubst foo ...)))
|
||||
;;
|
||||
;; But `eval-when-compile' byte compiles its contents and _then_
|
||||
;; evaluates it (in all current emacs versions, up to and including
|
||||
;; Emacs 20.6 and XEmacs 21.1 as of this writing). So this will
|
||||
;; still produce an error, since the byte compiler will get to the
|
||||
;; defsubst anyway. That's arguably a bug because the point with
|
||||
;; `eval-when-compile' is that it should evaluate rather than
|
||||
;; compile its contents.
|
||||
`(eval-when-compile (eval '(progn ,@body))))
|
||||
|
||||
(defun cc-bytecomp-setup-environment ()
|
||||
;; Eval'ed during compilation to setup variables, functions etc
|
||||
;; declared with `cc-bytecomp-defvar' et al.
|
||||
(if (= cc-bytecomp-load-depth 0)
|
||||
(let (p)
|
||||
(if cc-bytecomp-environment-set
|
||||
(error "Byte compilation environment already set - \
|
||||
perhaps a `cc-bytecomp-restore-environment' is forgotten somewhere"))
|
||||
(setq p cc-bytecomp-unbound-variables)
|
||||
(while p
|
||||
(if (not (boundp (car p)))
|
||||
(progn
|
||||
(eval `(defvar ,(car p)))
|
||||
(set (car p) 'cc-bytecomp-ignore)))
|
||||
(setq p (cdr p)))
|
||||
(setq p cc-bytecomp-original-functions)
|
||||
(while p
|
||||
(let ((fun (car (car p)))
|
||||
(temp-macro (car (cdr (car p)))))
|
||||
(if temp-macro
|
||||
(eval `(defmacro ,fun ,@temp-macro))
|
||||
(fset fun 'cc-bytecomp-ignore)))
|
||||
(setq p (cdr p)))
|
||||
(setq p cc-bytecomp-original-properties)
|
||||
(while p
|
||||
(let ((sym (car (car (car p))))
|
||||
(prop (cdr (car (car p))))
|
||||
(tempdef (car (cdr (car p)))))
|
||||
(put sym prop tempdef))
|
||||
(setq p (cdr p)))
|
||||
(setq cc-bytecomp-environment-set t))))
|
||||
|
||||
(defun cc-bytecomp-restore-environment ()
|
||||
;; Eval'ed during compilation to restore variables, functions etc
|
||||
;; declared with `cc-bytecomp-defvar' et al.
|
||||
(if (= cc-bytecomp-load-depth 0)
|
||||
(let (p)
|
||||
(setq p cc-bytecomp-unbound-variables)
|
||||
(while p
|
||||
(let ((var (car p)))
|
||||
(if (and (boundp var)
|
||||
(eq var 'cc-bytecomp-ignore))
|
||||
(makunbound var)))
|
||||
(setq p (cdr p)))
|
||||
(setq p cc-bytecomp-original-functions)
|
||||
(while p
|
||||
(let ((fun (car (car p)))
|
||||
(def (car (cdr (cdr (car p))))))
|
||||
(if (and (fboundp fun)
|
||||
(eq (symbol-function fun) 'cc-bytecomp-ignore))
|
||||
(if (eq def 'unbound)
|
||||
(fmakunbound fun)
|
||||
(fset fun def))))
|
||||
(setq p (cdr p)))
|
||||
(setq p cc-bytecomp-original-properties)
|
||||
(while p
|
||||
(let ((sym (car (car (car p))))
|
||||
(prop (cdr (car (car p))))
|
||||
(tempdef (car (cdr (car p))))
|
||||
(origdef (cdr (cdr (car p)))))
|
||||
(if (eq (get sym prop) tempdef)
|
||||
(put sym prop origdef)))
|
||||
(setq p (cdr p)))
|
||||
(setq cc-bytecomp-environment-set nil))))
|
||||
|
||||
(defun cc-bytecomp-load (cc-part)
|
||||
;; Eval'ed during compilation to load a CC Mode file from the source
|
||||
;; directory (assuming it's the same as the compiled file
|
||||
;; destination dir).
|
||||
(if (and (boundp 'byte-compile-dest-file)
|
||||
(stringp byte-compile-dest-file))
|
||||
(progn
|
||||
(cc-bytecomp-restore-environment)
|
||||
(let ((cc-bytecomp-load-depth (1+ cc-bytecomp-load-depth))
|
||||
(load-path
|
||||
(cons (file-name-directory byte-compile-dest-file)
|
||||
load-path))
|
||||
(cc-file (concat cc-part ".el")))
|
||||
(if (member cc-file cc-bytecomp-loaded-files)
|
||||
()
|
||||
(setq cc-bytecomp-loaded-files
|
||||
(cons cc-file cc-bytecomp-loaded-files))
|
||||
(load cc-file nil t t)))
|
||||
(cc-bytecomp-setup-environment)
|
||||
t)))
|
||||
|
||||
(defmacro cc-require (cc-part)
|
||||
"Force loading of the corresponding .el file in the current
|
||||
directory during compilation, but compile in a `require'. Don't use
|
||||
within `eval-when-compile'.
|
||||
|
||||
Having cyclic cc-require's will result in infinite recursion. That's
|
||||
somewhat intentional."
|
||||
`(progn
|
||||
(cc-eval-when-compile (cc-bytecomp-load (symbol-name ,cc-part)))
|
||||
(require ,cc-part)))
|
||||
|
||||
(defmacro cc-provide (feature)
|
||||
"A replacement for the `provide' form that restores the environment
|
||||
after the compilation. Don't use within `eval-when-compile'."
|
||||
`(progn
|
||||
(eval-when-compile (cc-bytecomp-restore-environment))
|
||||
(provide ,feature)))
|
||||
|
||||
(defmacro cc-load (cc-part)
|
||||
"Force loading of the corresponding .el file in the current
|
||||
directory during compilation. Don't use outside `eval-when-compile'
|
||||
or `eval-and-compile'.
|
||||
|
||||
Having cyclic cc-load's will result in infinite recursion. That's
|
||||
somewhat intentional."
|
||||
`(or (and (featurep 'cc-bytecomp)
|
||||
(cc-bytecomp-load ,cc-part))
|
||||
(load ,cc-part nil t nil)))
|
||||
|
||||
(defun cc-bytecomp-is-compiling ()
|
||||
"Return non-nil if eval'ed during compilation. Don't use outside
|
||||
`eval-when-compile'."
|
||||
(and (boundp 'byte-compile-dest-file)
|
||||
(stringp byte-compile-dest-file)))
|
||||
|
||||
(defmacro cc-bytecomp-defvar (var)
|
||||
"Binds the symbol as a variable during compilation of the file,
|
||||
to silence the byte compiler. Don't use within `eval-when-compile'."
|
||||
`(eval-when-compile
|
||||
(if (boundp ',var)
|
||||
nil
|
||||
(if (not (memq ',var cc-bytecomp-unbound-variables))
|
||||
(setq cc-bytecomp-unbound-variables
|
||||
(cons ',var cc-bytecomp-unbound-variables)))
|
||||
(if (and (cc-bytecomp-is-compiling)
|
||||
(= cc-bytecomp-load-depth 0))
|
||||
(progn
|
||||
(defvar ,var)
|
||||
(set ',var 'cc-bytecomp-ignore))))))
|
||||
|
||||
(defmacro cc-bytecomp-defun (fun)
|
||||
"Bind the symbol as a function during compilation of the file,
|
||||
to silence the byte compiler. Don't use within `eval-when-compile'."
|
||||
`(eval-when-compile
|
||||
(if (not (assq ',fun cc-bytecomp-original-functions))
|
||||
(setq cc-bytecomp-original-functions
|
||||
(cons (list ',fun
|
||||
nil
|
||||
(if (fboundp ',fun)
|
||||
(symbol-function ',fun)
|
||||
'unbound))
|
||||
cc-bytecomp-original-functions)))
|
||||
(if (and (cc-bytecomp-is-compiling)
|
||||
(= cc-bytecomp-load-depth 0)
|
||||
(not (fboundp ',fun)))
|
||||
(fset ',fun 'cc-bytecomp-ignore))))
|
||||
|
||||
(put 'cc-bytecomp-defmacro 'lisp-indent-function 'defun)
|
||||
(defmacro cc-bytecomp-defmacro (fun &rest temp-macro)
|
||||
"Bind the symbol as a macro during compilation (and evaluation) of the
|
||||
file. Don't use outside `eval-when-compile'."
|
||||
`(progn
|
||||
(if (not (assq ',fun cc-bytecomp-original-functions))
|
||||
(setq cc-bytecomp-original-functions
|
||||
(cons (list ',fun
|
||||
',temp-macro
|
||||
(if (fboundp ',fun)
|
||||
(symbol-function ',fun)
|
||||
'unbound))
|
||||
cc-bytecomp-original-functions)))
|
||||
(defmacro ,fun ,@temp-macro)))
|
||||
|
||||
(defmacro cc-bytecomp-put (symbol propname value)
|
||||
"Set a property on a symbol during compilation (and evaluation) of
|
||||
the file. Don't use outside `eval-when-compile'."
|
||||
`(cc-eval-when-compile
|
||||
(if (not (assoc (cons ,symbol ,propname) cc-bytecomp-original-properties))
|
||||
(setq cc-bytecomp-original-properties
|
||||
(cons (cons (cons ,symbol ,propname)
|
||||
(cons ,value (get ,symbol ,propname)))
|
||||
cc-bytecomp-original-properties)))
|
||||
(put ,symbol ,propname ,value)))
|
||||
|
||||
(defmacro cc-bytecomp-obsolete-var (symbol)
|
||||
"Suppress warnings about that the given symbol is an obsolete variable.
|
||||
Don't use within `eval-when-compile'."
|
||||
`(eval-when-compile
|
||||
(if (get ',symbol 'byte-obsolete-variable)
|
||||
(cc-bytecomp-put ',symbol 'byte-obsolete-variable nil))))
|
||||
|
||||
(defun cc-bytecomp-ignore-obsolete (form)
|
||||
;; Wraps a call to `byte-compile-obsolete' that suppresses the warning.
|
||||
(let ((byte-compile-warnings
|
||||
(delq 'obsolete (append byte-compile-warnings nil))))
|
||||
(byte-compile-obsolete form)))
|
||||
|
||||
(defmacro cc-bytecomp-obsolete-fun (symbol)
|
||||
"Suppress warnings about that the given symbol is an obsolete function.
|
||||
Don't use within `eval-when-compile'."
|
||||
`(eval-when-compile
|
||||
(if (eq (get ',symbol 'byte-compile) 'byte-compile-obsolete)
|
||||
(cc-bytecomp-put ',symbol 'byte-compile
|
||||
'cc-bytecomp-ignore-obsolete))))
|
||||
|
||||
;; Override ourselves with a version loaded from source if we're
|
||||
;; compiling, like cc-require does for all the other files.
|
||||
(if (and (cc-bytecomp-is-compiling)
|
||||
(= cc-bytecomp-load-depth 0))
|
||||
(let ((load-path
|
||||
(cons (file-name-directory byte-compile-dest-file) load-path))
|
||||
(cc-bytecomp-load-depth 1))
|
||||
(load "cc-bytecomp.el" nil t t)))
|
||||
|
||||
|
||||
(provide 'cc-bytecomp)
|
||||
|
||||
;;; cc-bytecomp.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-bytecomp.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-bytecomp.elc
Normal file
Binary file not shown.
2574
site-lisp/cc-mode/zbrad-integrated/cc-cmds.el
Normal file
2574
site-lisp/cc-mode/zbrad-integrated/cc-cmds.el
Normal file
File diff suppressed because it is too large
Load diff
BIN
site-lisp/cc-mode/zbrad-integrated/cc-cmds.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-cmds.elc
Normal file
Binary file not shown.
164
site-lisp/cc-mode/zbrad-integrated/cc-compat.el
Normal file
164
site-lisp/cc-mode/zbrad-integrated/cc-compat.el
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
;;; cc-compat.el --- cc-mode compatibility with c-mode.el confusion
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1994-1997 Barry A. Warsaw
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: August 1994, split from cc-mode.el
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
;;
|
||||
;; Boring old c-mode.el (BOCM) is confusion and brain melt. cc-mode.el
|
||||
;; is clarity of thought and purity of chi. If you are still unwilling
|
||||
;; to accept enlightenment, this might help, or it may prolong your
|
||||
;; agony.
|
||||
;;
|
||||
;; To use, add the following to your c-mode-hook:
|
||||
;;
|
||||
;; (require 'cc-compat)
|
||||
;; (c-set-style "BOCM")
|
||||
;;
|
||||
;; This file is completely unsupported! Although it has been patched
|
||||
;; superficially to keep pace with the rest of CC Mode, it hasn't been
|
||||
;; tested for a long time.
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
(cc-require 'cc-defs)
|
||||
(cc-require 'cc-vars)
|
||||
(cc-require 'cc-styles)
|
||||
(cc-require 'cc-engine)
|
||||
|
||||
|
||||
;; In case c-mode.el isn't loaded
|
||||
(defvar c-indent-level 2
|
||||
"*Indentation of C statements with respect to containing block.")
|
||||
(defvar c-brace-imaginary-offset 0
|
||||
"*Imagined indentation of a C open brace that actually follows a statement.")
|
||||
(defvar c-brace-offset 0
|
||||
"*Extra indentation for braces, compared with other text in same context.")
|
||||
(defvar c-argdecl-indent 5
|
||||
"*Indentation level of declarations of C function arguments.")
|
||||
(defvar c-label-offset -2
|
||||
"*Offset of C label lines and case statements relative to usual indentation.")
|
||||
(defvar c-continued-statement-offset 2
|
||||
"*Extra indent for lines not starting new statements.")
|
||||
(defvar c-continued-brace-offset 0
|
||||
"*Extra indent for substatements that start with open-braces.
|
||||
This is in addition to c-continued-statement-offset.")
|
||||
|
||||
|
||||
|
||||
;; these offsets are taken by brute force testing c-mode.el, since
|
||||
;; there's no logic to what it does.
|
||||
(let* ((offsets '(c-offsets-alist .
|
||||
((defun-block-intro . cc-block-intro-offset)
|
||||
(statement-block-intro . cc-block-intro-offset)
|
||||
(defun-open . 0)
|
||||
(class-open . 0)
|
||||
(inline-open . c-brace-offset)
|
||||
(block-open . c-brace-offset)
|
||||
(block-close . cc-block-close-offset)
|
||||
(brace-list-open . c-brace-offset)
|
||||
(substatement-open . cc-substatement-open-offset)
|
||||
(substatement . c-continued-statement-offset)
|
||||
(knr-argdecl-intro . c-argdecl-indent)
|
||||
(case-label . c-label-offset)
|
||||
(access-label . c-label-offset)
|
||||
(label . c-label-offset)
|
||||
))))
|
||||
(c-add-style "BOCM" offsets))
|
||||
|
||||
|
||||
(defun cc-block-intro-offset (langelem)
|
||||
;; taken directly from calculate-c-indent confusion
|
||||
(save-excursion
|
||||
(c-backward-syntactic-ws)
|
||||
(if (eq (char-before) ?{)
|
||||
(forward-char -1)
|
||||
(goto-char (cdr langelem)))
|
||||
(let* ((curcol (save-excursion
|
||||
(goto-char (cdr langelem))
|
||||
(current-column)))
|
||||
(bocm-lossage
|
||||
;; If no previous statement, indent it relative to line
|
||||
;; brace is on. For open brace in column zero, don't let
|
||||
;; statement start there too. If c-indent-level is zero,
|
||||
;; use c-brace-offset + c-continued-statement-offset
|
||||
;; instead. For open-braces not the first thing in a line,
|
||||
;; add in c-brace-imaginary-offset.
|
||||
(+ (if (and (bolp) (zerop c-indent-level))
|
||||
(+ c-brace-offset c-continued-statement-offset)
|
||||
c-indent-level)
|
||||
;; Move back over whitespace before the openbrace. If
|
||||
;; openbrace is not first nonwhite thing on the line,
|
||||
;; add the c-brace-imaginary-offset.
|
||||
(progn (skip-chars-backward " \t")
|
||||
(if (bolp) 0 c-brace-imaginary-offset))
|
||||
;; If the openbrace is preceded by a parenthesized exp,
|
||||
;; move to the beginning of that; possibly a different
|
||||
;; line
|
||||
(progn
|
||||
(if (eq (char-before) ?\))
|
||||
(c-forward-sexp -1))
|
||||
;; Get initial indentation of the line we are on.
|
||||
(current-indentation)))))
|
||||
(- bocm-lossage curcol))))
|
||||
|
||||
|
||||
(defun cc-block-close-offset (langelem)
|
||||
(save-excursion
|
||||
(let* ((here (point))
|
||||
bracep
|
||||
(curcol (progn
|
||||
(goto-char (cdr langelem))
|
||||
(current-column)))
|
||||
(bocm-lossage (progn
|
||||
(goto-char (cdr langelem))
|
||||
(if (eq (char-after) ?{)
|
||||
(setq bracep t)
|
||||
(goto-char here)
|
||||
(beginning-of-line)
|
||||
(backward-up-list 1)
|
||||
(forward-char 1)
|
||||
(c-forward-syntactic-ws))
|
||||
(current-column))))
|
||||
(- bocm-lossage curcol
|
||||
(if bracep 0 c-indent-level)))))
|
||||
|
||||
|
||||
(defun cc-substatement-open-offset (langelem)
|
||||
(+ c-continued-statement-offset c-continued-brace-offset))
|
||||
|
||||
|
||||
(cc-provide 'cc-compat)
|
||||
;;; cc-compat.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-compat.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-compat.elc
Normal file
Binary file not shown.
354
site-lisp/cc-mode/zbrad-integrated/cc-defs.el
Normal file
354
site-lisp/cc-mode/zbrad-integrated/cc-defs.el
Normal file
|
|
@ -0,0 +1,354 @@
|
|||
;;; cc-defs.el --- compile time definitions for CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
;; cc-mode-19.el contains compatibility macros that should be used if
|
||||
;; needed.
|
||||
(eval-and-compile
|
||||
(if (or (not (fboundp 'functionp))
|
||||
(not (condition-case nil
|
||||
(progn (eval '(char-before)) t)
|
||||
(error nil)))
|
||||
(not (condition-case nil
|
||||
(progn (eval '(char-after)) t)
|
||||
(error nil)))
|
||||
(not (fboundp 'when))
|
||||
(not (fboundp 'unless)))
|
||||
(cc-load "cc-mode-19")))
|
||||
|
||||
;; Silence the compiler.
|
||||
(cc-bytecomp-defvar c-enable-xemacs-performance-kludge-p) ; In cc-vars.el
|
||||
(cc-bytecomp-defun buffer-syntactic-context-depth) ; XEmacs
|
||||
(cc-bytecomp-defun region-active-p) ; XEmacs
|
||||
(cc-bytecomp-defvar zmacs-region-stays) ; XEmacs
|
||||
(cc-bytecomp-defvar zmacs-regions) ; XEmacs
|
||||
(cc-bytecomp-defvar mark-active) ; Emacs
|
||||
(cc-bytecomp-defun scan-lists) ; 5 args in XEmacs, 3 in Emacs
|
||||
(require 'derived) ; Only necessary in Emacs
|
||||
|
||||
|
||||
;;; Macros.
|
||||
|
||||
;;; Helpers for building regexps.
|
||||
(defmacro c-paren-re (re)
|
||||
`(concat "\\(" ,re "\\)"))
|
||||
(defmacro c-identifier-re (re)
|
||||
`(concat "\\<\\(" ,re "\\)\\>[^_]"))
|
||||
|
||||
(defmacro c-point (position &optional point)
|
||||
;; Returns the value of certain commonly referenced POSITIONs
|
||||
;; relative to POINT. The current point is used if POINT isn't
|
||||
;; specified. POSITION can be one of the following symbols:
|
||||
;;
|
||||
;; bol -- beginning of line
|
||||
;; eol -- end of line
|
||||
;; bod -- beginning of defun
|
||||
;; eod -- end of defun
|
||||
;; boi -- back to indentation
|
||||
;; ionl -- indentation of next line
|
||||
;; iopl -- indentation of previous line
|
||||
;; bonl -- beginning of next line
|
||||
;; bopl -- beginning of previous line
|
||||
;;
|
||||
;; This function does not modify point or mark.
|
||||
`(save-excursion
|
||||
,(if point `(goto-char ,point))
|
||||
,(if (and (eq (car-safe position) 'quote)
|
||||
(symbolp (eval position)))
|
||||
(let ((position (eval position)))
|
||||
(cond
|
||||
((eq position 'bol) `(beginning-of-line))
|
||||
((eq position 'eol) `(end-of-line))
|
||||
((eq position 'boi) `(back-to-indentation))
|
||||
((eq position 'bonl) `(forward-line 1))
|
||||
((eq position 'bopl) `(forward-line -1))
|
||||
((eq position 'bod) `(c-beginning-of-defun-1))
|
||||
((eq position 'eod) `(c-end-of-defun-1))
|
||||
((eq position 'iopl) `(progn
|
||||
(forward-line -1)
|
||||
(back-to-indentation)))
|
||||
((eq position 'ionl) `(progn
|
||||
(forward-line 1)
|
||||
(back-to-indentation)))
|
||||
(t (error "unknown buffer position requested: %s" position))))
|
||||
;;(message "c-point long expansion")
|
||||
`(let ((position ,position))
|
||||
(cond
|
||||
((eq position 'bol) (beginning-of-line))
|
||||
((eq position 'eol) (end-of-line))
|
||||
((eq position 'boi) (back-to-indentation))
|
||||
((eq position 'bonl) (forward-line 1))
|
||||
((eq position 'bopl) (forward-line -1))
|
||||
((eq position 'bod) (c-beginning-of-defun-1))
|
||||
((eq position 'eod) (c-end-of-defun-1))
|
||||
((eq position 'iopl) (progn
|
||||
(forward-line -1)
|
||||
(back-to-indentation)))
|
||||
((eq position 'ionl) (progn
|
||||
(forward-line 1)
|
||||
(back-to-indentation)))
|
||||
(t (error "unknown buffer position requested: %s" position)))))
|
||||
(point)))
|
||||
|
||||
(defmacro c-safe (&rest body)
|
||||
;; safely execute BODY, return nil if an error occurred
|
||||
`(condition-case nil
|
||||
(progn ,@body)
|
||||
(error nil)))
|
||||
|
||||
(defmacro c-forward-sexp (&optional arg)
|
||||
;; like forward-sexp except
|
||||
;; 1. this is much stripped down from the XEmacs version
|
||||
;; 2. this cannot be used as a command, so we're insulated from
|
||||
;; XEmacs' losing efforts to make forward-sexp more user
|
||||
;; friendly
|
||||
;; 3. Preserves the semantics most of CC Mode is based on
|
||||
(or arg (setq arg 1))
|
||||
`(goto-char (or (scan-sexps (point) ,arg)
|
||||
,(if (numberp arg)
|
||||
(if (> arg 0) `(point-max) `(point-min))
|
||||
`(if (> ,arg 0) (point-max) (point-min))))))
|
||||
|
||||
(defmacro c-backward-sexp (&optional arg)
|
||||
;; See c-forward-sexp and reverse directions
|
||||
(or arg (setq arg 1))
|
||||
`(c-forward-sexp ,(if (numberp arg) (- arg) `(- ,arg))))
|
||||
|
||||
(defmacro c-add-syntax (symbol &optional relpos)
|
||||
;; a simple macro to append the syntax in symbol to the syntax list.
|
||||
;; try to increase performance by using this macro
|
||||
`(setq syntax (cons (cons ,symbol ,relpos) syntax)))
|
||||
|
||||
(defmacro c-add-class-syntax (symbol classkey)
|
||||
;; The inclass and class-close syntactic symbols are added in
|
||||
;; several places and some work is needed to fix everything.
|
||||
;; Therefore it's collected here. This is a macro mostly because
|
||||
;; c-add-syntax doesn't work otherwise.
|
||||
`(save-restriction
|
||||
(widen)
|
||||
(let ((symbol ,symbol)
|
||||
(classkey ,classkey)
|
||||
inexpr)
|
||||
(goto-char (aref classkey 1))
|
||||
(if (and (eq symbol 'inclass) (= (point) (c-point 'boi)))
|
||||
(c-add-syntax symbol (point))
|
||||
(c-add-syntax symbol (aref classkey 0))
|
||||
(if (and c-inexpr-class-key
|
||||
(setq inexpr (c-looking-at-inexpr-block))
|
||||
(/= (cdr inexpr) (c-point 'boi (cdr inexpr))))
|
||||
(c-add-syntax 'inexpr-class))))))
|
||||
|
||||
(defmacro c-update-modeline ()
|
||||
;; set the c-auto-hungry-string for the correct designation on the modeline
|
||||
`(progn
|
||||
(setq c-auto-hungry-string
|
||||
(if c-auto-newline
|
||||
(if c-hungry-delete-key "/ah" "/a")
|
||||
(if c-hungry-delete-key "/h" nil)))
|
||||
(force-mode-line-update)))
|
||||
|
||||
(defmacro c-with-syntax-table (table &rest code)
|
||||
;; Temporarily switches to the specified syntax table in a failsafe
|
||||
;; way to execute code.
|
||||
`(let ((c-with-syntax-table-orig-table (syntax-table)))
|
||||
(unwind-protect
|
||||
(progn
|
||||
(set-syntax-table ,table)
|
||||
,@code)
|
||||
(set-syntax-table c-with-syntax-table-orig-table))))
|
||||
(put 'c-with-syntax-table 'lisp-indent-function 1)
|
||||
|
||||
;;; Inline functions.
|
||||
|
||||
;; Note: All these after the macros, to be on safe side in avoiding
|
||||
;; bugs where macros are defined too late. These bugs often only show
|
||||
;; when the files are compiled in a certain order within the same
|
||||
;; session.
|
||||
|
||||
(defsubst c-beginning-of-defun-1 ()
|
||||
;; Wrapper around beginning-of-defun.
|
||||
;;
|
||||
;; NOTE: This function should contain the only explicit use of
|
||||
;; beginning-of-defun in CC Mode. Eventually something better than
|
||||
;; b-o-d will be available and this should be the only place the
|
||||
;; code needs to change. Everything else should use
|
||||
;; (c-beginning-of-defun-1)
|
||||
(if (and (fboundp 'buffer-syntactic-context-depth)
|
||||
c-enable-xemacs-performance-kludge-p)
|
||||
;; XEmacs only. This can improve the performance of
|
||||
;; c-parse-state to between 3 and 60 times faster when
|
||||
;; braces are hung. It can also degrade performance by
|
||||
;; about as much when braces are not hung.
|
||||
(let (pos)
|
||||
(while (not pos)
|
||||
(save-restriction
|
||||
(widen)
|
||||
(setq pos (scan-lists (point) -1
|
||||
(buffer-syntactic-context-depth)
|
||||
nil t)))
|
||||
(cond
|
||||
((bobp) (setq pos (point-min)))
|
||||
((not pos)
|
||||
(let ((distance (skip-chars-backward "^{")))
|
||||
;; unbalanced parenthesis, while illegal C code,
|
||||
;; shouldn't cause an infloop! See unbal.c
|
||||
(when (zerop distance)
|
||||
;; Punt!
|
||||
(beginning-of-defun)
|
||||
(setq pos (point)))))
|
||||
((= pos 0))
|
||||
((not (eq (char-after pos) ?{))
|
||||
(goto-char pos)
|
||||
(setq pos nil))
|
||||
))
|
||||
(goto-char pos))
|
||||
;; Emacs, which doesn't have buffer-syntactic-context-depth
|
||||
(beginning-of-defun))
|
||||
;; if defun-prompt-regexp is non-nil, b-o-d won't leave us at the
|
||||
;; open brace.
|
||||
(and defun-prompt-regexp
|
||||
(looking-at defun-prompt-regexp)
|
||||
(goto-char (match-end 0))))
|
||||
|
||||
(defsubst c-end-of-defun-1 ()
|
||||
;; Replacement for end-of-defun that use c-beginning-of-defun-1.
|
||||
(let ((start (point)))
|
||||
;; Skip forward into the next defun block. Don't bother to avoid
|
||||
;; comments, literals etc, since beginning-of-defun doesn't do that
|
||||
;; anyway.
|
||||
(skip-chars-forward "^}")
|
||||
(c-beginning-of-defun-1)
|
||||
(if (eq (char-after) ?{)
|
||||
(c-forward-sexp))
|
||||
(if (< (point) start)
|
||||
(goto-char (point-max)))))
|
||||
|
||||
(defsubst c-forward-comment (count)
|
||||
;; Insulation from various idiosyncrasies in implementations of
|
||||
;; `forward-comment'.
|
||||
;;
|
||||
;; Note: Some emacsen considers incorrectly that any line comment
|
||||
;; ending with a backslash continues to the next line. I can't
|
||||
;; think of any way to work around that in a reliable way without
|
||||
;; changing the buffer though. Suggestions welcome. ;)
|
||||
;;
|
||||
;; Another note: When moving backwards over a block comment, there's
|
||||
;; a bug in forward-comment that can make it stop at "/*" inside a
|
||||
;; line comment. Haven't yet found a reasonably cheap way to kludge
|
||||
;; around that one either. :\
|
||||
(let ((here (point)))
|
||||
(if (>= count 0)
|
||||
(when (forward-comment count)
|
||||
;; Emacs includes the ending newline in a b-style (c++)
|
||||
;; comment, but XEmacs doesn't. We depend on the Emacs
|
||||
;; behavior (which also is symmetric).
|
||||
(if (and (eolp) (nth 7 (parse-partial-sexp here (point))))
|
||||
(condition-case nil (forward-char 1)))
|
||||
t)
|
||||
;; When we got newline terminated comments,
|
||||
;; forward-comment in all supported emacsen so far will
|
||||
;; stop at eol of each line not ending with a comment when
|
||||
;; moving backwards. The following corrects for it when
|
||||
;; count is -1. The other common case, when count is
|
||||
;; large and negative, works regardless. It's too much
|
||||
;; work to correct for the rest of the cases.
|
||||
(skip-chars-backward " \t\n\r\f")
|
||||
(if (bobp)
|
||||
;; Some emacsen return t when moving backwards at bob.
|
||||
nil
|
||||
(re-search-forward "[\n\r]" here t)
|
||||
(if (forward-comment count)
|
||||
(if (eolp) (forward-comment -1) t))))))
|
||||
|
||||
(defsubst c-intersect-lists (list alist)
|
||||
;; return the element of ALIST that matches the first element found
|
||||
;; in LIST. Uses assq.
|
||||
(let (match)
|
||||
(while (and list
|
||||
(not (setq match (assq (car list) alist))))
|
||||
(setq list (cdr list)))
|
||||
match))
|
||||
|
||||
(defsubst c-lookup-lists (list alist1 alist2)
|
||||
;; first, find the first entry from LIST that is present in ALIST1,
|
||||
;; then find the entry in ALIST2 for that entry.
|
||||
(assq (car (c-intersect-lists list alist1)) alist2))
|
||||
|
||||
(defsubst c-langelem-col (langelem &optional preserve-point)
|
||||
;; convenience routine to return the column of langelem's relpos.
|
||||
;; Leaves point at the relpos unless preserve-point is non-nil.
|
||||
(if (cdr langelem)
|
||||
(let ((here (point)))
|
||||
(goto-char (cdr langelem))
|
||||
(prog1 (current-column)
|
||||
(if preserve-point
|
||||
(goto-char here))
|
||||
))
|
||||
0))
|
||||
|
||||
(defsubst c-keep-region-active ()
|
||||
;; Do whatever is necessary to keep the region active in XEmacs.
|
||||
;; This is not needed for Emacs.
|
||||
(and (boundp 'zmacs-region-stays)
|
||||
(setq zmacs-region-stays t)))
|
||||
|
||||
(defsubst c-region-is-active-p ()
|
||||
;; Return t when the region is active. The determination of region
|
||||
;; activeness is different in both Emacs and XEmacs.
|
||||
(cond
|
||||
;; XEmacs
|
||||
((and (fboundp 'region-active-p)
|
||||
(boundp 'zmacs-regions)
|
||||
zmacs-regions)
|
||||
(region-active-p))
|
||||
;; Emacs
|
||||
((boundp 'mark-active) mark-active)
|
||||
;; fallback; shouldn't get here
|
||||
(t (mark t))))
|
||||
|
||||
(defsubst c-major-mode-is (mode)
|
||||
(eq (derived-mode-class major-mode) mode))
|
||||
|
||||
|
||||
(cc-provide 'cc-defs)
|
||||
|
||||
;;; cc-defs.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-defs.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-defs.elc
Normal file
Binary file not shown.
2804
site-lisp/cc-mode/zbrad-integrated/cc-engine.el
Normal file
2804
site-lisp/cc-mode/zbrad-integrated/cc-engine.el
Normal file
File diff suppressed because it is too large
Load diff
BIN
site-lisp/cc-mode/zbrad-integrated/cc-engine.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-engine.elc
Normal file
Binary file not shown.
682
site-lisp/cc-mode/zbrad-integrated/cc-langs.el
Normal file
682
site-lisp/cc-mode/zbrad-integrated/cc-langs.el
Normal file
|
|
@ -0,0 +1,682 @@
|
|||
;;; cc-langs.el --- language specific settings for CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
(cc-require 'cc-defs)
|
||||
(cc-require 'cc-vars)
|
||||
|
||||
|
||||
(defvar c-buffer-is-cc-mode nil
|
||||
"Non-nil for all buffers with a `major-mode' derived from CC Mode.
|
||||
Otherwise, this variable is nil. I.e. this variable is non-nil for
|
||||
`c-mode', `c++-mode', `objc-mode', `java-mode', `idl-mode',
|
||||
`pike-mode', `csharp-mode' and any other non-CC Mode mode that calls
|
||||
`c-initialize-cc-mode' (e.g. `awk-mode').")
|
||||
(make-variable-buffer-local 'c-buffer-is-cc-mode)
|
||||
(put 'c-buffer-is-cc-mode 'permanent-local t)
|
||||
|
||||
|
||||
;; Regular expressions and other values which must be parameterized on
|
||||
;; a per-language basis.
|
||||
|
||||
;; Regex describing a `symbol' in all languages. We cannot use just
|
||||
;; `word' syntax class since `_' cannot be in word class. Putting
|
||||
;; underscore in word class breaks forward word movement behavior that
|
||||
;; users are familiar with. Besides, this runs counter to Emacs
|
||||
;; convention.
|
||||
;;
|
||||
;; I suspect this definition isn't correct in light of Java's
|
||||
;; definition of a symbol as being Unicode. I know so little about
|
||||
;; I18N (except how to sound cool and say I18N :-) that I'm willing to
|
||||
;; punt on this for now.
|
||||
(defvar c-symbol-key "[_a-zA-Z]\\(\\w\\|\\s_\\)*")
|
||||
|
||||
;; HELPME: Many of the following keyword lists are more or less bogus
|
||||
;; for some languages (notably ObjC and IDL). The effects of the
|
||||
;; erroneous values in the language handling is miniscule since these
|
||||
;; constants are not used very much (yet, anyway) in the actual syntax
|
||||
;; detection code, but I'd still appreciate help to get them correct.
|
||||
|
||||
;; Primitive type keywords.
|
||||
(defconst c-C-primitive-type-kwds
|
||||
"char\\|double\\|float\\|int\\|long\\|short\\|signed\\|unsigned\\|void")
|
||||
(defconst c-C++-primitive-type-kwds c-C-primitive-type-kwds)
|
||||
(defconst c-ObjC-primitive-type-kwds c-C-primitive-type-kwds)
|
||||
(defconst c-Java-primitive-type-kwds
|
||||
"boolean\\|byte\\|char\\|double\\|float\\|int\\|long\\|short\\|void")
|
||||
(defconst c-IDL-primitive-type-kwds c-C-primitive-type-kwds)
|
||||
(defconst c-Pike-primitive-type-kwds
|
||||
(concat "constant\\|float\\|int\\|mapping\\|multiset\\|object\\|"
|
||||
"program\\|string\\|void"))
|
||||
(defconst c-csharp-primitive-type-kwds
|
||||
(concat "bool\\|char\\|double\\|float\\|void\\|"
|
||||
"sbyte\\|int\\|long\\|short\\|"
|
||||
"byte\\|uint\\|ulong\\|ushort\\|"
|
||||
"event\\|enum\\|string\\|delegate\\|object"
|
||||
))
|
||||
|
||||
;; Declaration specifier keywords.
|
||||
(defconst c-C-specifier-kwds
|
||||
"auto\\|const\\|extern\\|register\\|static\\|volatile")
|
||||
(defconst c-C++-specifier-kwds
|
||||
(concat c-C-specifier-kwds "\\|friend\\|inline\\|virtual"))
|
||||
(defconst c-ObjC-specifier-kwds c-C++-specifier-kwds)
|
||||
(defconst c-Java-specifier-kwds
|
||||
;; Note: `const' is not used, but it's still a reserved keyword.
|
||||
(concat "abstract\\|const\\|final\\|native\\|private\\|protected\\|"
|
||||
"public\\|static\\|synchronized\\|transient\\|volatile"))
|
||||
(defconst c-IDL-specifier-kwds c-C++-specifier-kwds)
|
||||
(defconst c-Pike-specifier-kwds
|
||||
(concat "final\\|inline\\|local\\|nomask\\|optional\\|private\\|"
|
||||
"protected\\|static\\|variant"))
|
||||
|
||||
(defconst c-csharp-classmod-kwds
|
||||
(concat "sealed\\|\\new\\|abstract"
|
||||
))
|
||||
(defconst c-csharp-fieldmod-kwds
|
||||
(concat "readonly\\|\\new\\|static\\|volatile"
|
||||
))
|
||||
(defconst c-csharp-methodmod-kwds
|
||||
(concat "new\\|static\\|virtual\\|sealed\\|override\\|abstract\\|extern"
|
||||
))
|
||||
|
||||
(defconst c-csharp-specifier-kwds
|
||||
(concat c-csharp-classmod-kwds
|
||||
c-csharp-fieldmod-kwds
|
||||
c-csharp-methodmod-kwds
|
||||
))
|
||||
|
||||
;; Class/struct declaration keywords.
|
||||
(defconst c-C-class-kwds "struct\\|union")
|
||||
(defconst c-C++-class-kwds (concat c-C-class-kwds "\\|class"))
|
||||
(defconst c-ObjC-class-kwds "interface\\|implementation")
|
||||
(defconst c-Java-class-kwds "class\\|interface")
|
||||
(defconst c-IDL-class-kwds
|
||||
(concat c-C++-class-kwds "\\|interface\\|valuetype"))
|
||||
(defconst c-Pike-class-kwds "class")
|
||||
(defconst c-csharp-class-kwds "class\\|interface\\|struct")
|
||||
|
||||
;; Keywords introducing other declaration-level blocks.
|
||||
(defconst c-C-extra-toplevel-kwds "extern")
|
||||
(defconst c-C++-extra-toplevel-kwds
|
||||
(concat c-C-extra-toplevel-kwds "\\|namespace"))
|
||||
;;(defconst c-ObjC-extra-toplevel-kwds nil)
|
||||
;;(defconst c-Java-extra-toplevel-kwds nil)
|
||||
(defconst c-IDL-extra-toplevel-kwds "module")
|
||||
;;(defconst c-Pike-extra-toplevel-kwds nil)
|
||||
(defconst c-csharp-extra-toplevel-kwds "namespace")
|
||||
|
||||
;; Keywords introducing other declaration-level constructs.
|
||||
(defconst c-C-other-decl-kwds "enum\\|typedef")
|
||||
(defconst c-C++-other-decl-kwds (concat c-C-other-decl-kwds "\\|template"))
|
||||
;;(defconst c-ObjC-other-decl-kwds nil)
|
||||
(defconst c-Java-other-decl-kwds "import\\|package")
|
||||
;;(defconst c-IDL-other-decl-kwds nil)
|
||||
(defconst c-Pike-other-decl-kwds "import\\|inherit")
|
||||
(defconst c-csharp-other-decl-kwds "using")
|
||||
|
||||
;; Keywords that occur in declaration-level constructs.
|
||||
;;(defconst c-C-decl-level-kwds nil)
|
||||
;;(defconst c-C++-decl-level-kwds nil)
|
||||
;;(defconst c-ObjC-decl-level-kwds nil)
|
||||
(defconst c-Java-decl-level-kwds "extends\\|implements\\|throws")
|
||||
;;(defconst c-IDL-decl-level-kwds nil)
|
||||
;;(defconst c-Pike-decl-level-kwds nil)
|
||||
;;(defconst c-csharp-decl-level-kwds nil)
|
||||
|
||||
;; Protection label keywords in classes.
|
||||
;;(defconst c-C-protection-kwds nil)
|
||||
(defconst c-C++-protection-kwds "private\\|protected\\|public")
|
||||
(defconst c-ObjC-protection-kwds c-C++-protection-kwds)
|
||||
;;(defconst c-Java-protection-kwds nil)
|
||||
;;(defconst c-IDL-protection-kwds nil)
|
||||
;;(defconst c-Pike-protection-kwds nil)
|
||||
(defconst c-csharp-protection-kwds "private\\|protected\\|public\\|internal")
|
||||
|
||||
(defconst c-C-protection-key "\\<\\(public\\|protected\\|private\\)\\>")
|
||||
(defconst c-csharp-protection-key (c-paren-re c-csharp-protection-kwds))
|
||||
|
||||
;; Keywords defining protection levels
|
||||
(defvar c-protection-key c-C-protection-key)
|
||||
;(defvar c-protection-key c-csharp-protection-key)
|
||||
(make-variable-buffer-local 'c-protection-key)
|
||||
|
||||
;; Statement keywords followed directly by a block.
|
||||
(defconst c-C-block-stmt-1-kwds "do\\|else")
|
||||
(defconst c-C++-block-stmt-1-kwds
|
||||
(concat c-C-block-stmt-1-kwds "\\|asm\\|try"))
|
||||
(defconst c-ObjC-block-stmt-1-kwds c-C++-block-stmt-1-kwds)
|
||||
(defconst c-Java-block-stmt-1-kwds
|
||||
(concat c-C-block-stmt-1-kwds "\\|finally\\|try"))
|
||||
;;(defconst c-IDL-block-stmt-1-kwds nil)
|
||||
(defconst c-Pike-block-stmt-1-kwds c-C-block-stmt-1-kwds)
|
||||
(defconst c-csharp-block-stmt-1-kwds
|
||||
(concat c-C-block-stmt-1-kwds "\\|finally\\|try"))
|
||||
|
||||
|
||||
;; Statement keywords followed by a paren sexp and then by a block.
|
||||
(defconst c-C-block-stmt-2-kwds "for\\|if\\|switch\\|while")
|
||||
(defconst c-C++-block-stmt-2-kwds (concat c-C-block-stmt-2-kwds "\\|catch"))
|
||||
(defconst c-ObjC-block-stmt-2-kwds c-C++-block-stmt-2-kwds)
|
||||
(defconst c-Java-block-stmt-2-kwds
|
||||
(concat c-C++-block-stmt-2-kwds "\\|synchronized"))
|
||||
;;(defconst c-IDL-block-stmt-2-kwds nil)
|
||||
(defconst c-Pike-block-stmt-2-kwds c-C-block-stmt-2-kwds)
|
||||
(defconst c-csharp-block-stmt-2-kwds
|
||||
(concat c-C++-block-stmt-2-kwds
|
||||
"\\|foreach\\|lock\\|checked\\|unchecked\\|fixed"
|
||||
))
|
||||
|
||||
;; Statement keywords followed by an expression or nothing.
|
||||
(defconst c-C-simple-stmt-kwds "break\\|continue\\|goto\\|return")
|
||||
(defconst c-C++-simple-stmt-kwds c-C-simple-stmt-kwds)
|
||||
(defconst c-ObjC-simple-stmt-kwds c-C-simple-stmt-kwds)
|
||||
(defconst c-Java-simple-stmt-kwds
|
||||
;; Note: `goto' is not a valid statement, but the keyword is still reserved.
|
||||
(concat c-C-simple-stmt-kwds "\\|throw"))
|
||||
;;(defconst c-IDL-simple-stmt-kwds nil)
|
||||
(defconst c-Pike-simple-stmt-kwds "break\\|continue\\|return")
|
||||
(defconst c-csharp-simple-stmt-kwds
|
||||
(concat c-C-simple-stmt-kwds "\\|throw"))
|
||||
|
||||
;; Keywords introducing labels in blocks.
|
||||
(defconst c-C-label-kwds "case\\|default")
|
||||
(defconst c-C++-label-kwds c-C-label-kwds)
|
||||
(defconst c-ObjC-label-kwds c-C-label-kwds)
|
||||
(defconst c-Java-label-kwds c-C-label-kwds)
|
||||
;;(defconst c-IDL-label-kwds nil)
|
||||
(defconst c-Pike-label-kwds c-C-label-kwds)
|
||||
(defconst c-csharp-label-kwds c-C-label-kwds)
|
||||
|
||||
;; Keywords that can occur anywhere in expressions.
|
||||
(defconst c-C-expr-kwds "sizeof")
|
||||
(defconst c-C++-expr-kwds
|
||||
(concat c-C-expr-kwds "\\|delete\\|new\\|operator\\|this\\|throw"))
|
||||
(defconst c-ObjC-expr-kwds c-C-expr-kwds)
|
||||
(defconst c-Java-expr-kwds "instanceof\\|new\\|super\\|this")
|
||||
;;(defconst c-IDL-expr-kwds nil)
|
||||
(defconst c-Pike-expr-kwds
|
||||
(concat c-C-expr-kwds "\\|catch\\|class\\|gauge\\|lambda\\|predef"))
|
||||
(defconst c-csharp-expr-kwds
|
||||
(concat "as\\|is\\|new\\|"
|
||||
"sizeof\\|typeof\\|stackalloc\\|checked\\|unchecked\\|"
|
||||
"base\\|this"
|
||||
))
|
||||
|
||||
;; All keywords.
|
||||
(defconst c-C-keywords
|
||||
(concat c-C-primitive-type-kwds "\\|" c-C-specifier-kwds
|
||||
"\\|" c-C-class-kwds "\\|" c-C-extra-toplevel-kwds
|
||||
"\\|" c-C-other-decl-kwds
|
||||
;; "\\|" c-C-decl-level-kwds "\\|" c-C-protection-kwds
|
||||
"\\|" c-C-block-stmt-1-kwds "\\|" c-C-block-stmt-2-kwds
|
||||
"\\|" c-C-simple-stmt-kwds "\\|" c-C-label-kwds
|
||||
"\\|" c-C-expr-kwds))
|
||||
(defconst c-C++-keywords
|
||||
(concat c-C++-primitive-type-kwds "\\|" c-C++-specifier-kwds
|
||||
"\\|" c-C++-class-kwds "\\|" c-C++-extra-toplevel-kwds
|
||||
"\\|" c-C++-other-decl-kwds
|
||||
;; "\\|" c-C++-decl-level-kwds
|
||||
"\\|" c-C++-protection-kwds
|
||||
"\\|" c-C++-block-stmt-1-kwds "\\|" c-C++-block-stmt-2-kwds
|
||||
"\\|" c-C++-simple-stmt-kwds "\\|" c-C++-label-kwds
|
||||
"\\|" c-C++-expr-kwds))
|
||||
(defconst c-ObjC-keywords
|
||||
(concat c-ObjC-primitive-type-kwds "\\|" c-ObjC-specifier-kwds
|
||||
"\\|" c-ObjC-class-kwds
|
||||
;; "\\|" c-ObjC-extra-toplevel-kwds
|
||||
;; "\\|" c-ObjC-other-decl-kwds "\\|" c-ObjC-decl-level-kwds
|
||||
"\\|" c-ObjC-protection-kwds
|
||||
"\\|" c-ObjC-block-stmt-1-kwds "\\|" c-ObjC-block-stmt-2-kwds
|
||||
"\\|" c-ObjC-simple-stmt-kwds "\\|" c-ObjC-label-kwds
|
||||
"\\|" c-ObjC-expr-kwds))
|
||||
(defconst c-Java-keywords
|
||||
(concat c-Java-primitive-type-kwds "\\|" c-Java-specifier-kwds
|
||||
"\\|" c-Java-class-kwds
|
||||
;; "\\|" c-Java-extra-toplevel-kwds
|
||||
"\\|" c-Java-other-decl-kwds "\\|" c-Java-decl-level-kwds
|
||||
;; "\\|" c-Java-protection-kwds
|
||||
"\\|" c-Java-block-stmt-1-kwds "\\|" c-Java-block-stmt-2-kwds
|
||||
"\\|" c-Java-simple-stmt-kwds "\\|" c-Java-label-kwds
|
||||
"\\|" c-Java-expr-kwds))
|
||||
(defconst c-IDL-keywords
|
||||
(concat c-IDL-primitive-type-kwds "\\|" c-IDL-specifier-kwds
|
||||
"\\|" c-IDL-class-kwds "\\|" c-IDL-extra-toplevel-kwds
|
||||
;; "\\|" c-IDL-other-decl-kwds "\\|" c-IDL-decl-level-kwds
|
||||
;; "\\|" c-IDL-protection-kwds
|
||||
;; "\\|" c-IDL-block-stmt-1-kwds "\\|" c-IDL-block-stmt-2-kwds
|
||||
;; "\\|" c-IDL-simple-stmt-kwds "\\|" c-IDL-label-kwds
|
||||
;; "\\|" c-IDL-expr-kwds)
|
||||
))
|
||||
(defconst c-Pike-keywords
|
||||
(concat c-Pike-primitive-type-kwds "\\|" c-Pike-specifier-kwds
|
||||
"\\|" c-Pike-class-kwds
|
||||
;; "\\|" c-Pike-extra-toplevel-kwds
|
||||
"\\|" c-Pike-other-decl-kwds
|
||||
;; "\\|" c-Pike-decl-level-kwds "\\|" c-Pike-protection-kwds
|
||||
"\\|" c-Pike-block-stmt-1-kwds "\\|" c-Pike-block-stmt-2-kwds
|
||||
"\\|" c-Pike-simple-stmt-kwds "\\|" c-Pike-label-kwds
|
||||
"\\|" c-Pike-expr-kwds))
|
||||
(defconst c-csharp-keywords
|
||||
(concat c-csharp-primitive-type-kwds
|
||||
"\\|" c-csharp-specifier-kwds
|
||||
"\\|" c-csharp-class-kwds
|
||||
"\\|" c-csharp-extra-toplevel-kwds
|
||||
"\\|" c-csharp-other-decl-kwds
|
||||
"\\|" c-csharp-protection-kwds
|
||||
"\\|" c-csharp-block-stmt-1-kwds
|
||||
"\\|" c-csharp-block-stmt-2-kwds
|
||||
"\\|" c-csharp-simple-stmt-kwds
|
||||
"\\|" c-csharp-label-kwds
|
||||
"\\|" c-csharp-expr-kwds))
|
||||
|
||||
(defvar c-keywords nil)
|
||||
(make-variable-buffer-local 'c-keywords)
|
||||
|
||||
;; Regexps introducing class definitions.
|
||||
(defconst c-C-class-key (c-paren-re c-C-class-kwds))
|
||||
(defconst c-C++-class-key (c-paren-re c-C++-class-kwds))
|
||||
(defconst c-IDL-class-key (c-paren-re c-IDL-class-kwds))
|
||||
(defconst c-ObjC-class-key
|
||||
(concat
|
||||
"@\\(" c-ObjC-class-kwds "\\)\\s +"
|
||||
c-symbol-key ;name of the class
|
||||
"\\(\\s *:\\s *" c-symbol-key "\\)?" ;maybe followed by the superclass
|
||||
"\\(\\s *<[^>]+>\\)?" ;and maybe the adopted protocols list
|
||||
))
|
||||
(defconst c-Java-class-key
|
||||
(concat
|
||||
"\\(" c-C-protection-key "\\s +\\)?"
|
||||
"\\(" c-Java-class-kwds "\\)\\s +"
|
||||
c-symbol-key ;name of the class
|
||||
"\\(\\s *extends\\s *" c-symbol-key "\\)?" ;maybe followed by superclass
|
||||
;;"\\(\\s *implements *[^{]+{\\)?" ;maybe the adopted protocols list
|
||||
))
|
||||
(defconst c-Pike-class-key (c-paren-re c-Pike-class-kwds))
|
||||
|
||||
(defconst c-csharp-class-key
|
||||
(concat
|
||||
; "\\(\\[[^]]+\\][ \t\n]+\\)*"
|
||||
"\\(\\(" c-csharp-protection-kwds "\\|" c-csharp-classmod-kwds
|
||||
"\\)*[ \t\n]+\\)?"
|
||||
"\\(" c-csharp-class-kwds "\\)"
|
||||
"[ \tn\]+"
|
||||
"\\(\\(" c-symbol-key "[ \t\n]*.[ \t\n]*\\)+\\)?"
|
||||
c-symbol-key
|
||||
))
|
||||
|
||||
(defvar c-class-key c-C-class-key)
|
||||
(make-variable-buffer-local 'c-class-key)
|
||||
|
||||
(defconst c-C-extra-toplevel-key (c-paren-re c-C-extra-toplevel-kwds))
|
||||
(defconst c-C++-extra-toplevel-key (c-paren-re c-C++-extra-toplevel-kwds))
|
||||
(defconst c-IDL-extra-toplevel-key (c-paren-re c-IDL-extra-toplevel-kwds))
|
||||
(defconst c-csharp-extra-toplevel-key (c-paren-re c-csharp-extra-toplevel-kwds))
|
||||
|
||||
(defvar c-extra-toplevel-key c-C-extra-toplevel-key)
|
||||
(make-variable-buffer-local 'c-extra-toplevel-key)
|
||||
|
||||
;; Keywords that can introduce bitfields in the languages that supports that.
|
||||
(defconst c-C-bitfield-key "\\(char\\|int\\|long\\|signed\\|unsigned\\)")
|
||||
|
||||
(defvar c-bitfield-key nil)
|
||||
(make-variable-buffer-local 'c-bitfield-key)
|
||||
|
||||
;; regexp describing access protection clauses. language specific
|
||||
(defvar c-access-key nil)
|
||||
(make-variable-buffer-local 'c-access-key)
|
||||
(defconst c-C++-access-key
|
||||
(concat "\\<\\(" c-C++-protection-kwds "\\)\\>[ \t]*:"))
|
||||
;;(defconst c-IDL-access-key nil)
|
||||
(defconst c-ObjC-access-key (concat "@" c-C-protection-key))
|
||||
;;(defconst c-Java-access-key nil)
|
||||
;;(defconst c-Pike-access-key nil)
|
||||
(defconst c-csharp-access-key
|
||||
(concat "\\<\\(" c-csharp-protection-kwds "\\)\\>"))
|
||||
|
||||
;; keywords introducing conditional blocks
|
||||
(defconst c-C-conditional-key nil)
|
||||
(defconst c-C++-conditional-key nil)
|
||||
(defconst c-IDL-conditional-key nil)
|
||||
(defconst c-ObjC-conditional-key nil)
|
||||
(defconst c-Java-conditional-key nil)
|
||||
(defconst c-Pike-conditional-key nil)
|
||||
(defconst c-csharp-conditional-key nil)
|
||||
|
||||
(let ((all-kws "for\\|if\\|do\\|else\\|while\\|switch")
|
||||
(exc-kws "\\|try\\|catch")
|
||||
(thr-kws "\\|finally\\|synchronized")
|
||||
(front "\\<\\(")
|
||||
(back "\\)\\>[^_]"))
|
||||
(setq c-C-conditional-key (concat front all-kws back)
|
||||
c-C++-conditional-key (concat front all-kws exc-kws back)
|
||||
;; c-IDL-conditional-key is nil.
|
||||
c-ObjC-conditional-key c-C-conditional-key
|
||||
c-Java-conditional-key (concat front all-kws exc-kws thr-kws back)
|
||||
c-Pike-conditional-key (concat front all-kws "\\|foreach" back)
|
||||
c-csharp-conditional-key (concat front
|
||||
all-kws exc-kws
|
||||
"\\|finally\\|"
|
||||
"foreach\\|lock\\|"
|
||||
"checked\\|unchecked\\|fixed"
|
||||
back
|
||||
)
|
||||
))
|
||||
|
||||
(defvar c-conditional-key c-C-conditional-key)
|
||||
(make-variable-buffer-local 'c-conditional-key)
|
||||
|
||||
;; keywords describing method definition introductions
|
||||
(defvar c-method-key nil)
|
||||
(make-variable-buffer-local 'c-method-key)
|
||||
|
||||
(defconst c-csharp-method-key
|
||||
(concat
|
||||
; "\\(\\[[^]]+\\][ \t\n]+\\)*"
|
||||
"\\(\\(" c-csharp-protection-kwds "\\|" c-csharp-methodmod-kwds
|
||||
"\\)[ \t\n]+\\)*"
|
||||
"\\(" c-csharp-primitive-type-kwds "\\|"
|
||||
"\\(\\(" c-symbol-key "[ \t\n]*.[ \t\n]*\\)*" c-symbol-key "\\)"
|
||||
"\\)"
|
||||
"[ \t\n]+"
|
||||
"\\(" c-symbol-key "[ \t\n]*.[ \t\n]*\\)*" c-symbol-key "[ \t\n]*("
|
||||
))
|
||||
|
||||
(defconst c-ObjC-method-key
|
||||
(concat
|
||||
"^\\s *[+-]\\s *"
|
||||
"\\(([^)]*)\\)?" ; return type
|
||||
;; \\s- in objc syntax table does not include \n
|
||||
;; since it is considered the end of //-comments.
|
||||
"[ \t\n]*" c-symbol-key))
|
||||
|
||||
;; comment starter definitions for various languages. language specific
|
||||
(defconst c-C++-comment-start-regexp "/[/*]")
|
||||
(defconst c-C-comment-start-regexp c-C++-comment-start-regexp)
|
||||
(defconst c-IDL-comment-start-regexp c-C++-comment-start-regexp)
|
||||
(defconst c-ObjC-comment-start-regexp c-C++-comment-start-regexp)
|
||||
(defconst c-Pike-comment-start-regexp c-C++-comment-start-regexp)
|
||||
;; We need to match all 3 Java style comments
|
||||
;; 1) Traditional C block; 2) javadoc /** ...; 3) C++ style
|
||||
(defconst c-Java-comment-start-regexp "/\\(/\\|[*][*]?\\)")
|
||||
(defconst c-csharp-comment-start-regexp "/\\(//?\\|[*]\\)")
|
||||
(defvar c-comment-start-regexp c-C++-comment-start-regexp)
|
||||
(make-variable-buffer-local 'c-comment-start-regexp)
|
||||
|
||||
;; Regexp describing a switch's case or default label for all languages
|
||||
(defconst c-switch-label-key "\\(\\(case[( \t]+\\S .*\\)\\|default[ \t]*\\):")
|
||||
;; Regexp describing any label.
|
||||
(defconst c-C-label-key (concat c-symbol-key ":\\([^:]\\|$\\)"))
|
||||
(defconst c-csharp-label-key (concat c-symbol-key ":\\([^:]\\|$\\)"))
|
||||
(defvar c-label-key c-C-label-key)
|
||||
(make-variable-buffer-local 'c-label-key)
|
||||
|
||||
|
||||
;; Regexp describing class inheritance declarations. TBD: this should
|
||||
;; be language specific, and only makes sense for C++
|
||||
(defconst c-C++-inher-key
|
||||
(concat "\\(\\<static\\>\\s +\\)?"
|
||||
c-C++-class-key "[ \t]+" c-symbol-key
|
||||
"\\([ \t]*:[ \t]*\\)\\s *[^;]"))
|
||||
|
||||
(defconst c-csharp-inher-key
|
||||
(concat c-csharp-class-key "[ \t\n]*:[^{]"))
|
||||
;; default to c++
|
||||
(defvar c-inher-key c-C++-inher-key)
|
||||
|
||||
;; Regexp describing C++ base classes in a derived class definition.
|
||||
;; TBD: this should be language specific, and only makes sense for C++
|
||||
(defvar c-baseclass-key
|
||||
(concat
|
||||
":?[ \t]*\\(virtual[ \t]+\\)?\\("
|
||||
c-C-protection-key "[ \t]+\\)" c-symbol-key))
|
||||
(make-variable-buffer-local 'c-baseclass-key)
|
||||
|
||||
;; Regexp describing friend declarations in C++ classes.
|
||||
(defconst c-C++-friend-key
|
||||
"friend[ \t]+\\|template[ \t]*<.+>[ \t]*friend[ \t]+")
|
||||
|
||||
;; Regexp describing Java inheritance and throws clauses.
|
||||
(defconst c-Java-special-key "\\(implements\\|extends\\|throws\\)[^_]")
|
||||
|
||||
;; Regexp describing the beginning of a Java top-level definition.
|
||||
(defconst c-Java-defun-prompt-regexp
|
||||
"^[ \t]*\\(\\(\\(public\\|protected\\|private\\|const\\|abstract\\|synchronized\\|final\\|static\\|threadsafe\\|transient\\|native\\|volatile\\)\\s-+\\)*\\(\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*[][_$.a-zA-Z0-9]+\\|[[a-zA-Z]\\)\\s-*\\)\\s-+\\)\\)?\\(\\([[a-zA-Z][][_$.a-zA-Z0-9]*\\s-+\\)\\s-*\\)?\\([_a-zA-Z][^][ \t:;.,{}()=]*\\|\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)\\)\\s-*\\(([^);{}]*)\\)?\\([] \t]*\\)\\(\\s-*\\<throws\\>\\s-*\\(\\([_$a-zA-Z][_$.a-zA-Z0-9]*\\)[, \t\n\r\f]*\\)+\\)?\\s-*")
|
||||
|
||||
;; Regexp to append to paragraph-start.
|
||||
(defvar c-append-paragraph-start "$")
|
||||
(make-variable-buffer-local 'c-append-paragraph-start)
|
||||
(defconst c-Java-javadoc-paragraph-start
|
||||
"\\(@[a-zA-Z]+\\>\\|$\\)")
|
||||
(defconst c-Pike-pikedoc-paragraph-start
|
||||
"\\(@[a-zA-Z]+\\>\\([^{]\\|$\\)\\|$\\)")
|
||||
(defconst c-csharp-xmldoc-paragraph-start
|
||||
"<\\(remarks\\|summary\\|value\\)[^>]+>")
|
||||
|
||||
|
||||
;; Regexp to append to paragraph-separate.
|
||||
(defvar c-append-paragraph-separate "$")
|
||||
(make-variable-buffer-local 'c-append-paragraph-separate)
|
||||
(defconst c-Pike-pikedoc-paragraph-separate c-Pike-pikedoc-paragraph-start)
|
||||
(defconst c-csharp-xmldoc-paragraph-separate "<para>")
|
||||
|
||||
;; Regexp that starts lambda constructs.
|
||||
(defvar c-lambda-key nil)
|
||||
(make-variable-buffer-local 'c-lambda-key)
|
||||
(defconst c-Pike-lambda-key "\\<lambda\\>")
|
||||
|
||||
;; Regexp that are followed by a statement block in expressions.
|
||||
(defvar c-inexpr-block-key nil)
|
||||
(make-variable-buffer-local 'c-inexpr-block-key)
|
||||
(defconst c-Pike-inexpr-block-key "\\<\\(catch\\|gauge\\)\\>")
|
||||
|
||||
;; Regexp that may be followed by an anonymous class in expressions.
|
||||
(defvar c-inexpr-class-key nil)
|
||||
(make-variable-buffer-local 'c-inexpr-class-key)
|
||||
(defconst c-Java-inexpr-class-key "\\<new\\>")
|
||||
(defconst c-Pike-inexpr-class-key "\\<class\\>")
|
||||
;; inner classes in C# not coming until v2
|
||||
|
||||
;; List of open- and close-chars that makes up a pike-style brace
|
||||
;; list, ie for a `([ ])' list there should be a cons (?\[ . ?\]) in
|
||||
;; this list.
|
||||
(defvar c-special-brace-lists nil)
|
||||
(make-variable-buffer-local 'c-special-brace-lists)
|
||||
(defconst c-Pike-special-brace-lists '((?{ . ?})
|
||||
(?\[ . ?\])
|
||||
(?< . ?>)))
|
||||
|
||||
;;;;
|
||||
;; regexp for C# attributes
|
||||
(defconst c-csharp-attribute-key
|
||||
(concat "\\[[ \t\n]*"
|
||||
c-symbol-key
|
||||
"[ \t\n]*"
|
||||
"\\((" "\\)?"
|
||||
"\\]"
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
;; Syntax tables.
|
||||
|
||||
(defun c-populate-syntax-table (table)
|
||||
;; Populate the syntax TABLE
|
||||
;; DO NOT TRY TO SET _ (UNDERSCORE) TO WORD CLASS!
|
||||
(modify-syntax-entry ?_ "_" table)
|
||||
(modify-syntax-entry ?\\ "\\" table)
|
||||
(modify-syntax-entry ?+ "." table)
|
||||
(modify-syntax-entry ?- "." table)
|
||||
(modify-syntax-entry ?= "." table)
|
||||
(modify-syntax-entry ?% "." table)
|
||||
(modify-syntax-entry ?< "." table)
|
||||
(modify-syntax-entry ?> "." table)
|
||||
(modify-syntax-entry ?& "." table)
|
||||
(modify-syntax-entry ?| "." table)
|
||||
(modify-syntax-entry ?\' "\"" table)
|
||||
;; Set up block and line oriented comments. The new C standard
|
||||
;; mandates both comment styles even in C, so since all languages
|
||||
;; now require dual comments, we make this the default.
|
||||
(cond
|
||||
;; XEmacs 19 & 20
|
||||
((memq '8-bit c-emacs-features)
|
||||
(modify-syntax-entry ?/ ". 1456" table)
|
||||
(modify-syntax-entry ?* ". 23" table))
|
||||
;; Emacs 19 & 20
|
||||
((memq '1-bit c-emacs-features)
|
||||
(modify-syntax-entry ?/ ". 124b" table)
|
||||
(modify-syntax-entry ?* ". 23" table))
|
||||
;; incompatible
|
||||
(t (error "CC Mode is incompatible with this version of Emacs"))
|
||||
)
|
||||
(modify-syntax-entry ?\n "> b" table)
|
||||
;; Give CR the same syntax as newline, for selective-display
|
||||
(modify-syntax-entry ?\^m "> b" table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar c-mode-syntax-table nil
|
||||
"Syntax table used in c-mode buffers.")
|
||||
(if c-mode-syntax-table
|
||||
()
|
||||
(setq c-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table c-mode-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar c++-mode-syntax-table nil
|
||||
"Syntax table used in c++-mode buffers.")
|
||||
(if c++-mode-syntax-table
|
||||
()
|
||||
(setq c++-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table c++-mode-syntax-table)
|
||||
;; TBD: does it make sense for colon to be symbol class in C++?
|
||||
;; I'm not so sure, since c-label-key is busted on lines like:
|
||||
;; Foo::bar( i );
|
||||
;; maybe c-label-key should be fixed instead of commenting this out,
|
||||
;; but it also bothers me that this only seems appropriate for C++
|
||||
;; and not C.
|
||||
;;(modify-syntax-entry ?: "_" c++-mode-syntax-table)
|
||||
)
|
||||
|
||||
(defvar c++-template-syntax-table nil
|
||||
"A variant of `c++-mode-syntax-table' that defines `<' and `>' as
|
||||
parenthesis characters. Used temporarily when template argument lists
|
||||
are parsed.")
|
||||
(if c++-template-syntax-table
|
||||
()
|
||||
(setq c++-template-syntax-table
|
||||
(copy-syntax-table c++-mode-syntax-table))
|
||||
(modify-syntax-entry ?< "(>" c++-template-syntax-table)
|
||||
(modify-syntax-entry ?> ")<" c++-template-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar objc-mode-syntax-table nil
|
||||
"Syntax table used in objc-mode buffers.")
|
||||
(if objc-mode-syntax-table
|
||||
()
|
||||
(setq objc-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table objc-mode-syntax-table)
|
||||
;; add extra Objective-C only syntax
|
||||
(modify-syntax-entry ?@ "_" objc-mode-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar java-mode-syntax-table nil
|
||||
"Syntax table used in java-mode buffers.")
|
||||
(if java-mode-syntax-table
|
||||
()
|
||||
(setq java-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table java-mode-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar idl-mode-syntax-table nil
|
||||
"Syntax table used in idl-mode buffers.")
|
||||
(if idl-mode-syntax-table
|
||||
nil
|
||||
(setq idl-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table idl-mode-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar pike-mode-syntax-table nil
|
||||
"Syntax table used in pike-mode buffers.")
|
||||
(if pike-mode-syntax-table
|
||||
()
|
||||
(setq pike-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table pike-mode-syntax-table)
|
||||
(modify-syntax-entry ?@ "." pike-mode-syntax-table))
|
||||
|
||||
;;;###autoload
|
||||
(defvar csharp-mode-syntax-table nil
|
||||
"Syntax table used in C# mode buffers.")
|
||||
(if csharp-mode-syntax-table
|
||||
()
|
||||
(setq csharp-mode-syntax-table (make-syntax-table))
|
||||
(c-populate-syntax-table csharp-mode-syntax-table))
|
||||
;; @keyword can be used
|
||||
(modify-syntax-entry ?@ "_" csharp-mode-syntax-table)
|
||||
|
||||
;; try to treat "." as part of the sexp
|
||||
;; (modify-syntax-entry ?. "_" csharp-mode-syntax-table)
|
||||
;; try to treat "." as part of the word
|
||||
;; (modify-syntax-entry ?. "w" csharp-mode-syntax-table)
|
||||
|
||||
|
||||
;; internal state variables
|
||||
|
||||
;; Internal state of hungry delete key feature
|
||||
(defvar c-hungry-delete-key nil)
|
||||
(make-variable-buffer-local 'c-hungry-delete-key)
|
||||
|
||||
;; Internal state of auto newline feature.
|
||||
(defvar c-auto-newline nil)
|
||||
(make-variable-buffer-local 'c-auto-newline)
|
||||
|
||||
;; Internal auto-newline/hungry-delete designation string for mode line.
|
||||
(defvar c-auto-hungry-string nil)
|
||||
(make-variable-buffer-local 'c-auto-hungry-string)
|
||||
|
||||
;; Non-nil means K&R style argument declarations are valid.
|
||||
(defvar c-recognize-knr-p t)
|
||||
(make-variable-buffer-local 'c-recognize-knr-p)
|
||||
|
||||
|
||||
(cc-provide 'cc-langs)
|
||||
|
||||
;;; cc-langs.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-langs.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-langs.elc
Normal file
Binary file not shown.
457
site-lisp/cc-mode/zbrad-integrated/cc-menus.el
Normal file
457
site-lisp/cc-mode/zbrad-integrated/cc-menus.el
Normal file
|
|
@ -0,0 +1,457 @@
|
|||
;;; cc-menus.el --- imenu support for CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
;; Try to pull in imenu if it exists.
|
||||
(condition-case nil
|
||||
(require 'imenu)
|
||||
(error nil))
|
||||
|
||||
;; The things referenced in imenu, which we don't require.
|
||||
(cc-bytecomp-defvar imenu-case-fold-search)
|
||||
(cc-bytecomp-defvar imenu-generic-expression)
|
||||
(cc-bytecomp-defun imenu-progress-message)
|
||||
|
||||
|
||||
;; imenu integration
|
||||
(defvar cc-imenu-c-prototype-macro-regexp nil
|
||||
"RE matching macro names used to conditionally specify function prototypes.
|
||||
|
||||
For example:
|
||||
|
||||
#ifdef __STDC__
|
||||
#define _P(x) x
|
||||
#else
|
||||
#define _P(x) /*nothing*/
|
||||
#endif
|
||||
|
||||
int main _P( (int argc, char *argv[]) )
|
||||
|
||||
A sample value might look like: `\\(_P\\|_PROTO\\)'.")
|
||||
|
||||
(defvar cc-imenu-c++-generic-expression
|
||||
`(
|
||||
;; Try to match ::operator definitions first. Otherwise `X::operator new ()'
|
||||
;; will be incorrectly recognised as function `new ()' because the regexps
|
||||
;; work by backtracking from the end of the definition.
|
||||
(nil
|
||||
,(concat
|
||||
"^\\<.*"
|
||||
"[^a-zA-Z0-9_:<>~]" ; match any non-identifier char
|
||||
; (note: this can be `\n')
|
||||
"\\("
|
||||
"\\([a-zA-Z0-9_:<>~]*::\\)?" ; match an operator
|
||||
"operator\\>[ \t]*"
|
||||
"\\(()\\|[^(]*\\)" ; special case for `()' operator
|
||||
"\\)"
|
||||
|
||||
"[ \t]*([^)]*)[ \t]*[^ \t;]" ; followed by ws, arg list,
|
||||
; require something other than
|
||||
; a `;' after the (...) to
|
||||
; avoid prototypes. Can't
|
||||
; catch cases with () inside
|
||||
; the parentheses surrounding
|
||||
; the parameters. e.g.:
|
||||
; `int foo(int a=bar()) {...}'
|
||||
) 1)
|
||||
;; Special case to match a line like `main() {}'
|
||||
;; e.g. no return type, not even on the previous line.
|
||||
(nil
|
||||
,(concat
|
||||
"^"
|
||||
"\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name
|
||||
"[ \t]*(" ; see above, BUT
|
||||
"[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start
|
||||
"[ \t]*[^ \t;(]" ; with an asterisk or parentheses
|
||||
) 1)
|
||||
;; General function name regexp
|
||||
(nil
|
||||
,(concat
|
||||
"^\\<" ; line MUST start with word char
|
||||
"[^()]*" ; no parentheses before
|
||||
"[^a-zA-Z0-9_:<>~]" ; match any non-identifier char
|
||||
"\\([a-zA-Z_][a-zA-Z0-9_:<>~]*\\)" ; match function name
|
||||
"[ \t]*(" ; see above, BUT
|
||||
"[ \t]*\\([^ \t(*][^)]*\\)?)" ; the arg list must not start
|
||||
"[ \t]*[^ \t;(]" ; with an asterisk or parentheses
|
||||
) 1)
|
||||
;; Special case for definitions using phony prototype macros like:
|
||||
;; `int main _PROTO( (int argc,char *argv[]) )'.
|
||||
;; This case is only included if cc-imenu-c-prototype-macro-regexp is set.
|
||||
;; Only supported in c-code, so no `:<>~' chars in function name!
|
||||
,@(if cc-imenu-c-prototype-macro-regexp
|
||||
`((nil
|
||||
,(concat
|
||||
"^\\<.*" ; line MUST start with word char
|
||||
"[^a-zA-Z0-9_]" ; match any non-identifier char
|
||||
"\\([a-zA-Z_][a-zA-Z0-9_]*\\)" ; match function name
|
||||
"[ \t]*" ; whitespace before macro name
|
||||
cc-imenu-c-prototype-macro-regexp
|
||||
"[ \t]*(" ; ws followed by first paren.
|
||||
"[ \t]*([^)]*)[ \t]*)[ \t]*[^ \t;]" ; see above
|
||||
) 1)))
|
||||
;; Class definitions
|
||||
("Class"
|
||||
,(concat
|
||||
"^" ; beginning of line is required
|
||||
"\\(template[ \t]*<[^>]+>[ \t]*\\)?" ; there may be a `template <...>'
|
||||
"\\(class\\|struct\\)[ \t]+"
|
||||
"\\(" ; the string we want to get
|
||||
"[a-zA-Z0-9_]+" ; class name
|
||||
"\\(<[^>]+>\\)?" ; possibly explicitly specialized
|
||||
"\\)"
|
||||
"[ \t\n]*[:{]"
|
||||
) 3))
|
||||
"Imenu generic expression for C++ mode. See `imenu-generic-expression'.")
|
||||
|
||||
(defvar cc-imenu-c-generic-expression
|
||||
cc-imenu-c++-generic-expression
|
||||
"Imenu generic expression for C mode. See `imenu-generic-expression'.")
|
||||
|
||||
(defvar cc-imenu-java-generic-expression
|
||||
`((nil
|
||||
,(concat
|
||||
"^\\([ \t]\\)*"
|
||||
"\\([.A-Za-z0-9_-]+[ \t]+\\)?" ; type specs; there can be
|
||||
"\\([.A-Za-z0-9_-]+[ \t]+\\)?" ; more than 3 tokens, right?
|
||||
"\\([.A-Za-z0-9_-]+[ \t]*[[]?[]]?\\)"
|
||||
"\\([ \t]\\)"
|
||||
"\\([A-Za-z0-9_-]+\\)" ; the string we want to get
|
||||
"\\([ \t]*\\)+("
|
||||
"[][a-zA-Z,_1-9\n \t]*" ; arguments
|
||||
")[ \t]*"
|
||||
; "[^;(]"
|
||||
"[,a-zA-Z_1-9\n \t]*{"
|
||||
) 6))
|
||||
"Imenu generic expression for Java mode. See `imenu-generic-expression'.")
|
||||
|
||||
(defvar cc-imenu-csharp-generic-expression
|
||||
`(
|
||||
(nil
|
||||
,(concat
|
||||
"^"
|
||||
"\\("
|
||||
"private\\|protected\\|public\\|internal" ;; c-csharp-protection-kwds
|
||||
"\\|"
|
||||
;; c-csharp-specifier-kwds
|
||||
"new\\|static\\|virtual\\|sealed\\|override\\|abstract\\|extern\\|"
|
||||
"readonly\\|volatile"
|
||||
"\\)*"
|
||||
"\\("
|
||||
;; c-csharp-primitive-type-kwds
|
||||
"bool\\|char\\|double\\|float\\|void\\|"
|
||||
"sbyte\\|int\\|long\\|short\\|"
|
||||
"byte\\|uint\\|ulong\\|ushort\\|"
|
||||
"event\\|enum\\|string\\|delegate\\|object"
|
||||
"\\|" ; c# type name
|
||||
;; technically I think you could have a C# type using a C# reserved
|
||||
;; word, but it is so unlikely, and such bad programming practice, that
|
||||
;; I will explicitly ignore the possibility unless folks really want it.
|
||||
;; "\\(@\\(" c-csharp-keywords "\\)\\)\\|" ; @keyword name
|
||||
"\\("
|
||||
"[_a-zA-Z]\\(\\w\\|\\s_\\)*" ;; c-symbol-key
|
||||
"\\s *\.\\s *\\)*"
|
||||
"\\)"
|
||||
"\\("
|
||||
"\\(@\\("
|
||||
"[_a-zA-Z]\\(\\w\\|\\s_\\)*" ;; c-symbol-key
|
||||
"\\)\\)\\|" ; @keyword name
|
||||
"\\("
|
||||
"[_a-zA-Z]\\(\\w\\|\\s_\\)*" ;; c-symbol-key
|
||||
"\\)" ; function name
|
||||
"\\)"
|
||||
) 12))
|
||||
"Imenu generic expression for C# mode. See `imenu-generic-expression'.")
|
||||
|
||||
;; *Warning for cc-mode developers*
|
||||
;;
|
||||
;; `cc-imenu-objc-generic-expression' elements depend on
|
||||
;; `cc-imenu-c++-generic-expression'. So if you change this
|
||||
;; expression, you need to change following variables,
|
||||
;; `cc-imenu-objc-generic-expression-*-index',
|
||||
;; too. `cc-imenu-objc-function' uses these *-index variables, in
|
||||
;; order to know where the each regexp *group \\(foobar\\)* elements
|
||||
;; are started.
|
||||
;;
|
||||
;; *-index variables are initialized during `cc-imenu-objc-generic-expression'
|
||||
;; being initialized.
|
||||
;;
|
||||
|
||||
;; Internal variables
|
||||
(defvar cc-imenu-objc-generic-expression-noreturn-index nil)
|
||||
(defvar cc-imenu-objc-generic-expression-general-func-index nil)
|
||||
(defvar cc-imenu-objc-generic-expression-proto-index nil)
|
||||
(defvar cc-imenu-objc-generic-expression-objc-base-index nil)
|
||||
|
||||
(defvar cc-imenu-objc-generic-expression
|
||||
(concat
|
||||
;;
|
||||
;; For C
|
||||
;;
|
||||
;; > Special case to match a line like `main() {}'
|
||||
;; > e.g. no return type, not even on the previous line.
|
||||
;; Pick a token by (match-string 1)
|
||||
(car (cdr (nth 1 cc-imenu-c++-generic-expression))) ; -> index += 2
|
||||
(prog2 (setq cc-imenu-objc-generic-expression-noreturn-index 1) "")
|
||||
"\\|"
|
||||
;; > General function name regexp
|
||||
;; Pick a token by (match-string 3)
|
||||
(car (cdr (nth 2 cc-imenu-c++-generic-expression))) ; -> index += 2
|
||||
(prog2 (setq cc-imenu-objc-generic-expression-general-func-index 3) "")
|
||||
;; > Special case for definitions using phony prototype macros like:
|
||||
;; > `int main _PROTO( (int argc,char *argv[]) )'.
|
||||
;; Pick a token by (match-string 5)
|
||||
(if cc-imenu-c-prototype-macro-regexp
|
||||
(concat
|
||||
"\\|"
|
||||
(car (cdr (nth 3 cc-imenu-c++-generic-expression))) ; -> index += 1
|
||||
(prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 6) "")
|
||||
)
|
||||
(prog2 (setq cc-imenu-objc-generic-expression-objc-base-index 5) "")
|
||||
"") ; -> index += 0
|
||||
(prog2 (setq cc-imenu-objc-generic-expression-proto-index 5) "")
|
||||
;;
|
||||
;; For Objective-C
|
||||
;; Pick a token by (match-string 5 or 6)
|
||||
;;
|
||||
"\\|\\("
|
||||
"^[-+][:a-zA-Z0-9()*_<>\n\t ]*[;{]" ; Methods
|
||||
"\\|"
|
||||
"^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*:"
|
||||
"\\|"
|
||||
"^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*([a-zA-Z0-9_]+)"
|
||||
"\\|"
|
||||
;; For NSObject, NSProxy and Object... They don't have super class.
|
||||
"^@interface[\t ]+[a-zA-Z0-9_]+[\t ]*.*$"
|
||||
"\\|"
|
||||
"^@implementation[\t ]+[a-zA-Z0-9_]+[\t ]*([a-zA-Z0-9_]+)"
|
||||
"\\|"
|
||||
"^@implementation[\t ]+[a-zA-Z0-9_]+"
|
||||
"\\|"
|
||||
"^@protocol[\t ]+[a-zA-Z0-9_]+" "\\)")
|
||||
"Imenu generic expression for ObjC mode. See `imenu-generic-expression'.")
|
||||
|
||||
|
||||
;; Imenu support for objective-c uses functions.
|
||||
(defsubst cc-imenu-objc-method-to-selector (method)
|
||||
"Return the objc selector style string of METHOD.
|
||||
Example:
|
||||
- perform: (SEL)aSelector withObject: object1 withObject: object2; /* METHOD */
|
||||
=>
|
||||
-perform:withObject:withObject:withObject: /* selector */"
|
||||
(let ((return "") ; String to be returned
|
||||
(p 0) ; Current scanning position in METHOD
|
||||
(pmax (length method)) ;
|
||||
char ; Current scanning target
|
||||
(betweenparen 0) ; CHAR is in parentheses.
|
||||
argreq ; An argument is required.
|
||||
inargvar) ; position of CHAR is in an argument variable.
|
||||
(while (< p pmax)
|
||||
(setq char (aref method p)
|
||||
p (1+ p))
|
||||
(cond
|
||||
;; Is CHAR part of a objc token?
|
||||
((and (not inargvar) ; Ignore if CHAR is part of an argument variable.
|
||||
(eq 0 betweenparen) ; Ignore if CHAR is in parentheses.
|
||||
(or (and (<= ?a char) (<= char ?z))
|
||||
(and (<= ?A char) (<= char ?Z))
|
||||
(and (<= ?0 char) (<= char ?9))
|
||||
(= ?_ char)))
|
||||
(if argreq
|
||||
(setq inargvar t
|
||||
argreq nil)
|
||||
(setq return (concat return (char-to-string char)))))
|
||||
;; Or a white space?
|
||||
((and inargvar (or (eq ?\ char) (eq ?\n char))
|
||||
(setq inargvar nil)))
|
||||
;; Or a method separator?
|
||||
;; If a method separator, the next token will be an argument variable.
|
||||
((eq ?: char)
|
||||
(setq argreq t
|
||||
return (concat return (char-to-string char))))
|
||||
;; Or an open parentheses?
|
||||
((eq ?\( char)
|
||||
(setq betweenparen (1+ betweenparen)))
|
||||
;; Or a close parentheses?
|
||||
((eq ?\) char)
|
||||
(setq betweenparen (1- betweenparen)))))
|
||||
return))
|
||||
|
||||
(defun cc-imenu-objc-remove-white-space (str)
|
||||
"Remove all spaces and tabs from STR."
|
||||
(let ((return "")
|
||||
(p 0)
|
||||
(max (length str))
|
||||
char)
|
||||
(while (< p max)
|
||||
(setq char (aref str p))
|
||||
(setq p (1+ p))
|
||||
(if (or (= char ?\ ) (= char ?\t))
|
||||
()
|
||||
(setq return (concat return (char-to-string char)))))
|
||||
return))
|
||||
|
||||
(defun cc-imenu-objc-function ()
|
||||
"imenu supports for objc-mode."
|
||||
(let (methodlist
|
||||
clist
|
||||
;;
|
||||
;; OBJC, Cnoreturn, Cgeneralfunc, Cproto are constants.
|
||||
;;
|
||||
;; *Warning for developers*
|
||||
;; These constants depend on `cc-imenu-c++-generic-expression'.
|
||||
;;
|
||||
(OBJC cc-imenu-objc-generic-expression-objc-base-index)
|
||||
;; Special case to match a line like `main() {}'
|
||||
(Cnoreturn cc-imenu-objc-generic-expression-noreturn-index)
|
||||
;; General function name regexp
|
||||
(Cgeneralfunc cc-imenu-objc-generic-expression-general-func-index)
|
||||
;; Special case for definitions using phony prototype macros like:
|
||||
(Cproto cc-imenu-objc-generic-expression-proto-index)
|
||||
langnum
|
||||
;;
|
||||
(classcount 0)
|
||||
toplist
|
||||
stupid
|
||||
str
|
||||
str2
|
||||
(intflen (length "@interface"))
|
||||
(implen (length "@implementation"))
|
||||
(prtlen (length "@protocol"))
|
||||
(func
|
||||
;;
|
||||
;; Does this emacs has buffer-substring-no-properties?
|
||||
;;
|
||||
(if (fboundp 'buffer-substring-no-properties)
|
||||
'buffer-substring-no-properties
|
||||
'buffer-substring)))
|
||||
(goto-char (point-max))
|
||||
(imenu-progress-message stupid 0)
|
||||
;;
|
||||
(while (re-search-backward cc-imenu-objc-generic-expression nil t)
|
||||
(imenu-progress-message stupid)
|
||||
(setq langnum (if (match-beginning OBJC)
|
||||
OBJC
|
||||
(cond
|
||||
((match-beginning Cproto) Cproto)
|
||||
((match-beginning Cgeneralfunc) Cgeneralfunc)
|
||||
((match-beginning Cnoreturn) Cnoreturn))))
|
||||
(setq str (funcall func (match-beginning langnum) (match-end langnum)))
|
||||
;;
|
||||
(cond
|
||||
;;
|
||||
;; C
|
||||
;;
|
||||
((not (eq langnum OBJC))
|
||||
(setq clist (cons (cons str (match-beginning langnum)) clist)))
|
||||
;;
|
||||
;; ObjC
|
||||
;;
|
||||
;; An instance Method
|
||||
((eq (aref str 0) ?-)
|
||||
(setq str (concat "-" (cc-imenu-objc-method-to-selector str)))
|
||||
(setq methodlist (cons (cons str
|
||||
(match-beginning langnum))
|
||||
methodlist)))
|
||||
;; A factory Method
|
||||
((eq (aref str 0) ?+)
|
||||
(setq str (concat "+" (cc-imenu-objc-method-to-selector str)))
|
||||
(setq methodlist (cons (cons str
|
||||
(match-beginning langnum))
|
||||
methodlist)))
|
||||
;; Interface or implementation or protocol
|
||||
((eq (aref str 0) ?@)
|
||||
(setq classcount (1+ classcount))
|
||||
(cond
|
||||
((and (> (length str) implen)
|
||||
(string= (substring str 0 implen) "@implementation"))
|
||||
(setq str (substring str implen)
|
||||
str2 "@implementation"))
|
||||
((string= (substring str 0 intflen) "@interface")
|
||||
(setq str (substring str intflen)
|
||||
str2 "@interface"))
|
||||
((string= (substring str 0 prtlen) "@protocol")
|
||||
(setq str (substring str prtlen)
|
||||
str2 "@protocol")))
|
||||
(setq str (cc-imenu-objc-remove-white-space str))
|
||||
(setq methodlist (cons (cons str2
|
||||
(match-beginning langnum))
|
||||
methodlist))
|
||||
(setq toplist (cons nil (cons (cons str
|
||||
methodlist) toplist))
|
||||
methodlist nil))))
|
||||
;;
|
||||
(imenu-progress-message stupid 100)
|
||||
(if (eq (car toplist) nil)
|
||||
(setq toplist (cdr toplist)))
|
||||
|
||||
;; In this buffer, there is only one or zero @{interface|implementation|protocol}.
|
||||
(if (< classcount 2)
|
||||
(let ((classname (car (car toplist)))
|
||||
(p (cdr (car (cdr (car toplist)))))
|
||||
last)
|
||||
(setq toplist (cons (cons classname p) (cdr (cdr (car toplist)))))
|
||||
;; Add C lang token
|
||||
(if clist
|
||||
(progn
|
||||
(setq last toplist)
|
||||
(while (cdr last)
|
||||
(setq last (cdr last)))
|
||||
(setcdr last clist))))
|
||||
;; Add C lang tokens as a sub menu
|
||||
(setq toplist (cons (cons "C" clist) toplist)))
|
||||
;;
|
||||
toplist
|
||||
))
|
||||
|
||||
;(defvar cc-imenu-pike-generic-expression
|
||||
; ())
|
||||
; FIXME: Please contribute one!
|
||||
|
||||
(defun cc-imenu-init (mode-generic-expression)
|
||||
(setq imenu-generic-expression mode-generic-expression
|
||||
imenu-case-fold-search nil))
|
||||
|
||||
|
||||
(cc-provide 'cc-menus)
|
||||
|
||||
;;; cc-menus.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-menus.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-menus.elc
Normal file
Binary file not shown.
985
site-lisp/cc-mode/zbrad-integrated/cc-mode.el
Normal file
985
site-lisp/cc-mode/zbrad-integrated/cc-mode.el
Normal file
|
|
@ -0,0 +1,985 @@
|
|||
;;; cc-mode.el --- major mode for editing C, C++, Objective-C, and Java code
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: a long, long, time ago. adapted from the original c-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
(defconst c-version "5.28"
|
||||
"CC Mode version number.")
|
||||
|
||||
;; NOTE: Read the commentary below for the right way to submit bug reports!
|
||||
;; NOTE: See the accompanying texinfo manual for details on using this mode!
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;; This package provides GNU Emacs major modes for editing C, C++,
|
||||
;; Objective-C, Java, IDL and Pike code. As of the latest Emacs and
|
||||
;; XEmacs releases, it is the default package for editing these
|
||||
;; languages. This package is called "CC Mode", and should be spelled
|
||||
;; exactly this way.
|
||||
|
||||
;; CC Mode supports K&R and ANSI C, ANSI C++, Objective-C, Java,
|
||||
;; CORBA's IDL, and Pike with a consistent indentation model across
|
||||
;; all modes. This indentation model is intuitive and very flexible,
|
||||
;; so that almost any desired style of indentation can be supported.
|
||||
;; Installation, usage, and programming details are contained in an
|
||||
;; accompanying texinfo manual.
|
||||
|
||||
;; CC Mode's immediate ancestors were, c++-mode.el, cplus-md.el, and
|
||||
;; cplus-md1.el..
|
||||
|
||||
;; NOTE: This mode does not perform font-locking (a.k.a syntactic
|
||||
;; coloring, keyword highlighting, etc.) for any of the supported
|
||||
;; modes. Typically this is done by a package called font-lock.el
|
||||
;; which we do *not* maintain. You should contact the Emacs or XEmacs
|
||||
;; maintainers for questions about coloring or highlighting in any
|
||||
;; language mode.
|
||||
|
||||
;; To submit bug reports, type "C-c C-b". These will be sent to
|
||||
;; bug-gnu-emacs@gnu.org (mirrored as the Usenet newsgroup
|
||||
;; gnu.emacs.bug) as well as bug-cc-mode@gnu.org, which directly
|
||||
;; contacts the CC Mode maintainers. Questions can sent to
|
||||
;; help-gnu-emacs@gnu.org (mirrored as gnu.emacs.help) and/or
|
||||
;; bug-cc-mode@gnu.org. Please do not send bugs or questions to our
|
||||
;; personal accounts; we reserve the right to ignore such email!
|
||||
|
||||
;; Many, many thanks go out to all the folks on the beta test list.
|
||||
;; Without their patience, testing, insight, code contributions, and
|
||||
;; encouragement CC Mode would be a far inferior package.
|
||||
|
||||
;; You can get the latest version of CC Mode, including PostScript
|
||||
;; documentation and separate individual files from:
|
||||
;;
|
||||
;; http://cc-mode.sourceforge.net/
|
||||
;;
|
||||
;; You can join a moderated CC Mode announcement-only mailing list by
|
||||
;; visiting
|
||||
;;
|
||||
;; http://lists.sourceforge.net/mailman/listinfo/cc-mode-announce
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
(cc-require 'cc-defs)
|
||||
(cc-require 'cc-menus)
|
||||
(cc-require 'cc-vars)
|
||||
(cc-require 'cc-langs)
|
||||
(cc-require 'cc-styles)
|
||||
(cc-require 'cc-engine)
|
||||
(cc-require 'cc-cmds)
|
||||
(cc-require 'cc-align)
|
||||
|
||||
;; 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-defun set-keymap-parents) ; XEmacs
|
||||
|
||||
;; Menu support for both XEmacs and Emacs. If you don't have easymenu
|
||||
;; with your version of Emacs, you are incompatible!
|
||||
(require 'easymenu)
|
||||
|
||||
|
||||
;; Other modes and packages which depend on CC Mode should do the
|
||||
;; following to make sure everything is loaded and available for their
|
||||
;; use:
|
||||
;;
|
||||
;; (require 'cc-mode)
|
||||
;; (c-initialize-cc-mode)
|
||||
|
||||
;;;###autoload
|
||||
(defun c-initialize-cc-mode ()
|
||||
(setq c-buffer-is-cc-mode t)
|
||||
(let ((initprop 'cc-mode-is-initialized)
|
||||
c-initialization-ok)
|
||||
(unless (get 'c-initialize-cc-mode initprop)
|
||||
(unwind-protect
|
||||
(progn
|
||||
(put 'c-initialize-cc-mode initprop t)
|
||||
(c-initialize-builtin-style)
|
||||
(run-hooks 'c-initialization-hook)
|
||||
;; Fix obsolete variables.
|
||||
(if (boundp 'c-comment-continuation-stars)
|
||||
(setq c-block-comment-prefix c-comment-continuation-stars))
|
||||
(setq c-initialization-ok t))
|
||||
;; Will try initialization hooks again if they failed.
|
||||
(put 'c-initialize-cc-mode initprop c-initialization-ok)))
|
||||
))
|
||||
|
||||
|
||||
;; Common routines
|
||||
(defvar c-mode-base-map ()
|
||||
"Keymap shared by all CC Mode related modes.")
|
||||
|
||||
(defun c-make-inherited-keymap ()
|
||||
(let ((map (make-sparse-keymap)))
|
||||
(cond
|
||||
;; XEmacs 19 & 20
|
||||
((fboundp 'set-keymap-parents)
|
||||
(set-keymap-parents map c-mode-base-map))
|
||||
;; Emacs 19
|
||||
((fboundp 'set-keymap-parent)
|
||||
(set-keymap-parent map c-mode-base-map))
|
||||
;; incompatible
|
||||
(t (error "CC Mode is incompatible with this version of Emacs")))
|
||||
map))
|
||||
|
||||
(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)
|
||||
(define-key c-mode-base-map "\e\C-q" 'c-indent-exp)
|
||||
(substitute-key-definition 'backward-sentence
|
||||
'c-beginning-of-statement
|
||||
c-mode-base-map global-map)
|
||||
(substitute-key-definition 'forward-sentence
|
||||
'c-end-of-statement
|
||||
c-mode-base-map global-map)
|
||||
(substitute-key-definition 'indent-new-comment-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 due to the way it works.
|
||||
(substitute-key-definition 'fill-paragraph 'c-fill-paragraph
|
||||
c-mode-base-map global-map)
|
||||
;; In XEmacs the default fill function is called
|
||||
;; fill-paragraph-or-region.
|
||||
(substitute-key-definition 'fill-paragraph-or-region 'c-fill-paragraph
|
||||
c-mode-base-map global-map)
|
||||
;; 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 [delete] 'c-electric-delete)
|
||||
(define-key c-mode-base-map [backspace] 'c-electric-backspace))
|
||||
;; these are new keybindings, with no counterpart to BOCM
|
||||
(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 "/" 'c-electric-slash)
|
||||
(define-key c-mode-base-map "\C-c\C-q" 'c-indent-defun)
|
||||
(define-key c-mode-base-map "\C-c\C-\\" 'c-backslash-region)
|
||||
;; TBD: where if anywhere, to put c-backward|forward-into-nomenclature
|
||||
(define-key c-mode-base-map "\C-c\C-a" 'c-toggle-auto-state)
|
||||
(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-o" 'c-set-offset)
|
||||
(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-set-style)
|
||||
;; conflicts with OOBR
|
||||
;;(define-key c-mode-base-map "\C-c\C-v" 'c-version)
|
||||
)
|
||||
|
||||
(defvar c-c-menu nil)
|
||||
(defvar c-c++-menu nil)
|
||||
(defvar c-objc-menu nil)
|
||||
(defvar c-java-menu nil)
|
||||
(defvar c-pike-menu nil)
|
||||
|
||||
(defun c-mode-menu (modestr)
|
||||
(let ((m
|
||||
'(["Comment Out Region" comment-region (c-fn-region-is-active-p)]
|
||||
["Uncomment Region"
|
||||
(comment-region (region-beginning) (region-end) '(4))
|
||||
(c-fn-region-is-active-p)]
|
||||
["Fill Comment Paragraph" c-fill-paragraph t]
|
||||
"---"
|
||||
["Indent Expression" c-indent-exp
|
||||
(memq (char-after) '(?\( ?\[ ?\{))]
|
||||
["Indent Line or Region" c-indent-line-or-region t]
|
||||
["Up Conditional" c-up-conditional t]
|
||||
["Backward Conditional" c-backward-conditional t]
|
||||
["Forward Conditional" c-forward-conditional t]
|
||||
["Backward Statement" c-beginning-of-statement t]
|
||||
["Forward Statement" c-end-of-statement t]
|
||||
"---"
|
||||
["Macro Expand Region" c-macro-expand (c-fn-region-is-active-p)]
|
||||
["Backslashify" c-backslash-region
|
||||
(c-fn-region-is-active-p)]
|
||||
)))
|
||||
(cons modestr m)))
|
||||
|
||||
;; We don't require the outline package, but we configure it a bit anyway.
|
||||
(cc-bytecomp-defvar outline-level)
|
||||
|
||||
(defun c-common-init ()
|
||||
;; Common initializations for all modes.
|
||||
;; these variables should always be buffer local; they do not affect
|
||||
;; indentation style.
|
||||
(make-local-variable 'require-final-newline)
|
||||
(make-local-variable 'parse-sexp-ignore-comments)
|
||||
(make-local-variable 'indent-line-function)
|
||||
(make-local-variable 'indent-region-function)
|
||||
(make-local-variable 'outline-regexp)
|
||||
(make-local-variable 'outline-level)
|
||||
(make-local-variable 'normal-auto-fill-function)
|
||||
(make-local-variable 'comment-start)
|
||||
(make-local-variable 'comment-end)
|
||||
(make-local-variable 'comment-column)
|
||||
(make-local-variable 'comment-start-skip)
|
||||
(make-local-variable 'comment-multi-line)
|
||||
(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)
|
||||
(make-local-variable 'imenu-generic-expression) ;set in the mode functions
|
||||
;; X/Emacs 20 only
|
||||
(and (boundp 'comment-line-break-function)
|
||||
(progn
|
||||
(make-local-variable 'comment-line-break-function)
|
||||
(setq comment-line-break-function
|
||||
'c-indent-new-comment-line)))
|
||||
;; now set their values
|
||||
(setq require-final-newline t
|
||||
parse-sexp-ignore-comments t
|
||||
indent-line-function 'c-indent-line
|
||||
indent-region-function 'c-indent-region
|
||||
outline-regexp "[^#\n\^M]"
|
||||
outline-level 'c-outline-level
|
||||
normal-auto-fill-function 'c-do-auto-fill
|
||||
comment-column 32
|
||||
comment-start-skip "/\\*+ *\\|//+ *"
|
||||
comment-multi-line t)
|
||||
;; now set the mode style based on c-default-style
|
||||
(let ((style (if (stringp c-default-style)
|
||||
c-default-style
|
||||
(or (cdr (assq major-mode c-default-style))
|
||||
(cdr (assq 'other c-default-style))
|
||||
"gnu"))))
|
||||
;; Override style variables if `c-old-style-variable-behavior' is
|
||||
;; set. Also override if we are using global style variables,
|
||||
;; have already initialized a style once, and are switching to a
|
||||
;; different style. (It's doubtful whether this is desirable, but
|
||||
;; the whole situation with nonlocal style variables is a bit
|
||||
;; awkward. It's at least the most compatible way with the old
|
||||
;; style init procedure.)
|
||||
(c-set-style style (not (or c-old-style-variable-behavior
|
||||
(and (not c-style-variables-are-local-p)
|
||||
c-indentation-style
|
||||
(not (string-equal c-indentation-style
|
||||
style)))))))
|
||||
;; Fix things up for paragraph recognition and filling inside
|
||||
;; comments by using c-current-comment-prefix in the relevant
|
||||
;; places. We use adaptive filling for this to make it possible to
|
||||
;; use filladapt or some other fancy package.
|
||||
(setq c-current-comment-prefix
|
||||
(if (listp c-comment-prefix-regexp)
|
||||
(cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
|
||||
(assoc 'other c-comment-prefix-regexp)))
|
||||
c-comment-prefix-regexp))
|
||||
(let ((comment-line-prefix
|
||||
(concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*")))
|
||||
(setq paragraph-start (concat comment-line-prefix
|
||||
c-append-paragraph-start
|
||||
"\\|"
|
||||
page-delimiter)
|
||||
paragraph-separate (concat comment-line-prefix
|
||||
c-append-paragraph-separate
|
||||
"\\|"
|
||||
page-delimiter)
|
||||
paragraph-ignore-fill-prefix t
|
||||
adaptive-fill-mode t
|
||||
adaptive-fill-regexp
|
||||
(concat comment-line-prefix
|
||||
(if adaptive-fill-regexp
|
||||
(concat "\\(" adaptive-fill-regexp "\\)")
|
||||
"")))
|
||||
(when (boundp 'adaptive-fill-first-line-regexp)
|
||||
;; XEmacs (20.x) 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.
|
||||
"\\'"))))
|
||||
;; we have to do something special for c-offsets-alist so that the
|
||||
;; buffer local value has its own alist structure.
|
||||
(setq c-offsets-alist (copy-alist c-offsets-alist))
|
||||
;; setup the comment indent variable in a Emacs version portable way
|
||||
;; ignore any byte compiler warnings you might get here
|
||||
(make-local-variable 'comment-indent-function)
|
||||
(setq comment-indent-function 'c-comment-indent)
|
||||
;; add menus to menubar
|
||||
(easy-menu-add (c-mode-menu mode-name))
|
||||
;; put auto-hungry designators onto minor-mode-alist, but only once
|
||||
(or (assq 'c-auto-hungry-string minor-mode-alist)
|
||||
(setq minor-mode-alist
|
||||
(cons '(c-auto-hungry-string c-auto-hungry-string)
|
||||
minor-mode-alist)))
|
||||
)
|
||||
|
||||
(defun c-postprocess-file-styles ()
|
||||
"Function that post processes relevant file local variables.
|
||||
Currently, this function simply applies any style and offset settings
|
||||
found in the file's Local Variable list. It first applies any style
|
||||
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."
|
||||
;; apply file styles and offsets
|
||||
(if (or c-file-style c-file-offsets)
|
||||
(c-make-styles-buffer-local t))
|
||||
(and c-file-style
|
||||
(c-set-style c-file-style))
|
||||
(and c-file-offsets
|
||||
(mapcar
|
||||
(function
|
||||
(lambda (langentry)
|
||||
(let ((langelem (car langentry))
|
||||
(offset (cdr langentry)))
|
||||
(c-set-offset langelem offset)
|
||||
)))
|
||||
c-file-offsets)))
|
||||
|
||||
(add-hook 'hack-local-variables-hook 'c-postprocess-file-styles)
|
||||
|
||||
|
||||
;; Support for C
|
||||
|
||||
(defvar c-mode-abbrev-table nil
|
||||
"Abbreviation table used in c-mode buffers.")
|
||||
(define-abbrev-table 'c-mode-abbrev-table
|
||||
'(("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)))
|
||||
|
||||
(defvar c-mode-map ()
|
||||
"Keymap used in c-mode buffers.")
|
||||
(if c-mode-map
|
||||
nil
|
||||
(setq c-mode-map (c-make-inherited-keymap))
|
||||
;; add bindings which are only useful for C
|
||||
(define-key c-mode-map "\C-c\C-e" 'c-macro-expand)
|
||||
)
|
||||
|
||||
(easy-menu-define c-c-menu c-mode-map "C Mode Commands"
|
||||
(c-mode-menu "C"))
|
||||
|
||||
;;;###autoload
|
||||
(defun c-mode ()
|
||||
"Major mode for editing K&R and ANSI C code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
||||
c-mode buffer. This automatically sets up a mail buffer with version
|
||||
information already added. You just need to add a description of the
|
||||
problem, including a reproducible test case and send the message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `c-mode-hook' is run with no args, if that value is
|
||||
bound and has a non-nil value. Also the hook `c-mode-common-hook' is
|
||||
run first.
|
||||
|
||||
Key bindings:
|
||||
\\{c-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table c-mode-syntax-table)
|
||||
(setq major-mode 'c-mode
|
||||
mode-name "C"
|
||||
local-abbrev-table c-mode-abbrev-table
|
||||
abbrev-mode t)
|
||||
(use-local-map c-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "/* "
|
||||
comment-end " */"
|
||||
c-keywords (c-identifier-re c-C-keywords)
|
||||
c-conditional-key c-C-conditional-key
|
||||
c-class-key c-C-class-key
|
||||
c-baseclass-key nil
|
||||
c-comment-start-regexp c-C-comment-start-regexp
|
||||
c-bitfield-key c-C-bitfield-key
|
||||
)
|
||||
(cc-imenu-init cc-imenu-c-generic-expression)
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'c-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for C++
|
||||
|
||||
(defvar c++-mode-abbrev-table nil
|
||||
"Abbreviation table used in c++-mode buffers.")
|
||||
(define-abbrev-table 'c++-mode-abbrev-table
|
||||
'(("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)
|
||||
("catch" "catch" c-electric-continued-statement 0)))
|
||||
|
||||
(defvar c++-mode-map ()
|
||||
"Keymap used in c++-mode buffers.")
|
||||
(if c++-mode-map
|
||||
nil
|
||||
(setq c++-mode-map (c-make-inherited-keymap))
|
||||
;; add bindings which are only useful for C++
|
||||
(define-key c++-mode-map "\C-c\C-e" 'c-macro-expand)
|
||||
(define-key c++-mode-map "\C-c:" 'c-scope-operator)
|
||||
(define-key c++-mode-map "<" 'c-electric-lt-gt)
|
||||
(define-key c++-mode-map ">" 'c-electric-lt-gt))
|
||||
|
||||
(easy-menu-define c-c++-menu c++-mode-map "C++ Mode Commands"
|
||||
(c-mode-menu "C++"))
|
||||
|
||||
;;;###autoload
|
||||
(defun c++-mode ()
|
||||
"Major mode for editing C++ code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
||||
c++-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case, and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `c++-mode-hook' is run with no args, if that
|
||||
variable is bound and has a non-nil value. Also the hook
|
||||
`c-mode-common-hook' is run first.
|
||||
|
||||
Key bindings:
|
||||
\\{c++-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table c++-mode-syntax-table)
|
||||
(setq major-mode 'c++-mode
|
||||
mode-name "C++"
|
||||
local-abbrev-table c++-mode-abbrev-table
|
||||
abbrev-mode t)
|
||||
(use-local-map c++-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-C++-keywords)
|
||||
c-conditional-key c-C++-conditional-key
|
||||
c-comment-start-regexp c-C++-comment-start-regexp
|
||||
c-class-key c-C++-class-key
|
||||
c-extra-toplevel-key c-C++-extra-toplevel-key
|
||||
c-access-key c-C++-access-key
|
||||
c-recognize-knr-p nil
|
||||
c-bitfield-key c-C-bitfield-key
|
||||
)
|
||||
(cc-imenu-init cc-imenu-c++-generic-expression)
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'c++-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for Objective-C
|
||||
|
||||
(defvar objc-mode-abbrev-table nil
|
||||
"Abbreviation table used in objc-mode buffers.")
|
||||
(define-abbrev-table 'objc-mode-abbrev-table
|
||||
'(("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)))
|
||||
|
||||
(defvar objc-mode-map ()
|
||||
"Keymap used in objc-mode buffers.")
|
||||
(if objc-mode-map
|
||||
nil
|
||||
(setq objc-mode-map (c-make-inherited-keymap))
|
||||
;; add bindings which are only useful for Objective-C
|
||||
(define-key objc-mode-map "\C-c\C-e" 'c-macro-expand))
|
||||
|
||||
(easy-menu-define c-objc-menu objc-mode-map "ObjC Mode Commands"
|
||||
(c-mode-menu "ObjC"))
|
||||
|
||||
;;;###autoload
|
||||
(defun objc-mode ()
|
||||
"Major mode for editing Objective C code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
||||
objc-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case, and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `objc-mode-hook' is run with no args, if that value
|
||||
is bound and has a non-nil value. Also the hook `c-mode-common-hook'
|
||||
is run first.
|
||||
|
||||
Key bindings:
|
||||
\\{objc-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table objc-mode-syntax-table)
|
||||
(setq major-mode 'objc-mode
|
||||
mode-name "ObjC"
|
||||
local-abbrev-table objc-mode-abbrev-table
|
||||
abbrev-mode t)
|
||||
(use-local-map objc-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-ObjC-keywords)
|
||||
c-conditional-key c-ObjC-conditional-key
|
||||
c-comment-start-regexp c-ObjC-comment-start-regexp
|
||||
c-class-key c-ObjC-class-key
|
||||
c-baseclass-key nil
|
||||
c-access-key c-ObjC-access-key
|
||||
c-method-key c-ObjC-method-key
|
||||
)
|
||||
(cc-imenu-init cc-imenu-objc-generic-expression)
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'objc-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for Java
|
||||
|
||||
(defvar java-mode-abbrev-table nil
|
||||
"Abbreviation table used in java-mode buffers.")
|
||||
(define-abbrev-table 'java-mode-abbrev-table
|
||||
'(("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)
|
||||
("catch" "catch" c-electric-continued-statement 0)
|
||||
("finally" "finally" c-electric-continued-statement 0)))
|
||||
|
||||
(defvar java-mode-map ()
|
||||
"Keymap used in java-mode buffers.")
|
||||
(if java-mode-map
|
||||
nil
|
||||
(setq java-mode-map (c-make-inherited-keymap))
|
||||
;; add bindings which are only useful for Java
|
||||
)
|
||||
|
||||
(easy-menu-define c-java-menu java-mode-map "Java Mode Commands"
|
||||
(c-mode-menu "Java"))
|
||||
|
||||
;;;###autoload
|
||||
(defun java-mode ()
|
||||
"Major mode for editing Java code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from a
|
||||
java-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `java-mode-hook' is run with no args, if that value
|
||||
is bound and has a non-nil value. Also the common hook
|
||||
`c-mode-common-hook' is run first. Note that this mode automatically
|
||||
sets the \"java\" style before calling any hooks so be careful if you
|
||||
set styles in `c-mode-common-hook'.
|
||||
|
||||
Key bindings:
|
||||
\\{java-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table java-mode-syntax-table)
|
||||
(setq major-mode 'java-mode
|
||||
mode-name "Java"
|
||||
local-abbrev-table java-mode-abbrev-table
|
||||
abbrev-mode t
|
||||
c-append-paragraph-start c-Java-javadoc-paragraph-start)
|
||||
(use-local-map java-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-Java-keywords)
|
||||
c-conditional-key c-Java-conditional-key
|
||||
c-comment-start-regexp c-Java-comment-start-regexp
|
||||
c-class-key c-Java-class-key
|
||||
c-method-key nil
|
||||
c-baseclass-key nil
|
||||
c-recognize-knr-p nil
|
||||
c-inexpr-class-key c-Java-inexpr-class-key
|
||||
;defun-prompt-regexp c-Java-defun-prompt-regexp
|
||||
)
|
||||
(cc-imenu-init cc-imenu-java-generic-expression)
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'java-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for CORBA's IDL language
|
||||
|
||||
(defvar idl-mode-abbrev-table nil
|
||||
"Abbreviation table used in idl-mode buffers.")
|
||||
(define-abbrev-table 'idl-mode-abbrev-table ())
|
||||
|
||||
(defvar idl-mode-map ()
|
||||
"Keymap used in idl-mode buffers.")
|
||||
(if idl-mode-map
|
||||
nil
|
||||
(setq idl-mode-map (c-make-inherited-keymap))
|
||||
;; add bindings which are only useful for IDL
|
||||
)
|
||||
|
||||
(easy-menu-define c-idl-menu idl-mode-map "IDL Mode Commands"
|
||||
(c-mode-menu "IDL"))
|
||||
|
||||
;;;###autoload
|
||||
(defun idl-mode ()
|
||||
"Major mode for editing CORBA's IDL code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
||||
idl-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case, and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `idl-mode-hook' is run with no args, if that
|
||||
variable is bound and has a non-nil value. Also the hook
|
||||
`c-mode-common-hook' is run first.
|
||||
|
||||
Key bindings:
|
||||
\\{idl-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table idl-mode-syntax-table)
|
||||
(setq major-mode 'idl-mode
|
||||
mode-name "IDL"
|
||||
local-abbrev-table idl-mode-abbrev-table)
|
||||
(use-local-map idl-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-IDL-keywords)
|
||||
c-conditional-key c-IDL-conditional-key
|
||||
c-comment-start-regexp c-IDL-comment-start-regexp
|
||||
c-class-key c-IDL-class-key
|
||||
c-method-key nil
|
||||
c-baseclass-key nil
|
||||
c-extra-toplevel-key c-IDL-extra-toplevel-key
|
||||
c-recognize-knr-p nil
|
||||
)
|
||||
;;(cc-imenu-init cc-imenu-idl-generic-expression) ;FIXME
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'idl-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for Pike
|
||||
|
||||
(defvar pike-mode-abbrev-table nil
|
||||
"Abbreviation table used in pike-mode buffers.")
|
||||
(define-abbrev-table 'pike-mode-abbrev-table
|
||||
'(("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)))
|
||||
|
||||
(defvar pike-mode-map ()
|
||||
"Keymap used in pike-mode buffers.")
|
||||
(if pike-mode-map
|
||||
nil
|
||||
(setq pike-mode-map (c-make-inherited-keymap))
|
||||
;; additional bindings
|
||||
(define-key pike-mode-map "\C-c\C-e" 'c-macro-expand))
|
||||
|
||||
(easy-menu-define c-pike-menu pike-mode-map "Pike Mode Commands"
|
||||
(c-mode-menu "Pike"))
|
||||
|
||||
;;;###autoload
|
||||
(defun pike-mode ()
|
||||
"Major mode for editing Pike code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
||||
idl-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case, and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `pike-mode-hook' is run with no args, if that value
|
||||
is bound and has a non-nil value. Also the common hook
|
||||
`c-mode-common-hook' is run first.
|
||||
|
||||
Key bindings:
|
||||
\\{pike-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table pike-mode-syntax-table)
|
||||
(setq major-mode 'pike-mode
|
||||
mode-name "Pike"
|
||||
local-abbrev-table pike-mode-abbrev-table
|
||||
abbrev-mode t
|
||||
c-append-paragraph-start c-Pike-pikedoc-paragraph-start
|
||||
c-append-paragraph-separate c-Pike-pikedoc-paragraph-separate)
|
||||
(use-local-map pike-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-Pike-keywords)
|
||||
c-conditional-key c-Pike-conditional-key
|
||||
c-comment-start-regexp c-Pike-comment-start-regexp
|
||||
c-class-key c-Pike-class-key
|
||||
c-method-key nil
|
||||
c-baseclass-key nil
|
||||
c-recognize-knr-p nil
|
||||
c-lambda-key c-Pike-lambda-key
|
||||
c-inexpr-block-key c-Pike-inexpr-block-key
|
||||
c-inexpr-class-key c-Pike-inexpr-class-key
|
||||
c-special-brace-lists c-Pike-special-brace-lists
|
||||
)
|
||||
;;(cc-imenu-init cc-imenu-pike-generic-expression) ;FIXME
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'pike-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
;; Support for C#
|
||||
|
||||
(defvar csharp-mode-abbrev-table nil
|
||||
"Abbreviation table used in csharp-mode buffers.")
|
||||
(define-abbrev-table 'csharp-mode-abbrev-table
|
||||
'(
|
||||
("else" "else" c-electric-continued-statement 0)
|
||||
("while" "while" c-electric-continued-statement 0)
|
||||
("catch" "catch" c-electric-continued-statement 0)
|
||||
("finally" "finally" c-electric-continued-statement 0)
|
||||
)
|
||||
)
|
||||
|
||||
(defvar csharp-mode-map ()
|
||||
"Keymap used in csharp-mode buffers.")
|
||||
(if csharp-mode-map
|
||||
nil
|
||||
(setq csharp-mode-map (c-make-inherited-keymap))
|
||||
;; additional bindings
|
||||
(define-key csharp-mode-map "\C-c\C-e" 'c-macro-expand))
|
||||
|
||||
(easy-menu-define c-csharp-menu csharp-mode-map "C# Mode Commands"
|
||||
(c-mode-menu "C#"))
|
||||
|
||||
;;;###autoload
|
||||
(defun csharp-mode ()
|
||||
"Major mode for editing C# code.
|
||||
To submit a problem report, enter `\\[c-submit-bug-report]' from an
|
||||
idl-mode buffer. This automatically sets up a mail buffer with
|
||||
version information already added. You just need to add a description
|
||||
of the problem, including a reproducible test case, and send the
|
||||
message.
|
||||
|
||||
To see what version of CC Mode you are running, enter `\\[c-version]'.
|
||||
|
||||
The hook variable `csharp-mode-hook' is run with no args, if that value
|
||||
is bound and has a non-nil value. Also the common hook
|
||||
`c-mode-common-hook' is run first.
|
||||
|
||||
Key bindings:
|
||||
\\{csharp-mode-map}"
|
||||
(interactive)
|
||||
(c-initialize-cc-mode)
|
||||
(kill-all-local-variables)
|
||||
(set-syntax-table csharp-mode-syntax-table)
|
||||
(setq major-mode 'csharp-mode
|
||||
mode-name "C#"
|
||||
local-abbrev-table csharp-mode-abbrev-table
|
||||
abbrev-mode t)
|
||||
;;
|
||||
;; JohnDoty: Removed:
|
||||
;;
|
||||
;;(setq c-append-paragraph-start c-csharp-xmldoc-paragraph-start
|
||||
;; c-append-paragraph-separate c-csharp-xmldoc-paragraph-separate)
|
||||
;;
|
||||
(use-local-map csharp-mode-map)
|
||||
(c-common-init)
|
||||
(setq comment-start "// "
|
||||
comment-end ""
|
||||
c-keywords (c-identifier-re c-csharp-keywords)
|
||||
c-conditional-key c-csharp-conditional-key
|
||||
c-comment-start-regexp c-csharp-comment-start-regexp
|
||||
c-class-key c-csharp-class-key
|
||||
c-extra-toplevel-key c-csharp-extra-toplevel-key
|
||||
c-access-key c-csharp-access-key
|
||||
; c-access-key nil
|
||||
c-protection-key c-csharp-protection-key
|
||||
c-recognize-knr-p nil
|
||||
; c-method-key c-csharp-method-key
|
||||
c-baseclass-key nil
|
||||
c-special-brace-lists nil
|
||||
c-inher-key c-csharp-inher-key)
|
||||
(run-hooks 'c-mode-common-hook)
|
||||
(run-hooks 'csharp-mode-hook)
|
||||
(c-update-modeline))
|
||||
|
||||
|
||||
|
||||
;; Helper for setting up Filladapt mode. It's not used by CC Mode itself.
|
||||
|
||||
(cc-bytecomp-defvar filladapt-token-table)
|
||||
(cc-bytecomp-defvar filladapt-token-match-table)
|
||||
(cc-bytecomp-defvar filladapt-token-conversion-table)
|
||||
|
||||
(defun c-setup-filladapt ()
|
||||
"Convenience function to configure Kyle E. Jones' Filladapt mode for
|
||||
CC Mode by making sure the proper entries are present on
|
||||
`filladapt-token-table', `filladapt-token-match-table', and
|
||||
`filladapt-token-conversion-table'. This is intended to be used on
|
||||
`c-mode-common-hook' or similar."
|
||||
;; This function is intended to be used explicitly by the end user
|
||||
;; only.
|
||||
;;
|
||||
;; The default configuration already handles C++ comments, but we
|
||||
;; need to add handling of C block comments. A new filladapt token
|
||||
;; `c-comment' is added for that.
|
||||
(let (p)
|
||||
(setq p filladapt-token-table)
|
||||
(while (and p (not (eq (car-safe (cdr-safe (car-safe p))) 'c-comment)))
|
||||
(setq p (cdr-safe p)))
|
||||
(if p
|
||||
(setcar (car p) c-current-comment-prefix)
|
||||
(setq filladapt-token-table
|
||||
(append (list (car filladapt-token-table)
|
||||
(list c-current-comment-prefix 'c-comment))
|
||||
(cdr filladapt-token-table)))))
|
||||
(unless (assq 'c-comment filladapt-token-match-table)
|
||||
(setq filladapt-token-match-table
|
||||
(append '((c-comment c-comment))
|
||||
filladapt-token-match-table)))
|
||||
(unless (assq 'c-comment filladapt-token-conversion-table)
|
||||
(setq filladapt-token-conversion-table
|
||||
(append '((c-comment . exact))
|
||||
filladapt-token-conversion-table))))
|
||||
|
||||
|
||||
;; bug reporting
|
||||
|
||||
(defconst c-mode-help-address
|
||||
"bug-gnu-emacs@gnu.org, bug-cc-mode@gnu.org"
|
||||
"Addresses for CC Mode bug reports.")
|
||||
|
||||
(defun c-version ()
|
||||
"Echo the current version of CC Mode in the minibuffer."
|
||||
(interactive)
|
||||
(message "Using CC Mode version %s" c-version)
|
||||
(c-keep-region-active))
|
||||
|
||||
(defvar c-prepare-bug-report-hooks nil)
|
||||
|
||||
;; Dynamic variables used by reporter.
|
||||
(defvar reporter-prompt-for-summary-p)
|
||||
(defvar reporter-dont-compact-list)
|
||||
|
||||
(defun c-submit-bug-report ()
|
||||
"Submit via mail a bug report on CC Mode."
|
||||
(interactive)
|
||||
(require 'reporter)
|
||||
;; load in reporter
|
||||
(let ((reporter-prompt-for-summary-p t)
|
||||
(reporter-dont-compact-list '(c-offsets-alist))
|
||||
(style c-indentation-style)
|
||||
(c-features c-emacs-features))
|
||||
(and
|
||||
(if (y-or-n-p "Do you want to submit a report on CC Mode? ")
|
||||
t (message "") nil)
|
||||
(require 'reporter)
|
||||
(reporter-submit-bug-report
|
||||
c-mode-help-address
|
||||
(concat "CC Mode " c-version " ("
|
||||
(cond ((eq major-mode 'c++-mode) "C++")
|
||||
((eq major-mode 'c-mode) "C")
|
||||
((eq major-mode 'objc-mode) "ObjC")
|
||||
((eq major-mode 'java-mode) "Java")
|
||||
((eq major-mode 'idl-mode) "IDL")
|
||||
((eq major-mode 'pike-mode) "Pike")
|
||||
((eq major-mode 'csharp-mode) "C#")
|
||||
)
|
||||
")")
|
||||
(let ((vars (append
|
||||
;; report only the vars that affect indentation
|
||||
c-style-variables
|
||||
'(c-delete-function
|
||||
c-electric-pound-behavior
|
||||
c-indent-comments-syntactically-p
|
||||
c-tab-always-indent
|
||||
defun-prompt-regexp
|
||||
tab-width
|
||||
comment-column
|
||||
parse-sexp-ignore-comments
|
||||
;; A brain-damaged XEmacs only variable that, if
|
||||
;; set to nil can cause all kinds of chaos.
|
||||
signal-error-on-buffer-boundary
|
||||
;; Variables that affect line breaking and comments.
|
||||
auto-fill-function
|
||||
filladapt-mode
|
||||
comment-multi-line
|
||||
comment-start-skip
|
||||
fill-prefix
|
||||
paragraph-start
|
||||
adaptive-fill-mode
|
||||
adaptive-fill-regexp)
|
||||
nil)))
|
||||
(delq 'c-special-indent-hook vars)
|
||||
(mapcar (lambda (var) (unless (boundp var) (delq var vars)))
|
||||
'(signal-error-on-buffer-boundary
|
||||
filladapt-mode
|
||||
defun-prompt-regexp))
|
||||
vars)
|
||||
(function
|
||||
(lambda ()
|
||||
(run-hooks 'c-prepare-bug-report-hooks)
|
||||
(insert
|
||||
"Buffer Style: " style "\n\n"
|
||||
(format "c-emacs-features: %s\n" c-features)
|
||||
)))))))
|
||||
|
||||
|
||||
(cc-provide 'cc-mode)
|
||||
;;; cc-mode.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-mode.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-mode.elc
Normal file
Binary file not shown.
529
site-lisp/cc-mode/zbrad-integrated/cc-styles.el
Normal file
529
site-lisp/cc-mode/zbrad-integrated/cc-styles.el
Normal file
|
|
@ -0,0 +1,529 @@
|
|||
;;; cc-styles.el --- support for styles in CC Mode
|
||||
|
||||
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc.
|
||||
|
||||
;; Authors: 2000- Martin Stjernholm
|
||||
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm
|
||||
;; 1992-1997 Barry A. Warsaw
|
||||
;; 1987 Dave Detlefs and Stewart Clamen
|
||||
;; 1985 Richard M. Stallman
|
||||
;; Maintainer: bug-cc-mode@gnu.org
|
||||
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
||||
;; Version: See cc-mode.el
|
||||
;; Keywords: c languages oop
|
||||
|
||||
;; This file is part of GNU Emacs.
|
||||
|
||||
;; GNU Emacs 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.
|
||||
|
||||
;; GNU Emacs 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., 59 Temple Place - Suite 330,
|
||||
;; Boston, MA 02111-1307, USA.
|
||||
|
||||
;;; Commentary:
|
||||
|
||||
;;; 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)))
|
||||
(require 'cc-bytecomp)))
|
||||
|
||||
(cc-require 'cc-defs)
|
||||
(cc-require 'cc-vars)
|
||||
|
||||
|
||||
;; Warning: don't eval-defun this constant or you'll break style inheritance.
|
||||
(defconst c-style-alist
|
||||
'(("gnu"
|
||||
(c-basic-offset . 2)
|
||||
(c-comment-only-line-offset . (0 . 0))
|
||||
(c-offsets-alist . ((statement-block-intro . +)
|
||||
(knr-argdecl-intro . 5)
|
||||
(substatement-open . +)
|
||||
(label . 0)
|
||||
(statement-case-open . +)
|
||||
(statement-cont . +)
|
||||
(arglist-intro . c-lineup-arglist-intro-after-paren)
|
||||
(arglist-close . c-lineup-arglist)
|
||||
(inline-open . 0)
|
||||
(brace-list-open . +)
|
||||
))
|
||||
(c-special-indent-hook . c-gnu-impose-minimum)
|
||||
(c-block-comment-prefix . "")
|
||||
)
|
||||
("k&r"
|
||||
(c-basic-offset . 5)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-offsets-alist . ((statement-block-intro . +)
|
||||
(knr-argdecl-intro . 0)
|
||||
(substatement-open . 0)
|
||||
(label . 0)
|
||||
(statement-cont . +)
|
||||
))
|
||||
)
|
||||
("bsd"
|
||||
(c-basic-offset . 8)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-offsets-alist . ((statement-block-intro . +)
|
||||
(knr-argdecl-intro . +)
|
||||
(substatement-open . 0)
|
||||
(label . 0)
|
||||
(statement-cont . +)
|
||||
(inline-open . 0)
|
||||
(inexpr-class . 0)
|
||||
))
|
||||
)
|
||||
("stroustrup"
|
||||
(c-basic-offset . 4)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-offsets-alist . ((statement-block-intro . +)
|
||||
(substatement-open . 0)
|
||||
(label . 0)
|
||||
(statement-cont . +)
|
||||
))
|
||||
)
|
||||
("whitesmith"
|
||||
(c-basic-offset . 4)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-offsets-alist . ((knr-argdecl-intro . +)
|
||||
(label . 0)
|
||||
(statement-cont . +)
|
||||
(substatement-open . +)
|
||||
(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 . +)
|
||||
(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 . +)
|
||||
))
|
||||
)
|
||||
("ellemtel"
|
||||
(c-basic-offset . 3)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-hanging-braces-alist . ((substatement-open before after)))
|
||||
(c-offsets-alist . ((topmost-intro . 0)
|
||||
(topmost-intro-cont . 0)
|
||||
(substatement . +)
|
||||
(substatement-open . 0)
|
||||
(case-label . +)
|
||||
(access-label . -)
|
||||
(inclass . ++)
|
||||
(inline-open . 0)
|
||||
))
|
||||
)
|
||||
("linux"
|
||||
(c-basic-offset . 8)
|
||||
(c-comment-only-line-offset . 0)
|
||||
(c-hanging-braces-alist . ((brace-list-open)
|
||||
(brace-entry-open)
|
||||
(substatement-open after)
|
||||
(block-close . c-snug-do-while)))
|
||||
(c-cleanup-list . (brace-else-brace))
|
||||
(c-offsets-alist . ((statement-block-intro . +)
|
||||
(knr-argdecl-intro . 0)
|
||||
(substatement-open . 0)
|
||||
(label . 0)
|
||||
(statement-cont . +)
|
||||
))
|
||||
)
|
||||
("python"
|
||||
(indent-tabs-mode . t)
|
||||
(fill-column . 78)
|
||||
(c-basic-offset . 8)
|
||||
(c-offsets-alist . ((substatement-open . 0)
|
||||
(inextern-lang . 0)
|
||||
(arglist-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 . "")
|
||||
)
|
||||
("java"
|
||||
(c-basic-offset . 4)
|
||||
(c-comment-only-line-offset . (0 . 0))
|
||||
;; the following preserves Javadoc starter lines
|
||||
(c-offsets-alist . ((inline-open . 0)
|
||||
(topmost-intro-cont . +)
|
||||
(statement-block-intro . +)
|
||||
(knr-argdecl-intro . 5)
|
||||
(substatement-open . +)
|
||||
(label . +)
|
||||
(statement-case-open . +)
|
||||
(statement-cont . +)
|
||||
(arglist-intro . c-lineup-arglist-intro-after-paren)
|
||||
(arglist-close . c-lineup-arglist)
|
||||
(access-label . 0)
|
||||
(inher-cont . c-lineup-java-inher)
|
||||
(func-decl-cont . c-lineup-java-throws)
|
||||
))
|
||||
)
|
||||
("C#"
|
||||
(c-basic-offset . 4)
|
||||
(c-comment-only-line-offset . (0 . 0))
|
||||
(c-offsets-alist . (
|
||||
(inline-open . 0)
|
||||
(topmost-intro-cont . +)
|
||||
(statement-block-intro . +)
|
||||
(knr-argdecl-intro . 4)
|
||||
(substatement-open . +)
|
||||
(label . +)
|
||||
(statement-case-open . +)
|
||||
(statement-cont . +)
|
||||
(c . c-lineup-C-comments)
|
||||
(topmost-intro-cont . 0)
|
||||
(arglist-intro . c-lineup-arglist-intro-after-paren)
|
||||
(arglist-close . c-lineup-arglist)
|
||||
(inher-cont . c-lineup-multi-inher)
|
||||
(access-label . 0)
|
||||
))
|
||||
)
|
||||
)
|
||||
"Styles of indentation.
|
||||
Elements of this alist are of the form:
|
||||
|
||||
(STYLE-STRING [BASE-STYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
|
||||
|
||||
where STYLE-STRING is a short descriptive string used to select a
|
||||
style, VARIABLE is any Emacs variable, and VALUE is the intended value
|
||||
for that variable when using the selected style.
|
||||
|
||||
Optional BASE-STYLE if present, is a string and must follow
|
||||
STYLE-STRING. BASE-STYLE names a style that this style inherits from.
|
||||
By default, all styles inherit from the \"user\" style, which is
|
||||
computed at run time. Style loops generate errors.
|
||||
|
||||
Two variables are treated specially. When VARIABLE is
|
||||
`c-offsets-alist', the VALUE is a list containing elements of the
|
||||
form:
|
||||
|
||||
(SYNTACTIC-SYMBOL . OFFSET)
|
||||
|
||||
as described in `c-offsets-alist'. These are passed directly to
|
||||
`c-set-offset' so there is no need to set every syntactic symbol in
|
||||
your style, only those that are different from the default.
|
||||
|
||||
When VARIABLE is `c-special-indent-hook', its VALUE is added to
|
||||
`c-special-indent-hook' using `add-hook'. If VALUE is a list, each
|
||||
element of the list is added with `add-hook'.
|
||||
|
||||
Do not change this variable directly. Use the function `c-add-style'
|
||||
to add new styles or modify existing styles (it is not a good idea to
|
||||
modify existing styles -- you should create a new style that inherits
|
||||
the existing style.")
|
||||
|
||||
|
||||
|
||||
;; Functions that manipulate styles
|
||||
(defun c-set-style-1 (conscell dont-override)
|
||||
;; Set the style for one variable
|
||||
(let ((attr (car conscell))
|
||||
(val (cdr conscell)))
|
||||
(cond
|
||||
;; first special variable
|
||||
((eq attr 'c-offsets-alist)
|
||||
(mapcar
|
||||
(function
|
||||
(lambda (langentry)
|
||||
(let ((langelem (car langentry))
|
||||
(offset (cdr langentry)))
|
||||
(unless (and dont-override
|
||||
(assq langelem c-offsets-alist))
|
||||
(c-set-offset langelem offset))
|
||||
)))
|
||||
(if dont-override (reverse val) val)))
|
||||
;; second special variable
|
||||
((eq attr 'c-special-indent-hook)
|
||||
(let ((add-func (if dont-override
|
||||
(lambda (func)
|
||||
(unless (memq func c-special-indent-hook)
|
||||
(add-hook 'c-special-indent-hook func t)))
|
||||
(lambda (func)
|
||||
(add-hook 'c-special-indent-hook func)))))
|
||||
(if (listp val)
|
||||
(mapcar add-func (if dont-override (reverse val) val))
|
||||
(funcall add-func val))))
|
||||
;; all other variables
|
||||
(t (if (or (not dont-override)
|
||||
(not (memq attr c-style-variables))
|
||||
(eq (symbol-value attr) 'set-from-style))
|
||||
(set attr val))))
|
||||
))
|
||||
|
||||
(defun c-get-style-variables (style basestyles)
|
||||
;; Return all variables in a style by resolving inheritances.
|
||||
(let ((vars (cdr (or (assoc (downcase style) c-style-alist)
|
||||
(assoc (upcase style) c-style-alist)
|
||||
(assoc style c-style-alist)
|
||||
(error "Undefined style: %s" style)))))
|
||||
(if (string-equal style "user")
|
||||
(copy-alist vars)
|
||||
(let ((base (if (stringp (car vars))
|
||||
(prog1
|
||||
(downcase (car vars))
|
||||
(setq vars (cdr vars)))
|
||||
"user")))
|
||||
(if (memq base basestyles)
|
||||
(error "Style loop detected: %s in %s" base basestyles))
|
||||
(nconc (c-get-style-variables base (cons base basestyles))
|
||||
(copy-alist vars))))))
|
||||
|
||||
(defvar c-set-style-history nil)
|
||||
|
||||
;;;###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.
|
||||
|
||||
The variable `c-indentation-style' always contains the buffer's current
|
||||
style name.
|
||||
|
||||
If the optional argument DONT-OVERRIDE is non-nil, 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.
|
||||
|
||||
Obviously, specifying DONT-OVERRIDE is useful mainly when the initial
|
||||
style is chosen for a CC Mode buffer by a major mode. Since this is
|
||||
done internally by CC Mode, there's hardly ever a reason to use it."
|
||||
(interactive (list (let ((completion-ignore-case t)
|
||||
(prompt (format "Which %s indentation style? "
|
||||
mode-name)))
|
||||
(completing-read prompt c-style-alist nil t
|
||||
nil
|
||||
'c-set-style-history
|
||||
c-indentation-style))))
|
||||
(c-initialize-builtin-style)
|
||||
(let ((vars (c-get-style-variables stylename nil)))
|
||||
(mapcar (lambda (elem)
|
||||
(c-set-style-1 elem dont-override))
|
||||
;; Need to go through the variables backwards when we
|
||||
;; don't override.
|
||||
(if dont-override (nreverse vars) vars)))
|
||||
(setq c-indentation-style stylename)
|
||||
(c-keep-region-active))
|
||||
|
||||
;;;###autoload
|
||||
(defun c-add-style (style descrip &optional set-p)
|
||||
"Adds a style to `c-style-alist', or updates an existing one.
|
||||
STYLE is a string identifying the style to add or update. DESCRIP is
|
||||
an association list describing the style and must be of the form:
|
||||
|
||||
([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
|
||||
|
||||
See the variable `c-style-alist' for the semantics of BASESTYLE,
|
||||
VARIABLE and VALUE. This function also sets the current style to
|
||||
STYLE using `c-set-style' if the optional SET-P flag is non-nil."
|
||||
(interactive
|
||||
(let ((stylename (completing-read "Style to add: " c-style-alist
|
||||
nil nil nil 'c-set-style-history))
|
||||
(description (eval-minibuffer "Style description: ")))
|
||||
(list stylename description
|
||||
(y-or-n-p "Set the style too? "))))
|
||||
(setq style (downcase style))
|
||||
(let ((s (assoc style c-style-alist)))
|
||||
(if s
|
||||
(setcdr s (copy-alist descrip)) ; replace
|
||||
(setq c-style-alist (cons (cons style descrip) c-style-alist))))
|
||||
(and set-p (c-set-style style)))
|
||||
|
||||
|
||||
|
||||
(defvar c-read-offset-history nil)
|
||||
|
||||
(defun c-read-offset (langelem)
|
||||
;; read new offset value for LANGELEM from minibuffer. return a
|
||||
;; legal value only
|
||||
(let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist)
|
||||
(assq langelem (get 'c-offsets-alist
|
||||
'c-stylevar-fallback)))))
|
||||
(symname (symbol-name langelem))
|
||||
(defstr (format "(default %s): " oldoff))
|
||||
(errmsg (concat "Offset must be int, func, var, vector, list, "
|
||||
"or [+,-,++,--,*,/] "
|
||||
defstr))
|
||||
(prompt (concat symname " offset " defstr))
|
||||
offset input interned raw)
|
||||
(while (not offset)
|
||||
(setq input (completing-read prompt obarray 'fboundp nil nil
|
||||
'c-read-offset-history)
|
||||
offset (cond ((string-equal "" input) oldoff) ; default
|
||||
((string-equal "+" input) '+)
|
||||
((string-equal "-" input) '-)
|
||||
((string-equal "++" input) '++)
|
||||
((string-equal "--" input) '--)
|
||||
((string-equal "*" input) '*)
|
||||
((string-equal "/" input) '/)
|
||||
((string-match "^-?[0-9]+$" input)
|
||||
(string-to-int input))
|
||||
;; a symbol with a function binding
|
||||
((fboundp (setq interned (intern input)))
|
||||
interned)
|
||||
;; a symbol with variable binding
|
||||
((boundp interned) interned)
|
||||
;; a lambda function or a vector
|
||||
((progn
|
||||
(c-safe (setq raw (read input)))
|
||||
(or (functionp raw)
|
||||
(vectorp raw)))
|
||||
raw)
|
||||
;; error, but don't signal one, keep trying
|
||||
;; to read an input value
|
||||
(t (ding)
|
||||
(setq prompt errmsg)
|
||||
nil))))
|
||||
offset))
|
||||
|
||||
;;;###autoload
|
||||
(defun c-set-offset (symbol offset &optional ignored)
|
||||
"Change the value of a syntactic element symbol in `c-offsets-alist'.
|
||||
SYMBOL is the syntactic element symbol to change and OFFSET is the new
|
||||
offset for that syntactic element. The optional argument is not used
|
||||
and exists only for compatibility reasons."
|
||||
(interactive
|
||||
(let* ((langelem
|
||||
(intern (completing-read
|
||||
(concat "Syntactic symbol to change"
|
||||
(if current-prefix-arg " or add" "")
|
||||
": ")
|
||||
(mapcar
|
||||
#'(lambda (langelem)
|
||||
(cons (format "%s" (car langelem)) nil))
|
||||
(get 'c-offsets-alist 'c-stylevar-fallback))
|
||||
nil (not current-prefix-arg)
|
||||
;; initial contents tries to be the last element
|
||||
;; on the syntactic analysis list for the current
|
||||
;; line
|
||||
(let* ((syntax (c-guess-basic-syntax))
|
||||
(len (length syntax))
|
||||
(ic (format "%s" (car (nth (1- len) syntax)))))
|
||||
(cons ic 0))
|
||||
)))
|
||||
(offset (c-read-offset langelem)))
|
||||
(list langelem offset current-prefix-arg)))
|
||||
;; sanity check offset
|
||||
(unless (c-valid-offset offset)
|
||||
(error (concat "Offset must be int, func, var, vector, list, "
|
||||
"or in [+,-,++,--,*,/]: %s")
|
||||
offset))
|
||||
(let ((entry (assq symbol c-offsets-alist)))
|
||||
(if entry
|
||||
(setcdr entry offset)
|
||||
(if (assq symbol (get 'c-offsets-alist 'c-stylevar-fallback))
|
||||
(setq c-offsets-alist (cons (cons symbol offset) c-offsets-alist))
|
||||
(error "%s is not a valid syntactic symbol" symbol))))
|
||||
(c-keep-region-active))
|
||||
|
||||
|
||||
|
||||
(defun c-initialize-builtin-style ()
|
||||
;; Dynamically append the default value of most variables. This is
|
||||
;; 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!
|
||||
(unless (get 'c-initialize-builtin-style 'is-run)
|
||||
(put 'c-initialize-builtin-style 'is-run t)
|
||||
;;(c-initialize-cc-mode)
|
||||
(or (assoc "cc-mode" c-style-alist)
|
||||
(assoc "user" c-style-alist)
|
||||
(progn
|
||||
(c-add-style
|
||||
"user"
|
||||
(mapcar
|
||||
(lambda (var)
|
||||
(let ((val (symbol-value var)))
|
||||
(cons var
|
||||
(cond ((eq var 'c-offsets-alist)
|
||||
(mapcar
|
||||
(lambda (langentry)
|
||||
(setq langentry (or (assq (car langentry) val)
|
||||
langentry))
|
||||
(cons (car langentry)
|
||||
(cdr langentry)))
|
||||
(get var 'c-stylevar-fallback)))
|
||||
((eq var 'c-special-indent-hook)
|
||||
val)
|
||||
(t
|
||||
(if (eq val 'set-from-style)
|
||||
(get var 'c-stylevar-fallback)
|
||||
val))))))
|
||||
c-style-variables))
|
||||
(c-add-style "cc-mode" '("user"))))
|
||||
(if c-style-variables-are-local-p
|
||||
(c-make-styles-buffer-local))))
|
||||
|
||||
(defun c-make-styles-buffer-local (&optional this-buf-only-p)
|
||||
"Make all CC Mode style variables buffer local.
|
||||
If you edit primarily one style of C (or C++, Objective-C, Java, etc)
|
||||
code, you probably want style variables to be global. This is the
|
||||
default.
|
||||
|
||||
If you edit many different styles of C (or C++, Objective-C, Java,
|
||||
etc) at the same time, you probably want the CC Mode style variables
|
||||
to be buffer local. If you do, it's advicable to set any CC Mode
|
||||
style variables in a hook function (e.g. off of `c-mode-common-hook'),
|
||||
instead of at the top level of your ~/.emacs file.
|
||||
|
||||
This function makes all the CC Mode style variables buffer local.
|
||||
Call it after CC Mode is loaded into your Emacs environment.
|
||||
Conversely, set the variable `c-style-variables-are-local-p' to t in
|
||||
your .emacs file, before CC Mode is loaded, and this function will be
|
||||
automatically called when CC Mode is loaded.
|
||||
|
||||
Optional argument, when non-nil, means use `make-local-variable'
|
||||
instead of `make-variable-buffer-local'."
|
||||
;; style variables
|
||||
(let ((func (if this-buf-only-p
|
||||
'make-local-variable
|
||||
'make-variable-buffer-local))
|
||||
(varsyms (cons 'c-indentation-style (copy-alist c-style-variables))))
|
||||
(delq 'c-special-indent-hook varsyms)
|
||||
(mapcar func varsyms)
|
||||
;; 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)
|
||||
(setq c-style-variables-are-local-p t))
|
||||
))
|
||||
|
||||
|
||||
|
||||
(cc-provide 'cc-styles)
|
||||
|
||||
;;; cc-styles.el ends here
|
||||
BIN
site-lisp/cc-mode/zbrad-integrated/cc-styles.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-styles.elc
Normal file
Binary file not shown.
1124
site-lisp/cc-mode/zbrad-integrated/cc-vars.el
Normal file
1124
site-lisp/cc-mode/zbrad-integrated/cc-vars.el
Normal file
File diff suppressed because it is too large
Load diff
BIN
site-lisp/cc-mode/zbrad-integrated/cc-vars.elc
Normal file
BIN
site-lisp/cc-mode/zbrad-integrated/cc-vars.elc
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue