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