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