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