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