Merge from emacs-24
[bpt/emacs.git] / admin / admin.el
CommitLineData
74499542
GM
1;;; admin.el --- utilities for Emacs administration
2
ab422c4d 3;; Copyright (C) 2001-2013 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 131 "\\0\"")))
eec5fae2 132 ;; Major version only.
dcf8834b
GM
133 (when (string-match "\\([0-9]\\{2,\\}\\)" version)
134 (setq version (match-string 1 version))
eec5fae2
GM
135 (set-version-in-file root "src/msdos.c" version
136 (rx (and "Vwindow_system_version" (1+ not-newline)
137 ?\( (submatch (1+ (in "0-9"))) ?\))))
dcf8834b
GM
138 (set-version-in-file root "etc/refcards/ru-refcard.tex" version
139 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
140{\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")
141 (set-version-in-file root "etc/refcards/emacsver.tex" version
142 "\\\\def\\\\versionemacs\
143{\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs"))))
144
3f4a4bdf 145
a3045b7e
GM
146;; Note this makes some assumptions about form of short copyright.
147(defun set-copyright (root copyright)
148 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
149Root must be the root of an Emacs source tree."
150 (interactive (list
151 (read-directory-name "Emacs root directory: " nil nil t)
152 (read-string
153 "Short copyright string: "
154 (format "Copyright (C) %s Free Software Foundation, Inc."
155 (format-time-string "%Y")))))
156 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
157 (error "%s doesn't seem to be the root of an Emacs source tree" root))
78f83752
GM
158 (set-version-in-file root "configure.ac" copyright
159 (rx (and bol "copyright" (0+ (not (in ?\")))
287d4c2c 160 ?\" (submatch (1+ (not (in ?\")))) ?\")))
5ccd466c
GM
161 (set-version-in-file root "msdos/sed2v2.inp" copyright
162 (rx (and bol "/^#undef " (1+ not-newline)
163 "define COPYRIGHT" (1+ space)
164 ?\" (submatch (1+ (not (in ?\")))) ?\")))
78f83752
GM
165 (set-version-in-file root "nt/config.nt" copyright
166 (rx (and bol "#" (0+ blank) "define" (1+ blank)
167 "COPYRIGHT" (1+ blank)
168 ?\" (submatch (1+ (not (in ?\")))) ?\")))
a3045b7e 169 (set-version-in-file root "lib-src/rcs2log" copyright
287d4c2c
GM
170 (rx (and "Copyright" (0+ space) ?= (0+ space)
171 ?\' (submatch (1+ nonl)))))
287d4c2c
GM
172 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
173 (setq copyright (match-string 1 copyright))
dcf8834b
GM
174 (set-version-in-file root "etc/refcards/ru-refcard.tex" copyright
175 "\\\\newcommand{\\\\cyear}\\[0\\]\
176{\\([0-9]\\{4\\}\\)}.+%.+copyright year")
177 (set-version-in-file root "etc/refcards/emacsver.tex" copyright
178 "\\\\def\\\\year\
179{\\([0-9]\\{4\\}\\)}.+%.+copyright year")))
a3045b7e 180
8d9101d8
CY
181;;; Various bits of magic for generating the web manuals
182
183(defun make-manuals (root)
184 "Generate the web manuals for the Emacs webpage."
185 (interactive "DEmacs root directory: ")
186 (let* ((dest (expand-file-name "manual" root))
187 (html-node-dir (expand-file-name "html_node" dest))
188 (html-mono-dir (expand-file-name "html_mono" dest))
189 (txt-dir (expand-file-name "text" dest))
190 (dvi-dir (expand-file-name "dvi" dest))
191 (ps-dir (expand-file-name "ps" dest)))
192 (when (file-directory-p dest)
193 (if (y-or-n-p (format "Directory %s exists, delete it first?" dest))
194 (delete-directory dest t)
195 (error "Aborted")))
196 (make-directory dest)
197 (make-directory html-node-dir)
198 (make-directory html-mono-dir)
199 (make-directory txt-dir)
200 (make-directory dvi-dir)
201 (make-directory ps-dir)
202 ;; Emacs manual
203 (let ((texi (expand-file-name "doc/emacs/emacs.texi" root)))
204 (manual-html-node texi (expand-file-name "emacs" html-node-dir))
205 (manual-html-mono texi (expand-file-name "emacs.html" html-mono-dir))
206 (manual-txt texi (expand-file-name "emacs.txt" txt-dir))
207 (manual-pdf texi (expand-file-name "emacs.pdf" dest))
208 (manual-dvi texi (expand-file-name "emacs.dvi" dvi-dir)
f08b09fc 209 (expand-file-name "emacs.ps" ps-dir)))
8d9101d8
CY
210 ;; Lisp manual
211 (let ((texi (expand-file-name "doc/lispref/elisp.texi" root)))
212 (manual-html-node texi (expand-file-name "elisp" html-node-dir))
213 (manual-html-mono texi (expand-file-name "elisp.html" html-mono-dir))
214 (manual-txt texi (expand-file-name "elisp.txt" txt-dir))
215 (manual-pdf texi (expand-file-name "elisp.pdf" dest))
216 (manual-dvi texi (expand-file-name "elisp.dvi" dvi-dir)
f08b09fc
CY
217 (expand-file-name "elisp.ps" ps-dir)))
218 ;; Misc manuals
219 (let ((manuals '("ada-mode" "auth" "autotype" "calc" "cc-mode"
220 "cl" "dbus" "dired-x" "ebrowse" "ede" "ediff"
221 "edt" "eieio" "emacs-mime" "epa" "erc" "ert"
222 "eshell" "eudc" "faq" "flymake" "forms"
223 "gnus" "emacs-gnutls" "idlwave" "info"
224 "mairix-el" "message" "mh-e" "newsticker"
225 "nxml-mode" "org" "pcl-cvs" "pgg" "rcirc"
226 "remember" "reftex" "sasl" "sc" "semantic"
227 "ses" "sieve" "smtpmail" "speedbar" "tramp"
228 "url" "vip" "viper" "widget" "woman")))
229 (dolist (manual manuals)
230 (manual-misc-html manual root html-node-dir html-mono-dir)))
8d9101d8
CY
231 (message "Manuals created in %s" dest)))
232
233(defconst manual-doctype-string
234 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
235\"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
236
237(defconst manual-meta-string
238 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
239<link rev=\"made\" href=\"mailto:webmasters@gnu.org\">
240<link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
241<meta name=\"ICBM\" content=\"42.256233,-71.006581\">
242<meta name=\"DC.title\" content=\"gnu.org\">\n\n")
243
244(defconst manual-style-string "<style type=\"text/css\">
245@import url('/style.css');\n</style>\n")
246
f08b09fc
CY
247(defun manual-misc-html (name root html-node-dir html-mono-dir)
248 (let ((texi (expand-file-name (format "doc/misc/%s.texi" name) root)))
249 (manual-html-node texi (expand-file-name name html-node-dir))
250 (manual-html-mono texi (expand-file-name (concat name ".html")
251 html-mono-dir))))
252
8d9101d8
CY
253(defun manual-html-mono (texi-file dest)
254 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
255This function also edits the HTML files so that they validate as
256HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
257the @import directive."
258 (call-process "makeinfo" nil nil nil
259 "--html" "--no-split" texi-file "-o" dest)
260 (with-temp-buffer
261 (insert-file-contents dest)
262 (setq buffer-file-name dest)
263 (manual-html-fix-headers)
264 (manual-html-fix-index-1)
265 (manual-html-fix-index-2 t)
266 (manual-html-fix-node-div)
267 (goto-char (point-max))
268 (re-search-backward "</body>[\n \t]*</html>")
269 (insert "</div>\n\n")
270 (save-buffer)))
271
272(defun manual-html-node (texi-file dir)
273 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
274This function also edits the HTML files so that they validate as
275HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
276the @import directive."
277 (unless (file-exists-p texi-file)
278 (error "Manual file %s not found" texi-file))
279 (call-process "makeinfo" nil nil nil
280 "--html" texi-file "-o" dir)
281 ;; Loop through the node files, fixing them up.
282 (dolist (f (directory-files dir nil "\\.html\\'"))
283 (let (opoint)
284 (with-temp-buffer
285 (insert-file-contents (expand-file-name f dir))
286 (setq buffer-file-name (expand-file-name f dir))
287 (if (looking-at "<meta http-equiv")
288 ;; Ignore those HTML files that are just redirects.
289 (set-buffer-modified-p nil)
290 (manual-html-fix-headers)
291 (if (equal f "index.html")
292 (let (copyright-text)
293 (manual-html-fix-index-1)
294 ;; Move copyright notice to the end.
f08b09fc
CY
295 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
296 (setq opoint (match-beginning 0))
297 (re-search-forward "</blockquote>")
298 (setq copyright-text (buffer-substring opoint (point)))
299 (delete-region opoint (point)))
8d9101d8 300 (manual-html-fix-index-2)
f08b09fc
CY
301 (if copyright-text
302 (insert copyright-text))
303 (insert "\n</div>\n"))
8d9101d8
CY
304 ;; For normal nodes, give the header div a blue bg.
305 (manual-html-fix-node-div))
306 (save-buffer))))))
307
308(defun manual-txt (texi-file dest)
309 "Run Makeinfo on TEXI-FILE, emitting plaintext output to DEST."
310 (call-process "makeinfo" nil nil nil
311 "--plaintext" "--no-split" texi-file "-o" dest)
312 (shell-command (concat "gzip -c " dest " > " (concat dest ".gz"))))
313
314(defun manual-pdf (texi-file dest)
315 "Run texi2pdf on TEXI-FILE, emitting plaintext output to DEST."
316 (call-process "texi2pdf" nil nil nil texi-file "-o" dest))
317
318(defun manual-dvi (texi-file dest ps-dest)
319 "Run texi2dvi on TEXI-FILE, emitting dvi output to DEST.
7877f373 320Also generate PostScript output in PS-DEST."
8d9101d8
CY
321 (call-process "texi2dvi" nil nil nil texi-file "-o" dest)
322 (call-process "dvips" nil nil nil dest "-o" ps-dest)
323 (call-process "gzip" nil nil nil dest)
324 (call-process "gzip" nil nil nil ps-dest))
325
326(defun manual-html-fix-headers ()
327 "Fix up HTML headers for the Emacs manual in the current buffer."
328 (let (opoint)
329 (insert manual-doctype-string)
330 (search-forward "<head>\n")
331 (insert manual-meta-string)
332 (search-forward "<meta")
333 (setq opoint (match-beginning 0))
334 (re-search-forward "<!--")
335 (goto-char (match-beginning 0))
336 (delete-region opoint (point))
337 (insert manual-style-string)
338 (search-forward "<meta http-equiv=\"Content-Style")
339 (setq opoint (match-beginning 0))
340 (search-forward "</head>")
341 (delete-region opoint (match-beginning 0))))
342
343(defun manual-html-fix-node-div ()
344 "Fix up HTML \"node\" divs in the current buffer."
345 (let (opoint div-end)
346 (while (search-forward "<div class=\"node\">" nil t)
347 (replace-match
348 "<div class=\"node\" style=\"background-color:#DDDDFF\">"
349 t t)
350 (setq opoint (point))
351 (re-search-forward "</div>")
352 (setq div-end (match-beginning 0))
353 (goto-char opoint)
354 (if (search-forward "<hr>" div-end 'move)
355 (replace-match "" t t)))))
356
357(defun manual-html-fix-index-1 ()
358 (let (opoint)
f08b09fc
CY
359 (re-search-forward "<body>\n")
360 (setq opoint (match-end 0))
361 (search-forward "<h2 class=\"")
8d9101d8
CY
362 (goto-char (match-beginning 0))
363 (delete-region opoint (point))
364 (insert "<div id=\"content\" class=\"inner\">\n\n")))
365
366(defun manual-html-fix-index-2 (&optional table-workaround)
367 "Replace the index list in the current buffer with a HTML table."
368 (let (done open-td tag desc)
369 ;; Convert the list that Makeinfo made into a table.
f08b09fc
CY
370 (or (search-forward "<ul class=\"menu\">" nil t)
371 (search-forward "<ul>"))
8d9101d8
CY
372 (replace-match "<table style=\"float:left\" width=\"100%\">")
373 (forward-line 1)
374 (while (not done)
375 (cond
376 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
377 (looking-at "<li>\\(<a.+</a>\\)$"))
378 (setq tag (match-string 1))
379 (setq desc (match-string 2))
380 (replace-match "" t t)
381 (when open-td
382 (save-excursion
383 (forward-char -1)
384 (skip-chars-backward " ")
385 (delete-region (point) (line-end-position))
386 (insert "</td>\n </tr>")))
387 (insert " <tr>\n ")
388 (if table-workaround
389 ;; This works around a Firefox bug in the mono file.
390 (insert "<td bgcolor=\"white\">")
391 (insert "<td>"))
392 (insert tag "</td>\n <td>" (or desc ""))
393 (setq open-td t))
394 ((eq (char-after) ?\n)
395 (delete-char 1)
396 ;; Negate the following `forward-line'.
397 (forward-line -1))
398 ((looking-at "<!-- ")
399 (search-forward "-->"))
400 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
401 (replace-match " </td></tr></table>\n
402<h3>Detailed Node Listing</h3>\n\n" t t)
403 (search-forward "<p>")
f08b09fc 404 (search-forward "<p>" nil t)
8d9101d8
CY
405 (goto-char (match-beginning 0))
406 (skip-chars-backward "\n ")
407 (setq open-td nil)
408 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
409 ((looking-at "</li></ul>")
410 (replace-match "" t t))
411 ((looking-at "<p>")
412 (replace-match "" t t)
413 (when open-td
414 (insert " </td></tr>")
415 (setq open-td nil))
416 (insert " <tr>
417 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
f08b09fc
CY
418 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
419 (replace-match " </th></tr>")))
8d9101d8
CY
420 ((looking-at "[ \t]*</ul>[ \t]*$")
421 (replace-match
422 (if open-td
423 " </td></tr>\n</table>"
424 "</table>") t t)
425 (setq done t))
426 (t
427 (if (eobp)
dcddaabb 428 (error "Parse error in %s" f)) ; f is bound in manual-html-node
8d9101d8
CY
429 (unless open-td
430 (setq done t))))
431 (forward-line 1))))
432
58474503
GM
433\f
434;; Stuff to check new defcustoms got :version tags.
435;; Adapted from check-declare.el.
436
437(defun cusver-find-files (root &optional old)
438 "Find .el files beneath directory ROOT that contain defcustoms.
439If optional OLD is non-nil, also include defvars."
440 (process-lines find-program root
441 "-name" "*.el"
442 "-exec" grep-program
443 "-l" "-E" (format "^[ \\t]*\\(def%s"
444 (if old "(custom|var)"
445 "custom"
446 ))
447 "{}" "+"))
448
5407f8d2
GM
449(defvar cusver-new-version (format "%s.%s" emacs-major-version
450 (1+ emacs-minor-version))
1a316a53
GM
451 "Version number that new defcustoms should have.")
452
58474503
GM
453(defun cusver-scan (file &optional old)
454 "Scan FILE for `defcustom' calls.
455Return a list with elements of the form (VAR . VER),
456This means that FILE contains a defcustom for variable VAR, with
457a :version tag having value VER (may be nil).
458If optional argument OLD is non-nil, also scan for defvars."
459 (let ((m (format "Scanning %s..." file))
460 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
1a316a53
GM
461 (if old "\\(custom\\|var\\)" "\\(custom\\|group\\)")))
462 alist var ver form glist grp)
58474503
GM
463 (message "%s" m)
464 (with-temp-buffer
465 (insert-file-contents file)
466 ;; FIXME we could theoretically be inside a string.
467 (while (re-search-forward re nil t)
468 (goto-char (match-beginning 1))
469 (if (and (setq form (ignore-errors (read (current-buffer))))
1a316a53 470 (setq var (car-safe (cdr-safe form)))
58474503
GM
471 ;; Exclude macros, eg (defcustom ,varname ...).
472 (symbolp var))
1a316a53
GM
473 (progn
474 (setq ver (car (cdr-safe (memq :version form))))
475 (if (equal "group" (match-string 2))
476 ;; Group :version could be old.
477 (if (equal ver cusver-new-version)
478 (setq glist (cons (cons var ver) glist)))
479 ;; If it specifies a group and the whole group has a
480 ;; version. use that.
481 (unless ver
482 (setq grp (car (cdr-safe (memq :group form))))
483 (and grp
484 (setq grp (car (cdr-safe grp))) ; (quote foo) -> foo
485 (setq ver (assq grp glist))))
486 (setq alist (cons (cons var ver) alist))))
58474503
GM
487 (if form (message "Malformed defcustom: `%s'" form)))))
488 (message "%sdone" m)
489 alist))
490
2c35bdbb
GM
491(defun cusver-scan-cus-start (file)
492 "Scan cus-start.el and return an alist with elements (VAR . VER)."
493 (if (file-readable-p file)
494 (with-temp-buffer
495 (insert-file-contents file)
496 (when (search-forward "(let ((all '(" nil t)
497 (backward-char 1)
498 (let (var ver alist)
499 (dolist (elem (ignore-errors (read (current-buffer))))
500 (when (symbolp (setq var (car-safe elem)))
501 (or (stringp (setq ver (nth 3 elem)))
502 (setq ver nil))
503 (setq alist (cons (cons var ver) alist))))
504 alist)))))
505
58474503
GM
506(define-button-type 'cusver-xref 'action #'cusver-goto-xref)
507
508(defun cusver-goto-xref (button)
509 "Jump to a lisp file for the BUTTON at point."
510 (let ((file (button-get button 'file))
511 (var (button-get button 'var)))
512 (if (not (file-readable-p file))
513 (message "Cannot read `%s'" file)
514 (with-current-buffer (find-file-noselect file)
515 (goto-char (point-min))
516 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
517 (message "Unable to locate defcustom"))
518 (pop-to-buffer (current-buffer))))))
519
520;; You should probably at least do a grep over the old directory
2c35bdbb
GM
521;; to check the results of this look sensible.
522;; TODO Check cus-start if something moved from C to Lisp.
523;; TODO Handle renamed things with aliases to the old names.
1a316a53 524(defun cusver-check (newdir olddir version)
58474503
GM
525 "Check that defcustoms have :version tags where needed.
526NEWDIR is the current lisp/ directory, OLDDIR is that from the previous
527release. A defcustom that is only in NEWDIR should have a :version
528tag. We exclude cases where a defvar exists in OLDDIR, since
529just converting a defvar to a defcustom does not require a :version bump.
530
531Note that a :version tag should also be added if the value of a defcustom
532changes (in a non-trivial way). This function does not check for that."
5407f8d2
GM
533 (interactive (list (read-directory-name "New Lisp directory: ")
534 (read-directory-name "Old Lisp directory: ")
535 (number-to-string
536 (read-number "New version number: "
537 (string-to-number cusver-new-version)))))
58474503
GM
538 (or (file-directory-p (setq newdir (expand-file-name newdir)))
539 (error "Directory `%s' not found" newdir))
540 (or (file-directory-p (setq olddir (expand-file-name olddir)))
541 (error "Directory `%s' not found" olddir))
1a316a53 542 (setq cusver-new-version version)
58474503
GM
543 (let* ((newfiles (progn (message "Finding new files with defcustoms...")
544 (cusver-find-files newdir)))
545 (oldfiles (progn (message "Finding old files with defcustoms...")
546 (cusver-find-files olddir t)))
547 (newcus (progn (message "Reading new defcustoms...")
548 (mapcar
549 (lambda (file)
550 (cons file (cusver-scan file))) newfiles)))
dcf8834b 551 oldcus result thisfile file)
58474503
GM
552 (message "Reading old defcustoms...")
553 (dolist (file oldfiles)
554 (setq oldcus (append oldcus (cusver-scan file t))))
2c35bdbb
GM
555 (setq oldcus (append oldcus (cusver-scan-cus-start
556 (expand-file-name "cus-start.el" olddir))))
58474503
GM
557 ;; newcus has elements (FILE (VAR VER) ... ).
558 ;; oldcus just (VAR . VER).
559 (message "Checking for version tags...")
560 (dolist (new newcus)
561 (setq file (car new)
562 thisfile
563 (let (missing var)
564 (dolist (cons (cdr new))
565 (or (cdr cons)
566 (assq (setq var (car cons)) oldcus)
567 (push var missing)))
568 (if missing
569 (cons file missing))))
570 (if thisfile
571 (setq result (cons thisfile result))))
572 (message "Checking for version tags... done")
573 (if (not result)
574 (message "No missing :version tags")
575 (pop-to-buffer "*cusver*")
576 (erase-buffer)
577 (insert "These defcustoms might be missing :version tags:\n\n")
578 (dolist (elem result)
579 (let* ((str (file-relative-name (car elem) newdir))
580 (strlen (length str)))
581 (dolist (var (cdr elem))
582 (insert (format "%s: %s\n" str var))
583 (make-text-button (+ (line-beginning-position 0) strlen 2)
584 (line-end-position 0)
585 'file (car elem)
586 'var var
587 'help-echo "Mouse-2: visit this definition"
588 :type 'cusver-xref)))))))
589
69c52df1
GM
590(provide 'admin)
591
d3841127 592;;; admin.el ends here