gulp.el 6.1 KB

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