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