aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1998-02-17 07:13:59 +0000
committerRichard M. Stallman1998-02-17 07:13:59 +0000
commit0bacd8d0b26c549094d13db9fdcc638d4f10baa7 (patch)
tree59be7fadd3ed35ba97a509cf9129a633d62c6654
parent77e31a8d08567c244d3d448f4fc1512012119456 (diff)
downloademacs-0bacd8d0b26c549094d13db9fdcc638d4f10baa7.tar.gz
emacs-0bacd8d0b26c549094d13db9fdcc638d4f10baa7.zip
(c-make-styles-buffer-local): Take an optional argument which switches
between make-variable-buffer-local and make-local-variable. Generalize. (c-offsets-alist): Three new syntactic symbols: innamespace, namespace-open, namespace-close. These support C++ namespace blocks. Also, new syntactic symbol cpp-macro-cont, by default bound to c-lineup-dont-change. This symbol is assigned to subsequent lines of a multi-line C preprocess macro definition. (c-style-alist): "jdk" style for conformance with Sun's JDK style. (c-set-style-2, c-initialize-builtin-style): Don't special case "cc-mode", it's a derived style. Fix setup of derived style "cc-mode". Introduce the new default style "user" which contains all user customizations.
-rw-r--r--lisp/progmodes/cc-styles.el89
1 files changed, 58 insertions, 31 deletions
diff --git a/lisp/progmodes/cc-styles.el b/lisp/progmodes/cc-styles.el
index bbdcdcb8ce2..0e8b1247520 100644
--- a/lisp/progmodes/cc-styles.el
+++ b/lisp/progmodes/cc-styles.el
@@ -1,6 +1,6 @@
1;;; cc-styles.el --- support for styles in CC Mode 1;;; cc-styles.el --- support for styles in CC Mode
2 2
3;; Copyright (C) 1985,87,92,93,94,95,96,97 Free Software Foundation, Inc. 3;; Copyright (C) 1985,87,92,93,94,95,96,97,98 Free Software Foundation, Inc.
4 4
5;; Authors: 1992-1997 Barry A. Warsaw 5;; Authors: 1992-1997 Barry A. Warsaw
6;; 1987 Dave Detlefs and Stewart Clamen 6;; 1987 Dave Detlefs and Stewart Clamen
@@ -134,11 +134,12 @@
134 (fill-column . 78) 134 (fill-column . 78)
135 ) 135 )
136 ("java" 136 ("java"
137 (c-basic-offset . 2) 137 (c-basic-offset . 4)
138 (c-comment-only-line-offset . (0 . 0)) 138 (c-comment-only-line-offset . (0 . 0))
139 ;; the following preserves Javadoc starter lines 139 ;; the following preserves Javadoc starter lines
140 (c-hanging-comment-starter-p . nil) 140 (c-hanging-comment-starter-p . nil)
141 (c-offsets-alist . ((topmost-intro-cont . +) 141 (c-offsets-alist . ((inline-open . 0)
142 (topmost-intro-cont . +)
142 (statement-block-intro . +) 143 (statement-block-intro . +)
143 (knr-argdecl-intro . 5) 144 (knr-argdecl-intro . 5)
144 (substatement-open . +) 145 (substatement-open . +)
@@ -217,18 +218,18 @@ the existing style.")
217 218
218(defun c-set-style-2 (style basestyles) 219(defun c-set-style-2 (style basestyles)
219 ;; Recursively set the base style. If no base style is given, the 220 ;; Recursively set the base style. If no base style is given, the
220 ;; default base style is "cc-mode" and the recursion stops. Be sure 221 ;; default base style is "user" (a.k.a. "cc-mode") and the recursion
221 ;; to detect loops. 222 ;; stops. Be sure to detect loops.
222 (let ((vars (cdr (or (assoc (downcase style) c-style-alist) 223 (let ((vars (cdr (or (assoc (downcase style) c-style-alist)
223 (assoc (upcase style) c-style-alist) 224 (assoc (upcase style) c-style-alist)
224 (assoc style c-style-alist) 225 (assoc style c-style-alist)
225 (error "Undefined style: %s" style))))) 226 (error "Undefined style: %s" style)))))
226 (if (not (string-equal style "cc-mode")) 227 (if (not (string-equal style "user"))
227 (let ((base (if (stringp (car vars)) 228 (let ((base (if (stringp (car vars))
228 (prog1 229 (prog1
229 (downcase (car vars)) 230 (downcase (car vars))
230 (setq vars (cdr vars))) 231 (setq vars (cdr vars)))
231 "cc-mode"))) 232 "user")))
232 (if (memq base basestyles) 233 (if (memq base basestyles)
233 (error "Style loop detected: %s in %s" base basestyles)) 234 (error "Style loop detected: %s in %s" base basestyles))
234 (c-set-style-2 base (cons base basestyles)))) 235 (c-set-style-2 base (cons base basestyles))))
@@ -331,6 +332,7 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
331 (stream-op . c-lineup-streamop) 332 (stream-op . c-lineup-streamop)
332 (inclass . +) 333 (inclass . +)
333 (cpp-macro . -1000) 334 (cpp-macro . -1000)
335 (cpp-macro-cont . c-lineup-dont-change)
334 (friend . 0) 336 (friend . 0)
335 (objc-method-intro . -1000) 337 (objc-method-intro . -1000)
336 (objc-method-args-cont . c-lineup-ObjC-method-args) 338 (objc-method-args-cont . c-lineup-ObjC-method-args)
@@ -338,6 +340,9 @@ STYLE using `c-set-style' if the optional SET-P flag is non-nil."
338 (extern-lang-open . 0) 340 (extern-lang-open . 0)
339 (extern-lang-close . 0) 341 (extern-lang-close . 0)
340 (inextern-lang . +) 342 (inextern-lang . +)
343 (namespace-open . 0)
344 (namespace-close . 0)
345 (innamespace . +)
341 (template-args-cont . +) 346 (template-args-cont . +)
342 ) 347 )
343 "Association list of syntactic element symbols and indentation offsets. 348 "Association list of syntactic element symbols and indentation offsets.
@@ -429,14 +434,21 @@ Here is the current list of valid syntactic element symbols:
429 arglist-close -- the solo close paren of an argument list 434 arglist-close -- the solo close paren of an argument list
430 stream-op -- lines continuing a stream operator construct 435 stream-op -- lines continuing a stream operator construct
431 inclass -- the construct is nested inside a class definition 436 inclass -- the construct is nested inside a class definition
432 cpp-macro -- the start of a cpp macro 437 cpp-macro -- the start of a C preprocessor macro definition
438 cpp-macro-cont -- the second and subsequent lines in a
439 multi-line C preprocessor macro definition
433 friend -- a C++ friend declaration 440 friend -- a C++ friend declaration
434 objc-method-intro -- the first line of an Objective-C method definition 441 objc-method-intro -- the first line of an Objective-C method definition
435 objc-method-args-cont -- lines continuing an Objective-C method definition 442 objc-method-args-cont -- lines continuing an Objective-C method definition
436 objc-method-call-cont -- lines continuing an Objective-C method call 443 objc-method-call-cont -- lines continuing an Objective-C method call
437 extern-lang-open -- brace that opens an external language block 444 extern-lang-open -- brace that opens an external language block
438 extern-lang-close -- brace that closes an external language block 445 extern-lang-close -- brace that closes an external language block
439 inextern-lang -- analogous to `inclass' syntactic symbol 446 inextern-lang -- analogous to `inclass' syntactic symbol,
447 but used inside, e.g. extern \"C\" constructs
448 namespace-open -- brace that opens a C++ namespace block
449 namespace-close -- brace that closes a C++ namespace block
450 innamespace -- analogous to `inextern-lang' syntactic
451 symbol, but used inside C++ namespace constructs
440 template-args-cont -- C++ template argument list continuations 452 template-args-cont -- C++ template argument list continuations
441") 453")
442 454
@@ -569,18 +581,20 @@ offset for that syntactic element. Optional ADD says to add SYMBOL to
569 ;; crucial because future c-set-style calls will always reset the 581 ;; crucial because future c-set-style calls will always reset the
570 ;; variables first to the `cc-mode' style before instituting the new 582 ;; variables first to the `cc-mode' style before instituting the new
571 ;; style. Only do this once! 583 ;; style. Only do this once!
584 (c-initialize-cc-mode t)
572 (or (assoc "cc-mode" c-style-alist) 585 (or (assoc "cc-mode" c-style-alist)
586 (assoc "user" c-style-alist)
573 (let (copyfunc) 587 (let (copyfunc)
574 ;; use built-in copy-tree if its there. 588 ;; use built-in copy-tree if its there.
575 (if (and (fboundp 'copy-tree) 589 (if (and (fboundp 'copy-tree)
576 (functionp (symbol-function 'copy-tree))) 590 (functionp (symbol-function 'copy-tree)))
577 (setq copyfunc (symbol-function 'copy-tree)) 591 (setq copyfunc (symbol-function 'copy-tree))
578 (setq copyfunc (lambda (tree) 592 (setq copyfunc (lambda (tree)
579 (if (consp tree) 593 (if (consp tree)
580 (cons (funcall copyfunc (car tree)) 594 (cons (funcall copyfunc (car tree))
581 (funcall copyfunc (cdr tree))) 595 (funcall copyfunc (cdr tree)))
582 tree)))) 596 tree))))
583 (c-add-style "cc-mode" 597 (c-add-style "user"
584 (mapcar 598 (mapcar
585 (function 599 (function
586 (lambda (var) 600 (lambda (var)
@@ -601,14 +615,15 @@ offset for that syntactic element. Optional ADD says to add SYMBOL to
601 c-hanging-comment-ender-p 615 c-hanging-comment-ender-p
602 c-offsets-alist 616 c-offsets-alist
603 ))) 617 )))
618 (c-add-style "cc-mode" '("user"))
604 ;; the default style is now GNU. This can be overridden in 619 ;; the default style is now GNU. This can be overridden in
605 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook. 620 ;; c-mode-common-hook or {c,c++,objc,java}-mode-hook.
606 (c-set-style c-site-default-style))) 621 (c-set-style c-default-style)))
607 (if c-style-variables-are-local-p 622 (if c-style-variables-are-local-p
608 (c-make-styles-buffer-local))) 623 (c-make-styles-buffer-local)))
609 624
610 625
611(defun c-make-styles-buffer-local () 626(defun c-make-styles-buffer-local (&optional this-buf-only-p)
612 "Make all CC Mode style variables buffer local. 627 "Make all CC Mode style variables buffer local.
613If you edit primarily one style of C (or C++, Objective-C, Java) code, 628If you edit primarily one style of C (or C++, Objective-C, Java) code,
614you probably want style variables to be global. This is the default. 629you probably want style variables to be global. This is the default.
@@ -623,22 +638,34 @@ This function makes all the CC Mode style variables buffer local.
623Call it after CC Mode is loaded into your Emacs environment. 638Call it after CC Mode is loaded into your Emacs environment.
624Conversely, set the variable `c-style-variables-are-local-p' to t in 639Conversely, set the variable `c-style-variables-are-local-p' to t in
625your .emacs file, before CC Mode is loaded, and this function will be 640your .emacs file, before CC Mode is loaded, and this function will be
626automatically called when CC Mode is loaded." 641automatically called when CC Mode is loaded.
642
643Optional argument, when non-nil, means use `make-local-variable'
644instead of `make-variable-buffer-local'."
627 ;; style variables 645 ;; style variables
628 (make-variable-buffer-local 'c-offsets-alist) 646 (let ((func (if this-buf-only-p
629 (make-variable-buffer-local 'c-basic-offset) 647 'make-local-variable
630 (make-variable-buffer-local 'c-file-style) 648 'make-variable-buffer-local))
631 (make-variable-buffer-local 'c-file-offsets) 649 (varsyms '(c-offsets-alist
632 (make-variable-buffer-local 'c-comment-only-line-offset) 650 c-basic-offset
633 (make-variable-buffer-local 'c-cleanup-list) 651 c-file-style
634 (make-variable-buffer-local 'c-hanging-braces-alist) 652 c-file-offsets
635 (make-variable-buffer-local 'c-hanging-colons-alist) 653 c-comment-only-line-offset
636 (make-variable-buffer-local 'c-hanging-comment-starter-p) 654 c-cleanup-list
637 (make-variable-buffer-local 'c-hanging-comment-ender-p) 655 c-hanging-braces-alist
638 (make-variable-buffer-local 'c-backslash-column) 656 c-hanging-colons-alist
639 (make-variable-buffer-local 'c-label-minimum-indentation) 657 c-hanging-comment-starter-p
640 (make-variable-buffer-local 'c-special-indent-hook) 658 c-hanging-comment-ender-p
641 (make-variable-buffer-local 'c-indentation-style)) 659 c-backslash-column
660 c-label-minimum-indentation
661 c-indentation-style)))
662 (mapcar func varsyms)
663 ;; Hooks must be handled specially
664 (if this-buf-only-p
665 (make-local-hook 'c-special-indent-hook)
666 (make-variable-buffer-local 'c-special-indent-hook))
667 ))
668
642 669
643 670
644(provide 'cc-styles) 671(provide 'cc-styles)