1 |
;;; cc-styles.el --- support for styles in CC Mode |
;;; cc-styles.el --- support for styles in CC Mode |
2 |
|
|
3 |
;; Copyright (C) 1985,1987,1992-2001 Free Software Foundation, Inc. |
;; Copyright (C) 1985,1987,1992-2003 Free Software Foundation, Inc. |
4 |
|
|
5 |
;; Authors: 2000- Martin Stjernholm |
;; Authors: 1998- Martin Stjernholm |
6 |
;; 1998-1999 Barry A. Warsaw and Martin Stjernholm |
;; 1992-1999 Barry A. Warsaw |
|
;; 1992-1997 Barry A. Warsaw |
|
7 |
;; 1987 Dave Detlefs and Stewart Clamen |
;; 1987 Dave Detlefs and Stewart Clamen |
8 |
;; 1985 Richard M. Stallman |
;; 1985 Richard M. Stallman |
9 |
;; Maintainer: bug-cc-mode@gnu.org |
;; Maintainer: bug-cc-mode@gnu.org |
38 |
(stringp byte-compile-dest-file)) |
(stringp byte-compile-dest-file)) |
39 |
(cons (file-name-directory byte-compile-dest-file) load-path) |
(cons (file-name-directory byte-compile-dest-file) load-path) |
40 |
load-path))) |
load-path))) |
41 |
(require 'cc-bytecomp))) |
(load "cc-bytecomp" nil t))) |
42 |
|
|
43 |
(cc-require 'cc-defs) |
(cc-require 'cc-defs) |
|
(cc-require 'cc-langs) |
|
44 |
(cc-require 'cc-vars) |
(cc-require 'cc-vars) |
45 |
(cc-require 'cc-align) |
(cc-require 'cc-align) |
46 |
;; cc-align is only indirectly required: Styles added with |
;; cc-align is only indirectly required: Styles added with |
133 |
(namespace-open . +) |
(namespace-open . +) |
134 |
(innamespace . c-lineup-whitesmith-in-block) |
(innamespace . c-lineup-whitesmith-in-block) |
135 |
(namespace-close . +) |
(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 . +) |
142 |
)) |
)) |
143 |
) |
) |
144 |
("ellemtel" |
("ellemtel" |
246 |
;; Functions that manipulate styles |
;; Functions that manipulate styles |
247 |
(defun c-set-style-1 (conscell dont-override) |
(defun c-set-style-1 (conscell dont-override) |
248 |
;; Set the style for one variable |
;; Set the style for one variable |
249 |
|
;; |
250 |
|
;; This function does not do any hidden buffer changes. |
251 |
(let ((attr (car conscell)) |
(let ((attr (car conscell)) |
252 |
(val (cdr conscell))) |
(val (cdr conscell))) |
253 |
(cond |
(cond |
291 |
|
|
292 |
(defun c-get-style-variables (style basestyles) |
(defun c-get-style-variables (style basestyles) |
293 |
;; Return all variables in a style by resolving inheritances. |
;; Return all variables in a style by resolving inheritances. |
294 |
|
;; |
295 |
|
;; This function does not do any hidden buffer changes. |
296 |
(if (not style) |
(if (not style) |
297 |
(copy-alist c-fallback-style) |
(copy-alist c-fallback-style) |
298 |
(let ((vars (cdr (or (assoc (downcase style) c-style-alist) |
(let ((vars (cdr (or (assoc (downcase style) c-style-alist) |
375 |
(c-keep-region-active)) |
(c-keep-region-active)) |
376 |
|
|
377 |
;;;###autoload |
;;;###autoload |
378 |
(defun c-add-style (style descrip &optional set-p) |
(defun c-add-style (style description &optional set-p) |
379 |
"Adds a style to `c-style-alist', or updates an existing one. |
"Adds a style to `c-style-alist', or updates an existing one. |
380 |
STYLE is a string identifying the style to add or update. DESCRIP is |
STYLE is a string identifying the style to add or update. DESCRIPTION |
381 |
an association list describing the style and must be of the form: |
is an association list describing the style and must be of the form: |
382 |
|
|
383 |
([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) |
([BASESTYLE] (VARIABLE . VALUE) [(VARIABLE . VALUE) ...]) |
384 |
|
|
388 |
(interactive |
(interactive |
389 |
(let ((stylename (completing-read "Style to add: " c-style-alist |
(let ((stylename (completing-read "Style to add: " c-style-alist |
390 |
nil nil nil 'c-set-style-history)) |
nil nil nil 'c-set-style-history)) |
391 |
(description (eval-minibuffer "Style description: "))) |
(descr (eval-minibuffer "Style description: "))) |
392 |
(list stylename description |
(list stylename descr |
393 |
(y-or-n-p "Set the style too? ")))) |
(y-or-n-p "Set the style too? ")))) |
394 |
(setq style (downcase style)) |
(setq style (downcase style)) |
395 |
(let ((s (assoc style c-style-alist))) |
(let ((s (assoc style c-style-alist))) |
396 |
(if s |
(if s |
397 |
(setcdr s (copy-alist descrip)) ; replace |
(setcdr s (copy-alist description)) ; replace |
398 |
(setq c-style-alist (cons (cons style descrip) c-style-alist)))) |
(setq c-style-alist (cons (cons style description) c-style-alist)))) |
399 |
(and set-p (c-set-style style))) |
(and set-p (c-set-style style))) |
400 |
|
|
401 |
|
|
404 |
(defun c-read-offset (langelem) |
(defun c-read-offset (langelem) |
405 |
;; read new offset value for LANGELEM from minibuffer. return a |
;; read new offset value for LANGELEM from minibuffer. return a |
406 |
;; legal value only |
;; legal value only |
407 |
|
;; |
408 |
|
;; This function does not do any hidden buffer changes. |
409 |
(let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) |
(let* ((oldoff (cdr-safe (or (assq langelem c-offsets-alist) |
410 |
(assq langelem (get 'c-offsets-alist |
(assq langelem (get 'c-offsets-alist |
411 |
'c-stylevar-fallback))))) |
'c-stylevar-fallback))))) |
456 |
;; on the syntactic analysis list for the current |
;; on the syntactic analysis list for the current |
457 |
;; line |
;; line |
458 |
(and c-buffer-is-cc-mode |
(and c-buffer-is-cc-mode |
459 |
(let* ((syntax (c-guess-basic-syntax)) |
(c-save-buffer-state |
460 |
(len (length syntax)) |
((syntax (c-guess-basic-syntax)) |
461 |
(ic (format "%s" (car (nth (1- len) syntax))))) |
(len (length syntax)) |
462 |
|
(ic (format "%s" (car (nth (1- len) syntax))))) |
463 |
(cons ic 0))) |
(cons ic 0))) |
464 |
))) |
))) |
465 |
(offset (c-read-offset langelem))) |
(offset (c-read-offset langelem))) |
482 |
"Fix things up for paragraph recognition and filling inside comments by |
"Fix things up for paragraph recognition and filling inside comments by |
483 |
incorporating the value of `c-comment-prefix-regexp' in the relevant |
incorporating the value of `c-comment-prefix-regexp' in the relevant |
484 |
variables." |
variables." |
485 |
|
;; |
486 |
|
;; This function does not do any hidden buffer changes. |
487 |
|
|
488 |
(setq c-current-comment-prefix |
(setq c-current-comment-prefix |
489 |
(if (listp c-comment-prefix-regexp) |
(if (listp c-comment-prefix-regexp) |
490 |
(cdr-safe (or (assoc major-mode c-comment-prefix-regexp) |
(cdr-safe (or (assoc major-mode c-comment-prefix-regexp) |
493 |
(let ((comment-line-prefix |
(let ((comment-line-prefix |
494 |
(concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*"))) |
(concat "[ \t]*\\(" c-current-comment-prefix "\\)[ \t]*"))) |
495 |
(setq paragraph-start (concat comment-line-prefix |
(setq paragraph-start (concat comment-line-prefix |
496 |
(c-lang-var paragraph-start) |
c-paragraph-start |
497 |
"\\|" |
"\\|" |
498 |
page-delimiter) |
page-delimiter) |
499 |
paragraph-separate (concat comment-line-prefix |
paragraph-separate (concat comment-line-prefix |
500 |
(c-lang-var paragraph-separate) |
c-paragraph-separate |
501 |
"\\|" |
"\\|" |
502 |
page-delimiter) |
page-delimiter) |
503 |
paragraph-ignore-fill-prefix t |
paragraph-ignore-fill-prefix t |
535 |
;; This function is intended to be used explicitly by the end user |
;; This function is intended to be used explicitly by the end user |
536 |
;; only. |
;; only. |
537 |
;; |
;; |
538 |
|
;; This function does not do any hidden buffer changes. |
539 |
|
|
540 |
;; The default configuration already handles C++ comments, but we |
;; The default configuration already handles C++ comments, but we |
541 |
;; need to add handling of C block comments. A new filladapt token |
;; need to add handling of C block comments. A new filladapt token |
542 |
;; `c-comment' is added for that. |
;; `c-comment' is added for that. |
565 |
;; crucial because future c-set-style calls will always reset the |
;; crucial because future c-set-style calls will always reset the |
566 |
;; variables first to the `cc-mode' style before instituting the new |
;; variables first to the `cc-mode' style before instituting the new |
567 |
;; style. Only do this once! |
;; style. Only do this once! |
568 |
|
;; |
569 |
|
;; This function does not do any hidden buffer changes. |
570 |
(unless (get 'c-initialize-builtin-style 'is-run) |
(unless (get 'c-initialize-builtin-style 'is-run) |
571 |
(put 'c-initialize-builtin-style 'is-run t) |
(put 'c-initialize-builtin-style 'is-run t) |
572 |
;;(c-initialize-cc-mode) |
;;(c-initialize-cc-mode) |
591 |
|
|
592 |
(defun c-make-styles-buffer-local (&optional this-buf-only-p) |
(defun c-make-styles-buffer-local (&optional this-buf-only-p) |
593 |
"Make all CC Mode style variables buffer local. |
"Make all CC Mode style variables buffer local. |
594 |
If you edit primarily one style of C (or C++, Objective-C, Java, etc) |
If `this-buf-only-p' is non-nil, the style variables will be made |
595 |
code, you probably want style variables to be global. This is the |
buffer local only in the current buffer. Otherwise they'll be made |
596 |
default. |
permanently buffer local in any buffer that change their values. |
597 |
|
|
598 |
If you edit many different styles of C (or C++, Objective-C, Java, |
The buffer localness of the style variables are normally controlled |
599 |
etc) at the same time, you probably want the CC Mode style variables |
with the variable `c-style-variables-are-local-p', so there's seldom |
600 |
to be buffer local. If you do, it's advisable to set any CC Mode |
any reason to call this function directly." |
601 |
style variables in a hook function (e.g. off of `c-mode-common-hook'), |
;; |
602 |
instead of at the top level of your ~/.emacs file. |
;; This function does not do any hidden buffer changes. |
|
|
|
|
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. |
|
603 |
|
|
|
Optional argument, when non-nil, means use `make-local-variable' |
|
|
instead of `make-variable-buffer-local'." |
|
604 |
;; style variables |
;; style variables |
605 |
(let ((func (if this-buf-only-p |
(let ((func (if this-buf-only-p |
606 |
'make-local-variable |
'make-local-variable |