| 1 | ;; | 
|---|
| 2 | ;; SC.el: stuff for formatting files in the SC libraries | 
|---|
| 3 | ;; | 
|---|
| 4 | ;; Copyright (C) 1996 Limit Point Systems, Inc. | 
|---|
| 5 | ;; | 
|---|
| 6 | ;; Author: Curtis Janssen <cljanss@ca.sandia.gov> | 
|---|
| 7 | ;; Maintainer: SNL | 
|---|
| 8 | ;; | 
|---|
| 9 | ;; This file is part of MPQC. | 
|---|
| 10 | ;; | 
|---|
| 11 | ;; MPQC is free software; you can redistribute it and/or modify | 
|---|
| 12 | ;; it under the terms of the GNU General Public License as published by | 
|---|
| 13 | ;; the Free Software Foundation; either version 2, or (at your option) | 
|---|
| 14 | ;; any later version. | 
|---|
| 15 | ;; | 
|---|
| 16 | ;; MPQC 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 | 
|---|
| 19 | ;; GNU General Public License for more details. | 
|---|
| 20 | ;; | 
|---|
| 21 | ;; You should have received a copy of the GNU General Public License | 
|---|
| 22 | ;; along with the MPQC; see the file COPYING.  If not, write to | 
|---|
| 23 | ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. | 
|---|
| 24 | ;; | 
|---|
| 25 | ;; The U.S. Government is granted a limited license as per AL 91-7. | 
|---|
| 26 | ;; | 
|---|
| 27 |  | 
|---|
| 28 | (require 'cc-mode) | 
|---|
| 29 | (cond ((> emacs-major-version 19) (c-initialize-cc-mode))) | 
|---|
| 30 |  | 
|---|
| 31 | (setq clj-c-basic-half-offset 2) | 
|---|
| 32 |  | 
|---|
| 33 | (defun clj-adaptive-block-open (langelem) | 
|---|
| 34 | ;; when substatement is on semantics list, return | 
|---|
| 35 | ;; -(c-basic-offset - clj-c-basic-half-offset) to give a | 
|---|
| 36 | ;; total offset of clj-c-basic-half-offset, | 
|---|
| 37 | ;; otherwise return clj-c-basic-half-offset | 
|---|
| 38 | (if (assq 'substatement c-semantics) | 
|---|
| 39 | (+ clj-c-basic-half-offset (- c-basic-offset)) | 
|---|
| 40 | clj-c-basic-half-offset)) | 
|---|
| 41 |  | 
|---|
| 42 | (defun clj-lineup-math (langelem) | 
|---|
| 43 | ;; line up math statement-cont so that stuff after the "+", "-", etc | 
|---|
| 44 | ;; lines up with the stuff after the equals | 
|---|
| 45 | (save-excursion | 
|---|
| 46 | (let ((adjustment (progn | 
|---|
| 47 | (beginning-of-line) | 
|---|
| 48 | (skip-chars-forward " \t" (c-point 'eol)) | 
|---|
| 49 | (- (current-column) | 
|---|
| 50 | (progn (skip-chars-forward " \t+-/*" (c-point 'eol)) | 
|---|
| 51 | (current-column))))) | 
|---|
| 52 | (curcol (progn | 
|---|
| 53 | (goto-char (cdr langelem)) | 
|---|
| 54 | (current-column)))) | 
|---|
| 55 | (skip-chars-forward "^=" (c-point 'eol)) | 
|---|
| 56 | (if (/= (following-char) ?=) | 
|---|
| 57 | ;; there's no equal sign on the line | 
|---|
| 58 | c-basic-offset | 
|---|
| 59 | ;; calculate indentation column after equals and ws and sign | 
|---|
| 60 | (forward-char 1) | 
|---|
| 61 | (skip-chars-forward " \t-") | 
|---|
| 62 | (+ (- (current-column) curcol) adjustment)) | 
|---|
| 63 | ))) | 
|---|
| 64 |  | 
|---|
| 65 | (defun clj-adaptive-block-close (langelem) | 
|---|
| 66 | ;; these closes blocks in a way that is consistent with the way | 
|---|
| 67 | ;; clj-adaptive-statement-block-intro indents the first statement | 
|---|
| 68 | (- (clj-adaptive-statement-block-intro langelem) | 
|---|
| 69 | (- c-basic-offset clj-c-basic-half-offset)) | 
|---|
| 70 | ) | 
|---|
| 71 |  | 
|---|
| 72 | (defun clj-adaptive-statement-block-intro (langelem) | 
|---|
| 73 | ;; this lines up the first statement in a block by a full basic | 
|---|
| 74 | ;; offset, unless we are lining up to a "{" which is already | 
|---|
| 75 | ;; half indented | 
|---|
| 76 | (save-excursion | 
|---|
| 77 | (progn | 
|---|
| 78 | (goto-char (cdr langelem)) | 
|---|
| 79 | (if (/= (following-char) ?{) | 
|---|
| 80 | ;; next char is not a "{" | 
|---|
| 81 | c-basic-offset | 
|---|
| 82 | ;; use remainder of half offset | 
|---|
| 83 | (- c-basic-offset clj-c-basic-half-offset)) | 
|---|
| 84 | ))) | 
|---|
| 85 |  | 
|---|
| 86 | (defun clj-condensed-adaptive-statement-block-intro (langelem) | 
|---|
| 87 | ;; this lines up the first statement in a block by a full basic | 
|---|
| 88 | ;; offset, unless we are lining up to a "{" which is already | 
|---|
| 89 | ;; indented | 
|---|
| 90 | (save-excursion | 
|---|
| 91 | (progn | 
|---|
| 92 | (goto-char (cdr langelem)) | 
|---|
| 93 | (if (/= (following-char) ?{) | 
|---|
| 94 | ;; next char is not a "{" | 
|---|
| 95 | c-basic-offset | 
|---|
| 96 | ;; we're already indendted | 
|---|
| 97 | 0) | 
|---|
| 98 | ))) | 
|---|
| 99 |  | 
|---|
| 100 | (defun clj-condensed-adaptive-block-close (langelem) | 
|---|
| 101 | ;; these closes blocks in a way that is consistent with the way | 
|---|
| 102 | ;; clj-condensed-adaptive-statement-block-intro indents the first statement | 
|---|
| 103 | (clj-condensed-adaptive-statement-block-intro langelem) | 
|---|
| 104 | ) | 
|---|
| 105 |  | 
|---|
| 106 | ;; | 
|---|
| 107 | ;; this is the style to use when editting Ed's files | 
|---|
| 108 | ;; | 
|---|
| 109 | (c-add-style "ETS" '((c-basic-offset . 2) | 
|---|
| 110 | (c-offsets-alist . ((access-label      . -) | 
|---|
| 111 | (inclass           . ++) | 
|---|
| 112 | (label             . 0) | 
|---|
| 113 | )) | 
|---|
| 114 | ) | 
|---|
| 115 | ) | 
|---|
| 116 |  | 
|---|
| 117 | ;; | 
|---|
| 118 | ;; this is the style to use when editing Curt's files | 
|---|
| 119 | ;; | 
|---|
| 120 | (c-add-style "CLJ" '( | 
|---|
| 121 | (c-offsets-alist . ( | 
|---|
| 122 | (block-open      . clj-adaptive-block-open) | 
|---|
| 123 | (statement       . c-lineup-runin-statements) | 
|---|
| 124 | (statement-cont  . clj-lineup-math) | 
|---|
| 125 | (statement-block-intro . clj-adaptive-statement-block-intro) | 
|---|
| 126 | (defun-block-intro . 2) | 
|---|
| 127 | (inher-intro . 2) | 
|---|
| 128 | (access-label . -2) | 
|---|
| 129 | (block-close . clj-adaptive-block-close) | 
|---|
| 130 | (member-init-intro . 2) | 
|---|
| 131 | ) | 
|---|
| 132 | )) | 
|---|
| 133 | ) | 
|---|
| 134 |  | 
|---|
| 135 | ;; | 
|---|
| 136 | ;; Curt's other style | 
|---|
| 137 | ;; | 
|---|
| 138 | (c-add-style "CLJ-CONDENSED" '( | 
|---|
| 139 | ;(c-echo-syntactic-information-p . t) | 
|---|
| 140 | (c-basic-offset . 2) | 
|---|
| 141 | (c-offsets-alist . ( | 
|---|
| 142 | (statement-block-intro . clj-condensed-adaptive-statement-block-intro) | 
|---|
| 143 | (statement-cont . c-lineup-math) | 
|---|
| 144 | (inclass . ++) | 
|---|
| 145 | (access-label . -) | 
|---|
| 146 | (block-close . clj-condensed-adaptive-statement-block-intro) | 
|---|
| 147 | (substatement-open . +) | 
|---|
| 148 | (block-open . +) | 
|---|
| 149 | ) | 
|---|
| 150 | )) | 
|---|
| 151 | ) | 
|---|
| 152 |  | 
|---|
| 153 | (defun clj-condensed-style () | 
|---|
| 154 | "Change to condensed C indentation" | 
|---|
| 155 | (interactive) | 
|---|
| 156 | (c-set-style "CLJ-CONDENSED") | 
|---|
| 157 | ) | 
|---|
| 158 | (defun clj-style () | 
|---|
| 159 | "Change to insane C indentation" | 
|---|
| 160 | (interactive) | 
|---|
| 161 | (c-set-style "CLJ") | 
|---|
| 162 | ) | 
|---|
| 163 | (defun ets-style () | 
|---|
| 164 | "Change to sensible C indentation" | 
|---|
| 165 | (interactive) | 
|---|
| 166 | (c-set-style "ETS") | 
|---|
| 167 | ) | 
|---|
| 168 |  | 
|---|
| 169 | (define-key c-mode-map "\C-ce" 'ets-style) | 
|---|
| 170 | (define-key c-mode-map "\C-cj" 'clj-style) | 
|---|
| 171 | (define-key c-mode-map "\C-cc" 'clj-condensed-style) | 
|---|
| 172 | (define-key c-mode-map "\C-j"  'reindent-then-newline-and-indent) | 
|---|
| 173 | (define-key c-mode-map "\C-m"  'newline-and-indent) | 
|---|
| 174 |  | 
|---|
| 175 | (define-key c++-mode-map "\C-ce" 'ets-style) | 
|---|
| 176 | (define-key c++-mode-map "\C-cj" 'clj-style) | 
|---|
| 177 | (define-key c++-mode-map "\C-cc" 'clj-condensed-style) | 
|---|
| 178 | (define-key c++-mode-map "\C-j"  'reindent-then-newline-and-indent) | 
|---|
| 179 | (define-key c++-mode-map "\C-m"  'newline-and-indent) | 
|---|
| 180 |  | 
|---|
| 181 | (define-key java-mode-map "\C-ce" 'ets-style) | 
|---|
| 182 | (define-key java-mode-map "\C-cj" 'clj-style) | 
|---|
| 183 | (define-key java-mode-map "\C-cc" 'clj-condensed-style) | 
|---|
| 184 | (define-key java-mode-map "\C-j"  'reindent-then-newline-and-indent) | 
|---|
| 185 | (define-key java-mode-map "\C-m"  'newline-and-indent) | 
|---|
| 186 |  | 
|---|
| 187 | ;; | 
|---|
| 188 | ;; stuff for CLJ's compile hacks | 
|---|
| 189 | ;; | 
|---|
| 190 |  | 
|---|
| 191 | (defun compile-modify-path (thisdir) | 
|---|
| 192 | (let ((tmpdir (expand-file-name thisdir))) | 
|---|
| 193 | (setq thisdir "") | 
|---|
| 194 | (while (>= (length tmpdir) (length sc-src-dir)) | 
|---|
| 195 | (if (string= (substring tmpdir 0 (length sc-src-dir)) sc-src-dir) | 
|---|
| 196 | (let () | 
|---|
| 197 | (setq thisdir (concat thisdir sc-arch-dir)) | 
|---|
| 198 | (setq tmpdir (substring tmpdir (length sc-src-dir) nil)) | 
|---|
| 199 | ) | 
|---|
| 200 | (let () | 
|---|
| 201 | (setq thisdir (concat thisdir (substring tmpdir 0 1))) | 
|---|
| 202 | (setq tmpdir (substring tmpdir 1 nil)) | 
|---|
| 203 | ) | 
|---|
| 204 | ) | 
|---|
| 205 | ) | 
|---|
| 206 | (setq thisdir (concat thisdir tmpdir)) | 
|---|
| 207 | ) | 
|---|
| 208 | thisdir | 
|---|
| 209 | ) | 
|---|
| 210 |  | 
|---|
| 211 | ;; | 
|---|
| 212 | ;; stuff for inserting copyleft notices | 
|---|
| 213 | ;; | 
|---|
| 214 |  | 
|---|
| 215 | (defvar copyleft-owner "Limit Point Systems, Inc." | 
|---|
| 216 | "This is the owner of the copyleft.  Defaults to LPS.") | 
|---|
| 217 |  | 
|---|
| 218 | (defun set-copyleft-owner (owner) | 
|---|
| 219 | "Set the copyleft-owner variable." | 
|---|
| 220 | (interactive (list (read-from-minibuffer "Copyleft Owner: " | 
|---|
| 221 | copyleft-owner nil nil nil))) | 
|---|
| 222 | (setq copyleft-owner owner)) | 
|---|
| 223 |  | 
|---|
| 224 | (defvar copyleft-author user-full-name | 
|---|
| 225 | "This is the author of the file.  Defaults to the user editing the file.") | 
|---|
| 226 |  | 
|---|
| 227 | (defun set-copyleft-author (author) | 
|---|
| 228 | "Set the copyleft-author variable." | 
|---|
| 229 | (interactive (list (read-from-minibuffer "Author: " | 
|---|
| 230 | copyleft-author nil nil nil))) | 
|---|
| 231 | (setq copyleft-author author)) | 
|---|
| 232 |  | 
|---|
| 233 | (defvar copyleft-address user-mail-address | 
|---|
| 234 | "This is the email address of the author of the file.  Defaults to the | 
|---|
| 235 | address of the user editing the file.") | 
|---|
| 236 |  | 
|---|
| 237 | (defun set-copyleft-address (address) | 
|---|
| 238 | "Set the copyleft-address variable." | 
|---|
| 239 | (interactive (list (read-from-minibuffer "E-mail address: " | 
|---|
| 240 | copyleft-address nil nil nil))) | 
|---|
| 241 | (setq copyleft-address address)) | 
|---|
| 242 |  | 
|---|
| 243 | (defvar copyleft-maintainer "LPS" | 
|---|
| 244 | "This is the official maintaner of the file. Defaults to LPS") | 
|---|
| 245 |  | 
|---|
| 246 | (defun set-copyleft-maintainer (maintainer) | 
|---|
| 247 | "Set the copyleft-maintainer variable." | 
|---|
| 248 | (interactive (list (read-from-minibuffer "Maintainer: " | 
|---|
| 249 | copyleft-maintainer nil nil nil))) | 
|---|
| 250 | (setq copyleft-maintainer maintainer)) | 
|---|
| 251 |  | 
|---|
| 252 | (defvar copyleft-default-comment-start "#" | 
|---|
| 253 | "The default symbol to use to begin a comment. Defaults to \"#\".") | 
|---|
| 254 |  | 
|---|
| 255 | (defvar copyleft-default-comment-cont "#" | 
|---|
| 256 | "The default symbol to use to continue a comment. Defaults to \"#\".") | 
|---|
| 257 |  | 
|---|
| 258 | (defvar copyleft-default-comment-end "#" | 
|---|
| 259 | "The default symbol to use to end a comment. Defaults to \"#\".") | 
|---|
| 260 |  | 
|---|
| 261 | (defun copyleft-set-comments (start cont end) | 
|---|
| 262 | "Set the comment symbols. | 
|---|
| 263 |  | 
|---|
| 264 | (copyleft-set-comments START CONT END)" | 
|---|
| 265 | (interactive (list (read-from-minibuffer "Comment start: " | 
|---|
| 266 | copyleft-default-comment-start nil nil nil) | 
|---|
| 267 | (read-from-minibuffer "Comment continue: " | 
|---|
| 268 | copyleft-default-comment-cont nil nil nil) | 
|---|
| 269 | (read-from-minibuffer "Comment end: " | 
|---|
| 270 | copyleft-default-comment-end nil nil nil) | 
|---|
| 271 | )) | 
|---|
| 272 |  | 
|---|
| 273 | (setq copyleft-default-comment-start start) | 
|---|
| 274 | (setq copyleft-default-comment-cont cont) | 
|---|
| 275 | (setq copyleft-default-comment-end end) | 
|---|
| 276 | ) | 
|---|
| 277 |  | 
|---|
| 278 | (defun insert-copyleft () | 
|---|
| 279 | "Insert the notice." | 
|---|
| 280 | (interactive) | 
|---|
| 281 | (set-window-point (display-buffer (current-buffer)) (point-min)) | 
|---|
| 282 | (cond ((eq major-mode 'c++-mode) | 
|---|
| 283 | (setq comment-start "//") | 
|---|
| 284 | (setq comment-cont "//") | 
|---|
| 285 | (setq comment-end "//") | 
|---|
| 286 | ) | 
|---|
| 287 | ((eq major-mode 'c-mode) | 
|---|
| 288 | (setq comment-start "/*") | 
|---|
| 289 | (setq comment-cont " *") | 
|---|
| 290 | (setq comment-end " */") | 
|---|
| 291 | ) | 
|---|
| 292 | ((eq major-mode 'emacs-lisp-mode) | 
|---|
| 293 | (setq comment-start ";;") | 
|---|
| 294 | (setq comment-cont ";;") | 
|---|
| 295 | (setq comment-end ";;") | 
|---|
| 296 | ) | 
|---|
| 297 | ((eq major-mode 'makefile-mode) | 
|---|
| 298 | (setq comment-start "#") | 
|---|
| 299 | (setq comment-cont "#") | 
|---|
| 300 | (setq comment-end "#") | 
|---|
| 301 | ) | 
|---|
| 302 | ('t | 
|---|
| 303 | (setq comment-start copyleft-default-comment-start) | 
|---|
| 304 | (setq comment-cont copyleft-default-comment-cont) | 
|---|
| 305 | (setq comment-end copyleft-default-comment-end) | 
|---|
| 306 | ) | 
|---|
| 307 | ) | 
|---|
| 308 |  | 
|---|
| 309 | (setq description (read-from-minibuffer "Description: ")) | 
|---|
| 310 |  | 
|---|
| 311 | (insert comment-start "\n") | 
|---|
| 312 | (insert comment-cont " " (file-name-nondirectory buffer-file-name) | 
|---|
| 313 | (cond ((not (string= description "")) (concat " --- " description "\n")) | 
|---|
| 314 | ('t "\n"))) | 
|---|
| 315 | (insert comment-cont "\n") | 
|---|
| 316 | (insert comment-cont " Copyright (C) " | 
|---|
| 317 | (substring (current-time-string) 20) " " | 
|---|
| 318 | copyleft-owner "\n") | 
|---|
| 319 | (insert comment-cont "\n") | 
|---|
| 320 | (insert comment-cont " Author: " copyleft-author " <" copyleft-address ">\n") | 
|---|
| 321 | (insert comment-cont " Maintainer: " copyleft-maintainer "\n") | 
|---|
| 322 | (insert comment-cont "\n") | 
|---|
| 323 | (insert comment-cont " This file is part of the SC Toolkit.\n") | 
|---|
| 324 | (insert comment-cont "\n") | 
|---|
| 325 |  | 
|---|
| 326 | (insert comment-cont " The SC Toolkit is free software; you can redistribute it and/or modify\n") | 
|---|
| 327 | (insert comment-cont " it under the terms of the GNU Library General Public License as published by\n") | 
|---|
| 328 | (insert comment-cont " the Free Software Foundation; either version 2, or (at your option)\n") | 
|---|
| 329 | (insert comment-cont " any later version.\n") | 
|---|
| 330 | (insert comment-cont "\n") | 
|---|
| 331 |  | 
|---|
| 332 | (insert comment-cont " The SC Toolkit is distributed in the hope that it will be useful,\n") | 
|---|
| 333 | (insert comment-cont " but WITHOUT ANY WARRANTY; without even the implied warranty of\n") | 
|---|
| 334 | (insert comment-cont " MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n") | 
|---|
| 335 | (insert comment-cont " GNU Library General Public License for more details.\n") | 
|---|
| 336 | (insert comment-cont "\n") | 
|---|
| 337 |  | 
|---|
| 338 | (insert comment-cont " You should have received a copy of the GNU Library General Public License\n") | 
|---|
| 339 | (insert comment-cont " along with the SC Toolkit; see the file COPYING.LIB.  If not, write to\n") | 
|---|
| 340 | (insert comment-cont " the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.\n") | 
|---|
| 341 | (insert comment-cont "\n") | 
|---|
| 342 |  | 
|---|
| 343 | (insert comment-cont " The U.S. Government is granted a limited license as per AL 91-7.\n") | 
|---|
| 344 | (insert comment-end "\n") | 
|---|
| 345 | ) | 
|---|
| 346 |  | 
|---|
| 347 | (define-key c-mode-map "\C-ci" 'insert-copyleft) | 
|---|
| 348 | (define-key c++-mode-map "\C-ci" 'insert-copyleft) | 
|---|
| 349 | (define-key java-mode-map "\C-ci" 'insert-copyleft) | 
|---|