* admin/admin.el (add-log-time-format): Declare.
[bpt/emacs.git] / admin / admin.el
CommitLineData
74499542
GM
1;;; admin.el --- utilities for Emacs administration
2
acaf905b 3;; Copyright (C) 2001-2012 Free Software Foundation, Inc.
74499542
GM
4
5;; This file is part of GNU Emacs.
6
9ad5de0c 7;; GNU Emacs is free software: you can redistribute it and/or modify
74499542 8;; it under the terms of the GNU General Public License as published by
9ad5de0c
GM
9;; the Free Software Foundation, either version 3 of the License, or
10;; (at your option) any later version.
74499542
GM
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
9ad5de0c 18;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
74499542
GM
19
20;;; Commentary:
21
54381691
LK
22;; add-release-logs Add ``Version X released'' change log entries.
23;; set-version Change Emacs version number in source tree.
a3045b7e
GM
24;; set-copyright Change emacs short copyright string (eg as
25;; printed by --version) in source tree.
74499542
GM
26
27;;; Code:
28
dcddaabb
GM
29(defvar add-log-time-format) ; in add-log
30
74499542
GM
31(defun add-release-logs (root version)
32 "Add \"Version VERSION released.\" change log entries in ROOT.
33Root must be the root of an Emacs source tree."
34 (interactive "DEmacs root directory: \nNVersion number: ")
3f4a4bdf 35 (setq root (expand-file-name root))
74499542
GM
36 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
37 (error "%s doesn't seem to be the root of an Emacs source tree" root))
54381691 38 (require 'add-log)
74499542
GM
39 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
40 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
3f4a4bdf
FP
41 (funcall add-log-time-format)
42 (or add-log-full-name (user-full-name))
43 (or add-log-mailing-address user-mail-address)
44 version)))
74499542 45 (dolist (log logs)
e568708b 46 (unless (string-match "/gnus/" log)
74499542
GM
47 (find-file log)
48 (goto-char (point-min))
49 (insert entry)))))
50
74499542
GM
51(defun set-version-in-file (root file version rx)
52 (find-file (expand-file-name file root))
53 (goto-char (point-min))
54 (unless (re-search-forward rx nil t)
55 (error "Version not found in %s" file))
56 (replace-match (format "%s" version) nil nil nil 1))
57
74499542
GM
58(defun set-version (root version)
59 "Set Emacs version to VERSION in relevant files under ROOT.
60Root must be the root of an Emacs source tree."
91ebb8c9 61 (interactive "DEmacs root directory: \nsVersion number: ")
74499542
GM
62 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
63 (error "%s doesn't seem to be the root of an Emacs source tree" root))
74499542
GM
64 (set-version-in-file root "README" version
65 (rx (and "version" (1+ space)
66 (submatch (1+ (in "0-9."))))))
c4444d16 67 (set-version-in-file root "configure.ac" version
24bbe01e
GM
68 (rx (and "AC_INIT" (1+ (not (in ?,)))
69 ?, (0+ space)
70 (submatch (1+ (in "0-9."))))))
f4f358f1
GM
71 (set-version-in-file root "doc/emacs/emacsver.texi" version
72 (rx (and "EMACSVER" (1+ space)
73 (submatch (1+ (in "0-9."))))))
adf94aa6
GM
74 (set-version-in-file root "doc/man/emacs.1" version
75 (rx (and ".TH EMACS" (1+ not-newline)
76 "GNU Emacs" (1+ space)
77 (submatch (1+ (in "0-9."))))))
70b0d280
EZ
78 (set-version-in-file root "nt/config.nt" version
79 (rx (and bol "#" (0+ blank) "define" (1+ blank)
a0c64452 80 "VERSION" (1+ blank) "\""
1fe1ef05 81 (submatch (1+ (in "0-9."))))))
9d9d12cd
EZ
82 (set-version-in-file root "msdos/sed2v2.inp" version
83 (rx (and bol "/^#undef " (1+ not-newline)
a0c64452 84 "define VERSION" (1+ space) "\""
9d9d12cd 85 (submatch (1+ (in "0-9."))))))
e3aef5c6
CS
86 (set-version-in-file root "nt/makefile.w32-in" version
87 (rx (and "VERSION" (0+ space) "=" (0+ space)
88 (submatch (1+ (in "0-9."))))))
95f76284
JR
89 ;; nt/emacs.rc also contains the version number, but in an awkward
90 ;; format. It must contain four components, separated by commas, and
91 ;; in two places those commas are followed by space, in two other
92 ;; places they are not.
93 (let* ((version-components (append (split-string version "\\.")
94 '("0" "0")))
95 (comma-version
96 (concat (car version-components) ","
97 (cadr version-components) ","
d0834a5c 98 (cadr (cdr version-components)) ","
95f76284
JR
99 (cadr (cdr (cdr version-components)))))
100 (comma-space-version
101 (concat (car version-components) ", "
102 (cadr version-components) ", "
d0834a5c 103 (cadr (cdr version-components)) ", "
95f76284
JR
104 (cadr (cdr (cdr version-components))))))
105 (set-version-in-file root "nt/emacs.rc" comma-version
106 (rx (and "FILEVERSION" (1+ space)
107 (submatch (1+ (in "0-9,"))))))
108 (set-version-in-file root "nt/emacs.rc" comma-version
109 (rx (and "PRODUCTVERSION" (1+ space)
110 (submatch (1+ (in "0-9,"))))))
111 (set-version-in-file root "nt/emacs.rc" comma-space-version
112 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
113 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
114 (set-version-in-file root "nt/emacs.rc" comma-space-version
115 (rx (and "\"ProductVersion\"" (0+ space) ?,
116 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
b7063e7e
JR
117 "\\0\"")))
118 ;; Likewise for emacsclient.rc
119 (set-version-in-file root "nt/emacsclient.rc" comma-version
120 (rx (and "FILEVERSION" (1+ space)
121 (submatch (1+ (in "0-9,"))))))
122 (set-version-in-file root "nt/emacsclient.rc" comma-version
123 (rx (and "PRODUCTVERSION" (1+ space)
124 (submatch (1+ (in "0-9,"))))))
125 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
126 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
127 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
128 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
95f76284
JR
129 (rx (and "\"ProductVersion\"" (0+ space) ?,
130 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
dcf8834b
GM
131 "\\0\"")))
132 (when (string-match "\\([0-9]\\{2,\\}\\)" version)
133 (setq version (match-string 1 version))
134 (set-version-in-file root "etc/refcards/ru-refcard.tex" version
135 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
136{\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")
137 (set-version-in-file root "etc/refcards/emacsver.tex" version
138 "\\\\def\\\\versionemacs\
139{\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs"))))
140
3f4a4bdf 141
a3045b7e
GM
142;; Note this makes some assumptions about form of short copyright.
143(defun set-copyright (root copyright)
144 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
145Root must be the root of an Emacs source tree."
146 (interactive (list
147 (read-directory-name "Emacs root directory: " nil nil t)
148 (read-string
149 "Short copyright string: "
150 (format "Copyright (C) %s Free Software Foundation, Inc."
151 (format-time-string "%Y")))))
152 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
153 (error "%s doesn't seem to be the root of an Emacs source tree" root))
78f83752
GM
154 (set-version-in-file root "configure.ac" copyright
155 (rx (and bol "copyright" (0+ (not (in ?\")))
287d4c2c 156 ?\" (submatch (1+ (not (in ?\")))) ?\")))
78f83752
GM
157 (set-version-in-file root "nt/config.nt" copyright
158 (rx (and bol "#" (0+ blank) "define" (1+ blank)
159 "COPYRIGHT" (1+ blank)
160 ?\" (submatch (1+ (not (in ?\")))) ?\")))
a3045b7e 161 (set-version-in-file root "lib-src/rcs2log" copyright
287d4c2c
GM
162 (rx (and "Copyright" (0+ space) ?= (0+ space)
163 ?\' (submatch (1+ nonl)))))
287d4c2c
GM
164 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
165 (setq copyright (match-string 1 copyright))
dcf8834b
GM
166 (set-version-in-file root "etc/refcards/ru-refcard.tex" copyright
167 "\\\\newcommand{\\\\cyear}\\[0\\]\
168{\\([0-9]\\{4\\}\\)}.+%.+copyright year")
169 (set-version-in-file root "etc/refcards/emacsver.tex" copyright
170 "\\\\def\\\\year\
171{\\([0-9]\\{4\\}\\)}.+%.+copyright year")))
a3045b7e 172
8d9101d8
CY
173;;; Various bits of magic for generating the web manuals
174
175(defun make-manuals (root)
176 "Generate the web manuals for the Emacs webpage."
177 (interactive "DEmacs root directory: ")
178 (let* ((dest (expand-file-name "manual" root))
179 (html-node-dir (expand-file-name "html_node" dest))
180 (html-mono-dir (expand-file-name "html_mono" dest))
181 (txt-dir (expand-file-name "text" dest))
182 (dvi-dir (expand-file-name "dvi" dest))
183 (ps-dir (expand-file-name "ps" dest)))
184 (when (file-directory-p dest)
185 (if (y-or-n-p (format "Directory %s exists, delete it first?" dest))
186 (delete-directory dest t)
187 (error "Aborted")))
188 (make-directory dest)
189 (make-directory html-node-dir)
190 (make-directory html-mono-dir)
191 (make-directory txt-dir)
192 (make-directory dvi-dir)
193 (make-directory ps-dir)
194 ;; Emacs manual
195 (let ((texi (expand-file-name "doc/emacs/emacs.texi" root)))
196 (manual-html-node texi (expand-file-name "emacs" html-node-dir))
197 (manual-html-mono texi (expand-file-name "emacs.html" html-mono-dir))
198 (manual-txt texi (expand-file-name "emacs.txt" txt-dir))
199 (manual-pdf texi (expand-file-name "emacs.pdf" dest))
200 (manual-dvi texi (expand-file-name "emacs.dvi" dvi-dir)
f08b09fc 201 (expand-file-name "emacs.ps" ps-dir)))
8d9101d8
CY
202 ;; Lisp manual
203 (let ((texi (expand-file-name "doc/lispref/elisp.texi" root)))
204 (manual-html-node texi (expand-file-name "elisp" html-node-dir))
205 (manual-html-mono texi (expand-file-name "elisp.html" html-mono-dir))
206 (manual-txt texi (expand-file-name "elisp.txt" txt-dir))
207 (manual-pdf texi (expand-file-name "elisp.pdf" dest))
208 (manual-dvi texi (expand-file-name "elisp.dvi" dvi-dir)
f08b09fc
CY
209 (expand-file-name "elisp.ps" ps-dir)))
210 ;; Misc manuals
211 (let ((manuals '("ada-mode" "auth" "autotype" "calc" "cc-mode"
212 "cl" "dbus" "dired-x" "ebrowse" "ede" "ediff"
213 "edt" "eieio" "emacs-mime" "epa" "erc" "ert"
214 "eshell" "eudc" "faq" "flymake" "forms"
215 "gnus" "emacs-gnutls" "idlwave" "info"
216 "mairix-el" "message" "mh-e" "newsticker"
217 "nxml-mode" "org" "pcl-cvs" "pgg" "rcirc"
218 "remember" "reftex" "sasl" "sc" "semantic"
219 "ses" "sieve" "smtpmail" "speedbar" "tramp"
220 "url" "vip" "viper" "widget" "woman")))
221 (dolist (manual manuals)
222 (manual-misc-html manual root html-node-dir html-mono-dir)))
8d9101d8
CY
223 (message "Manuals created in %s" dest)))
224
225(defconst manual-doctype-string
226 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
227\"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
228
229(defconst manual-meta-string
230 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
231<link rev=\"made\" href=\"mailto:webmasters@gnu.org\">
232<link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
233<meta name=\"ICBM\" content=\"42.256233,-71.006581\">
234<meta name=\"DC.title\" content=\"gnu.org\">\n\n")
235
236(defconst manual-style-string "<style type=\"text/css\">
237@import url('/style.css');\n</style>\n")
238
f08b09fc
CY
239(defun manual-misc-html (name root html-node-dir html-mono-dir)
240 (let ((texi (expand-file-name (format "doc/misc/%s.texi" name) root)))
241 (manual-html-node texi (expand-file-name name html-node-dir))
242 (manual-html-mono texi (expand-file-name (concat name ".html")
243 html-mono-dir))))
244
8d9101d8
CY
245(defun manual-html-mono (texi-file dest)
246 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
247This function also edits the HTML files so that they validate as
248HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
249the @import directive."
250 (call-process "makeinfo" nil nil nil
251 "--html" "--no-split" texi-file "-o" dest)
252 (with-temp-buffer
253 (insert-file-contents dest)
254 (setq buffer-file-name dest)
255 (manual-html-fix-headers)
256 (manual-html-fix-index-1)
257 (manual-html-fix-index-2 t)
258 (manual-html-fix-node-div)
259 (goto-char (point-max))
260 (re-search-backward "</body>[\n \t]*</html>")
261 (insert "</div>\n\n")
262 (save-buffer)))
263
264(defun manual-html-node (texi-file dir)
265 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
266This function also edits the HTML files so that they validate as
267HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
268the @import directive."
269 (unless (file-exists-p texi-file)
270 (error "Manual file %s not found" texi-file))
271 (call-process "makeinfo" nil nil nil
272 "--html" texi-file "-o" dir)
273 ;; Loop through the node files, fixing them up.
274 (dolist (f (directory-files dir nil "\\.html\\'"))
275 (let (opoint)
276 (with-temp-buffer
277 (insert-file-contents (expand-file-name f dir))
278 (setq buffer-file-name (expand-file-name f dir))
279 (if (looking-at "<meta http-equiv")
280 ;; Ignore those HTML files that are just redirects.
281 (set-buffer-modified-p nil)
282 (manual-html-fix-headers)
283 (if (equal f "index.html")
284 (let (copyright-text)
285 (manual-html-fix-index-1)
286 ;; Move copyright notice to the end.
f08b09fc
CY
287 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
288 (setq opoint (match-beginning 0))
289 (re-search-forward "</blockquote>")
290 (setq copyright-text (buffer-substring opoint (point)))
291 (delete-region opoint (point)))
8d9101d8 292 (manual-html-fix-index-2)
f08b09fc
CY
293 (if copyright-text
294 (insert copyright-text))
295 (insert "\n</div>\n"))
8d9101d8
CY
296 ;; For normal nodes, give the header div a blue bg.
297 (manual-html-fix-node-div))
298 (save-buffer))))))
299
300(defun manual-txt (texi-file dest)
301 "Run Makeinfo on TEXI-FILE, emitting plaintext output to DEST."
302 (call-process "makeinfo" nil nil nil
303 "--plaintext" "--no-split" texi-file "-o" dest)
304 (shell-command (concat "gzip -c " dest " > " (concat dest ".gz"))))
305
306(defun manual-pdf (texi-file dest)
307 "Run texi2pdf on TEXI-FILE, emitting plaintext output to DEST."
308 (call-process "texi2pdf" nil nil nil texi-file "-o" dest))
309
310(defun manual-dvi (texi-file dest ps-dest)
311 "Run texi2dvi on TEXI-FILE, emitting dvi output to DEST.
7877f373 312Also generate PostScript output in PS-DEST."
8d9101d8
CY
313 (call-process "texi2dvi" nil nil nil texi-file "-o" dest)
314 (call-process "dvips" nil nil nil dest "-o" ps-dest)
315 (call-process "gzip" nil nil nil dest)
316 (call-process "gzip" nil nil nil ps-dest))
317
318(defun manual-html-fix-headers ()
319 "Fix up HTML headers for the Emacs manual in the current buffer."
320 (let (opoint)
321 (insert manual-doctype-string)
322 (search-forward "<head>\n")
323 (insert manual-meta-string)
324 (search-forward "<meta")
325 (setq opoint (match-beginning 0))
326 (re-search-forward "<!--")
327 (goto-char (match-beginning 0))
328 (delete-region opoint (point))
329 (insert manual-style-string)
330 (search-forward "<meta http-equiv=\"Content-Style")
331 (setq opoint (match-beginning 0))
332 (search-forward "</head>")
333 (delete-region opoint (match-beginning 0))))
334
335(defun manual-html-fix-node-div ()
336 "Fix up HTML \"node\" divs in the current buffer."
337 (let (opoint div-end)
338 (while (search-forward "<div class=\"node\">" nil t)
339 (replace-match
340 "<div class=\"node\" style=\"background-color:#DDDDFF\">"
341 t t)
342 (setq opoint (point))
343 (re-search-forward "</div>")
344 (setq div-end (match-beginning 0))
345 (goto-char opoint)
346 (if (search-forward "<hr>" div-end 'move)
347 (replace-match "" t t)))))
348
349(defun manual-html-fix-index-1 ()
350 (let (opoint)
f08b09fc
CY
351 (re-search-forward "<body>\n")
352 (setq opoint (match-end 0))
353 (search-forward "<h2 class=\"")
8d9101d8
CY
354 (goto-char (match-beginning 0))
355 (delete-region opoint (point))
356 (insert "<div id=\"content\" class=\"inner\">\n\n")))
357
358(defun manual-html-fix-index-2 (&optional table-workaround)
359 "Replace the index list in the current buffer with a HTML table."
360 (let (done open-td tag desc)
361 ;; Convert the list that Makeinfo made into a table.
f08b09fc
CY
362 (or (search-forward "<ul class=\"menu\">" nil t)
363 (search-forward "<ul>"))
8d9101d8
CY
364 (replace-match "<table style=\"float:left\" width=\"100%\">")
365 (forward-line 1)
366 (while (not done)
367 (cond
368 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
369 (looking-at "<li>\\(<a.+</a>\\)$"))
370 (setq tag (match-string 1))
371 (setq desc (match-string 2))
372 (replace-match "" t t)
373 (when open-td
374 (save-excursion
375 (forward-char -1)
376 (skip-chars-backward " ")
377 (delete-region (point) (line-end-position))
378 (insert "</td>\n </tr>")))
379 (insert " <tr>\n ")
380 (if table-workaround
381 ;; This works around a Firefox bug in the mono file.
382 (insert "<td bgcolor=\"white\">")
383 (insert "<td>"))
384 (insert tag "</td>\n <td>" (or desc ""))
385 (setq open-td t))
386 ((eq (char-after) ?\n)
387 (delete-char 1)
388 ;; Negate the following `forward-line'.
389 (forward-line -1))
390 ((looking-at "<!-- ")
391 (search-forward "-->"))
392 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
393 (replace-match " </td></tr></table>\n
394<h3>Detailed Node Listing</h3>\n\n" t t)
395 (search-forward "<p>")
f08b09fc 396 (search-forward "<p>" nil t)
8d9101d8
CY
397 (goto-char (match-beginning 0))
398 (skip-chars-backward "\n ")
399 (setq open-td nil)
400 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
401 ((looking-at "</li></ul>")
402 (replace-match "" t t))
403 ((looking-at "<p>")
404 (replace-match "" t t)
405 (when open-td
406 (insert " </td></tr>")
407 (setq open-td nil))
408 (insert " <tr>
409 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
f08b09fc
CY
410 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
411 (replace-match " </th></tr>")))
8d9101d8
CY
412 ((looking-at "[ \t]*</ul>[ \t]*$")
413 (replace-match
414 (if open-td
415 " </td></tr>\n</table>"
416 "</table>") t t)
417 (setq done t))
418 (t
419 (if (eobp)
dcddaabb 420 (error "Parse error in %s" f)) ; f is bound in manual-html-node
8d9101d8
CY
421 (unless open-td
422 (setq done t))))
423 (forward-line 1))))
424
58474503
GM
425\f
426;; Stuff to check new defcustoms got :version tags.
427;; Adapted from check-declare.el.
428
429(defun cusver-find-files (root &optional old)
430 "Find .el files beneath directory ROOT that contain defcustoms.
431If optional OLD is non-nil, also include defvars."
432 (process-lines find-program root
433 "-name" "*.el"
434 "-exec" grep-program
435 "-l" "-E" (format "^[ \\t]*\\(def%s"
436 (if old "(custom|var)"
437 "custom"
438 ))
439 "{}" "+"))
440
441;; TODO if a defgroup with a version tag, apply to all customs in that
442;; group (eg for new files).
443(defun cusver-scan (file &optional old)
444 "Scan FILE for `defcustom' calls.
445Return a list with elements of the form (VAR . VER),
446This means that FILE contains a defcustom for variable VAR, with
447a :version tag having value VER (may be nil).
448If optional argument OLD is non-nil, also scan for defvars."
449 (let ((m (format "Scanning %s..." file))
450 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
451 (if old "\\(?:custom\\|var\\)" "custom")))
dcf8834b 452 alist var ver form)
58474503
GM
453 (message "%s" m)
454 (with-temp-buffer
455 (insert-file-contents file)
456 ;; FIXME we could theoretically be inside a string.
457 (while (re-search-forward re nil t)
458 (goto-char (match-beginning 1))
459 (if (and (setq form (ignore-errors (read (current-buffer))))
460 (setq var (car-safe (cdr-safe form)))
461 ;; Exclude macros, eg (defcustom ,varname ...).
462 (symbolp var))
463 (setq ver (car (cdr-safe (memq :version form)))
464 alist (cons (cons var ver) alist))
465 (if form (message "Malformed defcustom: `%s'" form)))))
466 (message "%sdone" m)
467 alist))
468
469(define-button-type 'cusver-xref 'action #'cusver-goto-xref)
470
471(defun cusver-goto-xref (button)
472 "Jump to a lisp file for the BUTTON at point."
473 (let ((file (button-get button 'file))
474 (var (button-get button 'var)))
475 (if (not (file-readable-p file))
476 (message "Cannot read `%s'" file)
477 (with-current-buffer (find-file-noselect file)
478 (goto-char (point-min))
479 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
480 (message "Unable to locate defcustom"))
481 (pop-to-buffer (current-buffer))))))
482
483;; You should probably at least do a grep over the old directory
484;; to check the results of this look sensible. Eg cus-start if
485;; something moved from C to Lisp.
486;; TODO handle renamed things with aliases to the old names.
487;; What to do about new files? Does everything in there need a :version,
488;; or eg just the defgroup?
489(defun cusver-check (newdir olddir)
490 "Check that defcustoms have :version tags where needed.
491NEWDIR is the current lisp/ directory, OLDDIR is that from the previous
492release. A defcustom that is only in NEWDIR should have a :version
493tag. We exclude cases where a defvar exists in OLDDIR, since
494just converting a defvar to a defcustom does not require a :version bump.
495
496Note that a :version tag should also be added if the value of a defcustom
497changes (in a non-trivial way). This function does not check for that."
498 (interactive "DNew Lisp directory: \nDOld Lisp directory: ")
499 (or (file-directory-p (setq newdir (expand-file-name newdir)))
500 (error "Directory `%s' not found" newdir))
501 (or (file-directory-p (setq olddir (expand-file-name olddir)))
502 (error "Directory `%s' not found" olddir))
503 (let* ((newfiles (progn (message "Finding new files with defcustoms...")
504 (cusver-find-files newdir)))
505 (oldfiles (progn (message "Finding old files with defcustoms...")
506 (cusver-find-files olddir t)))
507 (newcus (progn (message "Reading new defcustoms...")
508 (mapcar
509 (lambda (file)
510 (cons file (cusver-scan file))) newfiles)))
dcf8834b 511 oldcus result thisfile file)
58474503
GM
512 (message "Reading old defcustoms...")
513 (dolist (file oldfiles)
514 (setq oldcus (append oldcus (cusver-scan file t))))
515 ;; newcus has elements (FILE (VAR VER) ... ).
516 ;; oldcus just (VAR . VER).
517 (message "Checking for version tags...")
518 (dolist (new newcus)
519 (setq file (car new)
520 thisfile
521 (let (missing var)
522 (dolist (cons (cdr new))
523 (or (cdr cons)
524 (assq (setq var (car cons)) oldcus)
525 (push var missing)))
526 (if missing
527 (cons file missing))))
528 (if thisfile
529 (setq result (cons thisfile result))))
530 (message "Checking for version tags... done")
531 (if (not result)
532 (message "No missing :version tags")
533 (pop-to-buffer "*cusver*")
534 (erase-buffer)
535 (insert "These defcustoms might be missing :version tags:\n\n")
536 (dolist (elem result)
537 (let* ((str (file-relative-name (car elem) newdir))
538 (strlen (length str)))
539 (dolist (var (cdr elem))
540 (insert (format "%s: %s\n" str var))
541 (make-text-button (+ (line-beginning-position 0) strlen 2)
542 (line-end-position 0)
543 'file (car elem)
544 'var var
545 'help-echo "Mouse-2: visit this definition"
546 :type 'cusver-xref)))))))
547
69c52df1
GM
548(provide 'admin)
549
d3841127 550;;; admin.el ends here