1 ;;; lisp-mnt.el --- minor mode for Emacs Lisp maintainers
3 ;; Copyright (C) 1992, 1994 Free Software Foundation, Inc.
5 ;; Author: Eric S. Raymond <esr@snark.thyrsus.com>
6 ;; Maintainer: Eric S. Raymond <esr@snark.thyrsus.com>
7 ;; Created: 14 Jul 1992
8 ;; Keywords: docs, maint
9 ;; X-Modified-by: Bob Weiner <weiner@beopen.com>, 4/14/95, to support
11 ;; X-Bogus-Bureaucratic-Cruft: Gruad will get you if you don't watch out!
13 ;; This file is part of XEmacs.
15 ;; XEmacs is free software; you can redistribute it and/or modify it
16 ;; under the terms of the GNU General Public License as published by
17 ;; the Free Software Foundation; either version 2, or (at your option)
20 ;; XEmacs is distributed in the hope that it will be useful, but
21 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
22 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 ;; General Public License for more details.
25 ;; You should have received a copy of the GNU General Public License
26 ;; along with XEmacs; see the file COPYING. If not, write to the Free
27 ;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
30 ;;; Synched up with: FSF 20.2.
34 ;; This minor mode adds some services to Emacs-Lisp editing mode.
36 ;; First, it knows about the header conventions for library packages.
37 ;; One entry point supports generating synopses from a library directory.
38 ;; Another can be used to check for missing headers in library files.
40 ;; Another entry point automatically addresses bug mail to a package's
41 ;; maintainer or author.
43 ;; This file can be loaded by your lisp-mode-hook. Have it (require 'lisp-mnt)
45 ;; This file is an example of the header conventions. Note the following
48 ;; * Header line --- makes it possible to extract a one-line summary of
49 ;; the package's uses automatically for use in library synopses, KWIC
50 ;; indexes and the like.
52 ;; Format is three semicolons, followed by the filename, followed by
53 ;; three dashes, followed by the summary. All fields space-separated.
55 ;; * Author line --- contains the name and net address of at least
56 ;; the principal author.
58 ;; If there are multiple authors, they should be listed on continuation
59 ;; lines led by ;;<TAB><TAB> (or multiple blanks), like this:
61 ;; ;; Author: Ashwin Ram <Ram-Ashwin@cs.yale.edu>
62 ;; ;; Dave Sill <de5@ornl.gov>
63 ;; ;; David Lawrence <tale@pawl.rpi.edu>
64 ;; ;; Noah Friedman <friedman@ai.mit.edu>
65 ;; ;; Joe Wells <jbw@maverick.uswest.com>
66 ;; ;; Dave Brennan <brennan@hal.com>
67 ;; ;; Eric Raymond <esr@snark.thyrsus.com>
69 ;; This field may have some special values; notably "FSF", meaning
70 ;; "Free Software Foundation".
72 ;; * Maintainer line --- should be a single name/address as in the Author
73 ;; line, or an address only, or the string "FSF". If there is no maintainer
74 ;; line, the person(s) in the Author field are presumed to be it. The example
75 ;; in this file is mildly bogus because the maintainer line is redundant.
76 ;; The idea behind these two fields is to be able to write a Lisp function
77 ;; that does "send mail to the author" without having to mine the name out by
78 ;; hand. Please be careful about surrounding the network address with <> if
79 ;; there's also a name in the field.
81 ;; * Created line --- optional, gives the original creation date of the
82 ;; file. For historical interest, basically.
84 ;; * Version line --- intended to give the reader a clue if they're looking
85 ;; at a different version of the file than the one they're accustomed to. This
86 ;; may be an RCS or SCCS header.
88 ;; * Adapted-By line --- this is for FSF's internal use. The person named
89 ;; in this field was the one responsible for installing and adapting the
90 ;; package for the distribution. (This file doesn't have one because the
91 ;; author *is* one of the maintainers.)
93 ;; * Keywords line --- used by the finder code (now under construction)
94 ;; for finding Emacs Lisp code related to a topic.
96 ;; * X-Bogus-Bureaucratic-Cruft line --- this is a joke and an example
97 ;; of a comment header. Headers starting with `X-' should never be used
98 ;; for any real purpose; this is the way to safely add random headers
99 ;; without invoking the wrath of any program.
101 ;; * Commentary line --- enables Lisp code to find the developer's and
102 ;; maintainers' explanations of the package internals.
104 ;; * Change log line --- optional, exists to terminate the commentary
105 ;; section and start a change-log part, if one exists.
107 ;; * Code line --- exists so Lisp can know where commentary and/or
108 ;; change-log sections end.
110 ;; * Footer line --- marks end-of-file so it can be distinguished from
111 ;; an expanded formfeed or the results of truncation.
115 ;; Tue Jul 14 23:44:17 1992 ESR
120 (require 'picture) ; provides move-to-column-force
121 ;(require 'emacsbug) ; XEmacs, not needed for bytecompilation
125 (defvar lm-header-prefix "^;;*[ \t]+\\(@\(#\)\\)?[ \t]*\\([\$]\\)?"
126 "Prefix that is ignored before the tag.
127 For example, you can write the 1st line synopsis string and headers like this
128 in your Lisp package:
130 ;; @(#) package.el -- package description
132 ;; @(#) $Maintainer: Person Foo Bar $
134 The @(#) construct is used by unix what(1) and
135 then $identifier: doc string $ is used by GNU ident(1)")
137 (defvar lm-comment-column 16
138 "Column used for placing formatted output.")
140 (defvar lm-commentary-header "Commentary\\|Documentation"
141 "Regexp which matches start of documentation section.")
143 (defvar lm-history-header "Change Log\\|History"
144 "Regexp which matches the start of code log section.")
148 ;; These functions all parse the headers of the current buffer
150 (defsubst lm-get-header-re (header &optional mode)
151 "Returns regexp for matching HEADER.
152 If called with optional MODE and with value `section',
153 return section regexp instead."
154 (cond ((eq mode 'section)
155 (concat "^;;;;* " header ":[ \t]*$"))
157 (concat lm-header-prefix header ":[ \t]*"))))
159 (defsubst lm-get-package-name ()
160 "Returns package name by looking at the first line."
162 (goto-char (point-min))
163 (if (and (looking-at (concat lm-header-prefix))
164 (progn (goto-char (match-end 0))
165 (looking-at "\\([^\t ]+\\)")
167 (buffer-substring (match-beginning 1) (match-end 1))
170 (defun lm-section-mark (header &optional after)
171 "Return the buffer location of a given section start marker.
172 The HEADER is the section mark string to search for.
173 If AFTER is non-nil, return the location of the next line."
175 (let ((case-fold-search t))
176 (goto-char (point-min))
177 (if (re-search-forward (lm-get-header-re header 'section) nil t)
180 (if after (forward-line 1))
184 (defsubst lm-code-mark ()
185 "Return the buffer location of the `Code' start marker."
186 (lm-section-mark "Code"))
188 (defsubst lm-commentary-mark ()
189 "Return the buffer location of the `Commentary' start marker."
190 (lm-section-mark lm-commentary-header))
192 (defsubst lm-history-mark ()
193 "Return the buffer location of the `History' start marker."
194 (lm-section-mark lm-history-header))
196 (defun lm-header (header)
197 "Return the contents of the header named HEADER."
198 (goto-char (point-min))
199 (let ((case-fold-search t))
200 (if (and (re-search-forward (lm-get-header-re header) (lm-code-mark) t)
201 ;; RCS ident likes format "$identifier: data$"
202 (looking-at "\\([^$\n]+\\)")
204 (buffer-substring (match-beginning 1) (match-end 1))
207 (defun lm-header-multiline (header)
208 "Return the contents of the header named HEADER, with continuation lines.
209 The returned value is a list of strings, one per line."
211 (goto-char (point-min))
212 (let ((res (lm-header header)))
215 (setq res (list res))
218 (while (and (looking-at (concat lm-header-prefix "[\t ]+"))
220 (goto-char (match-end 0))
221 (looking-at "\\(.*\\)"))
223 (setq res (cons (buffer-substring
232 ;; These give us smart access to the header fields and commentary
234 (defun lm-summary (&optional file)
235 "Return the one-line summary of file FILE, or current buffer if FILE is nil."
239 (goto-char (point-min))
242 (looking-at lm-header-prefix)
243 (progn (goto-char (match-end 0))
244 (looking-at "[^ ]+[ \t]+--+[ \t]+\\(.*\\)")))
245 (buffer-substring (match-beginning 1) (match-end 1)))
247 (kill-buffer (current-buffer)))
250 (defun lm-crack-address (x)
251 "Split up an email address into full name and real email address.
252 The value is a cons of the form (FULLNAME . ADDRESS)."
253 (cond ((string-match "\\(.+\\) [(<]\\(\\S-+@\\S-+\\)[>)]" x)
254 (cons (substring x (match-beginning 1) (match-end 1))
255 (substring x (match-beginning 2) (match-end 2))))
256 ((string-match "\\(\\S-+@\\S-+\\) [(<]\\(.*\\)[>)]" x)
257 (cons (substring x (match-beginning 2) (match-end 2))
258 (substring x (match-beginning 1) (match-end 1))))
259 ((string-match "\\S-+@\\S-+" x)
264 (defun lm-authors (&optional file)
265 "Return the author list of file FILE, or current buffer if FILE is nil.
266 Each element of the list is a cons; the car is the full name,
267 the cdr is an email address."
271 ;; XEmacs change (Is E-MAIL an infodock header? -sb)
272 (let* ((authorlist (lm-header-multiline "author"))
273 (email-list (lm-header-multiline "E-MAIL"))
274 (authors authorlist))
276 (if (null email-list)
277 (mapcar 'lm-crack-address authorlist)
278 (while (and email-list authors)
279 (setcar authors (cons (car authors) (car email-list)))
280 (setq email-list (cdr email-list)
281 authors (cdr authors)))
284 (kill-buffer (current-buffer))))
287 (defun lm-maintainer (&optional file)
288 "Return the maintainer of file FILE, or current buffer if FILE is nil.
289 The return value has the form (NAME . ADDRESS)."
294 (let ((maint (lm-header "maintainer")))
296 (lm-crack-address maint)
299 (kill-buffer (current-buffer))))))
301 (defun lm-creation-date (&optional file)
302 "Return the created date given in file FILE, or current buffer if FILE is nil."
307 ;; XEmacs change (Is ORIG-DATE an Infodock header? -sb)
308 (or (lm-header "created")
309 (let ((date-and-time (lm-header "ORIG-DATE")))
311 (substring date-and-time 0
312 (string-match " " date-and-time)))))
314 (kill-buffer (current-buffer)))
317 (defun lm-last-modified-date (&optional file)
318 "Return the modify-date given in file FILE, or current buffer if FILE is nil."
324 (goto-char (point-min))
326 "\\$[I]d: [^ ]+ [^ ]+ \\([^/]+\\)/\\([^/]+\\)/\\([^ ]+\\) "
329 (buffer-substring (match-beginning 3) (match-end 3))
331 (buffer-substring (match-beginning 2) (match-end 2)))
332 '("" "Jan" "Feb" "Mar" "Apr" "May" "Jun"
333 "Jul" "Aug" "Sep" "Oct" "Nov" "Dec"))
334 (buffer-substring (match-beginning 1) (match-end 1)))
335 ;; XEmacs change (Infodock change? -sb)
336 (let ((date-and-time (lm-header "LAST-MOD")))
338 (substring date-and-time 0
339 (string-match " " date-and-time)))))
341 (kill-buffer (current-buffer)))
344 (defun lm-version (&optional file)
345 "Return the version listed in file FILE, or current buffer if FILE is nil.
346 This can be found in an RCS or SCCS header to crack it out of."
352 (lm-header "version")
353 (let ((header-max (lm-code-mark)))
354 (goto-char (point-min))
356 ;; Look for an RCS header
357 ((re-search-forward "\\$[I]d: [^ ]+ \\([^ ]+\\) " header-max t)
358 (buffer-substring (match-beginning 1) (match-end 1)))
360 ;; Look for an SCCS header
363 (regexp-quote "@(#)")
364 (regexp-quote (file-name-nondirectory (buffer-file-name)))
365 "\t\\([012345679.]*\\)")
367 (buffer-substring (match-beginning 1) (match-end 1)))
371 (kill-buffer (current-buffer)))
374 (defun lm-keywords (&optional file)
375 "Return the keywords given in file FILE, or current buffer if FILE is nil."
380 (let ((keywords (lm-header "keywords")))
381 (and keywords (downcase keywords)))
383 (kill-buffer (current-buffer)))
386 (defun lm-adapted-by (&optional file)
387 "Return the adapted-by names in file FILE, or current buffer if FILE is nil.
388 This is the name of the person who cleaned up this package for
394 (lm-header "adapted-by")
396 (kill-buffer (current-buffer)))
399 (defun lm-commentary (&optional file)
400 "Return the commentary in file FILE, or current buffer if FILE is nil.
401 The value is returned as a string. In the text, the commentary starts
402 with tag `Commentary' and ends with tag `Change Log' or `History'."
407 (let ((commentary (lm-commentary-mark))
408 (change-log (lm-history-mark))
409 (code (lm-code-mark))
412 ((and commentary change-log)
413 (buffer-substring commentary change-log))
414 ((and commentary code)
415 (buffer-substring commentary code))
417 ;; XEmacs change (Infodock headers? -sb)
418 (setq commentary (lm-section-mark "DESCRIPTION" t))
419 (setq end (lm-section-mark "DESCRIP-END"))
420 (and commentary end (buffer-substring commentary end)))))
422 (kill-buffer (current-buffer)))
425 ;;; Verification and synopses
427 (defun lm-insert-at-column (col &rest strings)
428 "Insert list of STRINGS, at column COL."
429 (if (> (current-column) col) (insert "\n"))
430 (move-to-column-force col)
431 (apply 'insert strings))
433 (defun lm-verify (&optional file showok &optional verb)
434 "Check that the current buffer (or FILE if given) is in proper format.
435 If FILE is a directory, recurse on its files and generate a report in
438 (let* ((verb (or verb (interactive-p)))
443 (setq ret "Ok.")) ;init value
445 (if (and file (file-directory-p file))
449 (switch-to-buffer (get-buffer-create "*lm-verify*"))
453 (if (string-match ".*\\.el$" f)
454 (let ((status (lm-verify f)))
458 (lm-insert-at-column lm-comment-column status "\n"))
462 (lm-insert-at-column lm-comment-column "OK\n")))))))
463 (directory-files file))
468 (setq name (lm-get-package-name))
475 "Can't find a package NAME")
478 "Author: tag missing.")
480 ((not (lm-maintainer))
481 "Maintainer: tag missing.")
484 "Can't find a one-line 'Summary' description")
487 "Keywords: tag missing.")
489 ((not (lm-commentary-mark))
490 "Can't find a 'Commentary' section marker.")
492 ((not (lm-history-mark))
493 "Can't find a 'History' section marker.")
495 ((not (lm-code-mark))
496 "Can't find a 'Code' section marker")
499 (goto-char (point-max))
502 (concat "^;;;[ \t]+" name "[ \t]+ends here[ \t]*$"
503 "\\|^;;;[ \t]+ End of file[ \t]+" name)
506 (format "Can't find a footer line for [%s]" name))
510 (kill-buffer (current-buffer)))
517 (defun lm-synopsis (&optional file showall)
518 "Generate a synopsis listing for the buffer or the given FILE if given.
519 If FILE is a directory, recurse on its files and generate a report in
520 a temporary buffer. If SHOWALL is non-nil, also generate a line for files
521 which do not include a recognizable synopsis."
524 (read-file-name "Synopsis for (file or dir): ")))
526 (if (and file (file-directory-p file))
528 (switch-to-buffer (get-buffer-create "*lm-verify*"))
531 (lambda (f) ; XEmacs - dequote
532 (if (string-match ".*\\.el$" f)
533 (let ((syn (lm-synopsis f)))
537 (lm-insert-at-column lm-comment-column syn "\n"))
541 (lm-insert-at-column lm-comment-column "NA\n")))))))
542 (directory-files file))
550 (kill-buffer (current-buffer)))
553 (defun lm-report-bug (topic)
554 "Report a bug in the package currently being visited to its maintainer.
555 Prompts for bug subject. Leaves you in a mail buffer."
556 (interactive "sBug Subject: ")
557 (let ((package (lm-get-package-name))
558 (addr (lm-maintainer))
559 (version (lm-version)))
562 (concat (car addr) " <" (cdr addr) ">")
563 (or (and (boundp 'report-emacs-bug-beta-address)
564 report-emacs-bug-beta-address)
565 "<xemacs-beta@xemacs.org>"))
567 (goto-char (point-max))
570 (if version (concat " version " version) "")
573 (substitute-command-keys "Type \\[mail-send] to send bug report."))))
577 ;;; lisp-mnt.el ends here