Remove unused local variable
[emacs.git] / admin / admin.el
blobdab61bb916613fb17b223890f6fb31c3ccd9ba9e
1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001-2018 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/>.
20 ;;; Commentary:
22 ;; add-release-logs Add ``Version X released'' change log entries.
23 ;; set-version Change Emacs version number in source tree.
24 ;; set-copyright Change Emacs short copyright string (eg as
25 ;; printed by --version) in source tree.
27 ;;; Code:
29 (defvar add-log-time-format) ; in add-log
31 (defun add-release-logs (root version &optional date)
32 "Add \"Version VERSION released.\" change log entries in ROOT.
33 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
39 emacs-minor-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
51 ;; with the existing?
52 (with-temp-buffer
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?")))
56 (or
57 (zerop (call-process "make" nil nil nil "-C" root "ChangeLog"))
58 (error "Problem generating ChangeLog"))))
59 (require 'add-log)
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"
63 date
64 (or add-log-full-name (user-full-name))
65 (or add-log-mailing-address user-mail-address)
66 version)))
67 (dolist (log logs)
68 (find-file log)
69 (goto-char (point-min))
70 (insert entry)))
71 (let ((histfile (expand-file-name "etc/HISTORY" root)))
72 (unless (file-exists-p histfile)
73 (error "%s not present" histfile))
74 (find-file 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)
88 (kill-buffer)
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."
94 (interactive (list
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 ?,)))
108 ?, (0+ space)
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 PACKAGE_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")))
128 (let* ((oldversion
129 (with-temp-buffer
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
137 (+ (cadr newversion)
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?
145 (with-temp-buffer
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!"))))
151 (when (and majorbump
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)
156 (with-temp-buffer
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 (unless (save-match-data
162 (when (looking-at "\\(\\..*\\), \\(\\.\\.\\.\\|…\\)")
163 (replace-match
164 (format ".%s, NEWS.%s" oldmajor (1- oldmajor))
165 nil nil nil 1)
167 (replace-match (format "NEWS.%s, NEWS" oldmajor) nil nil nil 1)
168 (let ((start (line-beginning-position)))
169 (search-forward "in older Emacs versions")
170 (or (equal start (line-beginning-position))
171 (fill-region start (line-beginning-position 2)))))
172 (re-search-forward "^\f$")
173 (forward-line -1)
174 (let ((start (point)))
175 (goto-char (point-max))
176 (re-search-backward "^\f$" nil nil 2)
177 (delete-region start (line-beginning-position 0)))
178 (write-region nil nil newsfile)))
179 (when (or majorbump minorbump)
180 (find-file newsfile)
181 (goto-char (point-min))
182 (if (re-search-forward (format "^\\* .*in Emacs %s" newshort) nil t)
183 (progn
184 (kill-buffer)
185 (message "No need to update etc/NEWS"))
186 (goto-char (point-min))
187 (re-search-forward "^\f$")
188 (forward-line -1)
189 (dolist (s '("Installation Changes" "Startup Changes" "Changes"
190 "Editing Changes"
191 "Changes in Specialized Modes and Packages"
192 "New Modes and Packages"
193 "Incompatible Lisp Changes"
194 "Lisp Changes"))
195 (insert (format "\n\f\n* %s in Emacs %s\n" s newshort)))
196 (insert (format "\n\f\n* Changes in Emacs %s on \
197 Non-Free Operating Systems\n" newshort)))
198 ;; Because we skip "bump version" commits when merging between branches.
199 ;; Probably doesn't matter in practice, because NEWS changes
200 ;; will only happen on master anyway.
201 (message "Commit any NEWS changes separately")))
202 (message "Setting version numbers...done"))
204 ;; Note this makes some assumptions about form of short copyright.
205 (defun set-copyright (root copyright)
206 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
207 Root must be the root of an Emacs source tree."
208 (interactive (list
209 (read-directory-name "Emacs root directory: " nil nil t)
210 (read-string
211 "Short copyright string: "
212 (format "Copyright (C) %s Free Software Foundation, Inc."
213 (format-time-string "%Y")))))
214 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
215 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
216 (message "Setting copyrights...")
217 (set-version-in-file root "configure.ac" copyright
218 (rx (and bol "copyright" (0+ (not (in ?\")))
219 ?\" (submatch (1+ (not (in ?\")))) ?\")))
220 (set-version-in-file root "msdos/sed2v2.inp" copyright
221 (rx (and bol "/^#undef " (1+ not-newline)
222 "define COPYRIGHT" (1+ space)
223 ?\" (submatch (1+ (not (in ?\")))) ?\")))
224 (set-version-in-file root "lib-src/rcs2log" copyright
225 (rx (and "Copyright" (0+ space) ?= (0+ space)
226 ?\' (submatch (1+ nonl)))))
227 (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
228 (setq copyright (match-string 1 copyright))
229 (set-version-in-file root "etc/refcards/ru-refcard.tex" copyright
230 "\\\\newcommand{\\\\cyear}\\[0\\]\
231 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")
232 (set-version-in-file root "etc/refcards/emacsver.tex.in" copyright
233 "\\\\def\\\\year\
234 {\\([0-9]\\{4\\}\\)}.+%.+copyright year"))
235 (message "Setting copyrights...done"))
237 ;;; Various bits of magic for generating the web manuals
239 (defun manual-misc-manuals (root)
240 "Return doc/misc manuals as list of strings.
241 ROOT should be the root of an Emacs source tree."
242 ;; Similar to `make -C doc/misc echo-info', but works if unconfigured,
243 ;; and for INFO_TARGETS rather than INFO_INSTALL.
244 (with-temp-buffer
245 (insert-file-contents (expand-file-name "doc/misc/Makefile.in" root))
246 ;; Should really use expanded value of INFO_TARGETS.
247 (search-forward "INFO_COMMON = ")
248 (let ((start (point)))
249 (end-of-line)
250 (while (and (looking-back "\\\\")
251 (zerop (forward-line 1)))
252 (end-of-line))
253 (append (split-string (replace-regexp-in-string
254 "\\(\\\\\\|\\.info\\)" ""
255 (buffer-substring start (point))))
256 '("efaq-w32")))))
258 ;; TODO report the progress
259 (defun make-manuals (root &optional type)
260 "Generate the web manuals for the Emacs webpage.
261 ROOT should be the root of an Emacs source tree.
262 Interactively with a prefix argument, prompt for TYPE.
263 Optional argument TYPE is type of output (nil means all)."
264 (interactive (let ((root (read-directory-name "Emacs root directory: "
265 source-directory nil t)))
266 (list root
267 (if current-prefix-arg
268 (completing-read
269 "Type: "
270 (append
271 '("misc" "pdf" "ps")
272 (let (res)
273 (dolist (i '("emacs" "elisp" "eintr") res)
274 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
275 (push (concat i j) res))))
276 (manual-misc-manuals root)))))))
277 (let* ((dest (expand-file-name "manual" root))
278 (html-node-dir (expand-file-name "html_node" dest))
279 (html-mono-dir (expand-file-name "html_mono" dest))
280 (ps-dir (expand-file-name "ps" dest))
281 (pdf-dir (expand-file-name "pdf" dest))
282 (emacs (expand-file-name "doc/emacs/emacs.texi" root))
283 (emacs-xtra (expand-file-name "doc/emacs/emacs-xtra.texi" root))
284 (elisp (expand-file-name "doc/lispref/elisp.texi" root))
285 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root))
286 (misc (manual-misc-manuals root)))
287 ;; TODO this makes it non-continuable.
288 ;; Instead, delete the individual dest directory each time.
289 (when (file-directory-p dest)
290 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest))
291 (delete-directory dest t)
292 (user-error "Aborted")))
293 (if (member type '(nil "emacs" "emacs-node"))
294 (manual-html-node emacs (expand-file-name "emacs" html-node-dir)))
295 (if (member type '(nil "emacs" "emacs-mono"))
296 (manual-html-mono emacs (expand-file-name "emacs.html" html-mono-dir)))
297 (when (member type '(nil "emacs" "emacs-pdf" "pdf"))
298 (manual-pdf emacs (expand-file-name "emacs.pdf" pdf-dir))
299 ;; emacs-xtra exists only in pdf/ps format.
300 ;; In other formats it is included in the Emacs manual.
301 (manual-pdf emacs-xtra (expand-file-name "emacs-xtra.pdf" pdf-dir)))
302 (when (member type '(nil "emacs" "emacs-ps" "ps"))
303 (manual-ps emacs (expand-file-name "emacs.ps" ps-dir))
304 (manual-ps emacs-xtra (expand-file-name "emacs-xtra.ps" ps-dir)))
305 (if (member type '(nil "elisp" "elisp-node"))
306 (manual-html-node elisp (expand-file-name "elisp" html-node-dir)))
307 (if (member type '(nil "elisp" "elisp-mono"))
308 (manual-html-mono elisp (expand-file-name "elisp.html" html-mono-dir)))
309 (if (member type '(nil "elisp" "elisp-pdf" "pdf"))
310 (manual-pdf elisp (expand-file-name "elisp.pdf" pdf-dir)))
311 (if (member type '(nil "elisp" "elisp-ps" "ps"))
312 (manual-ps elisp (expand-file-name "elisp.ps" ps-dir)))
313 (if (member type '(nil "eintr" "eintr-node"))
314 (manual-html-node eintr (expand-file-name "eintr" html-node-dir)))
315 (if (member type '(nil "eintr" "eintr-node"))
316 (manual-html-mono eintr (expand-file-name "eintr.html" html-mono-dir)))
317 (if (member type '(nil "eintr" "eintr-pdf" "pdf"))
318 (manual-pdf eintr (expand-file-name "eintr.pdf" pdf-dir)))
319 (if (member type '(nil "eintr" "eintr-ps" "ps"))
320 (manual-ps eintr (expand-file-name "eintr.ps" ps-dir)))
321 ;; Misc manuals
322 (dolist (manual misc)
323 (if (member type `(nil ,manual "misc"))
324 (manual-misc-html manual root html-node-dir html-mono-dir)))
325 (message "Manuals created in %s" dest)))
327 (defconst manual-doctype-string
328 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
329 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
331 (defconst manual-meta-string
332 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
333 <link rev=\"made\" href=\"mailto:bug-gnu-emacs@gnu.org\">
334 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
335 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
336 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
338 (defconst manual-style-string "<style type=\"text/css\">
339 @import url('/software/emacs/manual.css');\n</style>\n")
341 (defun manual-misc-html (name root html-node-dir html-mono-dir)
342 ;; Hack to deal with the cases where .texi creates a different .info.
343 ;; Blech. TODO Why not just rename the .texi (or .info) files?
344 (let* ((texiname (cond ((equal name "ccmode") "cc-mode")
345 (t name)))
346 (texi (expand-file-name (format "doc/misc/%s.texi" texiname) root)))
347 (manual-html-node texi (expand-file-name name html-node-dir))
348 (manual-html-mono texi (expand-file-name (concat name ".html")
349 html-mono-dir))))
351 (defun manual-html-mono (texi-file dest)
352 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
353 This function also edits the HTML files so that they validate as
354 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
355 the @import directive."
356 (make-directory (or (file-name-directory dest) ".") t)
357 (call-process "makeinfo" nil nil nil
358 "-D" "WWW_GNU_ORG"
359 "-I" (expand-file-name "../emacs"
360 (file-name-directory texi-file))
361 "-I" (expand-file-name "../misc"
362 (file-name-directory texi-file))
363 "--html" "--no-split" texi-file "-o" dest)
364 (with-temp-buffer
365 (insert-file-contents dest)
366 (setq buffer-file-name dest)
367 (manual-html-fix-headers)
368 (manual-html-fix-index-1)
369 (manual-html-fix-index-2 t)
370 (manual-html-fix-node-div)
371 (goto-char (point-max))
372 (re-search-backward "</body>[\n \t]*</html>")
373 ;; Close the div id="content" that fix-index-1 added.
374 (insert "</div>\n\n")
375 (save-buffer)))
377 (defun manual-html-node (texi-file dir)
378 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
379 This function also edits the HTML files so that they validate as
380 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
381 the @import directive."
382 (unless (file-exists-p texi-file)
383 (user-error "Manual file %s not found" texi-file))
384 (make-directory dir t)
385 (call-process "makeinfo" nil nil nil
386 "-D" "WWW_GNU_ORG"
387 "-I" (expand-file-name "../emacs"
388 (file-name-directory texi-file))
389 "-I" (expand-file-name "../misc"
390 (file-name-directory texi-file))
391 "--html" texi-file "-o" dir)
392 ;; Loop through the node files, fixing them up.
393 (dolist (f (directory-files dir nil "\\.html\\'"))
394 (let (opoint)
395 (with-temp-buffer
396 (insert-file-contents (expand-file-name f dir))
397 (setq buffer-file-name (expand-file-name f dir))
398 (if (looking-at "<meta http-equiv")
399 ;; Ignore those HTML files that are just redirects.
400 (set-buffer-modified-p nil)
401 (manual-html-fix-headers)
402 (if (equal f "index.html")
403 (let (copyright-text)
404 (manual-html-fix-index-1)
405 ;; Move copyright notice to the end.
406 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
407 (setq opoint (match-beginning 0))
408 (re-search-forward "</blockquote>")
409 (setq copyright-text (buffer-substring opoint (point)))
410 (delete-region opoint (point)))
411 (manual-html-fix-index-2)
412 (if copyright-text
413 (insert copyright-text))
414 ;; Close the div id="content" that fix-index-1 added.
415 (insert "\n</div>\n"))
416 ;; For normal nodes, give the header div a blue bg.
417 (manual-html-fix-node-div t))
418 (save-buffer))))))
420 (defun manual-pdf (texi-file dest)
421 "Run texi2pdf on TEXI-FILE, emitting PDF output to DEST."
422 (make-directory (or (file-name-directory dest) ".") t)
423 (let ((default-directory (file-name-directory texi-file)))
424 (call-process "texi2pdf" nil nil nil
425 "-I" "../emacs" "-I" "../misc"
426 texi-file "-o" dest)))
428 (defun manual-ps (texi-file dest)
429 "Generate a PostScript version of TEXI-FILE as DEST."
430 (make-directory (or (file-name-directory dest) ".") t)
431 (let ((dvi-dest (concat (file-name-sans-extension dest) ".dvi"))
432 (default-directory (file-name-directory texi-file)))
433 ;; FIXME: Use `texi2dvi --ps'? --xfq
434 (call-process "texi2dvi" nil nil nil
435 "-I" "../emacs" "-I" "../misc"
436 texi-file "-o" dvi-dest)
437 (call-process "dvips" nil nil nil dvi-dest "-o" dest)
438 (delete-file dvi-dest)
439 (call-process "gzip" nil nil nil dest)))
441 (defun manual-html-fix-headers ()
442 "Fix up HTML headers for the Emacs manual in the current buffer."
443 (let ((texi5 (search-forward "<!DOCTYPE" nil t))
444 opoint)
445 ;; Texinfo 5 supplies a DOCTYPE.
446 (or texi5
447 (insert manual-doctype-string))
448 (search-forward "<head>\n")
449 (insert manual-meta-string)
450 (search-forward "<meta")
451 (setq opoint (match-beginning 0))
452 (unless texi5
453 (search-forward "<!--")
454 (goto-char (match-beginning 0))
455 (delete-region opoint (point))
456 (search-forward "<meta http-equiv=\"Content-Style")
457 (setq opoint (match-beginning 0)))
458 (search-forward "</head>")
459 (goto-char (match-beginning 0))
460 (delete-region opoint (point))
461 (insert manual-style-string)
462 ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink.
463 (when (re-search-forward "<body lang=\"[^\"]+\"" nil t)
464 (setq opoint (point))
465 (search-forward ">")
466 (if (> (point) (1+ opoint))
467 (delete-region opoint (1- (point))))
468 (search-backward "</head"))))
470 ;; Texinfo 5 changed these from class = "node" to "header", yay.
471 (defun manual-html-fix-node-div (&optional split)
472 "Fix up HTML \"node\" divs in the current buffer."
473 (let (opoint div-end type)
474 (while (re-search-forward "<div class=\"\\(node\\|header\\)\"\\(>\\)" nil t)
475 (setq type (match-string 1))
476 ;; NB it is this that makes the bg of non-header cells in the
477 ;; index tables be blue. Is that intended?
478 ;; Also, if you don't remove the <hr>, the color of the first
479 ;; row in the table will be wrong.
480 ;; This all seems rather odd to me...
481 (replace-match " style=\"background-color:#DDDDFF\">" t t nil 2)
482 (setq opoint (point))
483 (when (or split (equal type "node"))
484 ;; In Texinfo 4, the <hr> (and anchor) comes after the <div>.
485 (re-search-forward "</div>")
486 (setq div-end (if (equal type "node")
487 (match-beginning 0)
488 (line-end-position 2)))
489 (goto-char opoint)
490 (if (search-forward "<hr>" div-end 'move)
491 (replace-match "" t t)
492 (if split (forward-line -1))))
493 ;; In Texinfo 5, the <hr> (and anchor) comes before the <div> (?).
494 ;; Except in split output, where it comes on the line after
495 ;; the <div>. But only sometimes. I have no clue what the
496 ;; logic of where it goes is.
497 (when (equal type "header")
498 (goto-char opoint)
499 (when (re-search-backward "^<hr>$" (line-beginning-position -3) t)
500 (replace-match "")
501 (goto-char opoint))))))
504 (defun manual-html-fix-index-1 ()
505 "Remove the h1 header, and the short and long contents lists.
506 Also start a \"content\" div."
507 (let (opoint)
508 (re-search-forward "<body.*>\n")
509 (setq opoint (match-end 0))
510 ;; FIXME? Fragile if a Texinfo 5 document does not use @top.
511 (or (re-search-forward "<h1 class=\"top\"" nil t) ; Texinfo 5
512 (search-forward "<h2 class=\""))
513 (goto-char (match-beginning 0))
514 (delete-region opoint (point))
515 ;; NB caller must close this div.
516 (insert "<div id=\"content\" class=\"inner\">\n\n")))
518 (defun manual-html-fix-index-2 (&optional table-workaround)
519 "Replace the index list in the current buffer with a HTML table.
520 Leave point after the table."
521 (if (re-search-forward "<table class=\"menu\"\\(.*\\)>" nil t)
522 ;; Texinfo 5 already uses a table. Tweak it a bit.
523 (let (opoint done)
524 (replace-match " style=\"float:left\" width=\"100%\"" nil t nil 1)
525 (forward-line 1)
526 (while (not done)
527 (cond ((re-search-forward "<tr><td.*&bull; \\(<a.*</a>\\)\
528 :</td><td>&nbsp;&nbsp;</td><td[^>]*>\\(.*\\)" (line-end-position) t)
529 (replace-match (format "<tr><td%s>\\1</td>\n<td>\\2"
530 (if table-workaround
531 " bgcolor=\"white\"" "")))
532 (search-forward "</td></tr>")
533 (forward-line 1))
534 ((looking-at "<tr><th.*<pre class=\"menu-comment\">\n")
535 (replace-match "<tr><th colspan=\"2\" align=\"left\" \
536 style=\"text-align:left\">")
537 (search-forward "</pre></th></tr>")
538 (replace-match "</th></tr>\n"))
539 ;; Not all manuals have the detailed menu.
540 ;; If it is there, split it into a separate table.
541 ((re-search-forward "<tr>.*The Detailed Node Listing *"
542 (line-end-position) t)
543 (setq opoint (match-beginning 0))
544 (while (and (looking-at " *&mdash;")
545 (zerop (forward-line 1))))
546 (delete-region opoint (point))
547 (insert "</table>\n\n\
548 <h2>Detailed Node Listing</h2>\n\n<p>")
549 ;; FIXME Fragile!
550 ;; The Emacs and Elisp manual have some text at the
551 ;; start of the detailed menu that is not part of the menu.
552 ;; Other manuals do not.
553 (if (re-search-forward "in one step:" (line-end-position 3) t)
554 (forward-line 1))
555 (insert "</p>\n")
556 (search-forward "</pre></th></tr>")
557 (delete-region (match-beginning 0) (match-end 0))
558 (forward-line -1)
559 (or (looking-at "^$") (error "Parse error 1"))
560 (forward-line -1)
561 (if (looking-at "^$") (error "Parse error 2"))
562 (forward-line -1)
563 (or (looking-at "^$") (error "Parse error 3"))
564 (forward-line 1)
565 (insert "<table class=\"menu\" style=\"float:left\" width=\"100%\">\n\
566 <tr><th colspan=\"2\" align=\"left\" style=\"text-align:left\">\n")
567 (forward-line 1)
568 (insert "</th></tr>")
569 (forward-line 1))
570 ((looking-at ".*</table")
571 (forward-line 1)
572 (setq done t)))))
573 (let (done open-td tag desc)
574 ;; Convert the list that Makeinfo made into a table.
575 (or (search-forward "<ul class=\"menu\">" nil t)
576 ;; FIXME? The following search seems dangerously lax.
577 (search-forward "<ul>"))
578 (replace-match "<table style=\"float:left\" width=\"100%\">")
579 (forward-line 1)
580 (while (not done)
581 (cond
582 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
583 (looking-at "<li>\\(<a.+</a>\\)$"))
584 (setq tag (match-string 1))
585 (setq desc (match-string 2))
586 (replace-match "" t t)
587 (when open-td
588 (save-excursion
589 (forward-char -1)
590 (skip-chars-backward " ")
591 (delete-region (point) (line-end-position))
592 (insert "</td>\n </tr>")))
593 (insert " <tr>\n ")
594 (if table-workaround
595 ;; This works around a Firefox bug in the mono file.
596 (insert "<td bgcolor=\"white\">")
597 (insert "<td>"))
598 (insert tag "</td>\n <td>" (or desc ""))
599 (setq open-td t))
600 ((eq (char-after) ?\n)
601 (delete-char 1)
602 ;; Negate the following `forward-line'.
603 (forward-line -1))
604 ((looking-at "<!-- ")
605 (search-forward "-->"))
606 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
607 (replace-match " </td></tr></table>\n
608 <h3>Detailed Node Listing</h3>\n\n" t t)
609 (search-forward "<p>")
610 ;; FIXME Fragile!
611 ;; The Emacs and Elisp manual have some text at the
612 ;; start of the detailed menu that is not part of the menu.
613 ;; Other manuals do not.
614 (if (looking-at "Here are some other nodes")
615 (search-forward "<p>"))
616 (goto-char (match-beginning 0))
617 (skip-chars-backward "\n ")
618 (setq open-td nil)
619 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
620 ((looking-at "</li></ul>")
621 (replace-match "" t t))
622 ((looking-at "<p>")
623 (replace-match "" t t)
624 (when open-td
625 (insert " </td></tr>")
626 (setq open-td nil))
627 (insert " <tr>
628 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
629 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
630 (replace-match " </th></tr>")))
631 ((looking-at "[ \t]*</ul>[ \t]*$")
632 (replace-match
633 (if open-td
634 " </td></tr>\n</table>"
635 "</table>") t t)
636 (setq done t))
638 (if (eobp)
639 (error "Parse error in %s"
640 (file-name-nondirectory buffer-file-name)))
641 (unless open-td
642 (setq done t))))
643 (forward-line 1)))))
646 (defconst make-manuals-dist-output-variables
647 `(("@\\(top_\\)?srcdir@" . ".") ; top_srcdir is wrong, but not used
648 ("^\\(\\(?:texinfo\\|buildinfo\\|emacs\\)dir *=\\).*" . "\\1 .")
649 ("^\\(clean:.*\\)" . "\\1 infoclean")
650 ("@MAKEINFO@" . "makeinfo")
651 ("@MKDIR_P@" . "mkdir -p")
652 ("@INFO_EXT@" . ".info")
653 ("@INFO_OPTS@" . "")
654 ("@SHELL@" . "/bin/bash")
655 ("@prefix@" . "/usr/local")
656 ("@datarootdir@" . "${prefix}/share")
657 ("@datadir@" . "${datarootdir}")
658 ("@PACKAGE_TARNAME@" . "emacs")
659 ("@docdir@" . "${datarootdir}/doc/${PACKAGE_TARNAME}")
660 ("@\\(dvi\\|html\\|pdf\\|ps\\)dir@" . "${docdir}")
661 ("@GZIP_PROG@" . "gzip")
662 ("@INSTALL@" . "install -c")
663 ("@INSTALL_DATA@" . "${INSTALL} -m 644")
664 ("@configure_input@" . "")
665 ("@AM_DEFAULT_VERBOSITY@" . "0")
666 ("@AM_V@" . "${V}")
667 ("@AM_DEFAULT_V@" . "${AM_DEFAULT_VERBOSITY}"))
668 "Alist of (REGEXP . REPLACEMENT) pairs for `make-manuals-dist'.")
670 (defun make-manuals-dist--1 (root type)
671 "Subroutine of `make-manuals-dist'."
672 (let* ((dest (expand-file-name "manual" root))
673 (default-directory (progn (make-directory dest t)
674 (file-name-as-directory dest)))
675 (version (with-temp-buffer
676 (insert-file-contents "../doc/emacs/emacsver.texi")
677 (re-search-forward "@set EMACSVER \\([0-9.]+\\)")
678 (match-string 1)))
679 (stem (format "emacs-%s-%s" (if (equal type "emacs") "manual" type)
680 version))
681 (tarfile (format "%s.tar" stem)))
682 (message "Doing %s..." type)
683 (if (file-directory-p stem)
684 (delete-directory stem t))
685 (make-directory stem)
686 (copy-file "../doc/misc/texinfo.tex" stem)
687 (unless (equal type "emacs")
688 (copy-file "../doc/emacs/emacsver.texi" stem)
689 (copy-file "../doc/emacs/docstyle.texi" stem))
690 (dolist (file (directory-files (format "../doc/%s" type) t))
691 (if (or (string-match-p "\\(\\.texi\\'\\|/README\\'\\)" file)
692 (and (equal type "lispintro")
693 (string-match-p "\\.\\(eps\\|pdf\\)\\'" file)))
694 (copy-file file stem)))
695 (with-temp-buffer
696 (let ((outvars make-manuals-dist-output-variables))
697 (push `("@version@" . ,version) outvars)
698 (insert-file-contents (format "../doc/%s/Makefile.in" type))
699 (dolist (cons outvars)
700 (while (re-search-forward (car cons) nil t)
701 (replace-match (cdr cons) t))
702 (goto-char (point-min))))
703 (let (ats)
704 (while (re-search-forward "@[a-zA-Z_]+@" nil t)
705 (setq ats t)
706 (message "Unexpanded: %s" (match-string 0)))
707 (if ats (error "Unexpanded configure variables in Makefile?")))
708 (write-region nil nil (expand-file-name (format "%s/Makefile" stem))
709 nil 'silent))
710 (call-process "tar" nil nil nil "-cf" tarfile stem)
711 (delete-directory stem t)
712 (message "...created %s" tarfile)))
714 ;; Does anyone actually use these tarfiles?
715 (defun make-manuals-dist (root &optional type)
716 "Make the standalone manual source tarfiles for the Emacs webpage.
717 ROOT should be the root of an Emacs source tree.
718 Interactively with a prefix argument, prompt for TYPE.
719 Optional argument TYPE is type of output (nil means all)."
720 (interactive (let ((root (read-directory-name "Emacs root directory: "
721 source-directory nil t)))
722 (list root
723 (if current-prefix-arg
724 (completing-read
725 "Type: "
726 '("emacs" "lispref" "lispintro" "misc"))))))
727 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
728 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
729 (dolist (m '("emacs" "lispref" "lispintro" "misc"))
730 (if (member type (list nil m))
731 (make-manuals-dist--1 root m))))
734 ;; Stuff to check new `defcustom's got :version tags.
735 ;; Adapted from check-declare.el.
737 (defun cusver-find-files (root &optional old)
738 "Find .el files beneath directory ROOT that contain `defcustom's.
739 If optional OLD is non-nil, also include `defvar's."
740 (process-lines find-program root
741 "-name" "*.el"
742 "-exec" grep-program
743 "-l" "-E" (format "^[ \\t]*\\(def%s"
744 (if old "(custom|var)"
745 "custom"
747 "{}" "+"))
749 (defvar cusver-new-version (format "%s.%s" emacs-major-version
750 (1+ emacs-minor-version))
751 "Version number that new `defcustom's should have.")
753 (defun cusver-scan (file &optional old)
754 "Scan FILE for `defcustom' calls.
755 Return a list with elements of the form (VAR . VER),
756 This means that FILE contains a defcustom for variable VAR, with
757 a :version tag having value VER (may be nil).
758 If optional argument OLD is non-nil, also scan for `defvar's."
759 (let ((m (format "Scanning %s..." file))
760 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
761 (if old "\\(custom\\|var\\)" "\\(custom\\|group\\)")))
762 alist var ver form glist grp)
763 (message "%s" m)
764 (with-temp-buffer
765 (insert-file-contents file)
766 ;; FIXME we could theoretically be inside a string.
767 (while (re-search-forward re nil :noerror)
768 (goto-char (match-beginning 1))
769 (if (and (setq form (ignore-errors (read (current-buffer))))
770 (setq var (car-safe (cdr-safe form)))
771 ;; Exclude macros, eg (defcustom ,varname ...).
772 (symbolp var))
773 (progn
774 ;; FIXME It should be cus-test-apropos that does this.
775 (and (not old)
776 (equal "custom" (match-string 2))
777 (not (memq :type form))
778 (display-warning
779 'custom (format-message "Missing type in: `%s'" form)))
780 (setq ver (car (cdr-safe (memq :version form))))
781 (if (equal "group" (match-string 2))
782 ;; Group :version could be old.
783 (if (equal ver cusver-new-version)
784 (setq glist (cons (cons var ver) glist)))
785 ;; If it specifies a group and the whole group has a
786 ;; version. use that.
787 (unless ver
788 (setq grp (car (cdr-safe (memq :group form))))
789 (and grp
790 (setq grp (car (cdr-safe grp))) ; (quote foo) -> foo
791 (setq ver (assq grp glist))))
792 (setq alist (cons (cons var ver) alist))))
793 (if form (format-message "Malformed defcustom: `%s'" form)))))
794 (message "%sdone" m)
795 alist))
797 (defun cusver-scan-cus-start (file)
798 "Scan cus-start.el and return an alist with elements (VAR . VER)."
799 (if (file-readable-p file)
800 (with-temp-buffer
801 (insert-file-contents file)
802 (when (search-forward "(let ((all '(" nil t)
803 (backward-char 1)
804 (let (var ver alist)
805 (dolist (elem (ignore-errors (read (current-buffer))))
806 (when (symbolp (setq var (car-safe elem)))
807 (or (stringp (setq ver (nth 3 elem)))
808 (setq ver nil))
809 (setq alist (cons (cons var ver) alist))))
810 alist)))))
812 (define-button-type 'cusver-xref 'action #'cusver-goto-xref)
814 (defun cusver-goto-xref (button)
815 "Jump to a Lisp file for the BUTTON at point."
816 (let ((file (button-get button 'file))
817 (var (button-get button 'var)))
818 (if (not (file-readable-p file))
819 (message "Cannot read `%s'" file)
820 (with-current-buffer (find-file-noselect file)
821 (goto-char (point-min))
822 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
823 (message "Unable to locate defcustom"))
824 (pop-to-buffer (current-buffer))))))
826 ;; You should probably at least do a grep over the old directory
827 ;; to check the results of this look sensible.
828 ;; TODO Check cus-start if something moved from C to Lisp.
829 ;; TODO Handle renamed things with aliases to the old names.
830 (defun cusver-check (newdir olddir version)
831 "Check that `defcustom's have :version tags where needed.
832 NEWDIR is the current lisp/ directory, OLDDIR is that from the
833 previous release, VERSION is the new version number. A
834 `defcustom' that is only in NEWDIR should have a :version tag.
835 We exclude cases where a `defvar' exists in OLDDIR, since just
836 converting a `defvar' to a `defcustom' does not require
837 a :version bump.
839 Note that a :version tag should also be added if the value of a defcustom
840 changes (in a non-trivial way). This function does not check for that."
841 (interactive (list (read-directory-name "New Lisp directory: " nil nil t)
842 (read-directory-name "Old Lisp directory: " nil nil t)
843 (number-to-string
844 (read-number "New version number: "
845 (string-to-number cusver-new-version)))))
846 (or (file-directory-p (setq newdir (expand-file-name newdir)))
847 (user-error "Directory `%s' not found" newdir))
848 (or (file-directory-p (setq olddir (expand-file-name olddir)))
849 (user-error "Directory `%s' not found" olddir))
850 (setq cusver-new-version version)
851 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
852 (cusver-find-files newdir)))
853 (oldfiles (progn (message "Finding old files with `defcustom's...")
854 (cusver-find-files olddir t)))
855 (newcus (progn (message "Reading new `defcustom's...")
856 (mapcar
857 (lambda (file)
858 (cons file (cusver-scan file))) newfiles)))
859 oldcus result thisfile file)
860 (message "Reading old `defcustom's...")
861 (dolist (file oldfiles)
862 (setq oldcus (append oldcus (cusver-scan file t))))
863 (setq oldcus (append oldcus (cusver-scan-cus-start
864 (expand-file-name "cus-start.el" olddir))))
865 ;; newcus has elements (FILE (VAR VER) ... ).
866 ;; oldcus just (VAR . VER).
867 (message "Checking for version tags...")
868 (dolist (new newcus)
869 (setq file (car new)
870 thisfile
871 (let (missing var)
872 (dolist (cons (cdr new))
873 (or (cdr cons)
874 (assq (setq var (car cons)) oldcus)
875 (push var missing)))
876 (if missing
877 (cons file missing))))
878 (if thisfile
879 (setq result (cons thisfile result))))
880 (message "Checking for version tags... done")
881 (if (not result)
882 (message "No missing :version tags")
883 (pop-to-buffer "*cusver*")
884 (erase-buffer)
885 (insert (substitute-command-keys
886 "These `defcustom's might be missing :version tags:\n\n"))
887 (dolist (elem result)
888 (let* ((str (file-relative-name (car elem) newdir))
889 (strlen (length str)))
890 (dolist (var (cdr elem))
891 (insert (format "%s: %s\n" str var))
892 (make-text-button (+ (line-beginning-position 0) strlen 2)
893 (line-end-position 0)
894 'file (car elem)
895 'var var
896 'help-echo "Mouse-2: visit this definition"
897 :type 'cusver-xref)))))))
899 (provide 'admin)
901 ;;; admin.el ends here
903 ;; Local Variables:
904 ;; coding: utf-8
905 ;; End: