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