skelrc: Add docstrings for functions and variables.
[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
57(defun skelrc-component ()
58 (if (assq 'full-title skel-alist)
7fb0878b 59"[[cont-comment]] This file is part of [[full-title]].
441c920b 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
7fb0878b 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.
3a2c646e 68[[cont-comment]]
441c920b 69[[cont-comment]] [[Program-name]] is distributed in the hope that it will be useful,
7fb0878b 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.
3a2c646e 73[[cont-comment]]
7fb0878b 74[[cont-comment]] You should have received a copy of the GNU General Public License
441c920b 75[[cont-comment]] along with [[program-name]]; if not, write to the Free Software Foundation,
7fb0878b 76[[cont-comment]] Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.")
77
e7043698 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.
3a2c646e 83[[cont-comment]]
e7043698 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.
3a2c646e 88[[cont-comment]]
e7043698 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
7fb0878b 94(setq skelrc-lgpl
441c920b 95"[[cont-comment]] [[Library-name]] is free software; you can redistribute it and/or modify
7fb0878b 96[[cont-comment]] it under the terms of the GNU Library General Public License as
441c920b 97[[cont-comment]] published by the Free Software Foundation; either version 2 of the
7fb0878b 98[[cont-comment]] License, or (at your option) any later version.
3a2c646e 99[[cont-comment]]
441c920b 100[[cont-comment]] [[Library-name]] is distributed in the hope that it will be useful,
7fb0878b 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.
3a2c646e 104[[cont-comment]]
7fb0878b 105[[cont-comment]] You should have received a copy of the GNU Library General Public
46f73ec5 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.")
7fb0878b 109
3a2c646e 110(setq skelrc-bsd
0237168a 111"[[cont-comment]] Copyright (c) [[year]] [[author]]
112[[cont-comment]] All rights reserved.
3a2c646e 113[[cont-comment]]
0237168a 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:
3a2c646e 117[[cont-comment]]
0237168a 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.
3a2c646e 120[[cont-comment]]
0237168a 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.
3a2c646e 124[[cont-comment]]
0237168a 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.
3a2c646e 128[[cont-comment]]
0237168a 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.
3a2c646e 140[[cont-comment]]
0237168a 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
7fb0878b 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))
86ec878d 154 (header . "[[licence]][[preamble]]")
7fb0878b 155 (basename . (skel-basename))
441c920b 156 (licence . "[[licence-banner]]\n[[cont-comment]]\n[[component]][[licence-text]][[block-end]]\n\n")
7fb0878b 157 (licence-banner . (skelrc-banner "Licensing notice" t))
441c920b 158 (component . (skelrc-component))
7fb0878b 159 (licence-text . "[[gpl]]")
441c920b 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"))
7fb0878b 173 (gpl . skelrc-gpl)
e7043698 174 (wide-gpl . skelrc-wide-gpl)
7fb0878b 175 (lgpl . skelrc-lgpl)
0237168a 176 (bsd . skelrc-bsd)
7fb0878b 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 . "")
28330371 180 (trailer . "[[tag-line]]\n[[postamble]]")
7fb0878b 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))