(authors-print): Rephrase many-files string.
[bpt/emacs.git] / lisp / emacs-lisp / authors.el
1 ;;; authors.el --- utility for maintaining Emacs' AUTHORS file
2
3 ;; Copyright (C) 2000 Free Software Foundation, Inc.
4
5 ;; This file is part of GNU Emacs.
6
7 ;; GNU Emacs is free software; you can redistribute it and/or modify
8 ;; it under the terms of the GNU General Public License as published by
9 ;; the Free Software Foundation; either version 2, or (at your option)
10 ;; any later version.
11
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
17 ;; You should have received a copy of the GNU General Public License
18 ;; along with GNU Emacs; see the file COPYING. If not, write to the
19 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 ;; Boston, MA 02111-1307, USA.
21
22 ;;; Commentary:
23
24 ;; Use M-x authors RET to create an *Authors* buffer that can used as
25 ;; or merged with Emacs' AUTHORS file.
26
27 ;;; Code:
28
29 (defconst authors-many-files 20
30 "Maximum number of files for which to print individual information.
31 If an author has modified more files, only a single entry is
32 printed telling how many files he changed, instead of listing each
33 file individually.")
34
35 (defconst authors-aliases
36 '(("eliz" . "Eli Zaretskii")
37 ("Richard Stallman" . "Richard M. Stallman")
38 ("Richard M. Stallman,,," . "Richard M. Stallman")
39 ("Richard Stallmao" . "Richard M. Stallman")
40 ("rms@gnu.org" . "Richard M. Stallman")
41 ("NIIBE Yutaka" . "Yutaka NIIBE")
42 ("(saw@cebaf.gov)" . "Stephen A. Wood")
43 ("(pmr@legacy.pajato.com)" . "Paul Reilly")
44 ("(Eric Youngdale at youngdale@v6550c.nrl.navy.mil)" . "Eric Youngdale")
45 ("<Daniel.Pfeiffer@Informatik.START.db.de>" . "Daniel Pfeiffer")
46 ("<Daniel.Pfeiffer@Informatik.START.dbp.de>" . "Daniel Pfeiffer")
47 ("(afs@hplb.hpl.hp.com)" . "ignore")
48 ("<Use-Author-Address-Header@\\[127.1\\]>" . "ignore")
49 ("Code Extracted" . "ignore")
50 ("Fsf" . "ignore")
51 ("David M. Koppelman, Koppel@Ee.Lsu.Edu" . "David M. Koppelman")
52 ("jka@ece.cmu.edu" . "Jay K. Adams")
53 ("Per Abhiddenware; you can redistribute it and/or modify" . "Per Abrahamsen")
54 ("Andrw Innes" . "Andrew Innes")
55 ("Barry Warsaw" . "Barry A. Warsaw")
56 ("Barry A. Warsaw, Century Computing, Inc." . "Barry A. Warsaw")
57 ("Barry A. Warsaw, ITB" . "Barry A. Warsaw")
58 ("Ken'ichi Handa" . "Kenichi Handa")
59 ("Bob Chassell" . "Robert J. Chassell")
60 ("SL Baur" . "Steven L. Baur")
61 ("Steven L Baur" . "Steven L. Baur")
62 ("eggert" . "Paul Eggert")
63 ("voelker" . "Geoff Voelker")
64 ("rms" . "Richard M. Stallman")
65 ("Edward M Reingold" . "Edward M. Reingold")
66 ("Eric Ludlam" . "Eric M. Ludlam")
67 ("Eric Raymond" . "Eric S. Raymond")
68 ("Francois Pinard" . "François Pinard")
69 ("Fred Pierresteguy" . "Frederic Pierresteguy")
70 ("Hallvard B Furuseth" . "Hallvard B. Furuseth")
71 ("ISO-2022-JP" . "ignore")
72 ("Jens-Ulrik Petersen" . "Jens-Ulrik Holger Petersen")
73 ("Christoph.Wedler@sap.com" . "Christoph Wedler")
74 ("Jonathan Kamens" . "Jonathan I. Kamens")
75 ("Kim Storm" . "Kim F. Storm")
76 ("Marcus Daniels" . "Marcus G. Daniels")
77 ("Michael I Bushnell" . "Michael I. Bushnell")
78 ("Michael I. Bushnell, P/Bsg" . "Michael I. Bushnell")
79 ("Reingold Edward M" . "Edward M. Reingold")
80 ("Roland B Roberts" . "Roland B. Roberts")
81 ("Sam Shteingold" . "Sam Steingold")
82 ("Kenichi HANDA" . "Kenichi Handa"))
83 "Alist of author aliases.
84
85 Each entry is of the form (REGEXP . ALIAS). If an author's name
86 matches REGEXP, use ALIAS instead. The special alias \"ignore\" means
87 ignore that author.")
88
89
90 (defun authors-add (author file action table)
91 "Record that AUTHOR worked on FILE.
92 ACTION is a keyword symbol describing what he did. Record file,
93 author and what he did in hash table TABLE. See the description of
94 `authors-scan-change-log' for the structure of the hash table."
95 (let* ((value (gethash author table))
96 (entry (assoc file value)))
97 (if (null entry)
98 (puthash author (cons (list file action) value) table)
99 (unless (memq action entry)
100 (nconc entry (list action))))))
101
102
103 (defun authors-process-lines (program &rest args)
104 "Execute PROGRAM with ARGS, returning its output as a list of lines.
105 Signal an error if the program returns with a non-zero exit status."
106 (with-temp-buffer
107 (let ((status (apply 'call-process program nil (current-buffer) nil args)))
108 (unless (eq status 0)
109 (error "%s exited with status %s" program status))
110 (goto-char (point-min))
111 (let (lines)
112 (while (not (eobp))
113 (setq lines (cons (buffer-substring-no-properties
114 (line-beginning-position)
115 (line-end-position))
116 lines))
117 (forward-line 1))
118 (nreverse lines)))))
119
120
121 (defun authors-canonical-author-name (author)
122 "Return a canonicalized form of AUTHOR, an author name.
123 If AUTHOR has an alias, use that. Remove email addresses. Capitalize
124 words in the author's name."
125 (let ((aliases authors-aliases))
126 (while aliases
127 (when (string-match (car (car aliases)) author)
128 (setq author (cdr (car aliases))
129 aliases nil))
130 (setq aliases (cdr aliases))))
131 (setq author (replace-regexp-in-string "[ \t]*[(<].*$" "" author))
132 (setq author (replace-regexp-in-string "^[ \t]+" "" author))
133 (setq author (replace-regexp-in-string "[ \t]+$" "" author))
134 (capitalize author))
135
136
137 (defun authors-scan-change-log (file table)
138 "Scan change log FILE for author information.
139
140 For each change mentioned in the log, add an entry to hash table TABLE
141 under the author's canonical name.
142
143 Keys of TABLE are author names. Values are alists of entries (FILE
144 ACTION...). FILE is one file the author worked on. The rest of the
145 entry is a list of keyword symbols describing what he did with the
146 file.
147
148 :wrote means the author wrote the file
149 :changed means he changed the file."
150
151 (let* ((enable-local-variables t)
152 (enable-local-eval t)
153 (existing-buffer (get-file-buffer file))
154 (buffer (find-file-noselect file))
155 author)
156 (save-excursion
157 (set-buffer buffer)
158 (save-restriction
159 (widen)
160 (goto-char (point-min))
161 (while (re-search-forward "^[0-9]\\|^[ \t]+\\* " nil t)
162 (beginning-of-line)
163 (cond ((looking-at "^[0-9]+-[0-9]+-[0-9]+")
164 (skip-chars-forward " \t+:0-9-")
165 (setq author (buffer-substring-no-properties
166 (point) (line-end-position)))
167 (setq author (authors-canonical-author-name author))
168 (forward-line 1))
169 ((looking-at "^[ \t]+\\*")
170 (let ((line (buffer-substring-no-properties
171 (match-end 0) (line-end-position))))
172 (while (and (not (string-match ":" line))
173 (forward-line 1)
174 (not (looking-at ":\\|^[ \t]*$")))
175 (setq line (concat line
176 (buffer-substring-no-properties
177 (line-beginning-position)
178 (line-end-position)))))
179 (when (string-match ":" line)
180 (setq line (substring line 0 (match-beginning 0)))
181 (setq line (replace-regexp-in-string "[[(<{].*$" "" line))
182 (setq line (replace-regexp-in-string "," "" line))
183 (dolist (file (split-string line))
184 (setq file (file-name-nondirectory file))
185 ;(message "%s changed %s" author file)
186 (authors-add author file :changed table)))
187 (forward-line 1)))))))
188 (unless existing-buffer
189 (kill-buffer buffer))))
190
191
192 (defun authors-scan-el (file table)
193 "Scan Lisp file FILE for author information.
194 TABLE is a hash table to add author information to."
195 (let* ((existing-buffer (get-file-buffer file))
196 (enable-local-variables t)
197 (enable-local-eval t)
198 (buffer (find-file-noselect file)))
199 (save-excursion
200 (set-buffer buffer)
201 (save-restriction
202 (widen)
203 (goto-char (point-min))
204 (while (and (re-search-forward
205 "^;+[ \t]*\\(Author\\|Commentary\\):[ \t]*" nil t)
206 (not (string= (match-string 1) "Commentary")))
207 ;; Some entries contain a year range in front of the
208 ;; author's name.
209 (skip-chars-forward "-0-9 \t")
210 (let ((author (buffer-substring-no-properties
211 (point) (line-end-position))))
212 (setq author (authors-canonical-author-name author))
213 (setq file (file-name-nondirectory file))
214 (authors-add author file :wrote table)))))
215 (unless existing-buffer
216 (kill-buffer buffer))))
217
218
219 (defun authors-print (author changes)
220 "Insert information about AUTHOR's work on Emacs into the current buffer.
221 CHANGES is an alist of entries (FILE ACTION...), as produced by
222 `authors-scan-change-log'."
223 (unless (equal author "Ignore")
224 (let ((nchanged 0))
225 (dolist (change changes)
226 (let ((actions (cdr change))
227 (file (car change)))
228 (if (memq :wrote actions)
229 (insert author " (wrote) " file "\n")
230 (setq nchanged (1+ nchanged)))))
231 (if (> nchanged authors-many-files)
232 (insert author " (changed) [more than "
233 (int-to-string authors-many-files) " files]\n")
234 (dolist (change changes)
235 (let ((actions (cdr change))
236 (file (car change)))
237 (unless (memq :wrote actions)
238 (insert author " (changed) " file "\n"))))))))
239
240
241 ;;;###autoload
242 (defun authors (root)
243 "Extract author information from change logs and Lisp source files.
244 ROOT is the root directory under which to find the files. If called
245 interactively, ROOT is read from the minibuffer. Result is a
246 buffer *Authors* containing authorship information."
247 (interactive "DEmacs source directory: ")
248 (let ((logs (authors-process-lines "find" root "-name" "ChangeLog*"))
249 (table (make-hash-table :test 'equal))
250 (buffer-name "*Authors*"))
251 (setq root (expand-file-name root))
252 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
253 (error "Not the root directory of Emacs: %s" root))
254 (dolist (log logs)
255 (when (string-match "ChangeLog\\(.[0-9]+\\)?$" log)
256 (message "Scanning %s..." log)
257 (authors-scan-change-log log table)))
258 (let ((els (authors-process-lines "find" root "-name" "*.el")))
259 (dolist (file els)
260 (message "Scanning %s..." file)
261 (authors-scan-el file table)))
262 (set-buffer (get-buffer-create buffer-name))
263 (erase-buffer)
264 (maphash #'authors-print table)
265 (sort-lines nil (point-min) (point-max))
266 (pop-to-buffer buffer-name)))
267
268
269 ;; authors.el ends here