comparison lisp/progmodes/cc-styles.el @ 51714:bc91cbf50c24

Updated CC Mode to version 5.30.
author Martin Stjernholm <mast@lysator.liu.se>
date Thu, 03 Jul 2003 12:30:59 +0000
parents 425dcb97eca4
children f3cad02bce62
comparison
equal deleted inserted replaced
51713:205602055b5f 51714:bc91cbf50c24
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,1987,1992-2001 Free Software Foundation, Inc. 3 ;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc.
4 4
5 ;; Authors: 2000- Martin Stjernholm 5 ;; Authors: 1998- Martin Stjernholm
6 ;; 1998-1999 Barry A. Warsaw and Martin Stjernholm 6 ;; 1992-1999 Barry A. Warsaw
7 ;; 1992-1997 Barry A. Warsaw
8 ;; 1987 Dave Detlefs and Stewart Clamen 7 ;; 1987 Dave Detlefs and Stewart Clamen
9 ;; 1985 Richard M. Stallman 8 ;; 1985 Richard M. Stallman
10 ;; Maintainer: bug-cc-mode@gnu.org 9 ;; Maintainer: bug-cc-mode@gnu.org
11 ;; Created: 22-Apr-1997 (split from cc-mode.el) 10 ;; Created: 22-Apr-1997 (split from cc-mode.el)
12 ;; Version: See cc-mode.el 11 ;; Version: See cc-mode.el
37 (let ((load-path 36 (let ((load-path
38 (if (and (boundp 'byte-compile-dest-file) 37 (if (and (boundp 'byte-compile-dest-file)
39 (stringp byte-compile-dest-file)) 38 (stringp byte-compile-dest-file))
40 (cons (file-name-directory byte-compile-dest-file) load-path) 39 (cons (file-name-directory byte-compile-dest-file) load-path)
41 load-path))) 40 load-path)))
42 (require 'cc-bytecomp))) 41 (load "cc-bytecomp" nil t)))
43 42
44 (cc-require 'cc-defs) 43 (cc-require 'cc-defs)
45 (cc-require 'cc-langs)
46 (cc-require 'cc-vars) 44 (cc-require 'cc-vars)
47 (cc-require 'cc-align) 45 (cc-require 'cc-align)
48 ;; cc-align is only indirectly required: Styles added with 46 ;; cc-align is only indirectly required: Styles added with
49 ;; `c-add-style' often contains references to functions defined there. 47 ;; `c-add-style' often contains references to functions defined there.
50 48
133 (inextern-lang . c-lineup-whitesmith-in-block) 131 (inextern-lang . c-lineup-whitesmith-in-block)
134 (extern-lang-close . +) 132 (extern-lang-close . +)
135 (namespace-open . +) 133 (namespace-open . +)
136 (innamespace . c-lineup-whitesmith-in-block) 134 (innamespace . c-lineup-whitesmith-in-block)
137 (namespace-close . +) 135 (namespace-close . +)
136 (module-open . +)
137 (inmodule . c-lineup-whitesmith-in-block)
138 (module-close . +)
139 (composition-open . +)
140 (incomposition . c-lineup-whitesmith-in-block)
141 (composition-close . +)
138 )) 142 ))
139 ) 143 )
140 ("ellemtel" 144 ("ellemtel"
141 (c-basic-offset . 3) 145 (c-basic-offset . 3)
142 (c-comment-only-line-offset . 0) 146 (c-comment-only-line-offset . 0)
240 244
241 245
242 ;; Functions that manipulate styles 246 ;; Functions that manipulate styles
243 (defun c-set-style-1 (conscell dont-override) 247 (defun c-set-style-1 (conscell dont-override)
244 ;; Set the style for one variable 248 ;; Set the style for one variable
249 ;;
250 ;; This function does not do any hidden buffer changes.
245 (let ((attr (car conscell)) 251 (let ((attr (car conscell))
246 (val (cdr conscell))) 252 (val (cdr conscell)))
247 (cond 253 (cond
248 ;; first special variable 254 ;; first special variable
249 ((eq attr 'c-offsets-alist) 255 ((eq attr 'c-offsets-alist)
283 (if (eq attr 'c-comment-prefix-regexp) 289 (if (eq attr 'c-comment-prefix-regexp)
284 (c-setup-paragraph-variables))))))) 290 (c-setup-paragraph-variables)))))))
285 291
286 (defun c-get-style-variables (style basestyles) 292 (defun c-get-style-variables (style basestyles)
287 ;; Return all variables in a style by resolving inheritances. 293 ;; Return all variables in a style by resolving inheritances.
294 ;;
295 ;; This function does not do any hidden buffer changes.
288 (if (not style) 296 (if (not style)
289 (copy-alist c-fallback-style) 297 (copy-alist c-fallback-style)
290 (let ((vars (cdr (or (assoc (downcase style) c-style-alist) 298 (let ((vars (cdr (or (assoc (downcase style) c-style-alist)
291 (assoc (upcase style) c-style-alist) 299 (assoc (upcase style) c-style-alist)
292 (assoc style c-style-alist) 300 (assoc style c-style-alist)
365 (if (eq dont-override t) (nreverse vars) vars))) 373 (if (eq dont-override t) (nreverse vars) vars)))
366 (setq c-indentation-style stylename) 374 (setq c-indentation-style stylename)
367 (c-keep-region-active)) 375 (c-keep-region-active))
368 376
369 ;;;###autoload 377 ;;;###autoload
370 (defun c-add-style (style descrip &optional set-p) 378 (defun c-add-style (style description &optional set-p)
371 "Adds a style to `c-style-alist', or updates an existing one. 379 "Adds a style to `c-style-alist', or updates an existing one.
372 STYLE is a string identifying the style to add or update. DESCRIP is 380 STYLE is a string identifying the style to add or update. DESCRIPTION
373 an association list describing the style and must be of the form: 381 is an association list describing the style and must be of the form:
374 382
375 ([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) 383 ([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...])
376 384
377 See the variable `c-style-alist' for the semantics of BASESTYLE, 385 See the variable `c-style-alist' for the semantics of BASESTYLE,
378 VARIABLE and VALUE. This function also sets the current style to 386 VARIABLE and VALUE. This function also sets the current style to
379 STYLE using `c-set-style' if the optional SET-P flag is non-nil." 387 STYLE using `c-set-style' if the optional SET-P flag is non-nil."
380 (interactive 388 (interactive
381 (let ((stylename (completing-read "Style to add: " c-style-alist 389 (let ((stylename (completing-read "Style to add: " c-style-alist
382 nil nil nil 'c-set-style-history)) 390 nil nil nil 'c-set-style-history))
383 (description (eval-minibuffer "Style description: "))) 391 (descr (eval-minibuffer "Style description: ")))
384 (list stylename description 392 (list stylename descr
385 (y-or-n-p "Set the style too? ")))) 393 (y-or-n-p "Set the style too? "))))
386 (setq style (downcase style)) 394 (setq style (downcase style))
387 (let ((s (assoc style c-style-alist))) 395 (let ((s (assoc style c-style-alist)))
388 (if s 396 (if s
389 (setcdr s (copy-alist descrip)) ; replace 397 (setcdr s (copy-alist description)) ; replace
390 (setq c-style-alist (cons (cons style descrip) c-style-alist)))) 398 (setq c-style-alist (cons (cons style description) c-style-alist))))
391 (and set-p (c-set-style style))) 399 (and set-p (c-set-style style)))
392 400
393 401
394 (defvar c-read-offset-history nil) 402 (defvar c-read-offset-history nil)
395 403
396 (defun c-read-offset (langelem) 404 (defun c-read-offset (langelem)
397 ;; read new offset value for LANGELEM from minibuffer. return a 405 ;; read new offset value for LANGELEM from minibuffer. return a
398 ;; legal value only 406 ;; legal value only
407 ;;
408 ;; This function does not do any hidden buffer changes.
399 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) 409 (let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist)
400 (assq langelem (get 'c-offsets-alist 410 (assq langelem (get 'c-offsets-alist
401 'c-stylevar-fallback))))) 411 'c-stylevar-fallback)))))
402 (symname (symbol-name langelem)) 412 (symname (symbol-name langelem))
403 (defstr (format "(default %s): " oldoff)) 413 (defstr (format "(default %s): " oldoff))
444 nil (not current-prefix-arg) 454 nil (not current-prefix-arg)
445 ;; initial contents tries to be the last element 455 ;; initial contents tries to be the last element
446 ;; on the syntactic analysis list for the current 456 ;; on the syntactic analysis list for the current
447 ;; line 457 ;; line
448 (and c-buffer-is-cc-mode 458 (and c-buffer-is-cc-mode
449 (let* ((syntax (c-guess-basic-syntax)) 459 (c-save-buffer-state
450 (len (length syntax)) 460 ((syntax (c-guess-basic-syntax))
451 (ic (format "%s" (car (nth (1- len) syntax))))) 461 (len (length syntax))
462 (ic (format "%s" (car (nth (1- len) syntax)))))
452 (cons ic 0))) 463 (cons ic 0)))
453 ))) 464 )))
454 (offset (c-read-offset langelem))) 465 (offset (c-read-offset langelem)))
455 (list langelem offset current-prefix-arg))) 466 (list langelem offset current-prefix-arg)))
456 ;; sanity check offset 467 ;; sanity check offset
469 480
470 (defun c-setup-paragraph-variables () 481 (defun c-setup-paragraph-variables ()
471 "Fix things up for paragraph recognition and filling inside comments by 482 "Fix things up for paragraph recognition and filling inside comments by
472 incorporating the value of `c-comment-prefix-regexp' in the relevant 483 incorporating the value of `c-comment-prefix-regexp' in the relevant
473 variables." 484 variables."
485 ;;
486 ;; This function does not do any hidden buffer changes.
487
474 (setq c-current-comment-prefix 488 (setq c-current-comment-prefix
475 (if (listp c-comment-prefix-regexp) 489 (if (listp c-comment-prefix-regexp)
476 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp) 490 (cdr-safe (or (assoc major-mode c-comment-prefix-regexp)
477 (assoc 'other c-comment-prefix-regexp))) 491 (assoc 'other c-comment-prefix-regexp)))
478 c-comment-prefix-regexp)) 492 c-comment-prefix-regexp))
479 (let ((comment-line-prefix 493 (let ((comment-line-prefix
480 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*"))) 494 (concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*")))
481 (setq paragraph-start (concat comment-line-prefix 495 (setq paragraph-start (concat comment-line-prefix
482 (c-lang-var paragraph-start) 496 c-paragraph-start
483 "\\|" 497 "\\|"
484 page-delimiter) 498 page-delimiter)
485 paragraph-separate (concat comment-line-prefix 499 paragraph-separate (concat comment-line-prefix
486 (c-lang-var paragraph-separate) 500 c-paragraph-separate
487 "\\|" 501 "\\|"
488 page-delimiter) 502 page-delimiter)
489 paragraph-ignore-fill-prefix t 503 paragraph-ignore-fill-prefix t
490 adaptive-fill-mode t 504 adaptive-fill-mode t
491 adaptive-fill-regexp 505 adaptive-fill-regexp
519 `filladapt-token-conversion-table'. This is intended to be used on 533 `filladapt-token-conversion-table'. This is intended to be used on
520 `c-mode-common-hook' or similar." 534 `c-mode-common-hook' or similar."
521 ;; This function is intended to be used explicitly by the end user 535 ;; This function is intended to be used explicitly by the end user
522 ;; only. 536 ;; only.
523 ;; 537 ;;
538 ;; This function does not do any hidden buffer changes.
539
524 ;; The default configuration already handles C++ comments, but we 540 ;; The default configuration already handles C++ comments, but we
525 ;; need to add handling of C block comments. A new filladapt token 541 ;; need to add handling of C block comments. A new filladapt token
526 ;; `c-comment' is added for that. 542 ;; `c-comment' is added for that.
527 (let (p) 543 (let (p)
528 (setq p filladapt-token-table) 544 (setq p filladapt-token-table)
547 (defun c-initialize-builtin-style () 563 (defun c-initialize-builtin-style ()
548 ;; Dynamically append the default value of most variables. This is 564 ;; Dynamically append the default value of most variables. This is
549 ;; crucial because future c-set-style calls will always reset the 565 ;; crucial because future c-set-style calls will always reset the
550 ;; variables first to the `cc-mode' style before instituting the new 566 ;; variables first to the `cc-mode' style before instituting the new
551 ;; style. Only do this once! 567 ;; style. Only do this once!
568 ;;
569 ;; This function does not do any hidden buffer changes.
552 (unless (get 'c-initialize-builtin-style 'is-run) 570 (unless (get 'c-initialize-builtin-style 'is-run)
553 (put 'c-initialize-builtin-style 'is-run t) 571 (put 'c-initialize-builtin-style 'is-run t)
554 ;;(c-initialize-cc-mode) 572 ;;(c-initialize-cc-mode)
555 (unless (assoc "user" c-style-alist) 573 (unless (assoc "user" c-style-alist)
556 (let ((vars c-style-variables) var val uservars) 574 (let ((vars c-style-variables) var val uservars)
571 (if c-style-variables-are-local-p 589 (if c-style-variables-are-local-p
572 (c-make-styles-buffer-local)))) 590 (c-make-styles-buffer-local))))
573 591
574 (defun c-make-styles-buffer-local (&optional this-buf-only-p) 592 (defun c-make-styles-buffer-local (&optional this-buf-only-p)
575 "Make all CC Mode style variables buffer local. 593 "Make all CC Mode style variables buffer local.
576 If you edit primarily one style of C (or C++, Objective-C, Java, etc) 594 If `this-buf-only-p' is non-nil, the style variables will be made
577 code, you probably want style variables to be global. This is the 595 buffer local only in the current buffer. Otherwise they'll be made
578 default. 596 permanently buffer local in any buffer that change their values.
579 597
580 If you edit many different styles of C (or C++, Objective-C, Java, 598 The buffer localness of the style variables are normally controlled
581 etc) at the same time, you probably want the CC Mode style variables 599 with the variable `c-style-variables-are-local-p', so there's seldom
582 to be buffer local. If you do, it's advisable to set any CC Mode 600 any reason to call this function directly."
583 style variables in a hook function (e.g. off of `c-mode-common-hook'), 601 ;;
584 instead of at the top level of your ~/.emacs file. 602 ;; This function does not do any hidden buffer changes.
585 603
586 This function makes all the CC Mode style variables buffer local.
587 Call it after CC Mode is loaded into your Emacs environment.
588 Conversely, set the variable `c-style-variables-are-local-p' to t in
589 your .emacs file, before CC Mode is loaded, and this function will be
590 automatically called when CC Mode is loaded.
591
592 Optional argument, when non-nil, means use `make-local-variable'
593 instead of `make-variable-buffer-local'."
594 ;; style variables 604 ;; style variables
595 (let ((func (if this-buf-only-p 605 (let ((func (if this-buf-only-p
596 'make-local-variable 606 'make-local-variable
597 'make-variable-buffer-local)) 607 'make-variable-buffer-local))
598 (varsyms (cons 'c-indentation-style (copy-alist c-style-variables)))) 608 (varsyms (cons 'c-indentation-style (copy-alist c-style-variables))))