skelrc: Stanza for the GNU Affero General Public License.
[skel] / skelrc
1 ;;; -*-emacs-lisp-*-
2
3 (defun skelrc-strip-trailing-whitespace (string)
4 "Return STRING, but with trailing whitespace removed.
5
6 Whitespace characters are those with space syntax."
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
12 (defun skelrc-banner (title &optional block)
13 "Return a comment banner with the given TITLE, and maybe a BLOCK of text."
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)))))
17 (skelrc-strip-trailing-whitespace (concat start
18 "----- "
19 title
20 " "
21 (make-string barlen ?-)
22 end))))
23
24 (defvar skelrc-forced-major-mode 0
25 "The priority of the currently forced major mode")
26
27 (defun skelrc-force-mode (new-mode &optional priority)
28 "Force the use of major mode NEW-MODE.
29
30 If the PRIORITY (defaults to 1) is strictly greater than
31 `skelrc-forced-major-mode' then the NEW-MODE takes precedence. A `skelrc'
32 file which wants to delegate settings to another file should therefore force
33 its chosen major-mode before calling `skel-include'."
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 ()
46 "Return the mode dropping to put in a local-variables line."
47 (let* ((name (symbol-name major-mode))
48 (endind (string-match "-mode$" name)))
49 (if endind (substring name 0 endind)
50 (name))))
51
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)))
55 (and val (cdr val))))
56
57 (defun skelrc-prefix-lines (prefix lines)
58 "Return LINES, each with PREFIX prepended to the beginning.
59
60 If the LINES end with a newline character, there is not considered to be a
61 final empty line. When prepended to an empty line, trailing whitespace in
62 the 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
73 (defun skelrc-component ()
74 "Return a suitable a `This file is part of ...' line."
75 (if (assq 'full-title skel-alist)
76 "[[cont-comment]] This file is part of [[full-title]].
77 \[[cont-comment]]\n"
78 ""))
79
80 (setq skelrc-gpl (skelrc-prefix-lines "[[cont-comment]] "
81 "[[Program-name]] is free software; you can redistribute it and/or modify
82 it under the terms of the GNU General Public License as published by
83 the 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,
87 but WITHOUT ANY WARRANTY; without even the implied warranty of
88 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
89 GNU General Public License for more details.
90
91 You should have received a copy of the GNU General Public License
92 along with [[program-name]]; if not, write to the Free Software Foundation,
93 Inc., 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
98 it under the terms of the GNU General Public License as published by
99 the 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,
103 but WITHOUT ANY WARRANTY; without even the implied warranty of
104 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
105 GNU General Public License for more details.
106
107 You should have received a copy of the GNU General Public License
108 along with [[program-name]]; if not, write to the Free
109 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
110 MA 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
114 it under the terms of the GNU Library General Public License as
115 published by the Free Software Foundation; either version 2 of the
116 License, or (at your option) any later version.
117
118 \[[Library-name]] is distributed in the hope that it will be useful,
119 but WITHOUT ANY WARRANTY; without even the implied warranty of
120 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
121 GNU Library General Public License for more details.
122
123 You should have received a copy of the GNU Library General Public
124 License along with [[library-name]]; if not, write to the Free
125 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
126 MA 02111-1307, USA."))
127
128 (setq skelrc-agpl (skelrc-prefix-lines "[[cont-comment]] "
129 "[[Program-name]] is free software; you can redistribute it and/or modify
130 it under the terms of the GNU Affero General Public License as
131 published by the Free Software Foundation; either version 3 of the
132 License, or (at your option) any later version.
133
134 \[[Program-name]] is distributed in the hope that it will be useful,
135 but WITHOUT ANY WARRANTY; without even the implied warranty of
136 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
137 GNU Affero General Public License for more details.
138
139 You should have received a copy of the GNU Affero General Public
140 License along with [[program-name]]; if not, see
141 <http://www.gnu.org/licenses/>."))
142
143 (setq skelrc-bsd (skelrc-prefix-lines "[[cont-comment]] "
144 "Copyright (c) [[year]] [[author]]
145 All rights reserved.
146
147 Redistribution and use in source and binary forms, with or without
148 modification, are permitted provided that the following conditions are
149 met:
150
151 1. Redistributions of source code must retain the above copyright
152 notice, this list of conditions and the following disclaimer.
153
154 2, 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
158 3. 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
162 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
163 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
164 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
165 NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
166 INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
167 \(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
168 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
169 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
170 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
171 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
172 POSSIBILITY OF SUCH DAMAGE.
173
174 Instead of accepting the above terms, you may redistribute and/or modify
175 this software under the terms of either the GNU General Public License,
176 or the GNU Library General Public License, published by the Free
177 Software Foundation; either version 2 of the License, or (at your
178 option) any later version."))
179
180 (defun skel-basename ()
181 (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
182
183 (setq skel-alist
184 (append
185 `((first-line . "[[new-comment]] -*-[[emacs-mode]]-*-")
186 (emacs-mode . (skelrc-decode-major-mode))
187 (year . (substring (current-time-string) 20 24))
188 (header . "[[licence]][[preamble]]")
189 (basename . (skel-basename))
190 (licence . ,(concat "[[licence-banner]]\n"
191 "[[cont-comment]]\n"
192 "[[component]][[licence-text]]"
193 "[[block-end]]\n\n"))
194 (licence-banner . (skelrc-banner "Licensing notice" t))
195 (component . (skelrc-component))
196 (licence-text . "[[gpl]]")
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"))
210 (gpl . skelrc-gpl)
211 (wide-gpl . skelrc-wide-gpl)
212 (lgpl . skelrc-lgpl)
213 (agpl . skelrc-agpl)
214 (bsd . skelrc-bsd)
215 (revisions . ,(concat "[[revision-banner]]\n"
216 "[[cont-comment]]\n"
217 "[[cont-comment]] $Log$"
218 "[[block-end]]\n\n"))
219 (revision-banner . (skelrc-banner "Revision history" t))
220 (preamble . "")
221 (trailer . "[[tag-line]]\n[[postamble]]")
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))