Lots of fixes.
[bpt/emacs.git] / lisp / emacs-lisp / gulp.el
1 ;;; gulp.el --- Ask for updates for Lisp packages
2
3 ;; Copyright (C) 1996 Free Software Foundation, Inc.
4
5 ;; Author: Sam Shteingold <shteingd@math.ucla.edu>
6 ;; Maintainer: FSF
7 ;; Keywords: maintenance
8
9 ;; This file is part of GNU Emacs.
10
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to
23 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
25 ;;; Commentary:
26
27 ;; Search the emacs/{version}/lisp directory for *.el files, extract the
28 ;; name of the author or maintainer and send him e-mail requesting
29 ;; update.
30
31 ;;; Code:
32
33 (defvar gulp-discard "^;+ *Maintainer: *FSF *$"
34 "*The regexp matching the packages not requiring the request for updates.")
35
36 (defvar gulp-tmp-buffer "*gulp*" "The name of the temporary buffer.")
37
38 (defvar gulp-max-len 2000
39 "*Distance into a Lisp source file to scan for keywords.")
40
41 (defvar gulp-request-header
42 (concat
43 "This message was created automatically.
44 A new version of GNU Emacs, "
45 (format "%d.%d" emacs-major-version (+ emacs-minor-version 1))
46 ", is entering the pretest state,
47 and it is high time to submit the updates to the various emacs packages.
48 You're listed as the maintainer of the following package(s):\n\n")
49 "*The starting text of a gulp message.")
50
51 (defvar gulp-request-end
52 (concat
53 "\nIf you have any changes since the version in the previous release ("
54 (format "%d.%d" emacs-major-version emacs-minor-version)
55 "),
56 please send them to me ASAP.
57
58 Thanks.")
59 "*The closing text in a gulp message.")
60
61 (defun gulp-send-requests (dir &optional time)
62 "Send requests for updates to the authors of Lisp packages in directory DIR.
63 For each maintainer, the message consists of `gulp-request-header',
64 followed by the list of packages (with modification times if the optional
65 prefix argument TIME is non-nil), concluded with `gulp-request-end'.
66
67 You can't edit the messages, but you can confirm whether to send each one.
68
69 The list of addresses for which you decided not to send mail
70 is left in the `*gulp*' buffer at the end."
71 (interactive "DRequest updates for Lisp directory: \nP")
72 (save-excursion
73 (set-buffer (get-buffer-create gulp-tmp-buffer))
74 (let ((m-p-alist (gulp-create-m-p-alist
75 (directory-files dir nil "^[^=].*\\.el$" t)
76 dir))
77 ;; Temporarily inhibit undo in the *gulp* buffer.
78 (buffer-undo-list t)
79 mail-setup-hook msg node)
80 (while (setq node (car m-p-alist))
81 (setq msg (gulp-create-message (cdr node) time))
82 (setq mail-setup-hook
83 '(lambda ()
84 (mail-subject)
85 (insert "It's time for Emacs updates again")
86 (goto-char (point-max))
87 (insert msg)))
88 (mail nil (car node))
89 (if (y-or-n-p "Send? ") (mail-send)
90 (kill-this-buffer)
91 (set-buffer gulp-tmp-buffer)
92 (insert (format "%s\n\n" node)))
93 (setq m-p-alist (cdr m-p-alist))))
94 (set-buffer gulp-tmp-buffer)
95 (setq buffer-undo-list nil)))
96
97
98 (defun gulp-create-message (rec time)
99 "Return the message string for REC, which is a list like (FILE TIME)."
100 (let (node (str gulp-request-header))
101 (while (setq node (car rec))
102 (setq str (concat str "\t" (car node)
103 (if time (concat "\tLast modified:\t" (cdr node)))
104 "\n"))
105 (setq rec (cdr rec)))
106 (concat str gulp-request-end)))
107
108
109 (defun gulp-create-m-p-alist (flist dir)
110 "Create the maintainer/package alist for files in FLIST in DIR.
111 That is a list of elements, each of the form (MAINTAINER PACKAGES...)."
112 (save-excursion
113 (let (mplist filen node mnt-tm mnt tm)
114 (get-buffer-create gulp-tmp-buffer)
115 (set-buffer gulp-tmp-buffer)
116 (setq buffer-undo-list t)
117 (while flist
118 (setq fl-tm (gulp-maintainer (setq filen (car flist)) dir))
119 (if (setq tm (cdr fl-tm) mnt (car fl-tm));; there is a definite maintainer
120 (if (setq node (assoc mnt mplist));; this is not a new maintainer
121 (setq mplist (cons (cons mnt (cons (cons filen tm) (cdr node)))
122 (delete node mplist)))
123 (setq mplist (cons (list mnt (cons filen (cdr fl-tm))) mplist))))
124 (message "%s -- %s" filen fl-tm)
125 (setq flist (cdr flist)))
126 (erase-buffer)
127 mplist)))
128
129 (defun gulp-maintainer (filenm dir)
130 "Return a list (MAINTAINER TIMESTAMP) for the package FILENM in directory DIR."
131 (save-excursion
132 (let* ((fl (concat dir filenm)) mnt
133 (timest (format-time-string "%Y-%m-%d %a %T %Z"
134 (elt (file-attributes fl) 5))))
135 (set-buffer gulp-tmp-buffer)
136 (erase-buffer)
137 (insert-file-contents fl nil 0 gulp-max-len)
138 (goto-char 1)
139 (if (re-search-forward gulp-discard nil t)
140 (setq mnt nil) ;; do nothing, return nil
141 (goto-char 1)
142 (if (and (re-search-forward "^;+ *Maintainer: \\(.*\\)$" nil t)
143 (> (length (setq mnt (match-string 1))) 0))
144 () ;; found!
145 (goto-char 1)
146 (if (re-search-forward "^;+ *Author: \\(.*\\)$" nil t)
147 (setq mnt (match-string 1))))
148 (if (= (length mnt) 0) (setq mnt nil))) ;; "^;; Author: $" --> nil
149 (cons mnt timest))))
150
151 ;;; gulp.el ends here