Merge from emacs-23
[bpt/emacs.git] / lisp / emacs-lisp / gulp.el
CommitLineData
55535639 1;;; gulp.el --- ask for updates for Lisp packages
3ecaf18e 2
d59c3137 3;; Copyright (C) 1996, 2001, 2002, 2003, 2004, 2005,
5df4f04c 4;; 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
3ecaf18e
RS
5
6;; Author: Sam Shteingold <shteingd@math.ucla.edu>
7;; Maintainer: FSF
bc3b7853 8;; Keywords: maint
3ecaf18e
RS
9
10;; This file is part of GNU Emacs.
11
d6cba7ae 12;; GNU Emacs is free software: you can redistribute it and/or modify
3ecaf18e 13;; it under the terms of the GNU General Public License as published by
d6cba7ae
GM
14;; the Free Software Foundation, either version 3 of the License, or
15;; (at your option) any later version.
3ecaf18e
RS
16
17;; GNU Emacs is distributed in the hope that it will be useful,
18;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20;; GNU General Public License for more details.
21
22;; You should have received a copy of the GNU General Public License
d6cba7ae 23;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
3ecaf18e
RS
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:
666b9413
SE
32(defgroup gulp nil
33 "Ask for updates for Lisp packages."
34 :prefix "-"
35 :group 'maint)
36
37(defcustom gulp-discard "^;+ *Maintainer: *FSF *$"
cb711556 38 "The regexp matching the packages not requiring the request for updates."
666b9413
SE
39 :type 'regexp
40 :group 'gulp)
41
cb711556
GM
42(defcustom gulp-tmp-buffer "*gulp*"
43 "The name of the temporary buffer."
666b9413
SE
44 :type 'string
45 :group 'gulp)
46
47(defcustom gulp-max-len 2000
cb711556 48 "Distance into a Lisp source file to scan for keywords."
666b9413
SE
49 :type 'integer
50 :group 'gulp)
51
52(defcustom gulp-request-header
8060ee8f
RS
53 (concat
54 "This message was created automatically.
b6030d2f
RS
55I'm going to start pretesting a new version of GNU Emacs soon, so I'd
56like to ask if you have any updates for the Emacs packages you work on.
8060ee8f 57You're listed as the maintainer of the following package(s):\n\n")
cb711556 58 "The starting text of a gulp message."
666b9413
SE
59 :type 'string
60 :group 'gulp)
3ecaf18e 61
666b9413 62(defcustom gulp-request-end
8060ee8f
RS
63 (concat
64 "\nIf you have any changes since the version in the previous release ("
65 (format "%d.%d" emacs-major-version emacs-minor-version)
66 "),
67please send them to me ASAP.
3ecaf18e 68
b6030d2f
RS
69Please don't send the whole file. Instead, please send a patch made with
70`diff -c' that shows precisely the changes you would like me to install.
71Also please include itemized change log entries for your changes;
72please use lisp/ChangeLog as a guide for the style and for what kinds
73of information to include.
74
8060ee8f 75Thanks.")
cb711556 76 "The closing text in a gulp message."
666b9413
SE
77 :type 'string
78 :group 'gulp)
8060ee8f 79
2c52d7a3
GM
80(declare-function mail-subject "sendmail" ())
81(declare-function mail-send "sendmail" ())
6d00e226 82
8060ee8f 83(defun gulp-send-requests (dir &optional time)
30585116 84 "Send requests for updates to the authors of Lisp packages in directory DIR.
8060ee8f
RS
85For each maintainer, the message consists of `gulp-request-header',
86followed by the list of packages (with modification times if the optional
87prefix argument TIME is non-nil), concluded with `gulp-request-end'.
88
89You can't edit the messages, but you can confirm whether to send each one.
90
91The list of addresses for which you decided not to send mail
92is left in the `*gulp*' buffer at the end."
93 (interactive "DRequest updates for Lisp directory: \nP")
9a529312 94 (with-current-buffer (get-buffer-create gulp-tmp-buffer)
8060ee8f
RS
95 (let ((m-p-alist (gulp-create-m-p-alist
96 (directory-files dir nil "^[^=].*\\.el$" t)
97 dir))
98 ;; Temporarily inhibit undo in the *gulp* buffer.
99 (buffer-undo-list t)
100 mail-setup-hook msg node)
b6030d2f 101 (setq m-p-alist
a4929bfa
RS
102 (sort m-p-alist
103 (function (lambda (a b)
104 (string< (car a) (car b))))))
8060ee8f
RS
105 (while (setq node (car m-p-alist))
106 (setq msg (gulp-create-message (cdr node) time))
107 (setq mail-setup-hook
a1506d29 108 (lambda ()
811ec3a8
SM
109 (mail-subject)
110 (insert "It's time for Emacs updates again")
111 (goto-char (point-max))
112 (insert msg)))
8060ee8f 113 (mail nil (car node))
a4929bfa 114 (goto-char (point-min))
8060ee8f
RS
115 (if (y-or-n-p "Send? ") (mail-send)
116 (kill-this-buffer)
117 (set-buffer gulp-tmp-buffer)
118 (insert (format "%s\n\n" node)))
119 (setq m-p-alist (cdr m-p-alist))))
120 (set-buffer gulp-tmp-buffer)
121 (setq buffer-undo-list nil)))
122
123
124(defun gulp-create-message (rec time)
3ecaf18e
RS
125 "Return the message string for REC, which is a list like (FILE TIME)."
126 (let (node (str gulp-request-header))
127 (while (setq node (car rec))
8060ee8f
RS
128 (setq str (concat str "\t" (car node)
129 (if time (concat "\tLast modified:\t" (cdr node)))
130 "\n"))
3ecaf18e
RS
131 (setq rec (cdr rec)))
132 (concat str gulp-request-end)))
133
3ecaf18e 134
8060ee8f
RS
135(defun gulp-create-m-p-alist (flist dir)
136 "Create the maintainer/package alist for files in FLIST in DIR.
137That is a list of elements, each of the form (MAINTAINER PACKAGES...)."
138 (save-excursion
b6030d2f 139 (let (mplist filen node mnt-tm mnt tm fl-tm)
8060ee8f
RS
140 (get-buffer-create gulp-tmp-buffer)
141 (set-buffer gulp-tmp-buffer)
142 (setq buffer-undo-list t)
143 (while flist
144 (setq fl-tm (gulp-maintainer (setq filen (car flist)) dir))
145 (if (setq tm (cdr fl-tm) mnt (car fl-tm));; there is a definite maintainer
146 (if (setq node (assoc mnt mplist));; this is not a new maintainer
147 (setq mplist (cons (cons mnt (cons (cons filen tm) (cdr node)))
148 (delete node mplist)))
149 (setq mplist (cons (list mnt (cons filen (cdr fl-tm))) mplist))))
8060ee8f
RS
150 (setq flist (cdr flist)))
151 (erase-buffer)
152 mplist)))
153
154(defun gulp-maintainer (filenm dir)
155 "Return a list (MAINTAINER TIMESTAMP) for the package FILENM in directory DIR."
3ecaf18e 156 (save-excursion
4f1390ac 157 (let* ((fl (expand-file-name filenm dir)) mnt
3ecaf18e
RS
158 (timest (format-time-string "%Y-%m-%d %a %T %Z"
159 (elt (file-attributes fl) 5))))
160 (set-buffer gulp-tmp-buffer)
161 (erase-buffer)
162 (insert-file-contents fl nil 0 gulp-max-len)
163 (goto-char 1)
164 (if (re-search-forward gulp-discard nil t)
165 (setq mnt nil) ;; do nothing, return nil
166 (goto-char 1)
167 (if (and (re-search-forward "^;+ *Maintainer: \\(.*\\)$" nil t)
168 (> (length (setq mnt (match-string 1))) 0))
169 () ;; found!
170 (goto-char 1)
171 (if (re-search-forward "^;+ *Author: \\(.*\\)$" nil t)
172 (setq mnt (match-string 1))))
173 (if (= (length mnt) 0) (setq mnt nil))) ;; "^;; Author: $" --> nil
174 (cons mnt timest))))
175
456f0b95
MR
176(provide 'gulp)
177
cbee283d 178;; arch-tag: 42750a11-460a-4efc-829f-342d075530e5
3ecaf18e 179;;; gulp.el ends here