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