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