~mwinter4/maus/ckov_0_9_3

« back to all changes in this revision

Viewing changes to third_party/google-styleguide/.svn/text-base/google-c-style.el.svn-base

  • Committer: tunnell
  • Date: 2010-09-30 13:56:05 UTC
  • Revision ID: tunnell@itchy-20100930135605-wxbkfgy75p0sndk3
add third party

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
;;; google-c-style.el --- Google's C/C++ style for c-mode
 
2
 
 
3
;; Keywords: c, tools
 
4
 
 
5
;; google-c-style.el is Copyright (C) 2008 Google Inc. All Rights Reserved.
 
6
;;
 
7
;; It is free software; you can redistribute it and/or modify it under the
 
8
;; terms of either:
 
9
;;
 
10
;; a) the GNU General Public License as published by the Free Software
 
11
;; Foundation; either version 1, or (at your option) any later version, or
 
12
;;
 
13
;; b) the "Artistic License".
 
14
 
 
15
;;; Commentary:
 
16
 
 
17
;; Provides the google C/C++ coding style. You may wish to add
 
18
;; `google-set-c-style' to your `c-mode-common-hook' after requiring this
 
19
;; file. For example:
 
20
;;
 
21
;;    (add-hook 'c-mode-common-hook 'google-set-c-style)
 
22
;;
 
23
;; If you want the RETURN key to go to the next line and space over
 
24
;; to the right place, add this to your .emacs right after the load-file:
 
25
;;
 
26
;;    (add-hook 'c-mode-common-hook 'google-make-newline-indent)
 
27
 
 
28
;;; Code:
 
29
 
 
30
;; For some reason 1) c-backward-syntactic-ws is a macro and 2)  under Emacs 22
 
31
;; bytecode cannot call (unexpanded) macros at run time:
 
32
(eval-when-compile (require 'cc-defs))
 
33
 
 
34
;; Wrapper function needed for Emacs 21 and XEmacs (Emacs 22 offers the more
 
35
;; elegant solution of composing a list of lineup functions or quantities with
 
36
;; operators such as "add")
 
37
(defun google-c-lineup-expression-plus-4 (langelem)
 
38
  "Indents to the beginning of the current C expression plus 4 spaces.
 
39
 
 
40
This implements title \"Function Declarations and Definitions\" of the Google
 
41
C++ Style Guide for the case where the previous line ends with an open
 
42
parenthese.
 
43
 
 
44
\"Current C expression\", as per the Google Style Guide and as clarified by
 
45
subsequent discussions,
 
46
means the whole expression regardless of the number of nested parentheses, but
 
47
excluding non-expression material such as \"if(\" and \"for(\" control
 
48
structures.
 
49
 
 
50
Suitable for inclusion in `c-offsets-alist'."
 
51
  (save-excursion
 
52
    (back-to-indentation)
 
53
    ;; Go to beginning of *previous* line:
 
54
    (c-backward-syntactic-ws)
 
55
    (back-to-indentation)
 
56
    ;; We are making a reasonable assumption that if there is a control
 
57
    ;; structure to indent past, it has to be at the beginning of the line.
 
58
    (if (looking-at "\\(\\(if\\|for\\|while\\)\\s *(\\)")
 
59
        (goto-char (match-end 1)))
 
60
    (vector (+ 4 (current-column)))))
 
61
        
 
62
(defconst google-c-style
 
63
  `((c-recognize-knr-p . nil)
 
64
    (c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs
 
65
    (c-basic-offset . 2)
 
66
    (indent-tabs-mode . nil)
 
67
    (c-comment-only-line-offset . 0)
 
68
    (c-hanging-braces-alist . ((defun-open after)
 
69
                               (defun-close before after)
 
70
                               (class-open after)
 
71
                               (class-close before after)
 
72
                               (namespace-open after)
 
73
                               (inline-open after)
 
74
                               (inline-close before after)
 
75
                               (block-open after)
 
76
                               (block-close . c-snug-do-while)
 
77
                               (extern-lang-open after)
 
78
                               (extern-lang-close after)
 
79
                               (statement-case-open after)
 
80
                               (substatement-open after)))
 
81
    (c-hanging-colons-alist . ((case-label)
 
82
                               (label after)
 
83
                               (access-label after)
 
84
                               (member-init-intro before)
 
85
                               (inher-intro)))
 
86
    (c-hanging-semi&comma-criteria
 
87
     . (c-semi&comma-no-newlines-for-oneline-inliners
 
88
        c-semi&comma-inside-parenlist
 
89
        c-semi&comma-no-newlines-before-nonblanks))
 
90
    (c-indent-comments-syntactically-p . nil)
 
91
    (comment-column . 40)
 
92
    (c-cleanup-list . (brace-else-brace
 
93
                       brace-elseif-brace
 
94
                       brace-catch-brace
 
95
                       empty-defun-braces
 
96
                       defun-close-semi
 
97
                       list-close-comma
 
98
                       scope-operator))
 
99
    (c-offsets-alist . ((arglist-intro google-c-lineup-expression-plus-4)
 
100
                        (func-decl-cont . ++)
 
101
                        (member-init-intro . ++)
 
102
                        (inher-intro . ++)
 
103
                        (comment-intro . 0)
 
104
                        (arglist-close . c-lineup-arglist)
 
105
                        (topmost-intro . 0)
 
106
                        (block-open . 0)
 
107
                        (inline-open . 0)
 
108
                        (substatement-open . 0)
 
109
                        (statement-cont
 
110
                         .
 
111
                         (,(when (fboundp 'c-no-indent-after-java-annotations)
 
112
                             'c-no-indent-after-java-annotations)
 
113
                          ,(when (fboundp 'c-lineup-assignments)
 
114
                             'c-lineup-assignments)
 
115
                          ++))
 
116
                        (label . /)
 
117
                        (case-label . +)
 
118
                        (statement-case-open . +)
 
119
                        (statement-case-intro . +) ; case w/o {
 
120
                        (access-label . /)
 
121
                        (innamespace . 0))))
 
122
  "Google C/C++ Programming Style")
 
123
 
 
124
(defun google-set-c-style ()
 
125
  "Set the current buffer's c-style to Google C/C++ Programming
 
126
  Style. Meant to be added to `c-mode-common-hook'."
 
127
  (interactive)
 
128
  (make-local-variable 'c-tab-always-indent)
 
129
  (setq c-tab-always-indent t)
 
130
  (c-add-style "Google" google-c-style t))
 
131
 
 
132
(defun google-make-newline-indent ()
 
133
  "Sets up preferred newline behavior. Not set by default. Meant
 
134
  to be added to `c-mode-common-hook'."
 
135
  (interactive)
 
136
  (define-key c-mode-base-map "\C-m" 'newline-and-indent)
 
137
  (define-key c-mode-base-map [ret] 'newline-and-indent))
 
138
 
 
139
(provide 'google-c-style)
 
140
;;; google-c-style.el ends here