In x_set_tool_bar_lines of w32fns.c don't clear area on frames that are not visible.
[emacs.git] / admin / admin.el
blob007cb06e592b7b3874d57caf61ef61d8143a9275
1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001-2014 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 (user-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 "Subroutine of `set-version' and `set-copyright'."
66 (find-file (expand-file-name file root))
67 (goto-char (point-min))
68 (unless (re-search-forward rx nil :noerror)
69 (user-error "Version not found in %s" file))
70 (replace-match (format "%s" version) nil nil nil 1))
72 ;; TODO report the progress
73 (defun set-version (root version)
74 "Set Emacs version to VERSION in relevant files under ROOT.
75 Root must be the root of an Emacs source tree."
76 (interactive "DEmacs root directory: \nsVersion number: ")
77 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
78 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
79 ;; There's also a "version 3" (standing for GPLv3) at the end of
80 ;; `README', but since `set-version-in-file' only replaces the first
81 ;; occurrence, it won't be replaced.
82 (set-version-in-file root "README" version
83 (rx (and "version" (1+ space)
84 (submatch (1+ (in "0-9."))))))
85 (set-version-in-file root "configure.ac" version
86 (rx (and "AC_INIT" (1+ (not (in ?,)))
87 ?, (0+ space)
88 (submatch (1+ (in "0-9."))))))
89 (set-version-in-file root "doc/emacs/emacsver.texi" version
90 (rx (and "EMACSVER" (1+ space)
91 (submatch (1+ (in "0-9."))))))
92 (set-version-in-file root "doc/man/emacs.1" version
93 (rx (and ".TH EMACS" (1+ not-newline)
94 "GNU Emacs" (1+ space)
95 (submatch (1+ (in "0-9."))))))
96 (set-version-in-file root "nt/config.nt" version
97 (rx (and bol "#" (0+ blank) "define" (1+ blank)
98 "VERSION" (1+ blank) "\""
99 (submatch (1+ (in "0-9."))))))
100 (set-version-in-file root "msdos/sed2v2.inp" version
101 (rx (and bol "/^#undef " (1+ not-newline)
102 "define VERSION" (1+ space) "\""
103 (submatch (1+ (in "0-9."))))))
104 (set-version-in-file root "nt/makefile.w32-in" version
105 (rx (and "VERSION" (0+ space) "=" (0+ space)
106 (submatch (1+ (in "0-9."))))))
107 ;; nt/emacs.rc also contains the version number, but in an awkward
108 ;; format. It must contain four components, separated by commas, and
109 ;; in two places those commas are followed by space, in two other
110 ;; places they are not.
111 (let* ((version-components (append (split-string version "\\.")
112 '("0" "0")))
113 (comma-version
114 (concat (car version-components) ","
115 (cadr version-components) ","
116 (cadr (cdr version-components)) ","
117 (cadr (cdr (cdr version-components)))))
118 (comma-space-version
119 (concat (car version-components) ", "
120 (cadr version-components) ", "
121 (cadr (cdr version-components)) ", "
122 (cadr (cdr (cdr version-components))))))
123 (set-version-in-file root "nt/emacs.rc" comma-version
124 (rx (and "FILEVERSION" (1+ space)
125 (submatch (1+ (in "0-9,"))))))
126 (set-version-in-file root "nt/emacs.rc" comma-version
127 (rx (and "PRODUCTVERSION" (1+ space)
128 (submatch (1+ (in "0-9,"))))))
129 (set-version-in-file root "nt/emacs.rc" comma-space-version
130 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
131 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
132 (set-version-in-file root "nt/emacs.rc" comma-space-version
133 (rx (and "\"ProductVersion\"" (0+ space) ?,
134 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
135 "\\0\"")))
136 ;; Likewise for emacsclient.rc
137 (set-version-in-file root "nt/emacsclient.rc" comma-version
138 (rx (and "FILEVERSION" (1+ space)
139 (submatch (1+ (in "0-9,"))))))
140 (set-version-in-file root "nt/emacsclient.rc" comma-version
141 (rx (and "PRODUCTVERSION" (1+ space)
142 (submatch (1+ (in "0-9,"))))))
143 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
144 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
145 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
146 (set-version-in-file root "nt/emacsclient.rc" comma-space-version
147 (rx (and "\"ProductVersion\"" (0+ space) ?,
148 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
149 "\\0\"")))
150 ;; Major version only.
151 (when (string-match "\\([0-9]\\{2,\\}\\)" version)
152 (setq version (match-string 1 version))
153 (set-version-in-file root "src/msdos.c" version
154 (rx (and "Vwindow_system_version" (1+ not-newline)
155 ?\( (submatch (1+ (in "0-9"))) ?\))))
156 (set-version-in-file root "etc/refcards/ru-refcard.tex" version
157 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
158 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")
159 (set-version-in-file root "etc/refcards/emacsver.tex" version
160 "\\\\def\\\\versionemacs\
161 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs"))))
164 ;; Note this makes some assumptions about form of short copyright.
165 ;; TODO report the progress
166 (defun set-copyright (root copyright)
167 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
168 Root must be the root of an Emacs source tree."
169 (interactive (list
170 (read-directory-name "Emacs root directory: " nil nil t)
171 (read-string
172 "Short copyright string: "
173 (format "Copyright (C) %s Free Software Foundation, Inc."
174 (format-time-string "%Y")))))
175 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
176 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
177 (set-version-in-file root "configure.ac" copyright
178 (rx (and bol "copyright" (0+ (not (in ?\")))
179 ?\" (submatch (1+ (not (in ?\")))) ?\")))
180 (set-version-in-file root "msdos/sed2v2.inp" copyright
181 (rx (and bol "/^#undef " (1+ not-newline)
182 "define COPYRIGHT" (1+ space)
183 ?\" (submatch (1+ (not (in ?\")))) ?\")))
184 (set-version-in-file root "nt/config.nt" copyright
185 (rx (and bol "#" (0+ blank) "define" (1+ blank)
186 "COPYRIGHT" (1+ blank)
187 ?\" (submatch (1+ (not (in ?\")))) ?\")))
188 (set-version-in-file root "lib-src/rcs2log" copyright
189 (rx (and "Copyright" (0+ space) ?= (0+ space)
190 ?\' (submatch (1+ nonl)))))
191 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
192 (setq copyright (match-string 1 copyright))
193 (set-version-in-file root "etc/refcards/ru-refcard.tex" copyright
194 "\\\\newcommand{\\\\cyear}\\[0\\]\
195 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")
196 (set-version-in-file root "etc/refcards/emacsver.tex" copyright
197 "\\\\def\\\\year\
198 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")))
200 ;;; Various bits of magic for generating the web manuals
202 (defun manual-misc-manuals (root)
203 "Return doc/misc manuals as list of strings.
204 ROOT should be the root of an Emacs source tree."
205 ;; Similar to `make -C doc/misc echo-info', but works if unconfigured,
206 ;; and for INFO_TARGETS rather than INFO_INSTALL.
207 (with-temp-buffer
208 (insert-file-contents (expand-file-name "doc/misc/Makefile.in" root))
209 ;; Should really use expanded value of INFO_TARGETS.
210 (search-forward "INFO_COMMON = ")
211 (let ((start (point)))
212 (end-of-line)
213 (while (and (looking-back "\\\\")
214 (zerop (forward-line 1)))
215 (end-of-line))
216 (append (split-string (replace-regexp-in-string
217 "\\(\\\\\\|\\.info\\)" ""
218 (buffer-substring start (point))))
219 '("efaq-w32")))))
221 ;; TODO report the progress
222 (defun make-manuals (root &optional type)
223 "Generate the web manuals for the Emacs webpage.
224 ROOT should be the root of an Emacs source tree.
225 Interactively with a prefix argument, prompt for TYPE.
226 Optional argument TYPE is type of output (nil means all)."
227 (interactive (let ((root (read-directory-name "Emacs root directory: "
228 source-directory nil t)))
229 (list root
230 (if current-prefix-arg
231 (completing-read
232 "Type: "
233 (append
234 '("misc" "pdf" "ps")
235 (let (res)
236 (dolist (i '("emacs" "elisp" "eintr") res)
237 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
238 (push (concat i j) res))))
239 (manual-misc-manuals root)))))))
240 (let* ((dest (expand-file-name "manual" root))
241 (html-node-dir (expand-file-name "html_node" dest))
242 (html-mono-dir (expand-file-name "html_mono" dest))
243 (ps-dir (expand-file-name "ps" dest))
244 (pdf-dir (expand-file-name "pdf" dest))
245 (emacs (expand-file-name "doc/emacs/emacs.texi" root))
246 (elisp (expand-file-name "doc/lispref/elisp.texi" root))
247 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root))
248 (misc (manual-misc-manuals root)))
249 ;; TODO this makes it non-continuable.
250 ;; Instead, delete the individual dest directory each time.
251 (when (file-directory-p dest)
252 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest))
253 (delete-directory dest t)
254 (user-error "Aborted")))
255 (if (member type '(nil "emacs" "emacs-node"))
256 (manual-html-node emacs (expand-file-name "emacs" html-node-dir)))
257 (if (member type '(nil "emacs" "emacs-mono"))
258 (manual-html-mono emacs (expand-file-name "emacs.html" html-mono-dir)))
259 (if (member type '(nil "emacs" "emacs-pdf" "pdf"))
260 (manual-pdf emacs (expand-file-name "emacs.pdf" pdf-dir)))
261 (if (member type '(nil "emacs" "emacs-ps" "ps"))
262 (manual-ps emacs (expand-file-name "emacs.ps" ps-dir)))
263 (if (member type '(nil "elisp" "elisp-node"))
264 (manual-html-node elisp (expand-file-name "elisp" html-node-dir)))
265 (if (member type '(nil "elisp" "elisp-mono"))
266 (manual-html-mono elisp (expand-file-name "elisp.html" html-mono-dir)))
267 (if (member type '(nil "elisp" "elisp-pdf" "pdf"))
268 (manual-pdf elisp (expand-file-name "elisp.pdf" pdf-dir)))
269 (if (member type '(nil "elisp" "elisp-ps" "ps"))
270 (manual-ps elisp (expand-file-name "elisp.ps" ps-dir)))
271 (if (member type '(nil "eintr" "eintr-node"))
272 (manual-html-node eintr (expand-file-name "eintr" html-node-dir)))
273 (if (member type '(nil "eintr" "eintr-node"))
274 (manual-html-mono eintr (expand-file-name "eintr.html" html-mono-dir)))
275 (if (member type '(nil "eintr" "eintr-pdf" "pdf"))
276 (manual-pdf eintr (expand-file-name "eintr.pdf" pdf-dir)))
277 (if (member type '(nil "eintr" "eintr-ps" "ps"))
278 (manual-ps eintr (expand-file-name "eintr.ps" ps-dir)))
279 ;; Misc manuals
280 (dolist (manual misc)
281 (if (member type `(nil ,manual "misc"))
282 (manual-misc-html manual root html-node-dir html-mono-dir)))
283 (message "Manuals created in %s" dest)))
285 (defconst manual-doctype-string
286 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
287 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
289 (defconst manual-meta-string
290 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
291 <link rev=\"made\" href=\"mailto:webmasters@gnu.org\">
292 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
293 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
294 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
296 (defconst manual-style-string "<style type=\"text/css\">
297 @import url('/software/emacs/manual.css');\n</style>\n")
299 (defun manual-misc-html (name root html-node-dir html-mono-dir)
300 ;; Hack to deal with the cases where .texi creates a different .info.
301 ;; Blech. TODO Why not just rename the .texi (or .info) files?
302 (let* ((texiname (cond ((equal name "ccmode") "cc-mode")
303 (t name)))
304 (texi (expand-file-name (format "doc/misc/%s.texi" texiname) root)))
305 (manual-html-node texi (expand-file-name name html-node-dir))
306 (manual-html-mono texi (expand-file-name (concat name ".html")
307 html-mono-dir))))
309 (defun manual-html-mono (texi-file dest)
310 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
311 This function also edits the HTML files so that they validate as
312 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
313 the @import directive."
314 (make-directory (or (file-name-directory dest) ".") t)
315 (call-process "makeinfo" nil nil nil
316 "-D" "WWW_GNU_ORG"
317 "-I" (expand-file-name "../emacs"
318 (file-name-directory texi-file))
319 "-I" (expand-file-name "../misc"
320 (file-name-directory texi-file))
321 "--html" "--no-split" texi-file "-o" dest)
322 (with-temp-buffer
323 (insert-file-contents dest)
324 (setq buffer-file-name dest)
325 (manual-html-fix-headers)
326 (manual-html-fix-index-1)
327 (manual-html-fix-index-2 t)
328 (manual-html-fix-node-div)
329 (goto-char (point-max))
330 (re-search-backward "</body>[\n \t]*</html>")
331 ;; Close the div id="content" that fix-index-1 added.
332 (insert "</div>\n\n")
333 (save-buffer)))
335 (defun manual-html-node (texi-file dir)
336 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
337 This function also edits the HTML files so that they validate as
338 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
339 the @import directive."
340 (unless (file-exists-p texi-file)
341 (user-error "Manual file %s not found" texi-file))
342 (make-directory dir t)
343 (call-process "makeinfo" nil nil nil
344 "-D" "WWW_GNU_ORG"
345 "-I" (expand-file-name "../emacs"
346 (file-name-directory texi-file))
347 "-I" (expand-file-name "../misc"
348 (file-name-directory texi-file))
349 "--html" texi-file "-o" dir)
350 ;; Loop through the node files, fixing them up.
351 (dolist (f (directory-files dir nil "\\.html\\'"))
352 (let (opoint)
353 (with-temp-buffer
354 (insert-file-contents (expand-file-name f dir))
355 (setq buffer-file-name (expand-file-name f dir))
356 (if (looking-at "<meta http-equiv")
357 ;; Ignore those HTML files that are just redirects.
358 (set-buffer-modified-p nil)
359 (manual-html-fix-headers)
360 (if (equal f "index.html")
361 (let (copyright-text)
362 (manual-html-fix-index-1)
363 ;; Move copyright notice to the end.
364 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
365 (setq opoint (match-beginning 0))
366 (re-search-forward "</blockquote>")
367 (setq copyright-text (buffer-substring opoint (point)))
368 (delete-region opoint (point)))
369 (manual-html-fix-index-2)
370 (if copyright-text
371 (insert copyright-text))
372 ;; Close the div id="content" that fix-index-1 added.
373 (insert "\n</div>\n"))
374 ;; For normal nodes, give the header div a blue bg.
375 (manual-html-fix-node-div t))
376 (save-buffer))))))
378 (defun manual-pdf (texi-file dest)
379 "Run texi2pdf on TEXI-FILE, emitting PDF output to DEST."
380 (make-directory (or (file-name-directory dest) ".") t)
381 (let ((default-directory (file-name-directory texi-file)))
382 (call-process "texi2pdf" nil nil nil
383 "-I" "../emacs" "-I" "../misc"
384 texi-file "-o" dest)))
386 (defun manual-ps (texi-file dest)
387 "Generate a PostScript version of TEXI-FILE as DEST."
388 (make-directory (or (file-name-directory dest) ".") t)
389 (let ((dvi-dest (concat (file-name-sans-extension dest) ".dvi"))
390 (default-directory (file-name-directory texi-file)))
391 ;; FIXME: Use `texi2dvi --ps'? --xfq
392 (call-process "texi2dvi" nil nil nil
393 "-I" "../emacs" "-I" "../misc"
394 texi-file "-o" dvi-dest)
395 (call-process "dvips" nil nil nil dvi-dest "-o" dest)
396 (delete-file dvi-dest)
397 (call-process "gzip" nil nil nil dest)))
399 (defun manual-html-fix-headers ()
400 "Fix up HTML headers for the Emacs manual in the current buffer."
401 (let ((texi5 (search-forward "<!DOCTYPE" nil t))
402 opoint)
403 ;; Texinfo 5 supplies a DOCTYPE.
404 (or texi5
405 (insert manual-doctype-string))
406 (search-forward "<head>\n")
407 (insert manual-meta-string)
408 (search-forward "<meta")
409 (setq opoint (match-beginning 0))
410 (unless texi5
411 (search-forward "<!--")
412 (goto-char (match-beginning 0))
413 (delete-region opoint (point))
414 (search-forward "<meta http-equiv=\"Content-Style")
415 (setq opoint (match-beginning 0)))
416 (search-forward "</head>")
417 (goto-char (match-beginning 0))
418 (delete-region opoint (point))
419 (insert manual-style-string)
420 ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink.
421 (when (re-search-forward "<body lang=\"[^\"]+\"" nil t)
422 (setq opoint (point))
423 (search-forward ">")
424 (if (> (point) (1+ opoint))
425 (delete-region opoint (1- (point))))
426 (search-backward "</head"))))
428 ;; Texinfo 5 changed these from class = "node" to "header", yay.
429 (defun manual-html-fix-node-div (&optional split)
430 "Fix up HTML \"node\" divs in the current buffer."
431 (let (opoint div-end type)
432 (while (re-search-forward "<div class=\"\\(node\\|header\\)\"\\(>\\)" nil t)
433 (setq type (match-string 1))
434 ;; NB it is this that makes the bg of non-header cells in the
435 ;; index tables be blue. Is that intended?
436 ;; Also, if you don't remove the <hr>, the color of the first
437 ;; row in the table will be wrong.
438 ;; This all seems rather odd to me...
439 (replace-match " style=\"background-color:#DDDDFF\">" t t nil 2)
440 (setq opoint (point))
441 (when (or split (equal type "node"))
442 ;; In Texinfo 4, the <hr> (and anchor) comes after the <div>.
443 (re-search-forward "</div>")
444 (setq div-end (if (equal type "node")
445 (match-beginning 0)
446 (line-end-position 2)))
447 (goto-char opoint)
448 (if (search-forward "<hr>" div-end 'move)
449 (replace-match "" t t)
450 (if split (forward-line -1))))
451 ;; In Texinfo 5, the <hr> (and anchor) comes before the <div> (?).
452 ;; Except in split output, where it comes on the line after
453 ;; the <div>. But only sometimes. I have no clue what the
454 ;; logic of where it goes is.
455 (when (equal type "header")
456 (goto-char opoint)
457 (when (re-search-backward "^<hr>$" (line-beginning-position -3) t)
458 (replace-match "")
459 (goto-char opoint))))))
462 (defun manual-html-fix-index-1 ()
463 "Remove the h1 header, and the short and long contents lists.
464 Also start a \"content\" div."
465 (let (opoint)
466 (re-search-forward "<body.*>\n")
467 (setq opoint (match-end 0))
468 ;; FIXME? Fragile if a Texinfo 5 document does not use @top.
469 (or (re-search-forward "<h1 class=\"top\"" nil t) ; Texinfo 5
470 (search-forward "<h2 class=\""))
471 (goto-char (match-beginning 0))
472 (delete-region opoint (point))
473 ;; NB caller must close this div.
474 (insert "<div id=\"content\" class=\"inner\">\n\n")))
476 (defun manual-html-fix-index-2 (&optional table-workaround)
477 "Replace the index list in the current buffer with a HTML table.
478 Leave point after the table."
479 (if (re-search-forward "<table class=\"menu\"\\(.*\\)>" nil t)
480 ;; Texinfo 5 already uses a table. Tweak it a bit.
481 (let (opoint done)
482 (replace-match " style=\"float:left\" width=\"100%\"" nil t nil 1)
483 (forward-line 1)
484 (while (not done)
485 (cond ((re-search-forward "<tr><td.*&bull; \\(<a.*</a>\\)\
486 :</td><td>&nbsp;&nbsp;</td><td[^>]*>\\(.*\\)" (line-end-position) t)
487 (replace-match (format "<tr><td%s>\\1</td>\n<td>\\2"
488 (if table-workaround
489 " bgcolor=\"white\"" "")))
490 (search-forward "</td></tr>")
491 (forward-line 1))
492 ((looking-at "<tr><th.*<pre class=\"menu-comment\">\n")
493 (replace-match "<tr><th colspan=\"2\" align=\"left\" \
494 style=\"text-align:left\">")
495 (search-forward "</pre></th></tr>")
496 (replace-match "</th></tr>\n"))
497 ;; Not all manuals have the detailed menu.
498 ;; If it is there, split it into a separate table.
499 ((re-search-forward "<tr>.*The Detailed Node Listing *"
500 (line-end-position) t)
501 (setq opoint (match-beginning 0))
502 (while (and (looking-at " *&mdash;")
503 (zerop (forward-line 1))))
504 (delete-region opoint (point))
505 (insert "</table>\n\n\
506 <h2>Detailed Node Listing</h2>\n\n<p>")
507 ;; FIXME Fragile!
508 ;; The Emacs and Elisp manual have some text at the
509 ;; start of the detailed menu that is not part of the menu.
510 ;; Other manuals do not.
511 (if (re-search-forward "in one step:" (line-end-position 3) t)
512 (forward-line 1))
513 (insert "</p>\n")
514 (search-forward "</pre></th></tr>")
515 (delete-region (match-beginning 0) (match-end 0))
516 (forward-line -1)
517 (or (looking-at "^$") (error "Parse error 1"))
518 (forward-line -1)
519 (if (looking-at "^$") (error "Parse error 2"))
520 (forward-line -1)
521 (or (looking-at "^$") (error "Parse error 3"))
522 (forward-line 1)
523 (insert "<table class=\"menu\" style=\"float:left\" width=\"100%\">\n\
524 <tr><th colspan=\"2\" align=\"left\" style=\"text-align:left\">\n")
525 (forward-line 1)
526 (insert "</th></tr>")
527 (forward-line 1))
528 ((looking-at ".*</table")
529 (forward-line 1)
530 (setq done t)))))
531 (let (done open-td tag desc)
532 ;; Convert the list that Makeinfo made into a table.
533 (or (search-forward "<ul class=\"menu\">" nil t)
534 ;; FIXME? The following search seems dangerously lax.
535 (search-forward "<ul>"))
536 (replace-match "<table style=\"float:left\" width=\"100%\">")
537 (forward-line 1)
538 (while (not done)
539 (cond
540 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
541 (looking-at "<li>\\(<a.+</a>\\)$"))
542 (setq tag (match-string 1))
543 (setq desc (match-string 2))
544 (replace-match "" t t)
545 (when open-td
546 (save-excursion
547 (forward-char -1)
548 (skip-chars-backward " ")
549 (delete-region (point) (line-end-position))
550 (insert "</td>\n </tr>")))
551 (insert " <tr>\n ")
552 (if table-workaround
553 ;; This works around a Firefox bug in the mono file.
554 (insert "<td bgcolor=\"white\">")
555 (insert "<td>"))
556 (insert tag "</td>\n <td>" (or desc ""))
557 (setq open-td t))
558 ((eq (char-after) ?\n)
559 (delete-char 1)
560 ;; Negate the following `forward-line'.
561 (forward-line -1))
562 ((looking-at "<!-- ")
563 (search-forward "-->"))
564 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
565 (replace-match " </td></tr></table>\n
566 <h3>Detailed Node Listing</h3>\n\n" t t)
567 (search-forward "<p>")
568 ;; FIXME Fragile!
569 ;; The Emacs and Elisp manual have some text at the
570 ;; start of the detailed menu that is not part of the menu.
571 ;; Other manuals do not.
572 (if (looking-at "Here are some other nodes")
573 (search-forward "<p>"))
574 (goto-char (match-beginning 0))
575 (skip-chars-backward "\n ")
576 (setq open-td nil)
577 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
578 ((looking-at "</li></ul>")
579 (replace-match "" t t))
580 ((looking-at "<p>")
581 (replace-match "" t t)
582 (when open-td
583 (insert " </td></tr>")
584 (setq open-td nil))
585 (insert " <tr>
586 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
587 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
588 (replace-match " </th></tr>")))
589 ((looking-at "[ \t]*</ul>[ \t]*$")
590 (replace-match
591 (if open-td
592 " </td></tr>\n</table>"
593 "</table>") t t)
594 (setq done t))
596 (if (eobp)
597 (error "Parse error in %s"
598 (file-name-nondirectory buffer-file-name)))
599 (unless open-td
600 (setq done t))))
601 (forward-line 1)))))
604 ;; Stuff to check new `defcustom's got :version tags.
605 ;; Adapted from check-declare.el.
607 (defun cusver-find-files (root &optional old)
608 "Find .el files beneath directory ROOT that contain `defcustom's.
609 If optional OLD is non-nil, also include `defvar's."
610 (process-lines find-program root
611 "-name" "*.el"
612 "-exec" grep-program
613 "-l" "-E" (format "^[ \\t]*\\(def%s"
614 (if old "(custom|var)"
615 "custom"
617 "{}" "+"))
619 (defvar cusver-new-version (format "%s.%s" emacs-major-version
620 (1+ emacs-minor-version))
621 "Version number that new `defcustom's should have.")
623 (defun cusver-scan (file &optional old)
624 "Scan FILE for `defcustom' calls.
625 Return a list with elements of the form (VAR . VER),
626 This means that FILE contains a defcustom for variable VAR, with
627 a :version tag having value VER (may be nil).
628 If optional argument OLD is non-nil, also scan for `defvar's."
629 (let ((m (format "Scanning %s..." file))
630 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
631 (if old "\\(custom\\|var\\)" "\\(custom\\|group\\)")))
632 alist var ver form glist grp)
633 (message "%s" m)
634 (with-temp-buffer
635 (insert-file-contents file)
636 ;; FIXME we could theoretically be inside a string.
637 (while (re-search-forward re nil :noerror)
638 (goto-char (match-beginning 1))
639 (if (and (setq form (ignore-errors (read (current-buffer))))
640 (setq var (car-safe (cdr-safe form)))
641 ;; Exclude macros, eg (defcustom ,varname ...).
642 (symbolp var))
643 (progn
644 ;; FIXME It should be cus-test-apropos that does this.
645 (and (not old)
646 (equal "custom" (match-string 2))
647 (not (memq :type form))
648 (display-warning 'custom
649 (format "Missing type in: `%s'" form)))
650 (setq ver (car (cdr-safe (memq :version form))))
651 (if (equal "group" (match-string 2))
652 ;; Group :version could be old.
653 (if (equal ver cusver-new-version)
654 (setq glist (cons (cons var ver) glist)))
655 ;; If it specifies a group and the whole group has a
656 ;; version. use that.
657 (unless ver
658 (setq grp (car (cdr-safe (memq :group form))))
659 (and grp
660 (setq grp (car (cdr-safe grp))) ; (quote foo) -> foo
661 (setq ver (assq grp glist))))
662 (setq alist (cons (cons var ver) alist))))
663 (if form (message "Malformed defcustom: `%s'" form)))))
664 (message "%sdone" m)
665 alist))
667 (defun cusver-scan-cus-start (file)
668 "Scan cus-start.el and return an alist with elements (VAR . VER)."
669 (if (file-readable-p file)
670 (with-temp-buffer
671 (insert-file-contents file)
672 (when (search-forward "(let ((all '(" nil t)
673 (backward-char 1)
674 (let (var ver alist)
675 (dolist (elem (ignore-errors (read (current-buffer))))
676 (when (symbolp (setq var (car-safe elem)))
677 (or (stringp (setq ver (nth 3 elem)))
678 (setq ver nil))
679 (setq alist (cons (cons var ver) alist))))
680 alist)))))
682 (define-button-type 'cusver-xref 'action #'cusver-goto-xref)
684 (defun cusver-goto-xref (button)
685 "Jump to a Lisp file for the BUTTON at point."
686 (let ((file (button-get button 'file))
687 (var (button-get button 'var)))
688 (if (not (file-readable-p file))
689 (message "Cannot read `%s'" file)
690 (with-current-buffer (find-file-noselect file)
691 (goto-char (point-min))
692 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
693 (message "Unable to locate defcustom"))
694 (pop-to-buffer (current-buffer))))))
696 ;; You should probably at least do a grep over the old directory
697 ;; to check the results of this look sensible.
698 ;; TODO Check cus-start if something moved from C to Lisp.
699 ;; TODO Handle renamed things with aliases to the old names.
700 (defun cusver-check (newdir olddir version)
701 "Check that `defcustom's have :version tags where needed.
702 NEWDIR is the current lisp/ directory, OLDDIR is that from the
703 previous release, VERSION is the new version number. A
704 `defcustom' that is only in NEWDIR should have a :version tag.
705 We exclude cases where a `defvar' exists in OLDDIR, since just
706 converting a `defvar' to a `defcustom' does not require
707 a :version bump.
709 Note that a :version tag should also be added if the value of a defcustom
710 changes (in a non-trivial way). This function does not check for that."
711 (interactive (list (read-directory-name "New Lisp directory: " nil nil t)
712 (read-directory-name "Old Lisp directory: " nil nil t)
713 (number-to-string
714 (read-number "New version number: "
715 (string-to-number cusver-new-version)))))
716 (or (file-directory-p (setq newdir (expand-file-name newdir)))
717 (user-error "Directory `%s' not found" newdir))
718 (or (file-directory-p (setq olddir (expand-file-name olddir)))
719 (user-error "Directory `%s' not found" olddir))
720 (setq cusver-new-version version)
721 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
722 (cusver-find-files newdir)))
723 (oldfiles (progn (message "Finding old files with `defcustom's...")
724 (cusver-find-files olddir t)))
725 (newcus (progn (message "Reading new `defcustom's...")
726 (mapcar
727 (lambda (file)
728 (cons file (cusver-scan file))) newfiles)))
729 oldcus result thisfile file)
730 (message "Reading old `defcustom's...")
731 (dolist (file oldfiles)
732 (setq oldcus (append oldcus (cusver-scan file t))))
733 (setq oldcus (append oldcus (cusver-scan-cus-start
734 (expand-file-name "cus-start.el" olddir))))
735 ;; newcus has elements (FILE (VAR VER) ... ).
736 ;; oldcus just (VAR . VER).
737 (message "Checking for version tags...")
738 (dolist (new newcus)
739 (setq file (car new)
740 thisfile
741 (let (missing var)
742 (dolist (cons (cdr new))
743 (or (cdr cons)
744 (assq (setq var (car cons)) oldcus)
745 (push var missing)))
746 (if missing
747 (cons file missing))))
748 (if thisfile
749 (setq result (cons thisfile result))))
750 (message "Checking for version tags... done")
751 (if (not result)
752 (message "No missing :version tags")
753 (pop-to-buffer "*cusver*")
754 (erase-buffer)
755 (insert "These `defcustom's might be missing :version tags:\n\n")
756 (dolist (elem result)
757 (let* ((str (file-relative-name (car elem) newdir))
758 (strlen (length str)))
759 (dolist (var (cdr elem))
760 (insert (format "%s: %s\n" str var))
761 (make-text-button (+ (line-beginning-position 0) strlen 2)
762 (line-end-position 0)
763 'file (car elem)
764 'var var
765 'help-echo "Mouse-2: visit this definition"
766 :type 'cusver-xref)))))))
768 (provide 'admin)
770 ;;; admin.el ends here