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