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