;;; cc-styles.el --- support for styles in CC Mode
-;; Copyright (C) 1985,1987,1992-1999 Free Software Foundation, Inc.
+;; Copyright (C) 1985, 1987, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
+;; 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
+;; Free Software Foundation, Inc.
-;; Authors: 1998-1999 Barry A. Warsaw and Martin Stjernholm
-;; 1992-1997 Barry A. Warsaw
+;; Authors: 2004- Alan Mackenzie
+;; 1998- Martin Stjernholm
+;; 1992-1999 Barry A. Warsaw
;; 1987 Dave Detlefs and Stewart Clamen
;; 1985 Richard M. Stallman
;; Maintainer: bug-cc-mode@gnu.org
;; 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)
+;; the Free Software Foundation; either version 3, or (at your option)
;; any later version.
;; GNU Emacs is distributed in the hope that it will be useful,
;; 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.
+;; along with this program; see the file COPYING. If not, write to
+;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
+
+;;; Commentary:
+
+;;; Code:
(eval-when-compile
(let ((load-path
- (if (and (boundp 'byte-compile-current-file)
- (stringp byte-compile-current-file))
- (cons (file-name-directory byte-compile-current-file)
- load-path)
+ (if (and (boundp 'byte-compile-dest-file)
+ (stringp byte-compile-dest-file))
+ (cons (file-name-directory byte-compile-dest-file) load-path)
load-path)))
- (load "cc-defs" nil t)))
-(require 'cc-vars)
+ (load "cc-bytecomp" nil t)))
+(cc-require 'cc-defs)
+(cc-require 'cc-vars)
+(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
+(cc-bytecomp-obsolete-fun make-local-hook) ; Marked obsolete in Emacs 21.1.
\f
-;; Warning: don't eval-defun this constant or you'll break style inheritance.
-(defconst c-style-alist
+(defvar c-style-alist
'(("gnu"
(c-basic-offset . 2)
(c-comment-only-line-offset . (0 . 0))
+ (c-hanging-braces-alist . ((substatement-open before after)))
(c-offsets-alist . ((statement-block-intro . +)
(knr-argdecl-intro . 5)
(substatement-open . +)
+ (substatement-label . 0)
(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 . +)
+ (topmost-intro-cont
+ . (first c-lineup-topmost-intro-cont
+ c-lineup-gnu-DEFUN-intro-cont))))
(c-special-indent-hook . c-gnu-impose-minimum)
- (c-block-comment-prefix . "")
- )
+ (c-block-comment-prefix . ""))
+
("k&r"
(c-basic-offset . 5)
(c-comment-only-line-offset . 0)
(c-offsets-alist . ((statement-block-intro . +)
(knr-argdecl-intro . 0)
(substatement-open . 0)
+ (substatement-label . 0)
(label . 0)
- (statement-cont . +)
- ))
- )
+ (statement-cont . +))))
+
("bsd"
- (c-basic-offset . 4)
+ (c-basic-offset . 8)
(c-comment-only-line-offset . 0)
(c-offsets-alist . ((statement-block-intro . +)
(knr-argdecl-intro . +)
(substatement-open . 0)
+ (substatement-label . 0)
(label . 0)
(statement-cont . +)
(inline-open . 0)
- (inexpr-class . 0)
- ))
- )
+ (inexpr-class . 0))))
+
("stroustrup"
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
(c-offsets-alist . ((statement-block-intro . +)
(substatement-open . 0)
+ (substatement-label . 0)
(label . 0)
- (statement-cont . +)
- ))
- )
+ (statement-cont . +))))
+
("whitesmith"
(c-basic-offset . 4)
(c-comment-only-line-offset . 0)
- (c-offsets-alist . ((knr-argdecl-intro . +)
- (label . 0)
- (statement-cont . +)
- (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)
+ ;; It's obvious that the CC Mode way of choosing anchor positions
+ ;; doesn't fit this style at all. :P
+ (c-offsets-alist . ((defun-open . +)
(defun-close . c-lineup-whitesmith-in-block)
+ (defun-block-intro . (add c-lineup-whitesmith-in-block
+ c-indent-multi-line-block))
+ (class-open . +)
+ (class-close . +)
+ (inline-open . +)
+ (inline-close . c-lineup-whitesmith-in-block)
+ (knr-argdecl-intro . +)
+ (block-open . 0) ; Get indentation from `statement' instead.
+ (block-close . c-lineup-whitesmith-in-block)
(brace-list-open . +)
- (brace-list-intro . c-lineup-whitesmith-in-block)
- (brace-entry-open . c-indent-multi-line-block)
(brace-list-close . c-lineup-whitesmith-in-block)
- (class-open . +)
+ (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)
(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)
+ (module-open . +)
+ (composition-open . +)
+ (extern-lang-close . +)
(namespace-close . +)
- ))
- )
+ (module-close . +)
+ (composition-close . +)
+ (inextern-lang . c-lineup-whitesmith-in-block)
+ (innamespace . c-lineup-whitesmith-in-block)
+ (inmodule . c-lineup-whitesmith-in-block)
+ (incomposition . c-lineup-whitesmith-in-block)
+ (inexpr-class . 0))))
+
("ellemtel"
(c-basic-offset . 3)
(c-comment-only-line-offset . 0)
(c-hanging-braces-alist . ((substatement-open before after)))
(c-offsets-alist . ((topmost-intro . 0)
- (topmost-intro-cont . 0)
- (substatement . +)
+ (substatement . +)
(substatement-open . 0)
(case-label . +)
(access-label . -)
(inclass . ++)
- (inline-open . 0)
- ))
- )
+ (inline-open . 0))))
+
("linux"
(c-basic-offset . 8)
(c-comment-only-line-offset . 0)
(c-offsets-alist . ((statement-block-intro . +)
(knr-argdecl-intro . 0)
(substatement-open . 0)
+ (substatement-label . 0)
(label . 0)
- (statement-cont . +)
- ))
- )
+ (statement-cont . +))))
+
("python"
(indent-tabs-mode . t)
(fill-column . 78)
(c-offsets-alist . ((substatement-open . 0)
(inextern-lang . 0)
(arglist-intro . +)
- (knr-argdecl-intro . +)
- ))
+ (knr-argdecl-intro . +)))
(c-hanging-braces-alist . ((brace-list-open)
(brace-list-intro)
(brace-list-close)
(brace-entry-open)
(substatement-open after)
- (block-close . c-snug-do-while)
- ))
- (c-block-comment-prefix . "")
- )
+ (block-close . c-snug-do-while)))
+ (c-block-comment-prefix . ""))
+
("java"
(c-basic-offset . 4)
(c-comment-only-line-offset . (0 . 0))
(topmost-intro-cont . +)
(statement-block-intro . +)
(knr-argdecl-intro . 5)
- (substatement-open . +)
+ (substatement-open . +)
+ (substatement-label . +)
(label . +)
(statement-case-open . +)
(statement-cont . +)
(arglist-close . c-lineup-arglist)
(access-label . 0)
(inher-cont . c-lineup-java-inher)
- (func-decl-cont . c-lineup-java-throws)
- ))
- )
+ (func-decl-cont . c-lineup-java-throws))))
+
+ ;; awk style exists primarily for auto-newline settings. Otherwise it's
+ ;; pretty much like k&r.
+ ("awk"
+ (c-basic-offset . 4)
+ (c-comment-only-line-offset . 0)
+ (c-hanging-braces-alist . ((defun-open after)
+ (defun-close . c-snug-1line-defun-close)
+ (substatement-open after)
+ (block-close . c-snug-do-while)))
+ (c-hanging-semi&comma-criteria . nil)
+ (c-cleanup-list . nil) ; You might want one-liner-defun here.
+ (c-offsets-alist . ((statement-block-intro . +)
+ (substatement-open . 0)
+ (statement-cont . +))))
+
)
"Styles of indentation.
Elements of this alist are of the form:
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.")
-
+the existing style).")
\f
;; Functions that manipulate styles
(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)))
+ (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)))
;; 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)))))
+ ;; 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)))
(if (listp val)
- (mapcar add-func (if dont-override (reverse val) val))
- (funcall add-func val))))
+ (mapcar (lambda (func)
+ (add-hook 'c-special-indent-hook func t t))
+ val)
+ (add-hook 'c-special-indent-hook val t t))))
;; 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))))
- ))
+ (t (when (or (not dont-override)
+ (not (memq attr c-style-variables))
+ (eq (if (eq dont-override t)
+ (symbol-value attr)
+ (default-value attr))
+ 'set-from-style))
+ (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)))))))
(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 (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))))))
(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))))))
+ (c-benign-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
- (cons c-indentation-style 0)
- 'c-set-style-history))))
+ "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
+done in ~/.emacs. It is useful to call c-set-style from a mode hook in this
+way.
+
+If DONT-OVERRIDE is t, style variables that already have values (i.e., whose
+values are not the symbol `set-from-style') will not be overridden. CC Mode
+calls c-set-style internally in this way whilst initializing a buffer; if
+cc-set-style is called like this from anywhere else, it will usually behave as
+a null operation."
+ (interactive
+ (list (let ((completion-ignore-case t)
+ (prompt (format "Which %s indentation style? "
+ mode-name)))
+ (completing-read prompt c-style-alist nil t nil
+ 'c-set-style-history
+ c-indentation-style))))
+ (or c-buffer-is-cc-mode
+ (error "Buffer %s is not a CC Mode buffer (c-set-style)" (buffer-name)))
+ (or (stringp stylename)
+ (error "Argument to c-set-style was not a string"))
(c-initialize-builtin-style)
(let ((vars (c-get-style-variables stylename nil)))
+ (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)))
(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)))
+ ;; don't override any settings.
+ (if (eq dont-override t) (nreverse vars) vars)))
(setq c-indentation-style stylename)
(c-keep-region-active))
;;;###autoload
-(defun c-add-style (style descrip &optional set-p)
+(defun c-add-style (style description &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:
+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:
([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
(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
+ (descr (eval-minibuffer "Style description: ")))
+ (list stylename descr
(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))))
+ (setcdr s (copy-alist description)) ; replace
+ (setq c-style-alist (cons (cons style description) c-style-alist))))
(and set-p (c-set-style style)))
-
-\f
-(defun c-evaluate-offset (offset langelem symbol)
- ;; offset can be a number, a function, a variable, a list, or one of
- ;; the symbols + or -
- (cond
- ((eq offset '+) (setq offset c-basic-offset))
- ((eq offset '-) (setq offset (- c-basic-offset)))
- ((eq offset '++) (setq offset (* 2 c-basic-offset)))
- ((eq offset '--) (setq offset (* 2 (- c-basic-offset))))
- ((eq offset '*) (setq offset (/ c-basic-offset 2)))
- ((eq offset '/) (setq offset (/ (- c-basic-offset) 2)))
- ((functionp offset) (setq offset (funcall offset langelem)))
- ((listp offset)
- (setq offset
- (let (done)
- (while (and (not done) offset)
- (setq done (c-evaluate-offset (car offset) langelem symbol)
- offset (cdr offset)))
- (if (not done)
- (if c-strict-syntax-p
- (error "No offset found for syntactic symbol %s" symbol)
- 0)
- done))))
- ((not (numberp offset)) (setq offset (symbol-value offset)))
- )
- offset)
-
-(defun c-get-offset (langelem)
- ;; Get offset from LANGELEM which is a cons cell of the form:
- ;; (SYMBOL . RELPOS). The symbol is matched against
- ;; c-offsets-alist and the offset found there is either returned,
- ;; or added to the indentation at RELPOS. If RELPOS is nil, then
- ;; the offset is simply returned.
- (let* ((symbol (car langelem))
- (relpos (cdr langelem))
- (match (assq symbol c-offsets-alist))
- (offset (cdr-safe match)))
- (if (not match)
- (if c-strict-syntax-p
- (error "No offset found for syntactic symbol %s" symbol)
- (setq offset 0
- relpos 0))
- (setq offset (c-evaluate-offset offset langelem symbol)))
- (+ (if (and relpos
- (< relpos (c-point 'bol)))
- (save-excursion
- (goto-char relpos)
- (current-column))
- 0)
- (or (and (numberp offset) offset)
- (and (symbolp offset) (symbol-value offset))
- 0))
- ))
-
-
\f
(defvar c-read-offset-history nil)
'c-stylevar-fallback)))))
(symname (symbol-name langelem))
(defstr (format "(default %s): " oldoff))
- (errmsg (concat "Offset must be int, func, var, list, "
+ (errmsg (concat "Offset must be int, func, var, vector, list, "
"or [+,-,++,--,*,/] "
defstr))
(prompt (concat symname " offset " defstr))
- offset input interned raw)
+ (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)
(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 lambda function
- ((c-safe (functionp (setq raw (read input))))
- raw)
- ;; a symbol with variable binding
- ((boundp interned) interned)
- ;; error, but don't signal one, keep trying
- ;; to read an input value
- (t (ding)
- (setq prompt errmsg)
- nil))))
+ (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)))
offset))
;;;###autoload
;; 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))
+ (and c-buffer-is-cc-mode
+ (c-save-buffer-state
+ ((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 "Offset must be int, func, var, 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))))
+ (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))))
+ (c-benign-error "Invalid indentation setting for symbol %s: %S"
+ symbol offset))
(c-keep-region-active))
+\f
+(defun c-setup-paragraph-variables ()
+ "Fix things up for paragraph recognition and filling inside comments and
+strings by incorporating the values of `c-comment-prefix-regexp',
+`sentence-end', `paragraph-start' and `paragraph-separate' in the relevant
+variables."
+
+ (interactive)
+ (or c-buffer-is-cc-mode
+ (error "Buffer %s is not a CC Mode buffer (c-setup-paragraph-variables)"
+ (buffer-name)))
+ ;; Set up the values for use in comments.
+ (setq c-current-comment-prefix
+ (if (listp c-comment-prefix-regexp)
+ (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
+ (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-paragraph-start
+ "\\|"
+ page-delimiter)
+ paragraph-separate (concat comment-line-prefix
+ c-paragraph-separate
+ "\\|"
+ page-delimiter)
+ paragraph-ignore-fill-prefix t
+ adaptive-fill-mode t
+ adaptive-fill-regexp
+ (concat comment-line-prefix
+ (if (default-value 'adaptive-fill-regexp)
+ (concat "\\("
+ (default-value 'adaptive-fill-regexp)
+ "\\)")
+ "")))
+
+ (when (boundp 'adaptive-fill-first-line-regexp)
+ ;; XEmacs adaptive fill mode doesn't have this.
+ (make-local-variable 'adaptive-fill-first-line-regexp)
+ (setq adaptive-fill-first-line-regexp
+ (concat "\\`" comment-line-prefix
+ ;; Maybe we should incorporate the old value here,
+ ;; but then we have to do all sorts of kludges to
+ ;; deal with the \` and \' it probably contains.
+ "\\'"))))
+
+ ;; Set up the values for use in strings. These are the default
+ ;; paragraph-start/separate values, enhanced to accept escaped EOLs as
+ ;; whitespace. Used in c-beginning/end-of-sentence-in-string in cc-cmds.
+ (setq c-string-par-start
+ ;;(concat "\\(" (default-value 'paragraph-start) "\\)\\|[ \t]*\\\\$"))
+ "\f\\|[ \t]*\\\\?$")
+ (setq c-string-par-separate
+ ;;(concat "\\(" (default-value 'paragraph-separate) "\\)\\|[ \t]*\\\\$"))
+ "[ \t\f]*\\\\?$")
+ (setq c-sentence-end-with-esc-eol
+ (concat "\\(\\(" (c-default-value-sentence-end) "\\)"
+ ;; N.B.: "$" would be illegal when not enclosed like "\\($\\)".
+ "\\|" "[.?!][]\"')}]* ?\\\\\\($\\)[ \t\n]*"
+ "\\)")))
+
+\f
+;; 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))))
\f
(defun c-initialize-builtin-style ()
;; 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"))))
+ ;;(c-initialize-cc-mode)
+ (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")))
(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'."
+If `this-buf-only-p' is non-nil, the style variables will be made
+buffer local only in the current buffer. Otherwise they'll be made
+permanently buffer local in any buffer that changes their values.
+
+The buffer localness of the style variables are normally controlled
+with the variable `c-style-variables-are-local-p', so there's seldom
+any reason to call this function directly."
+
;; style variables
(let ((func (if this-buf-only-p
'make-local-variable
;; Hooks must be handled specially
(if this-buf-only-p
(make-local-hook 'c-special-indent-hook)
- (make-variable-buffer-local 'c-special-indent-hook)
+ (with-no-warnings (make-variable-buffer-local 'c-special-indent-hook))
(setq c-style-variables-are-local-p t))
))
\f
-(provide 'cc-styles)
+(cc-provide 'cc-styles)
+
+;;; arch-tag: c764f61a-96ba-484a-a68f-101c0e9d5d2c
;;; cc-styles.el ends here