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