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 <https://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 ("@AM_DEFAULT_VERBOSITY@" .
"0")
661 ("@AM_DEFAULT_V@" .
"${AM_DEFAULT_VERBOSITY}"))
662 "Alist of (REGEXP . REPLACEMENT) pairs for `make-manuals-dist'.")
664 (defun make-manuals-dist--1 (root type
)
665 "Subroutine of `make-manuals-dist'."
666 (let* ((dest (expand-file-name "manual" root
))
667 (default-directory (progn (make-directory dest t
)
668 (file-name-as-directory dest
)))
669 (version (with-temp-buffer
670 (insert-file-contents "../doc/emacs/emacsver.texi")
671 (re-search-forward "@set EMACSVER \\([0-9.]+\\)")
673 (stem (format "emacs-%s-%s" (if (equal type
"emacs") "manual" type
)
675 (tarfile (format "%s.tar" stem
)))
676 (message "Doing %s..." type
)
677 (if (file-directory-p stem
)
678 (delete-directory stem t
))
679 (make-directory stem
)
680 (copy-file "../doc/misc/texinfo.tex" stem
)
681 (unless (equal type
"emacs")
682 (copy-file "../doc/emacs/emacsver.texi" stem
)
683 (copy-file "../doc/emacs/docstyle.texi" stem
))
684 (dolist (file (directory-files (format "../doc/%s" type
) t
))
685 (if (or (string-match-p "\\(\\.texi\\'\\|/README\\'\\)" file
)
686 (and (equal type
"lispintro")
687 (string-match-p "\\.\\(eps\\|pdf\\)\\'" file
)))
688 (copy-file file stem
)))
690 (let ((outvars make-manuals-dist-output-variables
))
691 (push `("@version@" .
,version
) outvars
)
692 (insert-file-contents (format "../doc/%s/Makefile.in" type
))
693 (dolist (cons outvars
)
694 (while (re-search-forward (car cons
) nil t
)
695 (replace-match (cdr cons
) t
))
696 (goto-char (point-min))))
698 (while (re-search-forward "@[a-zA-Z_]+@" nil t
)
700 (message "Unexpanded: %s" (match-string 0)))
701 (if ats
(error "Unexpanded configure variables in Makefile?")))
702 (write-region nil nil
(expand-file-name (format "%s/Makefile" stem
))
704 (call-process "tar" nil nil nil
"-cf" tarfile stem
)
705 (delete-directory stem t
)
706 (message "...created %s" tarfile
)))
708 ;; Does anyone actually use these tarfiles?
709 (defun make-manuals-dist (root &optional type
)
710 "Make the standalone manual source tarfiles for the Emacs webpage.
711 ROOT should be the root of an Emacs source tree.
712 Interactively with a prefix argument, prompt for TYPE.
713 Optional argument TYPE is type of output (nil means all)."
714 (interactive (let ((root (read-directory-name "Emacs root directory: "
715 source-directory nil t
)))
717 (if current-prefix-arg
720 '("emacs" "lispref" "lispintro" "misc"))))))
721 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
722 (user-error "%s doesn't seem to be the root of an Emacs source tree" root
))
723 (dolist (m '("emacs" "lispref" "lispintro" "misc"))
724 (if (member type
(list nil m
))
725 (make-manuals-dist--1 root m
))))
728 ;; Stuff to check new `defcustom's got :version tags.
729 ;; Adapted from check-declare.el.
731 (defun cusver-find-files (root &optional old
)
732 "Find .el files beneath directory ROOT that contain `defcustom's.
733 If optional OLD is non-nil, also include `defvar's."
734 (process-lines find-program root
737 "-l" "-E" (format "^[ \\t]*\\(def%s"
738 (if old
"(custom|var)"
743 (defvar cusver-new-version
(format "%s.%s" emacs-major-version
744 (1+ emacs-minor-version
))
745 "Version number that new `defcustom's should have.")
747 (defun cusver-scan (file &optional old
)
748 "Scan FILE for `defcustom' calls.
749 Return a list with elements of the form (VAR . VER),
750 This means that FILE contains a defcustom for variable VAR, with
751 a :version tag having value VER (may be nil).
752 If optional argument OLD is non-nil, also scan for `defvar's."
753 (let ((m (format "Scanning %s..." file
))
754 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
755 (if old
"\\(custom\\|var\\)" "\\(custom\\|group\\)")))
756 alist var ver form glist grp
)
759 (insert-file-contents file
)
760 ;; FIXME we could theoretically be inside a string.
761 (while (re-search-forward re nil
:noerror
)
762 (goto-char (match-beginning 1))
763 (if (and (setq form
(ignore-errors (read (current-buffer))))
764 (setq var
(car-safe (cdr-safe form
)))
765 ;; Exclude macros, eg (defcustom ,varname ...).
768 ;; FIXME It should be cus-test-apropos that does this.
770 (equal "custom" (match-string 2))
771 (not (memq :type form
))
773 'custom
(format-message "Missing type in: `%s'" form
)))
774 (setq ver
(car (cdr-safe (memq :version form
))))
775 (if (equal "group" (match-string 2))
776 ;; Group :version could be old.
777 (if (equal ver cusver-new-version
)
778 (setq glist
(cons (cons var ver
) glist
)))
779 ;; If it specifies a group and the whole group has a
780 ;; version. use that.
782 (setq grp
(car (cdr-safe (memq :group form
))))
784 (setq grp
(car (cdr-safe grp
))) ; (quote foo) -> foo
785 (setq ver
(assq grp glist
))))
786 (setq alist
(cons (cons var ver
) alist
))))
787 (if form
(format-message "Malformed defcustom: `%s'" form
)))))
791 (defun cusver-scan-cus-start (file)
792 "Scan cus-start.el and return an alist with elements (VAR . VER)."
793 (if (file-readable-p file
)
795 (insert-file-contents file
)
796 (when (search-forward "(let ((all '(" nil t
)
799 (dolist (elem (ignore-errors (read (current-buffer))))
800 (when (symbolp (setq var
(car-safe elem
)))
801 (or (stringp (setq ver
(nth 3 elem
)))
803 (setq alist
(cons (cons var ver
) alist
))))
806 (define-button-type 'cusver-xref
'action
#'cusver-goto-xref
)
808 (defun cusver-goto-xref (button)
809 "Jump to a Lisp file for the BUTTON at point."
810 (let ((file (button-get button
'file
))
811 (var (button-get button
'var
)))
812 (if (not (file-readable-p file
))
813 (message "Cannot read `%s'" file
)
814 (with-current-buffer (find-file-noselect file
)
815 (goto-char (point-min))
816 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var
) nil t
)
817 (message "Unable to locate defcustom"))
818 (pop-to-buffer (current-buffer))))))
820 ;; You should probably at least do a grep over the old directory
821 ;; to check the results of this look sensible.
822 ;; TODO Check cus-start if something moved from C to Lisp.
823 ;; TODO Handle renamed things with aliases to the old names.
824 (defun cusver-check (newdir olddir version
)
825 "Check that `defcustom's have :version tags where needed.
826 NEWDIR is the current lisp/ directory, OLDDIR is that from the
827 previous release, VERSION is the new version number. A
828 `defcustom' that is only in NEWDIR should have a :version tag.
829 We exclude cases where a `defvar' exists in OLDDIR, since just
830 converting a `defvar' to a `defcustom' does not require
833 Note that a :version tag should also be added if the value of a defcustom
834 changes (in a non-trivial way). This function does not check for that."
835 (interactive (list (read-directory-name "New Lisp directory: " nil nil t
)
836 (read-directory-name "Old Lisp directory: " nil nil t
)
838 (read-number "New version number: "
839 (string-to-number cusver-new-version
)))))
840 (or (file-directory-p (setq newdir
(expand-file-name newdir
)))
841 (user-error "Directory `%s' not found" newdir
))
842 (or (file-directory-p (setq olddir
(expand-file-name olddir
)))
843 (user-error "Directory `%s' not found" olddir
))
844 (setq cusver-new-version version
)
845 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
846 (cusver-find-files newdir
)))
847 (oldfiles (progn (message "Finding old files with `defcustom's...")
848 (cusver-find-files olddir t
)))
849 (newcus (progn (message "Reading new `defcustom's...")
852 (cons file
(cusver-scan file
))) newfiles
)))
853 oldcus result thisfile file
)
854 (message "Reading old `defcustom's...")
855 (dolist (file oldfiles
)
856 (setq oldcus
(append oldcus
(cusver-scan file t
))))
857 (setq oldcus
(append oldcus
(cusver-scan-cus-start
858 (expand-file-name "cus-start.el" olddir
))))
859 ;; newcus has elements (FILE (VAR VER) ... ).
860 ;; oldcus just (VAR . VER).
861 (message "Checking for version tags...")
866 (dolist (cons (cdr new
))
868 (assq (setq var
(car cons
)) oldcus
)
871 (cons file missing
))))
873 (setq result
(cons thisfile result
))))
874 (message "Checking for version tags... done")
876 (message "No missing :version tags")
877 (pop-to-buffer "*cusver*")
879 (insert (substitute-command-keys
880 "These `defcustom's might be missing :version tags:\n\n"))
881 (dolist (elem result
)
882 (let* ((str (file-relative-name (car elem
) newdir
))
883 (strlen (length str
)))
884 (dolist (var (cdr elem
))
885 (insert (format "%s: %s\n" str var
))
886 (make-text-button (+ (line-beginning-position 0) strlen
2)
887 (line-end-position 0)
890 'help-echo
"Mouse-2: visit this definition"
891 :type
'cusver-xref
)))))))
895 ;;; admin.el ends here