chiark / gitweb /
skeleton, skelrc, skelrc.script: Variable shebang lines.
[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
128(setq skelrc-bsd (skelrc-prefix-lines "[[cont-comment]] "
129"Copyright (c) [[year]] [[author]]
130All rights reserved.
131
132Redistribution and use in source and binary forms, with or without
133modification, are permitted provided that the following conditions are
134met:
135
1361. Redistributions of source code must retain the above copyright
137 notice, this list of conditions and the following disclaimer.
138
1392, Redistributions in binary form must reproduce the above copyright
140 notice, this list of conditions and the following disclaimer in the
141 documentation and/or other materials provided with the distribution.
142
1433. The name of the authors may not be used to endorse or promote
144 products derived from this software without specific prior written
145 permission.
146
147THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
148WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
149MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
150NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
151INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
152\(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
153SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
154HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
155STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
156ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
157POSSIBILITY OF SUCH DAMAGE.
158
159Instead of accepting the above terms, you may redistribute and/or modify
160this software under the terms of either the GNU General Public License,
161or the GNU Library General Public License, published by the Free
162Software Foundation; either version 2 of the License, or (at your
163option) any later version."))
0237168a 164
7fb0878b 165(defun skel-basename ()
166 (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
167
168(setq skel-alist
169 (append
aaadf1ff
MW
170 `((first-line . "[[new-comment]] -*-[[emacs-mode]]-*-")
171 (emacs-mode . (skelrc-decode-major-mode))
7fb0878b 172 (year . (substring (current-time-string) 20 24))
86ec878d 173 (header . "[[licence]][[preamble]]")
7fb0878b 174 (basename . (skel-basename))
a6ca2716
MW
175 (licence . ,(concat "[[licence-banner]]\n"
176 "[[cont-comment]]\n"
177 "[[component]][[licence-text]]"
178 "[[block-end]]\n\n"))
7fb0878b 179 (licence-banner . (skelrc-banner "Licensing notice" t))
441c920b 180 (component . (skelrc-component))
7fb0878b 181 (licence-text . "[[gpl]]")
441c920b 182 (Program-name . (or (skelrc-assq 'Program skel-alist)
183 (skelrc-assq 'program skel-alist)
184 "This program"))
185 (program-name . (or (skelrc-assq 'program skel-alist)
186 "this program"))
187 (Library-name . (or (skelrc-assq 'Library skel-alist)
188 (skelrc-assq 'library skel-alist)
189 (skelrc-assq 'Program skel-alist)
190 (skelrc-assq 'program skel-alist)
191 "This library"))
192 (library-name . (or (skelrc-assq 'library skel-alist)
193 (skelrc-assq 'program skel-alist)
194 "this library"))
7fb0878b 195 (gpl . skelrc-gpl)
e7043698 196 (wide-gpl . skelrc-wide-gpl)
7fb0878b 197 (lgpl . skelrc-lgpl)
0237168a 198 (bsd . skelrc-bsd)
a6ca2716
MW
199 (revisions . ,(concat "[[revision-banner]]\n"
200 "[[cont-comment]]\n"
201 "[[cont-comment]] $Log$"
202 "[[block-end]]\n\n"))
7fb0878b 203 (revision-banner . (skelrc-banner "Revision history" t))
204 (preamble . "")
28330371 205 (trailer . "[[tag-line]]\n[[postamble]]")
7fb0878b 206 (postamble . "")
207 (tag-line . (skelrc-banner "That's all, folks"))
208 (block-start . (skel-lookup 'new-comment))
209 (block-banner-knob . "")
210 (block-banner-end . "")
211 (block-end . ""))
212 skel-alist))