1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001-2017 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 (defun add-release-logs (root version
&optional date
)
32 "Add \"Version VERSION released.\" change log entries in ROOT.
33 Also update the etc/HISTORY file.
34 Root must be the root of an Emacs source tree.
35 Optional argument DATE is the release date, default today."
36 (interactive (list (read-directory-name "Emacs root directory: ")
37 (read-string "Version number: "
38 (format "%s.%s" emacs-major-version
40 (read-string "Release date: "
41 (progn (require 'add-log
)
42 (funcall add-log-time-format nil t
)))))
43 (setq root
(expand-file-name root
))
44 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
45 (user-error "%s doesn't seem to be the root of an Emacs source tree" root
))
46 (let ((clog (expand-file-name "ChangeLog" root
)))
47 (if (file-exists-p clog
)
48 ;; Basic check that a ChangeLog that exists is not your personal one.
49 ;; TODO Perhaps we should move any existing file and unconditionally
50 ;; call make ChangeLog? Or make ChangeLog CHANGELOG=temp and compare
53 (insert-file-contents clog
)
54 (or (re-search-forward "^[ \t]*Copyright.*Free Software" nil t
)
55 (user-error "ChangeLog looks like a personal one - remove it?")))
57 (zerop (call-process "make" nil nil nil
"-C" root
"ChangeLog"))
58 (error "Problem generating ChangeLog"))))
60 (or date
(setq date
(funcall add-log-time-format nil t
)))
61 (let* ((logs (process-lines "find" root
"-name" "ChangeLog"))
62 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
64 (or add-log-full-name
(user-full-name))
65 (or add-log-mailing-address user-mail-address
)
69 (goto-char (point-min))
71 (let ((histfile (expand-file-name "etc/HISTORY" root
)))
72 (unless (file-exists-p histfile
)
73 (error "%s not present" histfile
))
75 (goto-char (point-max))
76 (search-backward "\f")
77 (insert (format "GNU Emacs %s (%s) emacs-%s\n\n" version date version
))))
79 (defun set-version-in-file (root file version rx
)
80 "Subroutine of `set-version' and `set-copyright'."
81 (find-file (expand-file-name file root
))
82 (goto-char (point-min))
83 (setq version
(format "%s" version
))
84 (unless (re-search-forward rx nil
:noerror
)
85 (user-error "Version not found in %s" file
))
86 (if (not (equal version
(match-string 1)))
87 (replace-match version nil nil nil
1)
89 (message "No need to update `%s'" file
)))
91 (defun set-version (root version
)
92 "Set Emacs version to VERSION in relevant files under ROOT.
93 Root must be the root of an Emacs source tree."
95 (read-directory-name "Emacs root directory: " source-directory
)
96 (read-string "Version number: " emacs-version
)))
97 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
98 (user-error "%s doesn't seem to be the root of an Emacs source tree" root
))
99 (message "Setting version numbers...")
100 ;; There's also a "version 3" (standing for GPLv3) at the end of
101 ;; `README', but since `set-version-in-file' only replaces the first
102 ;; occurrence, it won't be replaced.
103 (set-version-in-file root
"README" version
104 (rx (and "version" (1+ space
)
105 (submatch (1+ (in "0-9."))))))
106 (set-version-in-file root
"configure.ac" version
107 (rx (and "AC_INIT" (1+ (not (in ?
,)))
109 (submatch (1+ (in "0-9."))))))
110 (set-version-in-file root
"nt/README.W32" version
111 (rx (and "version" (1+ space
)
112 (submatch (1+ (in "0-9."))))))
113 ;; TODO: msdos could easily extract the version number from
114 ;; configure.ac with sed, rather than duplicating the information.
115 (set-version-in-file root
"msdos/sed2v2.inp" version
116 (rx (and bol
"/^#undef " (1+ not-newline
)
117 "define VERSION" (1+ space
) "\""
118 (submatch (1+ (in "0-9."))))))
119 ;; Major version only.
120 (when (string-match "\\([0-9]\\{2,\\}\\)" version
)
121 (let ((newmajor (match-string 1 version
)))
122 (set-version-in-file root
"src/msdos.c" newmajor
123 (rx (and "Vwindow_system_version" (1+ not-newline
)
124 ?\
( (submatch (1+ (in "0-9"))) ?\
))))
125 (set-version-in-file root
"etc/refcards/ru-refcard.tex" newmajor
126 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
127 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")))
130 (insert-file-contents (expand-file-name "README" root
))
131 (if (re-search-forward "version \\([0-9.]*\\)" nil t
)
132 (version-to-list (match-string 1)))))
133 (oldmajor (if oldversion
(car oldversion
)))
134 (newversion (version-to-list version
))
135 (newmajor (car newversion
))
136 (newshort (format "%s.%s" newmajor
138 (if (eq 2 (length newversion
)) 0 1))))
139 (majorbump (and oldversion
(not (equal oldmajor newmajor
))))
140 (minorbump (and oldversion
(not majorbump
)
141 (not (equal (cadr oldversion
) (cadr newversion
)))))
142 (newsfile (expand-file-name "etc/NEWS" root
))
143 (oldnewsfile (expand-file-name (format "etc/NEWS.%s" oldmajor
) root
)))
144 (unless (> (length newversion
) 2) ; pretest or release candidate?
146 (insert-file-contents newsfile
)
147 (if (re-search-forward "^\\(+++ *\\|--- *\\)$" nil t
)
148 (display-warning 'admin
149 "NEWS file still contains temporary markup.
150 Documentation changes might not have been completed!"))))
152 (not (file-exists-p oldnewsfile
)))
153 (rename-file newsfile oldnewsfile
)
154 (find-file oldnewsfile
) ; to prompt you to commit it
155 (copy-file oldnewsfile newsfile
)
157 (insert-file-contents newsfile
)
158 (re-search-forward "is about changes in Emacs version \\([0-9]+\\)")
159 (replace-match (number-to-string newmajor
) nil nil nil
1)
160 (re-search-forward "^See files \\(NEWS\\)")
161 (replace-match (format "NEWS.%s, NEWS" oldmajor
) nil nil nil
1)
162 (let ((start (line-beginning-position)))
163 (search-forward "in older Emacs versions")
164 (or (equal start
(line-beginning-position))
165 (fill-region start
(line-beginning-position 2))))
166 (re-search-forward "^\f$")
168 (let ((start (point)))
169 (goto-char (point-max))
170 (re-search-backward "^\f$" nil nil
2)
171 (delete-region start
(line-beginning-position 0)))
172 (write-region nil nil newsfile
)))
173 (when (or majorbump minorbump
)
175 (goto-char (point-min))
176 (if (re-search-forward (format "^\\* .*in Emacs %s" newshort
) nil t
)
179 (message "No need to update etc/NEWS"))
180 (goto-char (point-min))
181 (re-search-forward "^\f$")
183 (dolist (s '("Installation Changes" "Startup Changes" "Changes"
185 "Changes in Specialized Modes and Packages"
186 "New Modes and Packages"
187 "Incompatible Lisp Changes"
189 (insert (format "\n\f\n* %s in Emacs %s\n" s newshort
)))
190 (insert (format "\n\f\n* Changes in Emacs %s on \
191 Non-Free Operating Systems\n" newshort
)))
192 ;; Because we skip "bump version" commits when merging between branches.
193 ;; Probably doesn't matter in practice, because NEWS changes
194 ;; will only happen on master anyway.
195 (message "Commit any NEWS changes separately")))
196 (message "Setting version numbers...done"))
198 ;; Note this makes some assumptions about form of short copyright.
199 (defun set-copyright (root copyright
)
200 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
201 Root must be the root of an Emacs source tree."
203 (read-directory-name "Emacs root directory: " nil nil t
)
205 "Short copyright string: "
206 (format "Copyright (C) %s Free Software Foundation, Inc."
207 (format-time-string "%Y")))))
208 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
209 (user-error "%s doesn't seem to be the root of an Emacs source tree" root
))
210 (message "Setting copyrights...")
211 (set-version-in-file root
"configure.ac" copyright
212 (rx (and bol
"copyright" (0+ (not (in ?
\")))
213 ?
\" (submatch (1+ (not (in ?
\")))) ?
\")))
214 (set-version-in-file root
"msdos/sed2v2.inp" copyright
215 (rx (and bol
"/^#undef " (1+ not-newline
)
216 "define COPYRIGHT" (1+ space
)
217 ?
\" (submatch (1+ (not (in ?
\")))) ?
\")))
218 (set-version-in-file root
"lib-src/rcs2log" copyright
219 (rx (and "Copyright" (0+ space
) ?
= (0+ space
)
220 ?
\' (submatch (1+ nonl
)))))
221 (when (string-match "\\([0-9]\\{4\\}\\)" copyright
)
222 (setq copyright
(match-string 1 copyright
))
223 (set-version-in-file root
"etc/refcards/ru-refcard.tex" copyright
224 "\\\\newcommand{\\\\cyear}\\[0\\]\
225 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")
226 (set-version-in-file root
"etc/refcards/emacsver.tex.in" copyright
228 {\\([0-9]\\{4\\}\\)}.+%.+copyright year"))
229 (message "Setting copyrights...done"))
231 ;;; Various bits of magic for generating the web manuals
233 (defun manual-misc-manuals (root)
234 "Return doc/misc manuals as list of strings.
235 ROOT should be the root of an Emacs source tree."
236 ;; Similar to `make -C doc/misc echo-info', but works if unconfigured,
237 ;; and for INFO_TARGETS rather than INFO_INSTALL.
239 (insert-file-contents (expand-file-name "doc/misc/Makefile.in" root
))
240 ;; Should really use expanded value of INFO_TARGETS.
241 (search-forward "INFO_COMMON = ")
242 (let ((start (point)))
244 (while (and (looking-back "\\\\")
245 (zerop (forward-line 1)))
247 (append (split-string (replace-regexp-in-string
248 "\\(\\\\\\|\\.info\\)" ""
249 (buffer-substring start
(point))))
252 ;; TODO report the progress
253 (defun make-manuals (root &optional type
)
254 "Generate the web manuals for the Emacs webpage.
255 ROOT should be the root of an Emacs source tree.
256 Interactively with a prefix argument, prompt for TYPE.
257 Optional argument TYPE is type of output (nil means all)."
258 (interactive (let ((root (read-directory-name "Emacs root directory: "
259 source-directory nil t
)))
261 (if current-prefix-arg
267 (dolist (i '("emacs" "elisp" "eintr") res
)
268 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
269 (push (concat i j
) res
))))
270 (manual-misc-manuals root
)))))))
271 (let* ((dest (expand-file-name "manual" root
))
272 (html-node-dir (expand-file-name "html_node" dest
))
273 (html-mono-dir (expand-file-name "html_mono" dest
))
274 (ps-dir (expand-file-name "ps" dest
))
275 (pdf-dir (expand-file-name "pdf" dest
))
276 (emacs (expand-file-name "doc/emacs/emacs.texi" root
))
277 (emacs-xtra (expand-file-name "doc/emacs/emacs-xtra.texi" root
))
278 (elisp (expand-file-name "doc/lispref/elisp.texi" root
))
279 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root
))
280 (misc (manual-misc-manuals root
)))
281 ;; TODO this makes it non-continuable.
282 ;; Instead, delete the individual dest directory each time.
283 (when (file-directory-p dest
)
284 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest
))
285 (delete-directory dest t
)
286 (user-error "Aborted")))
287 (if (member type
'(nil "emacs" "emacs-node"))
288 (manual-html-node emacs
(expand-file-name "emacs" html-node-dir
)))
289 (if (member type
'(nil "emacs" "emacs-mono"))
290 (manual-html-mono emacs
(expand-file-name "emacs.html" html-mono-dir
)))
291 (when (member type
'(nil "emacs" "emacs-pdf" "pdf"))
292 (manual-pdf emacs
(expand-file-name "emacs.pdf" pdf-dir
))
293 ;; emacs-xtra exists only in pdf/ps format.
294 ;; In other formats it is included in the Emacs manual.
295 (manual-pdf emacs-xtra
(expand-file-name "emacs-xtra.pdf" pdf-dir
)))
296 (when (member type
'(nil "emacs" "emacs-ps" "ps"))
297 (manual-ps emacs
(expand-file-name "emacs.ps" ps-dir
))
298 (manual-ps emacs-xtra
(expand-file-name "emacs-xtra.ps" ps-dir
)))
299 (if (member type
'(nil "elisp" "elisp-node"))
300 (manual-html-node elisp
(expand-file-name "elisp" html-node-dir
)))
301 (if (member type
'(nil "elisp" "elisp-mono"))
302 (manual-html-mono elisp
(expand-file-name "elisp.html" html-mono-dir
)))
303 (if (member type
'(nil "elisp" "elisp-pdf" "pdf"))
304 (manual-pdf elisp
(expand-file-name "elisp.pdf" pdf-dir
)))
305 (if (member type
'(nil "elisp" "elisp-ps" "ps"))
306 (manual-ps elisp
(expand-file-name "elisp.ps" ps-dir
)))
307 (if (member type
'(nil "eintr" "eintr-node"))
308 (manual-html-node eintr
(expand-file-name "eintr" html-node-dir
)))
309 (if (member type
'(nil "eintr" "eintr-node"))
310 (manual-html-mono eintr
(expand-file-name "eintr.html" html-mono-dir
)))
311 (if (member type
'(nil "eintr" "eintr-pdf" "pdf"))
312 (manual-pdf eintr
(expand-file-name "eintr.pdf" pdf-dir
)))
313 (if (member type
'(nil "eintr" "eintr-ps" "ps"))
314 (manual-ps eintr
(expand-file-name "eintr.ps" ps-dir
)))
316 (dolist (manual misc
)
317 (if (member type
`(nil ,manual
"misc"))
318 (manual-misc-html manual root html-node-dir html-mono-dir
)))
319 (message "Manuals created in %s" dest
)))
321 (defconst manual-doctype-string
322 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
323 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
325 (defconst manual-meta-string
326 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
327 <link rev=\"made\" href=\"mailto:bug-gnu-emacs@gnu.org\">
328 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
329 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
330 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
332 (defconst manual-style-string
"<style type=\"text/css\">
333 @import url('/software/emacs/manual.css');\n</style>\n")
335 (defun manual-misc-html (name root html-node-dir html-mono-dir
)
336 ;; Hack to deal with the cases where .texi creates a different .info.
337 ;; Blech. TODO Why not just rename the .texi (or .info) files?
338 (let* ((texiname (cond ((equal name
"ccmode") "cc-mode")
340 (texi (expand-file-name (format "doc/misc/%s.texi" texiname
) root
)))
341 (manual-html-node texi
(expand-file-name name html-node-dir
))
342 (manual-html-mono texi
(expand-file-name (concat name
".html")
345 (defun manual-html-mono (texi-file dest
)
346 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
347 This function also edits the HTML files so that they validate as
348 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
349 the @import directive."
350 (make-directory (or (file-name-directory dest
) ".") t
)
351 (call-process "makeinfo" nil nil nil
353 "-I" (expand-file-name "../emacs"
354 (file-name-directory texi-file
))
355 "-I" (expand-file-name "../misc"
356 (file-name-directory texi-file
))
357 "--html" "--no-split" texi-file
"-o" dest
)
359 (insert-file-contents dest
)
360 (setq buffer-file-name dest
)
361 (manual-html-fix-headers)
362 (manual-html-fix-index-1)
363 (manual-html-fix-index-2 t
)
364 (manual-html-fix-node-div)
365 (goto-char (point-max))
366 (re-search-backward "</body>[\n \t]*</html>")
367 ;; Close the div id="content" that fix-index-1 added.
368 (insert "</div>\n\n")
371 (defun manual-html-node (texi-file dir
)
372 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
373 This function also edits the HTML files so that they validate as
374 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
375 the @import directive."
376 (unless (file-exists-p texi-file
)
377 (user-error "Manual file %s not found" texi-file
))
378 (make-directory dir t
)
379 (call-process "makeinfo" nil nil nil
381 "-I" (expand-file-name "../emacs"
382 (file-name-directory texi-file
))
383 "-I" (expand-file-name "../misc"
384 (file-name-directory texi-file
))
385 "--html" texi-file
"-o" dir
)
386 ;; Loop through the node files, fixing them up.
387 (dolist (f (directory-files dir nil
"\\.html\\'"))
390 (insert-file-contents (expand-file-name f dir
))
391 (setq buffer-file-name
(expand-file-name f dir
))
392 (if (looking-at "<meta http-equiv")
393 ;; Ignore those HTML files that are just redirects.
394 (set-buffer-modified-p nil
)
395 (manual-html-fix-headers)
396 (if (equal f
"index.html")
397 (let (copyright-text)
398 (manual-html-fix-index-1)
399 ;; Move copyright notice to the end.
400 (when (re-search-forward "[ \t]*<p>Copyright ©" nil t
)
401 (setq opoint
(match-beginning 0))
402 (re-search-forward "</blockquote>")
403 (setq copyright-text
(buffer-substring opoint
(point)))
404 (delete-region opoint
(point)))
405 (manual-html-fix-index-2)
407 (insert copyright-text
))
408 ;; Close the div id="content" that fix-index-1 added.
409 (insert "\n</div>\n"))
410 ;; For normal nodes, give the header div a blue bg.
411 (manual-html-fix-node-div t
))
414 (defun manual-pdf (texi-file dest
)
415 "Run texi2pdf on TEXI-FILE, emitting PDF output to DEST."
416 (make-directory (or (file-name-directory dest
) ".") t
)
417 (let ((default-directory (file-name-directory texi-file
)))
418 (call-process "texi2pdf" nil nil nil
419 "-I" "../emacs" "-I" "../misc"
420 texi-file
"-o" dest
)))
422 (defun manual-ps (texi-file dest
)
423 "Generate a PostScript version of TEXI-FILE as DEST."
424 (make-directory (or (file-name-directory dest
) ".") t
)
425 (let ((dvi-dest (concat (file-name-sans-extension dest
) ".dvi"))
426 (default-directory (file-name-directory texi-file
)))
427 ;; FIXME: Use `texi2dvi --ps'? --xfq
428 (call-process "texi2dvi" nil nil nil
429 "-I" "../emacs" "-I" "../misc"
430 texi-file
"-o" dvi-dest
)
431 (call-process "dvips" nil nil nil dvi-dest
"-o" dest
)
432 (delete-file dvi-dest
)
433 (call-process "gzip" nil nil nil dest
)))
435 (defun manual-html-fix-headers ()
436 "Fix up HTML headers for the Emacs manual in the current buffer."
437 (let ((texi5 (search-forward "<!DOCTYPE" nil t
))
439 ;; Texinfo 5 supplies a DOCTYPE.
441 (insert manual-doctype-string
))
442 (search-forward "<head>\n")
443 (insert manual-meta-string
)
444 (search-forward "<meta")
445 (setq opoint
(match-beginning 0))
447 (search-forward "<!--")
448 (goto-char (match-beginning 0))
449 (delete-region opoint
(point))
450 (search-forward "<meta http-equiv=\"Content-Style")
451 (setq opoint
(match-beginning 0)))
452 (search-forward "</head>")
453 (goto-char (match-beginning 0))
454 (delete-region opoint
(point))
455 (insert manual-style-string
)
456 ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink.
457 (when (re-search-forward "<body lang=\"[^\"]+\"" nil t
)
458 (setq opoint
(point))
460 (if (> (point) (1+ opoint
))
461 (delete-region opoint
(1- (point))))
462 (search-backward "</head"))))
464 ;; Texinfo 5 changed these from class = "node" to "header", yay.
465 (defun manual-html-fix-node-div (&optional split
)
466 "Fix up HTML \"node\" divs in the current buffer."
467 (let (opoint div-end type
)
468 (while (re-search-forward "<div class=\"\\(node\\|header\\)\"\\(>\\)" nil t
)
469 (setq type
(match-string 1))
470 ;; NB it is this that makes the bg of non-header cells in the
471 ;; index tables be blue. Is that intended?
472 ;; Also, if you don't remove the <hr>, the color of the first
473 ;; row in the table will be wrong.
474 ;; This all seems rather odd to me...
475 (replace-match " style=\"background-color:#DDDDFF\">" t t nil
2)
476 (setq opoint
(point))
477 (when (or split
(equal type
"node"))
478 ;; In Texinfo 4, the <hr> (and anchor) comes after the <div>.
479 (re-search-forward "</div>")
480 (setq div-end
(if (equal type
"node")
482 (line-end-position 2)))
484 (if (search-forward "<hr>" div-end
'move
)
485 (replace-match "" t t
)
486 (if split
(forward-line -
1))))
487 ;; In Texinfo 5, the <hr> (and anchor) comes before the <div> (?).
488 ;; Except in split output, where it comes on the line after
489 ;; the <div>. But only sometimes. I have no clue what the
490 ;; logic of where it goes is.
491 (when (equal type
"header")
493 (when (re-search-backward "^<hr>$" (line-beginning-position -
3) t
)
495 (goto-char opoint
))))))
498 (defun manual-html-fix-index-1 ()
499 "Remove the h1 header, and the short and long contents lists.
500 Also start a \"content\" div."
502 (re-search-forward "<body.*>\n")
503 (setq opoint
(match-end 0))
504 ;; FIXME? Fragile if a Texinfo 5 document does not use @top.
505 (or (re-search-forward "<h1 class=\"top\"" nil t
) ; Texinfo 5
506 (search-forward "<h2 class=\""))
507 (goto-char (match-beginning 0))
508 (delete-region opoint
(point))
509 ;; NB caller must close this div.
510 (insert "<div id=\"content\" class=\"inner\">\n\n")))
512 (defun manual-html-fix-index-2 (&optional table-workaround
)
513 "Replace the index list in the current buffer with a HTML table.
514 Leave point after the table."
515 (if (re-search-forward "<table class=\"menu\"\\(.*\\)>" nil t
)
516 ;; Texinfo 5 already uses a table. Tweak it a bit.
518 (replace-match " style=\"float:left\" width=\"100%\"" nil t nil
1)
521 (cond ((re-search-forward "<tr><td.*• \\(<a.*</a>\\)\
522 :</td><td> </td><td[^>]*>\\(.*\\)" (line-end-position) t
)
523 (replace-match (format "<tr><td%s>\\1</td>\n<td>\\2"
525 " bgcolor=\"white\"" "")))
526 (search-forward "</td></tr>")
528 ((looking-at "<tr><th.*<pre class=\"menu-comment\">\n")
529 (replace-match "<tr><th colspan=\"2\" align=\"left\" \
530 style=\"text-align:left\">")
531 (search-forward "</pre></th></tr>")
532 (replace-match "</th></tr>\n"))
533 ;; Not all manuals have the detailed menu.
534 ;; If it is there, split it into a separate table.
535 ((re-search-forward "<tr>.*The Detailed Node Listing *"
536 (line-end-position) t
)
537 (setq opoint
(match-beginning 0))
538 (while (and (looking-at " *—")
539 (zerop (forward-line 1))))
540 (delete-region opoint
(point))
541 (insert "</table>\n\n\
542 <h2>Detailed Node Listing</h2>\n\n<p>")
544 ;; The Emacs and Elisp manual have some text at the
545 ;; start of the detailed menu that is not part of the menu.
546 ;; Other manuals do not.
547 (if (re-search-forward "in one step:" (line-end-position 3) t
)
550 (search-forward "</pre></th></tr>")
551 (delete-region (match-beginning 0) (match-end 0))
553 (or (looking-at "^$") (error "Parse error 1"))
555 (if (looking-at "^$") (error "Parse error 2"))
557 (or (looking-at "^$") (error "Parse error 3"))
559 (insert "<table class=\"menu\" style=\"float:left\" width=\"100%\">\n\
560 <tr><th colspan=\"2\" align=\"left\" style=\"text-align:left\">\n")
562 (insert "</th></tr>")
564 ((looking-at ".*</table")
567 (let (done open-td tag desc
)
568 ;; Convert the list that Makeinfo made into a table.
569 (or (search-forward "<ul class=\"menu\">" nil t
)
570 ;; FIXME? The following search seems dangerously lax.
571 (search-forward "<ul>"))
572 (replace-match "<table style=\"float:left\" width=\"100%\">")
576 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
577 (looking-at "<li>\\(<a.+</a>\\)$"))
578 (setq tag
(match-string 1))
579 (setq desc
(match-string 2))
580 (replace-match "" t t
)
584 (skip-chars-backward " ")
585 (delete-region (point) (line-end-position))
586 (insert "</td>\n </tr>")))
589 ;; This works around a Firefox bug in the mono file.
590 (insert "<td bgcolor=\"white\">")
592 (insert tag
"</td>\n <td>" (or desc
""))
594 ((eq (char-after) ?
\n)
596 ;; Negate the following `forward-line'.
598 ((looking-at "<!-- ")
599 (search-forward "-->"))
600 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
601 (replace-match " </td></tr></table>\n
602 <h3>Detailed Node Listing</h3>\n\n" t t
)
603 (search-forward "<p>")
605 ;; The Emacs and Elisp manual have some text at the
606 ;; start of the detailed menu that is not part of the menu.
607 ;; Other manuals do not.
608 (if (looking-at "Here are some other nodes")
609 (search-forward "<p>"))
610 (goto-char (match-beginning 0))
611 (skip-chars-backward "\n ")
613 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
614 ((looking-at "</li></ul>")
615 (replace-match "" t t
))
617 (replace-match "" t t
)
619 (insert " </td></tr>")
622 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
623 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t
)
624 (replace-match " </th></tr>")))
625 ((looking-at "[ \t]*</ul>[ \t]*$")
628 " </td></tr>\n</table>"
633 (error "Parse error in %s"
634 (file-name-nondirectory buffer-file-name
)))
640 (defconst make-manuals-dist-output-variables
641 `(("@\\(top_\\)?srcdir@" .
".") ; top_srcdir is wrong, but not used
642 ("^\\(\\(?:texinfo\\|buildinfo\\|emacs\\)dir *=\\).*" .
"\\1 .")
643 ("^\\(clean:.*\\)" .
"\\1 infoclean")
644 ("@MAKEINFO@" .
"makeinfo")
645 ("@MKDIR_P@" .
"mkdir -p")
646 ("@INFO_EXT@" .
".info")
648 ("@SHELL@" .
"/bin/bash")
649 ("@prefix@" .
"/usr/local")
650 ("@datarootdir@" .
"${prefix}/share")
651 ("@datadir@" .
"${datarootdir}")
652 ("@PACKAGE_TARNAME@" .
"emacs")
653 ("@docdir@" .
"${datarootdir}/doc/${PACKAGE_TARNAME}")
654 ("@\\(dvi\\|html\\|pdf\\|ps\\)dir@" .
"${docdir}")
655 ("@GZIP_PROG@" .
"gzip")
656 ("@INSTALL@" .
"install -c")
657 ("@INSTALL_DATA@" .
"${INSTALL} -m 644")
658 ("@configure_input@" .
""))
659 "Alist of (REGEXP . REPLACEMENT) pairs for `make-manuals-dist'.")
661 (defun make-manuals-dist--1 (root type
)
662 "Subroutine of `make-manuals-dist'."
663 (let* ((dest (expand-file-name "manual" root
))
664 (default-directory (progn (make-directory dest t
)
665 (file-name-as-directory dest
)))
666 (version (with-temp-buffer
667 (insert-file-contents "../doc/emacs/emacsver.texi")
668 (re-search-forward "@set EMACSVER \\([0-9.]+\\)")
670 (stem (format "emacs-%s-%s" (if (equal type
"emacs") "manual" type
)
672 (tarfile (format "%s.tar" stem
)))
673 (message "Doing %s..." type
)
674 (if (file-directory-p stem
)
675 (delete-directory stem t
))
676 (make-directory stem
)
677 (copy-file "../doc/misc/texinfo.tex" stem
)
678 (or (equal type
"emacs") (copy-file "../doc/emacs/emacsver.texi" stem
))
679 (dolist (file (directory-files (format "../doc/%s" type
) t
))
680 (if (or (string-match-p "\\(\\.texi\\'\\|/README\\'\\)" file
)
681 (and (equal type
"lispintro")
682 (string-match-p "\\.\\(eps\\|pdf\\)\\'" file
)))
683 (copy-file file stem
)))
685 (let ((outvars make-manuals-dist-output-variables
))
686 (push `("@version@" .
,version
) outvars
)
687 (insert-file-contents (format "../doc/%s/Makefile.in" type
))
688 (dolist (cons outvars
)
689 (while (re-search-forward (car cons
) nil t
)
690 (replace-match (cdr cons
) t
))
691 (goto-char (point-min))))
693 (while (re-search-forward "@[a-zA-Z_]+@" nil t
)
695 (message "Unexpanded: %s" (match-string 0)))
696 (if ats
(error "Unexpanded configure variables in Makefile?")))
697 (write-region nil nil
(expand-file-name (format "%s/Makefile" stem
))
699 (call-process "tar" nil nil nil
"-cf" tarfile stem
)
700 (delete-directory stem t
)
701 (message "...created %s" tarfile
)))
703 ;; Does anyone actually use these tarfiles?
704 (defun make-manuals-dist (root &optional type
)
705 "Make the standalone manual source tarfiles for the Emacs webpage.
706 ROOT should be the root of an Emacs source tree.
707 Interactively with a prefix argument, prompt for TYPE.
708 Optional argument TYPE is type of output (nil means all)."
709 (interactive (let ((root (read-directory-name "Emacs root directory: "
710 source-directory nil t
)))
712 (if current-prefix-arg
715 '("emacs" "lispref" "lispintro" "misc"))))))
716 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
717 (user-error "%s doesn't seem to be the root of an Emacs source tree" root
))
718 (dolist (m '("emacs" "lispref" "lispintro" "misc"))
719 (if (member type
(list nil m
))
720 (make-manuals-dist--1 root m
))))
723 ;; Stuff to check new `defcustom's got :version tags.
724 ;; Adapted from check-declare.el.
726 (defun cusver-find-files (root &optional old
)
727 "Find .el files beneath directory ROOT that contain `defcustom's.
728 If optional OLD is non-nil, also include `defvar's."
729 (process-lines find-program root
732 "-l" "-E" (format "^[ \\t]*\\(def%s"
733 (if old
"(custom|var)"
738 (defvar cusver-new-version
(format "%s.%s" emacs-major-version
739 (1+ emacs-minor-version
))
740 "Version number that new `defcustom's should have.")
742 (defun cusver-scan (file &optional old
)
743 "Scan FILE for `defcustom' calls.
744 Return a list with elements of the form (VAR . VER),
745 This means that FILE contains a defcustom for variable VAR, with
746 a :version tag having value VER (may be nil).
747 If optional argument OLD is non-nil, also scan for `defvar's."
748 (let ((m (format "Scanning %s..." file
))
749 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
750 (if old
"\\(custom\\|var\\)" "\\(custom\\|group\\)")))
751 alist var ver form glist grp
)
754 (insert-file-contents file
)
755 ;; FIXME we could theoretically be inside a string.
756 (while (re-search-forward re nil
:noerror
)
757 (goto-char (match-beginning 1))
758 (if (and (setq form
(ignore-errors (read (current-buffer))))
759 (setq var
(car-safe (cdr-safe form
)))
760 ;; Exclude macros, eg (defcustom ,varname ...).
763 ;; FIXME It should be cus-test-apropos that does this.
765 (equal "custom" (match-string 2))
766 (not (memq :type form
))
768 'custom
(format-message "Missing type in: `%s'" form
)))
769 (setq ver
(car (cdr-safe (memq :version form
))))
770 (if (equal "group" (match-string 2))
771 ;; Group :version could be old.
772 (if (equal ver cusver-new-version
)
773 (setq glist
(cons (cons var ver
) glist
)))
774 ;; If it specifies a group and the whole group has a
775 ;; version. use that.
777 (setq grp
(car (cdr-safe (memq :group form
))))
779 (setq grp
(car (cdr-safe grp
))) ; (quote foo) -> foo
780 (setq ver
(assq grp glist
))))
781 (setq alist
(cons (cons var ver
) alist
))))
782 (if form
(format-message "Malformed defcustom: `%s'" form
)))))
786 (defun cusver-scan-cus-start (file)
787 "Scan cus-start.el and return an alist with elements (VAR . VER)."
788 (if (file-readable-p file
)
790 (insert-file-contents file
)
791 (when (search-forward "(let ((all '(" nil t
)
794 (dolist (elem (ignore-errors (read (current-buffer))))
795 (when (symbolp (setq var
(car-safe elem
)))
796 (or (stringp (setq ver
(nth 3 elem
)))
798 (setq alist
(cons (cons var ver
) alist
))))
801 (define-button-type 'cusver-xref
'action
#'cusver-goto-xref
)
803 (defun cusver-goto-xref (button)
804 "Jump to a Lisp file for the BUTTON at point."
805 (let ((file (button-get button
'file
))
806 (var (button-get button
'var
)))
807 (if (not (file-readable-p file
))
808 (message "Cannot read `%s'" file
)
809 (with-current-buffer (find-file-noselect file
)
810 (goto-char (point-min))
811 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var
) nil t
)
812 (message "Unable to locate defcustom"))
813 (pop-to-buffer (current-buffer))))))
815 ;; You should probably at least do a grep over the old directory
816 ;; to check the results of this look sensible.
817 ;; TODO Check cus-start if something moved from C to Lisp.
818 ;; TODO Handle renamed things with aliases to the old names.
819 (defun cusver-check (newdir olddir version
)
820 "Check that `defcustom's have :version tags where needed.
821 NEWDIR is the current lisp/ directory, OLDDIR is that from the
822 previous release, VERSION is the new version number. A
823 `defcustom' that is only in NEWDIR should have a :version tag.
824 We exclude cases where a `defvar' exists in OLDDIR, since just
825 converting a `defvar' to a `defcustom' does not require
828 Note that a :version tag should also be added if the value of a defcustom
829 changes (in a non-trivial way). This function does not check for that."
830 (interactive (list (read-directory-name "New Lisp directory: " nil nil t
)
831 (read-directory-name "Old Lisp directory: " nil nil t
)
833 (read-number "New version number: "
834 (string-to-number cusver-new-version
)))))
835 (or (file-directory-p (setq newdir
(expand-file-name newdir
)))
836 (user-error "Directory `%s' not found" newdir
))
837 (or (file-directory-p (setq olddir
(expand-file-name olddir
)))
838 (user-error "Directory `%s' not found" olddir
))
839 (setq cusver-new-version version
)
840 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
841 (cusver-find-files newdir
)))
842 (oldfiles (progn (message "Finding old files with `defcustom's...")
843 (cusver-find-files olddir t
)))
844 (newcus (progn (message "Reading new `defcustom's...")
847 (cons file
(cusver-scan file
))) newfiles
)))
848 oldcus result thisfile file
)
849 (message "Reading old `defcustom's...")
850 (dolist (file oldfiles
)
851 (setq oldcus
(append oldcus
(cusver-scan file t
))))
852 (setq oldcus
(append oldcus
(cusver-scan-cus-start
853 (expand-file-name "cus-start.el" olddir
))))
854 ;; newcus has elements (FILE (VAR VER) ... ).
855 ;; oldcus just (VAR . VER).
856 (message "Checking for version tags...")
861 (dolist (cons (cdr new
))
863 (assq (setq var
(car cons
)) oldcus
)
866 (cons file missing
))))
868 (setq result
(cons thisfile result
))))
869 (message "Checking for version tags... done")
871 (message "No missing :version tags")
872 (pop-to-buffer "*cusver*")
874 (insert (substitute-command-keys
875 "These `defcustom's might be missing :version tags:\n\n"))
876 (dolist (elem result
)
877 (let* ((str (file-relative-name (car elem
) newdir
))
878 (strlen (length str
)))
879 (dolist (var (cdr elem
))
880 (insert (format "%s: %s\n" str var
))
881 (make-text-button (+ (line-beginning-position 0) strlen
2)
882 (line-end-position 0)
885 'help-echo
"Mouse-2: visit this definition"
886 :type
'cusver-xref
)))))))
890 ;;; admin.el ends here