skelrc: Add docstrings for functions and variables.
[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-component ()
58 (if (assq 'full-title skel-alist)
59 "[[cont-comment]] This file is part of [[full-title]].
60 [[cont-comment]]\n"
61 ""))
62
63 (setq skelrc-gpl
64 "[[cont-comment]] [[Program-name]] is free software; you can redistribute it and/or modify
65 [[cont-comment]] it under the terms of the GNU General Public License as published by
66 [[cont-comment]] the Free Software Foundation; either version 2 of the License, or
67 [[cont-comment]] (at your option) any later version.
68 [[cont-comment]]
69 [[cont-comment]] [[Program-name]] is distributed in the hope that it will be useful,
70 [[cont-comment]] but WITHOUT ANY WARRANTY; without even the implied warranty of
71 [[cont-comment]] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 [[cont-comment]] GNU General Public License for more details.
73 [[cont-comment]]
74 [[cont-comment]] You should have received a copy of the GNU General Public License
75 [[cont-comment]] along with [[program-name]]; if not, write to the Free Software Foundation,
76 [[cont-comment]] Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.")
77
78 (setq skelrc-wide-gpl ;Version for wide program names
79 "[[cont-comment]] [[Program-name]] is free software; you can redistribute it and/or modify
80 [[cont-comment]] it under the terms of the GNU General Public License as published by
81 [[cont-comment]] the Free Software Foundation; either version 2 of the License, or
82 [[cont-comment]] (at your option) any later version.
83 [[cont-comment]]
84 [[cont-comment]] [[Program-name]] is distributed in the hope that it will be useful,
85 [[cont-comment]] but WITHOUT ANY WARRANTY; without even the implied warranty of
86 [[cont-comment]] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
87 [[cont-comment]] GNU General Public License for more details.
88 [[cont-comment]]
89 [[cont-comment]] You should have received a copy of the GNU General Public License
90 [[cont-comment]] along with [[program-name]]; if not, write to the Free
91 [[cont-comment]] Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
92 [[cont-comment]] MA 02111-1307, USA.")
93
94 (setq skelrc-lgpl
95 "[[cont-comment]] [[Library-name]] is free software; you can redistribute it and/or modify
96 [[cont-comment]] it under the terms of the GNU Library General Public License as
97 [[cont-comment]] published by the Free Software Foundation; either version 2 of the
98 [[cont-comment]] License, or (at your option) any later version.
99 [[cont-comment]]
100 [[cont-comment]] [[Library-name]] is distributed in the hope that it will be useful,
101 [[cont-comment]] but WITHOUT ANY WARRANTY; without even the implied warranty of
102 [[cont-comment]] MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
103 [[cont-comment]] GNU Library General Public License for more details.
104 [[cont-comment]]
105 [[cont-comment]] You should have received a copy of the GNU Library General Public
106 [[cont-comment]] License along with [[library-name]]; if not, write to the Free
107 [[cont-comment]] Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
108 [[cont-comment]] MA 02111-1307, USA.")
109
110 (setq skelrc-bsd
111 "[[cont-comment]] Copyright (c) [[year]] [[author]]
112 [[cont-comment]] All rights reserved.
113 [[cont-comment]]
114 [[cont-comment]] Redistribution and use in source and binary forms, with or without
115 [[cont-comment]] modification, are permitted provided that the following conditions are
116 [[cont-comment]] met:
117 [[cont-comment]]
118 [[cont-comment]] 1. Redistributions of source code must retain the above copyright
119 [[cont-comment]] notice, this list of conditions and the following disclaimer.
120 [[cont-comment]]
121 [[cont-comment]] 2, Redistributions in binary form must reproduce the above copyright
122 [[cont-comment]] notice, this list of conditions and the following disclaimer in the
123 [[cont-comment]] documentation and/or other materials provided with the distribution.
124 [[cont-comment]]
125 [[cont-comment]] 3. The name of the authors may not be used to endorse or promote
126 [[cont-comment]] products derived from this software without specific prior written
127 [[cont-comment]] permission.
128 [[cont-comment]]
129 [[cont-comment]] THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
130 [[cont-comment]] WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
131 [[cont-comment]] MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
132 [[cont-comment]] NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
133 [[cont-comment]] INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
134 [[cont-comment]] (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
135 [[cont-comment]] SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
136 [[cont-comment]] HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
137 [[cont-comment]] STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
138 [[cont-comment]] ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
139 [[cont-comment]] POSSIBILITY OF SUCH DAMAGE.
140 [[cont-comment]]
141 [[cont-comment]] Instead of accepting the above terms, you may redistribute and/or modify
142 [[cont-comment]] this software under the terms of either the GNU General Public License,
143 [[cont-comment]] or the GNU Library General Public License, published by the Free
144 [[cont-comment]] Software Foundation; either version 2 of the License, or (at your
145 [[cont-comment]] option) any later version.")
146
147 (defun skel-basename ()
148 (file-name-sans-extension (file-name-nondirectory buffer-file-name)))
149
150 (setq skel-alist
151 (append
152 '((emacs-mode . (skelrc-decode-major-mode))
153 (year . (substring (current-time-string) 20 24))
154 (header . "[[licence]][[preamble]]")
155 (basename . (skel-basename))
156 (licence . "[[licence-banner]]\n[[cont-comment]]\n[[component]][[licence-text]][[block-end]]\n\n")
157 (licence-banner . (skelrc-banner "Licensing notice" t))
158 (component . (skelrc-component))
159 (licence-text . "[[gpl]]")
160 (Program-name . (or (skelrc-assq 'Program skel-alist)
161 (skelrc-assq 'program skel-alist)
162 "This program"))
163 (program-name . (or (skelrc-assq 'program skel-alist)
164 "this program"))
165 (Library-name . (or (skelrc-assq 'Library skel-alist)
166 (skelrc-assq 'library skel-alist)
167 (skelrc-assq 'Program skel-alist)
168 (skelrc-assq 'program skel-alist)
169 "This library"))
170 (library-name . (or (skelrc-assq 'library skel-alist)
171 (skelrc-assq 'program skel-alist)
172 "this library"))
173 (gpl . skelrc-gpl)
174 (wide-gpl . skelrc-wide-gpl)
175 (lgpl . skelrc-lgpl)
176 (bsd . skelrc-bsd)
177 (revisions . "[[revision-banner]]\n[[cont-comment]]\n[[cont-comment]] $Log$[[block-end]]\n\n")
178 (revision-banner . (skelrc-banner "Revision history" t))
179 (preamble . "")
180 (trailer . "[[tag-line]]\n[[postamble]]")
181 (postamble . "")
182 (tag-line . (skelrc-banner "That's all, folks"))
183 (block-start . (skel-lookup 'new-comment))
184 (block-banner-knob . "")
185 (block-banner-end . "")
186 (block-end . ""))
187 skel-alist))