skelrc: Stanza for the GNU Affero General Public License.
[skel] / skelrc
CommitLineData
7fb0878b 1;;; -*-emacs-lisp-*-
2
7e2d1edc 3(defun skelrc-strip-trailing-whitespace (string)
70a2db6b
MW
4 "Return STRING, but with trailing whitespace removed.
5
6Whitespace characters are those with space syntax."
7e2d1edc
MW
7 (let ((i (1- (length string))))
8 (while (and (>= i 0) (= (char-syntax (aref string i)) ? ))
9 (setq i (1- i)))
10 (substring string 0 (1+ i))))
11
7fb0878b 12(defun skelrc-banner (title &optional block)
70a2db6b 13 "Return a comment banner with the given TITLE, and maybe a BLOCK of text."
7fb0878b 14 (let* ((start (skel-lookup 'block-start))
15 (end (skel-lookup (if block 'block-banner-knob 'block-banner-end)))
16 (barlen (- 77 (length (concat start end " ----- " title)))))
7e2d1edc
MW
17 (skelrc-strip-trailing-whitespace (concat start
18 "----- "
19 title
20 " "
21 (make-string barlen ?-)
22 end))))
7fb0878b 23
70a2db6b
MW
24(defvar skelrc-forced-major-mode 0
25 "The priority of the currently forced major mode")
7fb0878b 26
27(defun skelrc-force-mode (new-mode &optional priority)
70a2db6b
MW
28 "Force the use of major mode NEW-MODE.
29
30If the PRIORITY (defaults to 1) is strictly greater than
31`skelrc-forced-major-mode' then the NEW-MODE takes precedence. A `skelrc'
32file which wants to delegate settings to another file should therefore force
33its chosen major-mode before calling `skel-include'."
7fb0878b 34 (or priority (setq priority 1))
35 (if (> priority skelrc-forced-major-mode)
36 (progn
37 (or (eq new-mode major-mode)
38 (let ((old-skel-alist skel-alist))
39 (funcall new-mode)
40 (make-variable-buffer-local 'skel-alist)
41 (setq skel-alist old-skel-alist)))
42 (make-variable-buffer-local 'skelrc-forced-major-mode)
43 (setq skelrc-forced-major-mode priority))))
44
45(defun skelrc-decode-major-mode ()
70a2db6b 46 "Return the mode dropping to put in a local-variables line."
7fb0878b 47 (let* ((name (symbol-name major-mode))
48 (endind (string-match "-mode$" name)))
49 (if endind (substring name 0 endind)
50 (name))))
51
70a2db6b
MW
52(defun skelrc-assq (key alist)
53 "Pick out the value associated with KEY in ALIST (rather than the cons)."
54 (let ((val (assq key alist)))
441c920b 55 (and val (cdr val))))
56
6d349e29
MW
57(defun skelrc-prefix-lines (prefix lines)
58 "Return LINES, each with PREFIX prepended to the beginning.
59
60If the LINES end with a newline character, there is not considered to be a
61final empty line. When prepended to an empty line, trailing whitespace in
62the PREFIX is removed."
63 (with-temp-buffer
64 (insert lines)
65 (goto-char (point-min))
66 (while (< (point) (point-max))
67 (insert prefix)
68 (and (looking-at "\n")
69 (delete-horizontal-space t))
70 (forward-line))
71 (buffer-string)))
72
441c920b 73(defun skelrc-component ()
6d349e29 74 "Return a suitable a `This file is part of ...' line."
441c920b 75 (if (assq 'full-title skel-alist)
7fb0878b 76"[[cont-comment]] This file is part of [[full-title]].
6d349e29 77\[[cont-comment]]\n"
441c920b 78 ""))
79
6d349e29
MW
80(setq skelrc-gpl (skelrc-prefix-lines "[[cont-comment]] "
81"[[Program-name]] is free software; you can redistribute it and/or modify
82it under the terms of the GNU General Public License as published by
83the Free Software Foundation; either version 2 of the License, or
84\(at your option) any later version.
85
86\[[Program-name]] is distributed in the hope that it will be useful,
87but WITHOUT ANY WARRANTY; without even the implied warranty of
88MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89GNU General Public License for more details.
90
91You should have received a copy of the GNU General Public License
92along with [[program-name]]; if not, write to the Free Software Foundation,
93Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA."))
94
95(setq skelrc-wide-gpl (skelrc-prefix-lines "[[cont-comment]] "
96;;Version for wide program names
97"[[Program-name]] is free software; you can redistribute it and/or modify
98it under the terms of the GNU General Public License as published by
99the Free Software Foundation; either version 2 of the License, or
100\(at your option) any later version.
101
102\[[Program-name]] is distributed in the hope that it will be useful,
103but WITHOUT ANY WARRANTY; without even the implied warranty of
104MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105GNU General Public License for more details.
106
107You should have received a copy of the GNU General Public License
108along with [[program-name]]; if not, write to the Free
109Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
110MA 02111-1307, USA."))
111
112(setq skelrc-lgpl (skelrc-prefix-lines "[[cont-comment]] "
113"[[Library-name]] is free software; you can redistribute it and/or modify
114it under the terms of the GNU Library General Public License as
115published by the Free Software Foundation; either version 2 of the
116License, or (at your option) any later version.
117
118\[[Library-name]] is distributed in the hope that it will be useful,
119but WITHOUT ANY WARRANTY; without even the implied warranty of
120MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121GNU Library General Public License for more details.
122
123You should have received a copy of the GNU Library General Public
124License along with [[library-name]]; if not, write to the Free
125Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
126MA 02111-1307, USA."))
127
d18fb0e7
MW
128(setq skelrc-agpl (skelrc-prefix-lines "[[cont-comment]] "
129"[[Program-name]] is free software; you can redistribute it and/or modify
130it under the terms of the GNU Affero General Public License as
131published by the Free Software Foundation; either version 3 of the
132License, or (at your option) any later version.
133
134\[[Program-name]] is distributed in the hope that it will be useful,
135but WITHOUT ANY WARRANTY; without even the implied warranty of
136MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137GNU Affero General Public License for more details.
138
139You should have received a copy of the GNU Affero General Public
140License along with [[program-name]]; if not, see
141<http://www.gnu.org/licenses/>."))
142
6d349e29
MW
143(setq skelrc-bsd (skelrc-prefix-lines "[[cont-comment]] "
144"Copyright (c) [[year]] [[author]]
145All rights reserved.
146
147Redistribution and use in source and binary forms, with or without
148modification, are permitted provided that the following conditions are
149met:
150
1511. Redistributions of source code must retain the above copyright
152 notice, this list of conditions and the following disclaimer.
153
1542, Redistributions in binary form must reproduce the above copyright
155 notice, this list of conditions and the following disclaimer in the
156 documentation and/or other materials provided with the distribution.
157
1583. The name of the authors may not be used to endorse or promote
159 products derived from this software without specific prior written
160 permission.
161
162THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
163WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
164MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
165NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
166INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
167\(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
168SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
169HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
170STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
171ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
172POSSIBILITY OF SUCH DAMAGE.
173
174Instead of accepting the above terms, you may redistribute and/or modify
175this software under the terms of either the GNU General Public License,
176or the GNU Library General Public License, published by the Free
177Software Foundation; either version 2 of the License, or (at your
178option) any later version."))
0237168a 179
7fb0878b 180(defun skel-basename ()
181 (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
182
183(setq skel-alist
184 (append
aaadf1ff
MW
185 `((first-line . "[[new-comment]] -*-[[emacs-mode]]-*-")
186 (emacs-mode . (skelrc-decode-major-mode))
7fb0878b 187 (year . (substring (current-time-string) 20 24))
86ec878d 188 (header . "[[licence]][[preamble]]")
7fb0878b 189 (basename . (skel-basename))
a6ca2716
MW
190 (licence . ,(concat "[[licence-banner]]\n"
191 "[[cont-comment]]\n"
192 "[[component]][[licence-text]]"
193 "[[block-end]]\n\n"))
7fb0878b 194 (licence-banner . (skelrc-banner "Licensing notice" t))
441c920b 195 (component . (skelrc-component))
7fb0878b 196 (licence-text . "[[gpl]]")
441c920b 197 (Program-name . (or (skelrc-assq 'Program skel-alist)
198 (skelrc-assq 'program skel-alist)
199 "This program"))
200 (program-name . (or (skelrc-assq 'program skel-alist)
201 "this program"))
202 (Library-name . (or (skelrc-assq 'Library skel-alist)
203 (skelrc-assq 'library skel-alist)
204 (skelrc-assq 'Program skel-alist)
205 (skelrc-assq 'program skel-alist)
206 "This library"))
207 (library-name . (or (skelrc-assq 'library skel-alist)
208 (skelrc-assq 'program skel-alist)
209 "this library"))
7fb0878b 210 (gpl . skelrc-gpl)
e7043698 211 (wide-gpl . skelrc-wide-gpl)
7fb0878b 212 (lgpl . skelrc-lgpl)
d18fb0e7 213 (agpl . skelrc-agpl)
0237168a 214 (bsd . skelrc-bsd)
a6ca2716
MW
215 (revisions . ,(concat "[[revision-banner]]\n"
216 "[[cont-comment]]\n"
217 "[[cont-comment]] $Log$"
218 "[[block-end]]\n\n"))
7fb0878b 219 (revision-banner . (skelrc-banner "Revision history" t))
220 (preamble . "")
28330371 221 (trailer . "[[tag-line]]\n[[postamble]]")
7fb0878b 222 (postamble . "")
223 (tag-line . (skelrc-banner "That's all, folks"))
224 (block-start . (skel-lookup 'new-comment))
225 (block-banner-knob . "")
226 (block-banner-end . "")
227 (block-end . ""))
228 skel-alist))