1997-07-10 07:54:06 +00:00
|
|
|
|
;;; cc-styles.el --- support for styles in CC Mode
|
|
|
|
|
|
2013-01-01 09:11:05 +00:00
|
|
|
|
;; Copyright (C) 1985, 1987, 1992-2013 Free Software Foundation, Inc.
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
2007-01-20 18:33:11 +00:00
|
|
|
|
;; Authors: 2004- Alan Mackenzie
|
|
|
|
|
;; 1998- Martin Stjernholm
|
2003-07-03 12:30:59 +00:00
|
|
|
|
;; 1992-1999 Barry A. Warsaw
|
2009-01-11 00:37:05 +00:00
|
|
|
|
;; 1987 Dave Detlefs
|
|
|
|
|
;; 1987 Stewart Clamen
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; 1985 Richard M. Stallman
|
1999-02-08 16:53:18 +00:00
|
|
|
|
;; Maintainer: bug-cc-mode@gnu.org
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; Created: 22-Apr-1997 (split from cc-mode.el)
|
2010-08-29 12:17:13 -04:00
|
|
|
|
;; Keywords: c languages
|
|
|
|
|
;; Package: cc-mode
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
|
|
|
|
;; This file is part of GNU Emacs.
|
|
|
|
|
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; GNU Emacs is free software: you can redistribute it and/or modify
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; it under the terms of the GNU General Public License as published by
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
;; (at your option) any later version.
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
|
|
|
|
;; 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
|
2008-05-06 07:25:26 +00:00
|
|
|
|
;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
2001-07-16 07:46:48 +00:00
|
|
|
|
;;; Commentary:
|
|
|
|
|
|
|
|
|
|
;;; Code:
|
|
|
|
|
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(eval-when-compile
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(let ((load-path
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(if (and (boundp 'byte-compile-dest-file)
|
|
|
|
|
(stringp byte-compile-dest-file))
|
|
|
|
|
(cons (file-name-directory byte-compile-dest-file) load-path)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
load-path)))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(load "cc-bytecomp" nil t)))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(cc-require 'cc-defs)
|
|
|
|
|
(cc-require 'cc-vars)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(cc-require 'cc-align)
|
|
|
|
|
;; cc-align is only indirectly required: Styles added with
|
|
|
|
|
;; `c-add-style' often contains references to functions defined there.
|
|
|
|
|
|
|
|
|
|
;; Silence the compiler.
|
|
|
|
|
(cc-bytecomp-defvar adaptive-fill-first-line-regexp) ; Emacs
|
1999-02-08 16:53:18 +00:00
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
2003-07-05 19:54:33 +00:00
|
|
|
|
(defvar c-style-alist
|
1997-07-10 07:54:06 +00:00
|
|
|
|
'(("gnu"
|
|
|
|
|
(c-basic-offset . 2)
|
|
|
|
|
(c-comment-only-line-offset . (0 . 0))
|
2008-01-27 13:59:47 +00:00
|
|
|
|
(c-hanging-braces-alist . ((substatement-open before after)
|
|
|
|
|
(arglist-cont-nonempty)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-offsets-alist . ((statement-block-intro . +)
|
|
|
|
|
(knr-argdecl-intro . 5)
|
|
|
|
|
(substatement-open . +)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-label . 0)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(label . 0)
|
|
|
|
|
(statement-case-open . +)
|
|
|
|
|
(statement-cont . +)
|
|
|
|
|
(arglist-intro . c-lineup-arglist-intro-after-paren)
|
|
|
|
|
(arglist-close . c-lineup-arglist)
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(inline-open . 0)
|
2007-01-01 22:11:28 +00:00
|
|
|
|
(brace-list-open . +)
|
|
|
|
|
(topmost-intro-cont
|
|
|
|
|
. (first c-lineup-topmost-intro-cont
|
|
|
|
|
c-lineup-gnu-DEFUN-intro-cont))))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-special-indent-hook . c-gnu-impose-minimum)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(c-block-comment-prefix . ""))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("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)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-label . 0)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(label . 0)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(statement-cont . +))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("bsd"
|
2000-07-24 11:10:15 +00:00
|
|
|
|
(c-basic-offset . 8)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-comment-only-line-offset . 0)
|
|
|
|
|
(c-offsets-alist . ((statement-block-intro . +)
|
|
|
|
|
(knr-argdecl-intro . +)
|
|
|
|
|
(substatement-open . 0)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-label . 0)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(label . 0)
|
|
|
|
|
(statement-cont . +)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(inline-open . 0)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(inexpr-class . 0))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("stroustrup"
|
|
|
|
|
(c-basic-offset . 4)
|
|
|
|
|
(c-comment-only-line-offset . 0)
|
|
|
|
|
(c-offsets-alist . ((statement-block-intro . +)
|
|
|
|
|
(substatement-open . 0)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-label . 0)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(label . 0)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(statement-cont . +))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("whitesmith"
|
|
|
|
|
(c-basic-offset . 4)
|
|
|
|
|
(c-comment-only-line-offset . 0)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
;; It's obvious that the CC Mode way of choosing anchor positions
|
|
|
|
|
;; doesn't fit this style at all. :P
|
|
|
|
|
(c-offsets-alist . ((defun-open . +)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(defun-close . c-lineup-whitesmith-in-block)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(defun-block-intro . (add c-lineup-whitesmith-in-block
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(class-open . +)
|
|
|
|
|
(class-close . +)
|
|
|
|
|
(inline-open . +)
|
|
|
|
|
(inline-close . c-lineup-whitesmith-in-block)
|
|
|
|
|
(knr-argdecl-intro . +)
|
|
|
|
|
(block-open . 0) ; Get indentation from `statement' instead.
|
|
|
|
|
(block-close . c-lineup-whitesmith-in-block)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(brace-list-open . +)
|
|
|
|
|
(brace-list-close . c-lineup-whitesmith-in-block)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(brace-list-intro . (add c-lineup-whitesmith-in-block
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(brace-list-entry . (add c-lineup-after-whitesmith-blocks
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(brace-entry-open . (add c-lineup-after-whitesmith-blocks
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(statement . (add c-lineup-after-whitesmith-blocks
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(statement-block-intro . (add c-lineup-whitesmith-in-block
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(substatement-open . +)
|
|
|
|
|
(substatement-label . +)
|
|
|
|
|
(label . 0)
|
|
|
|
|
(arglist-intro . (add c-lineup-whitesmith-in-block
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(arglist-cont . (add c-lineup-after-whitesmith-blocks
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(arglist-cont-nonempty . (add c-lineup-whitesmith-in-block
|
|
|
|
|
c-indent-multi-line-block))
|
|
|
|
|
(arglist-close . c-lineup-whitesmith-in-block)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(inclass . c-lineup-whitesmith-in-block)
|
|
|
|
|
(extern-lang-open . +)
|
|
|
|
|
(namespace-open . +)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(module-open . +)
|
|
|
|
|
(composition-open . +)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(extern-lang-close . +)
|
|
|
|
|
(namespace-close . +)
|
|
|
|
|
(module-close . +)
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(composition-close . +)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(inextern-lang . c-lineup-whitesmith-in-block)
|
|
|
|
|
(innamespace . c-lineup-whitesmith-in-block)
|
|
|
|
|
(inmodule . c-lineup-whitesmith-in-block)
|
|
|
|
|
(incomposition . c-lineup-whitesmith-in-block)
|
|
|
|
|
(inexpr-class . 0))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("ellemtel"
|
|
|
|
|
(c-basic-offset . 3)
|
|
|
|
|
(c-comment-only-line-offset . 0)
|
2008-07-31 14:00:52 +00:00
|
|
|
|
(c-hanging-braces-alist . ((substatement-open before after)
|
|
|
|
|
(arglist-cont-nonempty)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-offsets-alist . ((topmost-intro . 0)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement . +)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(substatement-open . 0)
|
|
|
|
|
(case-label . +)
|
|
|
|
|
(access-label . -)
|
2008-07-31 14:00:52 +00:00
|
|
|
|
(inclass . +)
|
|
|
|
|
(inline-open . 0))))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("linux"
|
|
|
|
|
(c-basic-offset . 8)
|
|
|
|
|
(c-comment-only-line-offset . 0)
|
|
|
|
|
(c-hanging-braces-alist . ((brace-list-open)
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(brace-entry-open)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(substatement-open after)
|
2008-01-27 13:59:47 +00:00
|
|
|
|
(block-close . c-snug-do-while)
|
|
|
|
|
(arglist-cont-nonempty)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-cleanup-list . (brace-else-brace))
|
|
|
|
|
(c-offsets-alist . ((statement-block-intro . +)
|
|
|
|
|
(knr-argdecl-intro . 0)
|
|
|
|
|
(substatement-open . 0)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-label . 0)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(label . 0)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(statement-cont . +))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("python"
|
|
|
|
|
(indent-tabs-mode . t)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(fill-column . 78)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-basic-offset . 8)
|
|
|
|
|
(c-offsets-alist . ((substatement-open . 0)
|
1997-09-08 03:22:22 +00:00
|
|
|
|
(inextern-lang . 0)
|
|
|
|
|
(arglist-intro . +)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(knr-argdecl-intro . +)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-hanging-braces-alist . ((brace-list-open)
|
|
|
|
|
(brace-list-intro)
|
|
|
|
|
(brace-list-close)
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(brace-entry-open)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(substatement-open after)
|
2008-01-27 13:59:47 +00:00
|
|
|
|
(block-close . c-snug-do-while)
|
|
|
|
|
(arglist-cont-nonempty)))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(c-block-comment-prefix . ""))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
("java"
|
1998-02-17 07:13:59 +00:00
|
|
|
|
(c-basic-offset . 4)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-comment-only-line-offset . (0 . 0))
|
1997-08-09 18:36:45 +00:00
|
|
|
|
;; the following preserves Javadoc starter lines
|
1998-02-17 07:13:59 +00:00
|
|
|
|
(c-offsets-alist . ((inline-open . 0)
|
|
|
|
|
(topmost-intro-cont . +)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(statement-block-intro . +)
|
|
|
|
|
(knr-argdecl-intro . 5)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(substatement-open . +)
|
|
|
|
|
(substatement-label . +)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(label . +)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(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)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(func-decl-cont . c-lineup-java-throws))))
|
|
|
|
|
|
|
|
|
|
;; awk style exists primarily for auto-newline settings. Otherwise it's
|
|
|
|
|
;; pretty much like k&r.
|
|
|
|
|
("awk"
|
|
|
|
|
(c-basic-offset . 4)
|
|
|
|
|
(c-comment-only-line-offset . 0)
|
|
|
|
|
(c-hanging-braces-alist . ((defun-open after)
|
|
|
|
|
(defun-close . c-snug-1line-defun-close)
|
|
|
|
|
(substatement-open after)
|
2008-01-27 13:59:47 +00:00
|
|
|
|
(block-close . c-snug-do-while)
|
|
|
|
|
(arglist-cont-nonempty)))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(c-hanging-semi&comma-criteria . nil)
|
|
|
|
|
(c-cleanup-list . nil) ; You might want one-liner-defun here.
|
|
|
|
|
(c-offsets-alist . ((statement-block-intro . +)
|
|
|
|
|
(substatement-open . 0)
|
|
|
|
|
(statement-cont . +))))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
)
|
|
|
|
|
"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.
|
1999-12-12 18:24:19 +00:00
|
|
|
|
By default, all styles inherit from the \"user\" style, which is
|
1997-07-10 07:54:06 +00:00
|
|
|
|
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
|
2006-05-19 19:50:50 +00:00
|
|
|
|
the existing style).")
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; Functions that manipulate styles
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(defun c-set-style-1 (conscell dont-override)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; Set the style for one variable
|
|
|
|
|
(let ((attr (car conscell))
|
|
|
|
|
(val (cdr conscell)))
|
|
|
|
|
(cond
|
|
|
|
|
;; first special variable
|
|
|
|
|
((eq attr 'c-offsets-alist)
|
2002-06-08 23:38:42 +00:00
|
|
|
|
(let ((offsets (cond ((eq dont-override t)
|
|
|
|
|
c-offsets-alist)
|
|
|
|
|
(dont-override
|
|
|
|
|
(default-value 'c-offsets-alist)))))
|
|
|
|
|
(mapcar (lambda (langentry)
|
|
|
|
|
(let ((langelem (car langentry))
|
|
|
|
|
(offset (cdr langentry)))
|
|
|
|
|
(unless (assq langelem offsets)
|
|
|
|
|
(c-set-offset langelem offset))))
|
|
|
|
|
val)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; second special variable
|
|
|
|
|
((eq attr 'c-special-indent-hook)
|
2002-06-08 23:38:42 +00:00
|
|
|
|
;; Maybe we should ignore dont-override here and always add new
|
|
|
|
|
;; hooks?
|
|
|
|
|
(unless (cond ((eq dont-override t)
|
|
|
|
|
c-special-indent-hook)
|
|
|
|
|
(dont-override
|
|
|
|
|
(default-value 'c-special-indent-hook)))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(if (listp val)
|
2002-06-08 23:38:42 +00:00
|
|
|
|
(mapcar (lambda (func)
|
|
|
|
|
(add-hook 'c-special-indent-hook func t t))
|
|
|
|
|
val)
|
|
|
|
|
(add-hook 'c-special-indent-hook val t t))))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; all other variables
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(t (when (or (not dont-override)
|
|
|
|
|
(not (memq attr c-style-variables))
|
2002-06-08 23:38:42 +00:00
|
|
|
|
(eq (if (eq dont-override t)
|
|
|
|
|
(symbol-value attr)
|
|
|
|
|
(default-value attr))
|
|
|
|
|
'set-from-style))
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(set attr val)
|
|
|
|
|
;; Must update a number of other variables if
|
|
|
|
|
;; c-comment-prefix-regexp is set.
|
|
|
|
|
(if (eq attr 'c-comment-prefix-regexp)
|
|
|
|
|
(c-setup-paragraph-variables)))))))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(defun c-get-style-variables (style basestyles)
|
|
|
|
|
;; Return all variables in a style by resolving inheritances.
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(if (not style)
|
|
|
|
|
(copy-alist c-fallback-style)
|
|
|
|
|
(let ((vars (cdr (or (assoc (downcase style) c-style-alist)
|
|
|
|
|
(assoc (upcase style) c-style-alist)
|
|
|
|
|
(assoc style c-style-alist)
|
|
|
|
|
(progn
|
|
|
|
|
(c-benign-error "Undefined style: %s" style)
|
|
|
|
|
nil)))))
|
|
|
|
|
(let ((base (and (stringp (car-safe vars))
|
|
|
|
|
(prog1
|
|
|
|
|
(downcase (car vars))
|
|
|
|
|
(setq vars (cdr vars))))))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(if (memq base basestyles)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(c-benign-error "Style loop detected: %s in %s" base basestyles)
|
|
|
|
|
(nconc (c-get-style-variables base (cons base basestyles))
|
|
|
|
|
(copy-alist vars)))))))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(defvar c-set-style-history nil)
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(defun c-set-style (stylename &optional dont-override)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
"Set the current buffer to use the style STYLENAME.
|
|
|
|
|
STYLENAME, a string, must be an existing CC Mode style - These are contained
|
|
|
|
|
in the variable `c-style-alist'.
|
|
|
|
|
|
|
|
|
|
The variable `c-indentation-style' will get set to STYLENAME.
|
|
|
|
|
|
|
|
|
|
\"Setting the style\" is done by setting CC Mode's \"style variables\" to the
|
|
|
|
|
values indicated by the pertinent entry in `c-style-alist'. Other variables
|
|
|
|
|
might get set too.
|
|
|
|
|
|
|
|
|
|
If DONT-OVERRIDE is neither nil nor t, style variables whose default values
|
|
|
|
|
have been set (more precisely, whose default values are not the symbol
|
|
|
|
|
`set-from-style') will not be changed. This avoids overriding global settings
|
2012-09-17 13:41:04 +08:00
|
|
|
|
done in your init file. It is useful to call c-set-style from a mode hook
|
|
|
|
|
in this way.
|
2005-12-02 12:30:36 +00:00
|
|
|
|
|
|
|
|
|
If DONT-OVERRIDE is t, style variables that already have values (i.e., whose
|
|
|
|
|
values are not the symbol `set-from-style') will not be overridden. CC Mode
|
|
|
|
|
calls c-set-style internally in this way whilst initializing a buffer; if
|
|
|
|
|
cc-set-style is called like this from anywhere else, it will usually behave as
|
|
|
|
|
a null operation."
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(interactive
|
|
|
|
|
(list (let ((completion-ignore-case t)
|
|
|
|
|
(prompt (format "Which %s indentation style? "
|
|
|
|
|
mode-name)))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(completing-read prompt c-style-alist nil t nil
|
|
|
|
|
'c-set-style-history
|
|
|
|
|
c-indentation-style))))
|
|
|
|
|
(or c-buffer-is-cc-mode
|
|
|
|
|
(error "Buffer %s is not a CC Mode buffer (c-set-style)" (buffer-name)))
|
2004-08-11 16:22:21 +00:00
|
|
|
|
(or (stringp stylename)
|
|
|
|
|
(error "Argument to c-set-style was not a string"))
|
1997-08-09 18:36:45 +00:00
|
|
|
|
(c-initialize-builtin-style)
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(let ((vars (c-get-style-variables stylename nil)))
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(unless dont-override
|
|
|
|
|
;; Since we always add to c-special-indent-hook we must reset it
|
|
|
|
|
;; first, or else the hooks from the preceding style will
|
|
|
|
|
;; remain. This is not necessary for c-offsets-alist, since
|
|
|
|
|
;; c-get-style-variables contains every valid offset type in the
|
|
|
|
|
;; fallback entry.
|
|
|
|
|
(setq c-special-indent-hook
|
|
|
|
|
(default-value 'c-special-indent-hook)))
|
2007-10-13 03:01:12 +00:00
|
|
|
|
(mapc (lambda (elem)
|
|
|
|
|
(c-set-style-1 elem dont-override))
|
|
|
|
|
;; Need to go through the variables backwards when we
|
|
|
|
|
;; don't override any settings.
|
|
|
|
|
(if (eq dont-override t) (nreverse vars) vars)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(setq c-indentation-style stylename)
|
|
|
|
|
(c-keep-region-active))
|
|
|
|
|
|
|
|
|
|
;;;###autoload
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(defun c-add-style (style description &optional set-p)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
"Adds a style to `c-style-alist', or updates an existing one.
|
2003-07-03 12:30:59 +00:00
|
|
|
|
STYLE is a string identifying the style to add or update. DESCRIPTION
|
|
|
|
|
is an association list describing the style and must be of the form:
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
|
|
|
|
([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))
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(descr (eval-minibuffer "Style description: ")))
|
|
|
|
|
(list stylename descr
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(y-or-n-p "Set the style too? "))))
|
|
|
|
|
(setq style (downcase style))
|
|
|
|
|
(let ((s (assoc style c-style-alist)))
|
|
|
|
|
(if s
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(setcdr s (copy-alist description)) ; replace
|
|
|
|
|
(setq c-style-alist (cons (cons style description) c-style-alist))))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(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
|
2008-02-05 14:24:26 +00:00
|
|
|
|
;; valid value only
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist)
|
|
|
|
|
(assq langelem (get 'c-offsets-alist
|
|
|
|
|
'c-stylevar-fallback)))))
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(symname (symbol-name langelem))
|
|
|
|
|
(defstr (format "(default %s): " oldoff))
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(errmsg (concat "Offset must be int, func, var, vector, list, "
|
1999-02-08 16:53:18 +00:00
|
|
|
|
"or [+,-,++,--,*,/] "
|
|
|
|
|
defstr))
|
|
|
|
|
(prompt (concat symname " offset " defstr))
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(keymap (make-sparse-keymap))
|
|
|
|
|
(minibuffer-completion-table obarray)
|
|
|
|
|
(minibuffer-completion-predicate 'fboundp)
|
|
|
|
|
offset input)
|
|
|
|
|
;; In principle completing-read is used here, but SPC is unbound
|
|
|
|
|
;; to make it less annoying to enter lists.
|
|
|
|
|
(set-keymap-parent keymap minibuffer-local-completion-map)
|
|
|
|
|
(define-key keymap " " 'self-insert-command)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(while (not offset)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(setq input (read-from-minibuffer prompt nil keymap t
|
|
|
|
|
'c-read-offset-history
|
|
|
|
|
(format "%s" oldoff)))
|
|
|
|
|
(if (c-valid-offset input)
|
|
|
|
|
(setq offset input)
|
|
|
|
|
;; error, but don't signal one, keep trying
|
|
|
|
|
;; to read an input value
|
|
|
|
|
(ding)
|
|
|
|
|
(setq prompt errmsg)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
offset))
|
|
|
|
|
|
1997-08-07 17:36:36 +00:00
|
|
|
|
;;;###autoload
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(defun c-set-offset (symbol offset &optional ignored)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
"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
|
1999-12-12 18:24:19 +00:00
|
|
|
|
offset for that syntactic element. The optional argument is not used
|
|
|
|
|
and exists only for compatibility reasons."
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(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))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(get 'c-offsets-alist 'c-stylevar-fallback))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
nil (not current-prefix-arg)
|
|
|
|
|
;; initial contents tries to be the last element
|
|
|
|
|
;; on the syntactic analysis list for the current
|
|
|
|
|
;; line
|
2003-02-10 00:51:25 +00:00
|
|
|
|
(and c-buffer-is-cc-mode
|
2003-07-03 12:30:59 +00:00
|
|
|
|
(c-save-buffer-state
|
|
|
|
|
((syntax (c-guess-basic-syntax))
|
|
|
|
|
(len (length syntax))
|
|
|
|
|
(ic (format "%s" (car (nth (1- len) syntax)))))
|
2003-02-10 00:51:25 +00:00
|
|
|
|
(cons ic 0)))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
)))
|
|
|
|
|
(offset (c-read-offset langelem)))
|
|
|
|
|
(list langelem offset current-prefix-arg)))
|
|
|
|
|
;; sanity check offset
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(if (c-valid-offset 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))
|
|
|
|
|
(c-benign-error "%s is not a valid syntactic symbol" symbol))))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(c-benign-error "Invalid indentation setting for symbol %s: %S"
|
2002-04-22 00:35:36 +00:00
|
|
|
|
symbol offset))
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(c-keep-region-active))
|
|
|
|
|
|
2002-04-22 00:35:36 +00:00
|
|
|
|
|
|
|
|
|
(defun c-setup-paragraph-variables ()
|
2005-12-02 12:30:36 +00:00
|
|
|
|
"Fix things up for paragraph recognition and filling inside comments and
|
|
|
|
|
strings by incorporating the values of `c-comment-prefix-regexp',
|
|
|
|
|
`sentence-end', `paragraph-start' and `paragraph-separate' in the relevant
|
2002-04-22 00:35:36 +00:00
|
|
|
|
variables."
|
2003-07-03 12:30:59 +00:00
|
|
|
|
|
2003-09-24 13:56:27 +00:00
|
|
|
|
(interactive)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(or c-buffer-is-cc-mode
|
|
|
|
|
(error "Buffer %s is not a CC Mode buffer (c-setup-paragraph-variables)"
|
|
|
|
|
(buffer-name)))
|
|
|
|
|
;; Set up the values for use in comments.
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(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))
|
2003-09-24 13:56:27 +00:00
|
|
|
|
|
2009-01-05 21:22:20 +00:00
|
|
|
|
(let* ((empty-is-prefix (string-match c-current-comment-prefix ""))
|
|
|
|
|
(nonws-comment-line-prefix
|
|
|
|
|
(concat "\\(" c-current-comment-prefix "\\)[ \t]*"))
|
|
|
|
|
(comment-line-prefix (concat "[ \t]*" nonws-comment-line-prefix))
|
|
|
|
|
(blank-or-comment-line-prefix
|
|
|
|
|
(concat "[ \t]*"
|
|
|
|
|
(if empty-is-prefix "" "\\(")
|
|
|
|
|
nonws-comment-line-prefix
|
|
|
|
|
(if empty-is-prefix "" "\\)?"))))
|
|
|
|
|
|
|
|
|
|
(setq paragraph-start (concat blank-or-comment-line-prefix
|
2005-12-02 12:30:36 +00:00
|
|
|
|
c-paragraph-start
|
|
|
|
|
"\\|"
|
|
|
|
|
page-delimiter)
|
2009-01-05 21:22:20 +00:00
|
|
|
|
paragraph-separate (concat blank-or-comment-line-prefix
|
2005-12-02 12:30:36 +00:00
|
|
|
|
c-paragraph-separate
|
|
|
|
|
"\\|"
|
|
|
|
|
page-delimiter)
|
|
|
|
|
paragraph-ignore-fill-prefix t
|
|
|
|
|
adaptive-fill-mode t
|
|
|
|
|
adaptive-fill-regexp
|
|
|
|
|
(concat comment-line-prefix
|
|
|
|
|
(if (default-value 'adaptive-fill-regexp)
|
|
|
|
|
(concat "\\("
|
|
|
|
|
(default-value 'adaptive-fill-regexp)
|
|
|
|
|
"\\)")
|
|
|
|
|
"")))
|
2003-09-24 13:56:27 +00:00
|
|
|
|
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(when (boundp 'adaptive-fill-first-line-regexp)
|
2005-12-02 12:30:36 +00:00
|
|
|
|
;; XEmacs adaptive fill mode doesn't have this.
|
Derive from prog-mode, use derived-mode-p, and fix up various
minor style issues in lisp/progmodes.
* lisp/progmodes/vhdl-mode.el (vhdl-write-file-hooks-init)
(vhdl-hs-minor-mode, vhdl-ps-print-init): Fix make-local-variable ->
make-local-hook.
* lisp/progmodes/sh-script.el (sh-require-final-newline): Remove.
(sh-set-shell): Don't set require-final-newline since it's already done
by prog-mode.
* lisp/progmodes/modula2.el (m2-mode): Don't make m2-end-comment-column
since we never set it.
* lisp/progmodes/ebrowse.el (ebrowse-set-tree-indentation):
Use read-string and standard prompt.
* lisp/progmodes/dcl-mode.el (dcl-mode-map): Move init into declaration.
* lisp/progmodes/meta-mode.el (meta-mode-abbrev-table): Merge init and decl.
(meta-common-mode-syntax-table): Rename from meta-mode-syntax-table.
(meta-common-mode-map): Rename from meta-mode-map.
Remove C-m binding, which is a user preference, not mode specific.
(meta-common-mode): New major mode; replace meta-common-initialization.
* lisp/progmodes/js.el (js-mode): Call syntax-propertize rather than messing
around with font-lock.
* lisp/progmodes/etags.el (select-tags-table-mode):
Derive from special-mode.
* lisp/progmodes/octave-mod.el (octave-mode):
* lisp/progmodes/gdb-mi.el (gdb-inferior-io-mode, gdb-threads-mode)
(gdb-memory-mode, gdb-disassembly-mode, gdb-breakpoints-mode)
(gdb-frames-mode, gdb-locals-mode, gdb-registers-mode):
Let define-derived-mode do its job.
* lisp/progmodes/cpp.el (cpp-edit-mode-map):
Move initialization into declaration.
(cpp-edit-mode): Use define-derived-mode.
(cpp-edit-load): Use derived-mode-p.
* lisp/progmodes/mixal-mode.el (mixal-mode):
* lisp/progmodes/f90.el (f90-mode):
* lisp/progmodes/cfengine.el (cfengine-mode): Don't bother setting
require-final-newline since prog-mode does it already.
* lisp/progmodes/cc-cmds.el (c-update-modeline): Use match-string.
* lisp/progmodes/asm-mode.el (asm-mode-map): Fix menu setup.
* lisp/progmodes/antlr-mode.el: Require cc-mode upfront.
(antlr-mode-syntax-table, antlr-action-syntax-table): Initialize in
the declaration.
(antlr-directory-dependencies, antlr-show-makefile-rules):
Use derived-mode-p.
(antlr-language-option): Don't assume point-min==1.
(antlr-mode): Use define-derived-mode.
* lisp/progmodes/ada-mode.el: Use derived-mode-p.
(ada-mode): Use define-derived-mode.
Use hack-local-variables-hook.
* lisp/progmodes/vhdl-mode.el (vhdl-mode):
* lisp/progmodes/verilog-mode.el (verilog-mode):
* lisp/progmodes/vera-mode.el (vera-mode):
* lisp/progmodes/sql.el (sql-mode):
* lisp/progmodes/scheme.el (scheme-mode):
* lisp/progmodes/perl-mode.el (perl-mode):
* lisp/progmodes/octave-inf.el (inferior-octave-mode):
* lisp/progmodes/autoconf.el (autoconf-mode):
* lisp/progmodes/m4-mode.el (m4-mode):
* lisp/progmodes/inf-lisp.el (inferior-lisp-mode):
* lisp/progmodes/idlwave.el (idlwave-mode):
* lisp/progmodes/icon.el (icon-mode):
* lisp/progmodes/idlw-help.el (idlwave-help-mode):
* lisp/progmodes/dcl-mode.el (dcl-mode):
* lisp/progmodes/idlw-shell.el (idlwave-shell-mode):
* lisp/progmodes/ebrowse.el (ebrowse-tree-mode, ebrowse-electric-list-mode)
(ebrowse-member-mode, ebrowse-electric-position-mode):
Use define-derived-mode.
* lisp/progmodes/xscheme.el (xscheme-start)
(local-set-scheme-interaction-buffer, scheme-interaction-mode):
* lisp/progmodes/which-func.el (which-function):
* lisp/progmodes/vhdl-mode.el (vhdl-set-style):
* lisp/progmodes/verilog-mode.el (verilog-set-compile-command)
(verilog-modify-compile-command, verilog-error-regexp-add-xemacs)
(verilog-set-define, verilog-auto-reeval-locals):
* lisp/progmodes/sql.el (sql-product-font-lock, sql-interactive-mode):
* lisp/progmodes/simula.el (simula-mode):
* lisp/progmodes/scheme.el (scheme-mode-variables, dsssl-mode):
* lisp/progmodes/python.el (python-check, python-mode):
* lisp/progmodes/prolog.el (prolog-mode-variables):
* lisp/progmodes/gud.el (gud-tooltip-activate-mouse-motions):
* lisp/progmodes/ebrowse.el (ebrowse-view-file-other-frame):
* lisp/progmodes/delphi.el (delphi-mode):
* lisp/progmodes/cc-styles.el (c-setup-paragraph-variables):
* lisp/progmodes/cc-mode.el (c-basic-common-init, c-common-init)
(c-font-lock-init): Move make-local-variable to their setq.
* lisp/progmodes/xscheme.el (exit-scheme-interaction-mode)
(xscheme-enter-interaction-mode, xscheme-enter-debugger-mode)
(xscheme-debugger-mode-p, xscheme-send-string-1):
* lisp/progmodes/tcl.el (inferior-tcl-proc, tcl-current-word)
(tcl-load-file, tcl-restart-with-file):
* lisp/progmodes/ps-mode.el (ps-run-running):
* lisp/progmodes/gdb-mi.el (gud-watch, gdb-mouse-set-clear-breakpoint):
* lisp/progmodes/js.el (js--get-all-known-symbols):
* lisp/progmodes/inf-lisp.el (inferior-lisp-proc):
* lisp/progmodes/idlwave.el (idlwave-beginning-of-statement)
(idlwave-template, idlwave-update-buffer-routine-info)
(idlwave-update-current-buffer-info)
(idlwave-get-routine-info-from-buffers, idlwave-choose)
(idlwave-scan-class-info, idlwave-fix-keywords)
(idlwave-list-buffer-load-path-shadows):
* lisp/progmodes/idlw-toolbar.el (idlwave-toolbar, idlwave-toolbar-add)
(idlwave-toolbar-remove):
* lisp/progmodes/idlw-shell.el (idlwave-shell-save-and-action)
(idlwave-shell-file-name, idlwave-shell-electric-debug-all-off)
(idlwave-shell-menu-def):
* lisp/progmodes/idlw-complete-structtag.el
(idlwave-prepare-structure-tag-completion):
* lisp/progmodes/gud.el (gud-set-buffer):
* lisp/progmodes/f90.el (f90-backslash-not-special):
* lisp/progmodes/delphi.el (delphi-find-unit): Use derived-mode-p.
2010-12-10 15:00:25 -05:00
|
|
|
|
(set (make-local-variable 'adaptive-fill-first-line-regexp)
|
|
|
|
|
(concat "\\`" comment-line-prefix
|
|
|
|
|
;; Maybe we should incorporate the old value here,
|
|
|
|
|
;; but then we have to do all sorts of kludges to
|
|
|
|
|
;; deal with the \` and \' it probably contains.
|
|
|
|
|
"\\'"))))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
|
|
|
|
|
;; Set up the values for use in strings. These are the default
|
|
|
|
|
;; paragraph-start/separate values, enhanced to accept escaped EOLs as
|
|
|
|
|
;; whitespace. Used in c-beginning/end-of-sentence-in-string in cc-cmds.
|
|
|
|
|
(setq c-string-par-start
|
|
|
|
|
;;(concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$"))
|
|
|
|
|
"\f\\|[ \t]*\\\\?$")
|
|
|
|
|
(setq c-string-par-separate
|
|
|
|
|
;;(concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$"))
|
|
|
|
|
"[ \t\f]*\\\\?$")
|
|
|
|
|
(setq c-sentence-end-with-esc-eol
|
|
|
|
|
(concat "\\(\\(" (c-default-value-sentence-end) "\\)"
|
2008-02-05 14:24:26 +00:00
|
|
|
|
;; N.B.: "$" would be invalid when not enclosed like "\\($\\)".
|
2005-12-02 12:30:36 +00:00
|
|
|
|
"\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
|
|
|
|
|
"\\)")))
|
2002-04-22 00:35:36 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
;; 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.
|
2003-07-03 12:30:59 +00:00
|
|
|
|
|
2002-04-22 00:35:36 +00:00
|
|
|
|
;; 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))))
|
1999-02-08 16:53:18 +00:00
|
|
|
|
|
1999-12-12 18:24:19 +00:00
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
(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!
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(unless (get 'c-initialize-builtin-style 'is-run)
|
|
|
|
|
(put 'c-initialize-builtin-style 'is-run t)
|
2001-03-21 12:59:36 +00:00
|
|
|
|
;;(c-initialize-cc-mode)
|
2002-04-22 00:35:36 +00:00
|
|
|
|
(unless (assoc "user" c-style-alist)
|
|
|
|
|
(let ((vars c-style-variables) var val uservars)
|
|
|
|
|
(while vars
|
|
|
|
|
(setq var (car vars)
|
|
|
|
|
val (symbol-value var)
|
|
|
|
|
vars (cdr vars))
|
|
|
|
|
(cond ((eq var 'c-offsets-alist)
|
|
|
|
|
(or (null val)
|
|
|
|
|
(setq uservars (cons (cons 'c-offsets-alist val)
|
|
|
|
|
uservars))))
|
|
|
|
|
((not (eq val 'set-from-style))
|
|
|
|
|
(setq uservars (cons (cons var val)
|
|
|
|
|
uservars)))))
|
|
|
|
|
(c-add-style "user" uservars)))
|
|
|
|
|
(unless (assoc "cc-mode" c-style-alist)
|
|
|
|
|
(c-add-style "cc-mode" '("user")))
|
1999-02-08 16:53:18 +00:00
|
|
|
|
(if c-style-variables-are-local-p
|
|
|
|
|
(c-make-styles-buffer-local))))
|
1997-08-09 18:36:45 +00:00
|
|
|
|
|
1998-02-17 07:13:59 +00:00
|
|
|
|
(defun c-make-styles-buffer-local (&optional this-buf-only-p)
|
1997-07-10 07:54:06 +00:00
|
|
|
|
"Make all CC Mode style variables buffer local.
|
2003-07-03 12:30:59 +00:00
|
|
|
|
If `this-buf-only-p' is non-nil, the style variables will be made
|
|
|
|
|
buffer local only in the current buffer. Otherwise they'll be made
|
2005-12-02 12:30:36 +00:00
|
|
|
|
permanently buffer local in any buffer that changes their values.
|
2003-07-03 12:30:59 +00:00
|
|
|
|
|
|
|
|
|
The buffer localness of the style variables are normally controlled
|
|
|
|
|
with the variable `c-style-variables-are-local-p', so there's seldom
|
|
|
|
|
any reason to call this function directly."
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;; style variables
|
1998-02-17 07:13:59 +00:00
|
|
|
|
(let ((func (if this-buf-only-p
|
|
|
|
|
'make-local-variable
|
|
|
|
|
'make-variable-buffer-local))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(varsyms (cons 'c-indentation-style (copy-alist c-style-variables))))
|
|
|
|
|
(delq 'c-special-indent-hook varsyms)
|
2007-10-13 03:01:12 +00:00
|
|
|
|
(mapc func varsyms)
|
1998-02-17 07:13:59 +00:00
|
|
|
|
;; Hooks must be handled specially
|
|
|
|
|
(if this-buf-only-p
|
2010-10-02 18:53:04 -07:00
|
|
|
|
(if (featurep 'xemacs) (make-local-hook 'c-special-indent-hook))
|
2005-12-02 12:30:36 +00:00
|
|
|
|
(with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
|
1999-12-12 18:24:19 +00:00
|
|
|
|
(setq c-style-variables-are-local-p t))
|
1998-02-17 07:13:59 +00:00
|
|
|
|
))
|
|
|
|
|
|
2011-06-30 20:45:12 +00:00
|
|
|
|
(defun cc-choose-style-for-mode (mode default-style)
|
|
|
|
|
"Return suitable style for MODE from DEFAULT-STYLE.
|
|
|
|
|
DEFAULT-STYLE has the same format as `c-default-style'."
|
|
|
|
|
(if (stringp default-style)
|
|
|
|
|
default-style
|
|
|
|
|
(or (cdr (assq mode default-style))
|
|
|
|
|
(cdr (assq 'other default-style))
|
|
|
|
|
"gnu")))
|
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
|
|
|
|
|
|
2001-03-21 12:59:36 +00:00
|
|
|
|
(cc-provide 'cc-styles)
|
2001-07-16 07:46:48 +00:00
|
|
|
|
|
1997-07-10 07:54:06 +00:00
|
|
|
|
;;; cc-styles.el ends here
|