| 1 |
;; |
| 2 |
;; KIM-API: An API for interatomic models |
| 3 |
;; Copyright (c) 2013--2022, Regents of the University of Minnesota. |
| 4 |
;; All rights reserved. |
| 5 |
;; |
| 6 |
;; Contributors: |
| 7 |
;; Ryan S. Elliott |
| 8 |
;; |
| 9 |
;; SPDX-License-Identifier: LGPL-2.1-or-later |
| 10 |
;; |
| 11 |
;; This library is free software; you can redistribute it and/or |
| 12 |
;; modify it under the terms of the GNU Lesser General Public |
| 13 |
;; License as published by the Free Software Foundation; either |
| 14 |
;; version 2.1 of the License, or (at your option) any later version. |
| 15 |
;; |
| 16 |
;; This library is distributed in the hope that it will be useful, |
| 17 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 |
;; Lesser General Public License for more details. |
| 20 |
;; |
| 21 |
;; You should have received a copy of the GNU Lesser General Public License |
| 22 |
;; along with this library; if not, write to the Free Software Foundation, |
| 23 |
;; Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 24 |
;; |
| 25 |
|
| 26 |
;; |
| 27 |
;; Release: This file is part of the kim-api.git repository. |
| 28 |
;; |
| 29 |
|
| 30 |
|
| 31 |
;;; kim-api-c-style.el --- kim-api's C/C++ style for c-mode |
| 32 |
|
| 33 |
;; Keywords: c, tools |
| 34 |
|
| 35 |
;; This file derives from the google-c-style.el file. |
| 36 |
|
| 37 |
|
| 38 |
;;; Commentary: |
| 39 |
|
| 40 |
;; Provides the kim-api C/C++ coding style. You may wish to add |
| 41 |
;; 'kim-api-set-c-style' to your 'c-mode-common-hook' after requiring this |
| 42 |
;; file. For example: |
| 43 |
;; |
| 44 |
;; (add-hook 'c-mode-common-hook 'kim-api-set-c-style) |
| 45 |
;; |
| 46 |
;; If you want the RETURN key to go to the next line and space over |
| 47 |
;; to the right place, add this to your .emacs right after the load-file: |
| 48 |
;; |
| 49 |
;; (add-hook 'c-mode-common-hook 'kim-api-make-newline-indent) |
| 50 |
|
| 51 |
;;; Code: |
| 52 |
|
| 53 |
;; For some reason 1) c-backward-syntactic-ws is a macro and 2) under Emacs 22 |
| 54 |
;; bytecode cannot call (unexpanded) macros at run time: |
| 55 |
(eval-when-compile (require 'cc-defs)) |
| 56 |
|
| 57 |
(defconst kim-api-c-style |
| 58 |
`((c-recognize-knr-p . nil) |
| 59 |
(c-enable-xemacs-performance-kludge-p . t) ; speed up indentation in XEmacs |
| 60 |
(c-basic-offset . 2) |
| 61 |
(indent-tabs-mode . nil) |
| 62 |
(c-comment-only-line-offset . 0) |
| 63 |
(c-hanging-braces-alist . ((defun-open before after) |
| 64 |
(defun-close before after) |
| 65 |
(class-open before after) |
| 66 |
(class-close before after) |
| 67 |
(inexpr-class-open before after) |
| 68 |
(inexpr-class-close before after) |
| 69 |
(namespace-open before after) |
| 70 |
(inline-open before after) |
| 71 |
(inline-close before after) |
| 72 |
(block-open before after) |
| 73 |
(block-close . c-snug-do-while) |
| 74 |
(extern-lang-open before after) |
| 75 |
(extern-lang-close before after) |
| 76 |
(statement-case-open before after) |
| 77 |
(substatement-open before after))) |
| 78 |
(c-hanging-colons-alist . ((case-label) |
| 79 |
(label after) |
| 80 |
(access-label after) |
| 81 |
(member-init-intro before) |
| 82 |
(inher-intro))) |
| 83 |
(c-hanging-semi&comma-criteria |
| 84 |
. (c-semi&comma-no-newlines-for-oneline-inliners |
| 85 |
c-semi&comma-inside-parenlist |
| 86 |
c-semi&comma-no-newlines-before-nonblanks)) |
| 87 |
(c-indent-comments-syntactically-p . t) |
| 88 |
(comment-column . 40) |
| 89 |
(c-indent-comment-alist . ((other . (space . 2)))) |
| 90 |
(c-cleanup-list . (empty-defun-braces |
| 91 |
defun-close-semi |
| 92 |
list-close-comma |
| 93 |
scope-operator)) |
| 94 |
(c-offsets-alist . ( |
| 95 |
(access-label . *) |
| 96 |
(arglist-cont . 0) |
| 97 |
(arglist-intro . ++) |
| 98 |
(class-close . 0) |
| 99 |
(class-open . 0) |
| 100 |
(cpp-define-intro . +) |
| 101 |
(defun-block-intro . +) |
| 102 |
(func-decl-cont . 0) |
| 103 |
(inclass . +) |
| 104 |
(inline-close . 0) |
| 105 |
(innamespace . 0) |
| 106 |
(namespace-close . 0) |
| 107 |
(namespace-open . 0) |
| 108 |
(topmost-intro . 0) |
| 109 |
(topmost-intro-cont . 0) |
| 110 |
(annotation-top-cont . 0) |
| 111 |
(annotation-var-cont . +) |
| 112 |
(arglist-close . c-lineup-close-paren) |
| 113 |
(arglist-cont-nonempty . (c-lineup-string-cont |
| 114 |
c-lineup-arglist)) |
| 115 |
(block-close . 0) |
| 116 |
(block-open . 0) |
| 117 |
(brace-entry-open . 0) |
| 118 |
(brace-list-close . 0) |
| 119 |
(brace-list-entry . c-lineup-under-anchor) |
| 120 |
(brace-list-intro . +) |
| 121 |
(brace-list-open . 0) |
| 122 |
(c . c-lineup-C-comments) |
| 123 |
(case-label . +) |
| 124 |
(catch-clause . 0) |
| 125 |
(comment-intro . c-lineup-comment) |
| 126 |
(composition-close . 0) |
| 127 |
(composition-open . 0) |
| 128 |
(cpp-macro . -1000) |
| 129 |
(cpp-macro-cont . +) |
| 130 |
(defun-close . 0) |
| 131 |
(defun-open . 0) |
| 132 |
(do-while-closure . 0) |
| 133 |
(else-clause . 0) |
| 134 |
(extern-lang-close . 0) |
| 135 |
(extern-lang-open . 0) |
| 136 |
(friend . 0) |
| 137 |
(incomposition . +) |
| 138 |
(inexpr-class . +) |
| 139 |
(inexpr-statement . +) |
| 140 |
(inextern-lang . 0) |
| 141 |
(inher-cont . c-lineup-multi-inher) |
| 142 |
(inher-intro . ++) |
| 143 |
(inlambda . c-lineup-inexpr-block) |
| 144 |
(inline-open . 0) |
| 145 |
(inmodule . +) |
| 146 |
(knr-argdecl . 0) |
| 147 |
(knr-argdecl-intro . +) |
| 148 |
(label . /) |
| 149 |
(lambda-intro-cont . +) |
| 150 |
(member-init-cont . c-lineup-multi-inher) |
| 151 |
(member-init-intro . ++) |
| 152 |
(module-close . 0) |
| 153 |
(module-open . 0) |
| 154 |
(statement . 0) |
| 155 |
(statement-block-intro . +) |
| 156 |
(statement-case-intro . +) |
| 157 |
(statement-case-open . 0) |
| 158 |
(statement-cont . (c-lineup-string-cont |
| 159 |
c-lineup-cascaded-calls |
| 160 |
c-lineup-assignments |
| 161 |
++)) |
| 162 |
(stream-op . c-lineup-streamop) |
| 163 |
(string . -1000) |
| 164 |
(substatement . +) |
| 165 |
(substatement-label . 2) |
| 166 |
(substatement-open . 0) |
| 167 |
(template-args-cont c-lineup-template-args +) |
| 168 |
) |
| 169 |
) |
| 170 |
) |
| 171 |
"kim-api C/C++ Programming Style.") |
| 172 |
|
| 173 |
(defun kim-api-set-c-style () |
| 174 |
"Set the current buffer's c-style to kim-api C/C++ Programming |
| 175 |
Style. Meant to be added to `c-mode-common-hook'." |
| 176 |
(interactive) |
| 177 |
(make-local-variable 'c-tab-always-indent) |
| 178 |
(setq c-tab-always-indent t) |
| 179 |
(c-add-style "kim-api" kim-api-c-style t)) |
| 180 |
|
| 181 |
(defun kim-api-make-newline-indent () |
| 182 |
"Sets up preferred newline behavior. Not set by default. Meant |
| 183 |
to be added to `c-mode-common-hook'." |
| 184 |
(interactive) |
| 185 |
(define-key c-mode-base-map "\C-m" 'newline-and-indent) |
| 186 |
(define-key c-mode-base-map [ret] 'newline-and-indent)) |
| 187 |
|
| 188 |
(provide 'kim-api-c-style) |
| 189 |
;;; kim-api-c-style.el ends here |