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