comparison lisp/progmodes/cc-styles.el @ 20918:8e64bd5b1b5f

(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.
author Richard M. Stallman <rms@gnu.org>
date Tue, 17 Feb 1998 07:13:59 +0000
parents 481af10544cc
children 81c1f55424f2
comparison
equal deleted inserted replaced
20917:c6e2c4d9a305 20918:8e64bd5b1b5f
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
7 ;; 1985 Richard M. Stallman 7 ;; 1985 Richard M. Stallman
8 ;; Maintainer: cc-mode-help@python.org 8 ;; Maintainer: cc-mode-help@python.org
132 (c-comment-continuation-stars . "") 132 (c-comment-continuation-stars . "")
133 (c-hanging-comment-ender-p . nil) 133 (c-hanging-comment-ender-p . nil)
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 . +)
145 (label . 0) 146 (label . 0)
146 (statement-case-open . +) 147 (statement-case-open . +)
215 (t (set attr val))) 216 (t (set attr val)))
216 )) 217 ))
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))))
235 (mapcar 'c-set-style-1 vars))) 236 (mapcar 'c-set-style-1 vars)))
236 237
329 (arglist-cont-nonempty . c-lineup-arglist) 330 (arglist-cont-nonempty . c-lineup-arglist)
330 (arglist-close . +) 331 (arglist-close . +)
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)
337 (objc-method-call-cont . c-lineup-ObjC-method-call) 339 (objc-method-call-cont . c-lineup-ObjC-method-call)
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.
344 As described below, each cons cell in this list has the form: 349 As described below, each cons cell in this list has the form:
345 350
427 least one argument follows on the same 432 least one argument follows on the same
428 line as the arglist opening paren 433 line as the arglist opening paren
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
443 (defun c-get-offset (langelem) 455 (defun c-get-offset (langelem)
444 ;; Get offset from LANGELEM which is a cons cell of the form: 456 ;; Get offset from LANGELEM which is a cons cell of the form:
567 (defun c-initialize-builtin-style () 579 (defun c-initialize-builtin-style ()
568 ;; Dynamically append the default value of most variables. This is 580 ;; Dynamically append the default value of most variables. This is
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)
587 (let ((val (symbol-value var))) 601 (let ((val (symbol-value var)))
588 (cons var (if (atom val) 602 (cons var (if (atom val)
599 c-hanging-colons-alist 613 c-hanging-colons-alist
600 c-hanging-comment-starter-p 614 c-hanging-comment-starter-p
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.
613 If you edit primarily one style of C (or C++, Objective-C, Java) code, 628 If you edit primarily one style of C (or C++, Objective-C, Java) code,
614 you probably want style variables to be global. This is the default. 629 you probably want style variables to be global. This is the default.
615 630
616 If you edit many different styles of C (or C++, Objective-C, Java) at 631 If you edit many different styles of C (or C++, Objective-C, Java) at
621 636
622 This function makes all the CC Mode style variables buffer local. 637 This function makes all the CC Mode style variables buffer local.
623 Call it after CC Mode is loaded into your Emacs environment. 638 Call it after CC Mode is loaded into your Emacs environment.
624 Conversely, set the variable `c-style-variables-are-local-p' to t in 639 Conversely, set the variable `c-style-variables-are-local-p' to t in
625 your .emacs file, before CC Mode is loaded, and this function will be 640 your .emacs file, before CC Mode is loaded, and this function will be
626 automatically called when CC Mode is loaded." 641 automatically called when CC Mode is loaded.
642
643 Optional argument, when non-nil, means use `make-local-variable'
644 instead 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)
645 ;;; cc-styles.el ends here 672 ;;; cc-styles.el ends here