Fix TTY colors breakage by 'clear-face-cache'
[emacs.git] / admin / admin.el
blob3cb5dbc2d924a8b3ef43809811f6e9deb4de7513
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
265 (if noninteractive
266 (or (pop command-line-args-left)
267 default-directory)
268 (read-directory-name "Emacs root directory: "
269 source-directory nil t))))
270 (list root
271 (if current-prefix-arg
272 (completing-read
273 "Type: "
274 (append
275 '("misc" "pdf" "ps")
276 (let (res)
277 (dolist (i '("emacs" "elisp" "eintr") res)
278 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
279 (push (concat i j) res))))
280 (manual-misc-manuals root)))))))
281 (let* ((dest (expand-file-name "manual" root))
282 (html-node-dir (expand-file-name "html_node" dest))
283 (html-mono-dir (expand-file-name "html_mono" dest))
284 (ps-dir (expand-file-name "ps" dest))
285 (pdf-dir (expand-file-name "pdf" dest))
286 (emacs (expand-file-name "doc/emacs/emacs.texi" root))
287 (emacs-xtra (expand-file-name "doc/emacs/emacs-xtra.texi" root))
288 (elisp (expand-file-name "doc/lispref/elisp.texi" root))
289 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root))
290 (misc (manual-misc-manuals root)))
291 ;; TODO this makes it non-continuable.
292 ;; Instead, delete the individual dest directory each time.
293 (when (file-directory-p dest)
294 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest))
295 (delete-directory dest t)
296 (user-error "Aborted")))
297 (if (member type '(nil "emacs" "emacs-node"))
298 (manual-html-node emacs (expand-file-name "emacs" html-node-dir)))
299 (if (member type '(nil "emacs" "emacs-mono"))
300 (manual-html-mono emacs (expand-file-name "emacs.html" html-mono-dir)))
301 (when (member type '(nil "emacs" "emacs-pdf" "pdf"))
302 (manual-pdf emacs (expand-file-name "emacs.pdf" pdf-dir))
303 ;; emacs-xtra exists only in pdf/ps format.
304 ;; In other formats it is included in the Emacs manual.
305 (manual-pdf emacs-xtra (expand-file-name "emacs-xtra.pdf" pdf-dir)))
306 (when (member type '(nil "emacs" "emacs-ps" "ps"))
307 (manual-ps emacs (expand-file-name "emacs.ps" ps-dir))
308 (manual-ps emacs-xtra (expand-file-name "emacs-xtra.ps" ps-dir)))
309 (if (member type '(nil "elisp" "elisp-node"))
310 (manual-html-node elisp (expand-file-name "elisp" html-node-dir)))
311 (if (member type '(nil "elisp" "elisp-mono"))
312 (manual-html-mono elisp (expand-file-name "elisp.html" html-mono-dir)))
313 (if (member type '(nil "elisp" "elisp-pdf" "pdf"))
314 (manual-pdf elisp (expand-file-name "elisp.pdf" pdf-dir)))
315 (if (member type '(nil "elisp" "elisp-ps" "ps"))
316 (manual-ps elisp (expand-file-name "elisp.ps" ps-dir)))
317 (if (member type '(nil "eintr" "eintr-node"))
318 (manual-html-node eintr (expand-file-name "eintr" html-node-dir)))
319 (if (member type '(nil "eintr" "eintr-node"))
320 (manual-html-mono eintr (expand-file-name "eintr.html" html-mono-dir)))
321 (if (member type '(nil "eintr" "eintr-pdf" "pdf"))
322 (manual-pdf eintr (expand-file-name "eintr.pdf" pdf-dir)))
323 (if (member type '(nil "eintr" "eintr-ps" "ps"))
324 (manual-ps eintr (expand-file-name "eintr.ps" ps-dir)))
325 ;; Misc manuals
326 (dolist (manual misc)
327 (if (member type `(nil ,manual "misc"))
328 (manual-misc-html manual root html-node-dir html-mono-dir)))
329 (message "Manuals created in %s" dest)))
331 (defconst manual-doctype-string
332 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
333 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
335 (defconst manual-meta-string
336 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
337 <link rev=\"made\" href=\"mailto:bug-gnu-emacs@gnu.org\">
338 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
339 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
340 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
342 (defconst manual-style-string "<style type=\"text/css\">
343 @import url('/software/emacs/manual.css');\n</style>\n")
345 (defun manual-misc-html (name root html-node-dir html-mono-dir)
346 ;; Hack to deal with the cases where .texi creates a different .info.
347 ;; Blech. TODO Why not just rename the .texi (or .info) files?
348 (let* ((texiname (cond ((equal name "ccmode") "cc-mode")
349 (t name)))
350 (texi (expand-file-name (format "doc/misc/%s.texi" texiname) root)))
351 (manual-html-node texi (expand-file-name name html-node-dir))
352 (manual-html-mono texi (expand-file-name (concat name ".html")
353 html-mono-dir))))
355 (defun manual-html-mono (texi-file dest)
356 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
357 This function also edits the HTML files so that they validate as
358 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
359 the @import directive."
360 (make-directory (or (file-name-directory dest) ".") t)
361 (call-process "makeinfo" nil nil nil
362 "-D" "WWW_GNU_ORG"
363 "-I" (expand-file-name "../emacs"
364 (file-name-directory texi-file))
365 "-I" (expand-file-name "../misc"
366 (file-name-directory texi-file))
367 "--html" "--no-split" texi-file "-o" dest)
368 (with-temp-buffer
369 (insert-file-contents dest)
370 (setq buffer-file-name dest)
371 (manual-html-fix-headers)
372 (manual-html-fix-index-1)
373 (manual-html-fix-index-2 t)
374 (manual-html-fix-node-div)
375 (goto-char (point-max))
376 (re-search-backward "</body>[\n \t]*</html>")
377 ;; Close the div id="content" that fix-index-1 added.
378 (insert "</div>\n\n")
379 (save-buffer)))
381 (defun manual-html-node (texi-file dir)
382 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
383 This function also edits the HTML files so that they validate as
384 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
385 the @import directive."
386 (unless (file-exists-p texi-file)
387 (user-error "Manual file %s not found" texi-file))
388 (make-directory dir t)
389 (call-process "makeinfo" nil nil nil
390 "-D" "WWW_GNU_ORG"
391 "-I" (expand-file-name "../emacs"
392 (file-name-directory texi-file))
393 "-I" (expand-file-name "../misc"
394 (file-name-directory texi-file))
395 "--html" texi-file "-o" dir)
396 ;; Loop through the node files, fixing them up.
397 (dolist (f (directory-files dir nil "\\.html\\'"))
398 (let (opoint)
399 (with-temp-buffer
400 (insert-file-contents (expand-file-name f dir))
401 (setq buffer-file-name (expand-file-name f dir))
402 (if (looking-at "<meta http-equiv")
403 ;; Ignore those HTML files that are just redirects.
404 (set-buffer-modified-p nil)
405 (manual-html-fix-headers)
406 (if (equal f "index.html")
407 (let (copyright-text)
408 (manual-html-fix-index-1)
409 ;; Move copyright notice to the end.
410 (when (re-search-forward "[ \t]*<p>Copyright &copy;" nil t)
411 (setq opoint (match-beginning 0))
412 (re-search-forward "</blockquote>")
413 (setq copyright-text (buffer-substring opoint (point)))
414 (delete-region opoint (point)))
415 (manual-html-fix-index-2)
416 (if copyright-text
417 (insert copyright-text))
418 ;; Close the div id="content" that fix-index-1 added.
419 (insert "\n</div>\n"))
420 ;; For normal nodes, give the header div a blue bg.
421 (manual-html-fix-node-div t))
422 (save-buffer))))))
424 (defun manual-pdf (texi-file dest)
425 "Run texi2pdf on TEXI-FILE, emitting PDF output to DEST."
426 (make-directory (or (file-name-directory dest) ".") t)
427 (let ((default-directory (file-name-directory texi-file)))
428 (call-process "texi2pdf" nil nil nil
429 "-I" "../emacs" "-I" "../misc"
430 texi-file "-o" dest)))
432 (defun manual-ps (texi-file dest)
433 "Generate a PostScript version of TEXI-FILE as DEST."
434 (make-directory (or (file-name-directory dest) ".") t)
435 (let ((dvi-dest (concat (file-name-sans-extension dest) ".dvi"))
436 (default-directory (file-name-directory texi-file)))
437 ;; FIXME: Use `texi2dvi --ps'? --xfq
438 (call-process "texi2dvi" nil nil nil
439 "-I" "../emacs" "-I" "../misc"
440 texi-file "-o" dvi-dest)
441 (call-process "dvips" nil nil nil dvi-dest "-o" dest)
442 (delete-file dvi-dest)
443 (call-process "gzip" nil nil nil dest)))
445 (defun manual-html-fix-headers ()
446 "Fix up HTML headers for the Emacs manual in the current buffer."
447 (let ((texi5 (search-forward "<!DOCTYPE" nil t))
448 opoint)
449 ;; Texinfo 5 supplies a DOCTYPE.
450 (or texi5
451 (insert manual-doctype-string))
452 (search-forward "<head>\n")
453 (insert manual-meta-string)
454 (search-forward "<meta")
455 (setq opoint (match-beginning 0))
456 (unless texi5
457 (search-forward "<!--")
458 (goto-char (match-beginning 0))
459 (delete-region opoint (point))
460 (search-forward "<meta http-equiv=\"Content-Style")
461 (setq opoint (match-beginning 0)))
462 (search-forward "</head>")
463 (goto-char (match-beginning 0))
464 (delete-region opoint (point))
465 (insert manual-style-string)
466 ;; Remove Texinfo 5 hard-coding bgcolor, text, link, vlink, alink.
467 (when (re-search-forward "<body lang=\"[^\"]+\"" nil t)
468 (setq opoint (point))
469 (search-forward ">")
470 (if (> (point) (1+ opoint))
471 (delete-region opoint (1- (point))))
472 (search-backward "</head"))))
474 ;; Texinfo 5 changed these from class = "node" to "header", yay.
475 (defun manual-html-fix-node-div (&optional split)
476 "Fix up HTML \"node\" divs in the current buffer."
477 (let (opoint div-end type)
478 (while (re-search-forward "<div class=\"\\(node\\|header\\)\"\\(>\\)" nil t)
479 (setq type (match-string 1))
480 ;; NB it is this that makes the bg of non-header cells in the
481 ;; index tables be blue. Is that intended?
482 ;; Also, if you don't remove the <hr>, the color of the first
483 ;; row in the table will be wrong.
484 ;; This all seems rather odd to me...
485 (replace-match " style=\"background-color:#DDDDFF\">" t t nil 2)
486 (setq opoint (point))
487 (when (or split (equal type "node"))
488 ;; In Texinfo 4, the <hr> (and anchor) comes after the <div>.
489 (re-search-forward "</div>")
490 (setq div-end (if (equal type "node")
491 (match-beginning 0)
492 (line-end-position 2)))
493 (goto-char opoint)
494 (if (search-forward "<hr>" div-end 'move)
495 (replace-match "" t t)
496 (if split (forward-line -1))))
497 ;; In Texinfo 5, the <hr> (and anchor) comes before the <div> (?).
498 ;; Except in split output, where it comes on the line after
499 ;; the <div>. But only sometimes. I have no clue what the
500 ;; logic of where it goes is.
501 (when (equal type "header")
502 (goto-char opoint)
503 (when (re-search-backward "^<hr>$" (line-beginning-position -3) t)
504 (replace-match "")
505 (goto-char opoint))))))
508 (defun manual-html-fix-index-1 ()
509 "Remove the h1 header, and the short and long contents lists.
510 Also start a \"content\" div."
511 (let (opoint)
512 (re-search-forward "<body.*>\n")
513 (setq opoint (match-end 0))
514 ;; FIXME? Fragile if a Texinfo 5 document does not use @top.
515 (or (re-search-forward "<h1 class=\"top\"" nil t) ; Texinfo 5
516 (search-forward "<h2 class=\""))
517 (goto-char (match-beginning 0))
518 (delete-region opoint (point))
519 ;; NB caller must close this div.
520 (insert "<div id=\"content\" class=\"inner\">\n\n")))
522 (defun manual-html-fix-index-2 (&optional table-workaround)
523 "Replace the index list in the current buffer with a HTML table.
524 Leave point after the table."
525 (if (re-search-forward "<table class=\"menu\"\\(.*\\)>" nil t)
526 ;; Texinfo 5 already uses a table. Tweak it a bit.
527 (let (opoint done)
528 (replace-match " style=\"float:left\" width=\"100%\"" nil t nil 1)
529 (forward-line 1)
530 (while (not done)
531 (cond ((re-search-forward "<tr><td.*&bull; \\(<a.*</a>\\)\
532 :</td><td>&nbsp;&nbsp;</td><td[^>]*>\\(.*\\)" (line-end-position) t)
533 (replace-match (format "<tr><td%s>\\1</td>\n<td>\\2"
534 (if table-workaround
535 " bgcolor=\"white\"" "")))
536 (search-forward "</td></tr>")
537 (forward-line 1))
538 ((looking-at "<tr><th.*<pre class=\"menu-comment\">\n")
539 (replace-match "<tr><th colspan=\"2\" align=\"left\" \
540 style=\"text-align:left\">")
541 (search-forward "</pre></th></tr>")
542 (replace-match "</th></tr>\n"))
543 ;; Not all manuals have the detailed menu.
544 ;; If it is there, split it into a separate table.
545 ((re-search-forward "<tr>.*The Detailed Node Listing *"
546 (line-end-position) t)
547 (setq opoint (match-beginning 0))
548 (while (and (looking-at " *&mdash;")
549 (zerop (forward-line 1))))
550 (delete-region opoint (point))
551 (insert "</table>\n\n\
552 <h2>Detailed Node Listing</h2>\n\n<p>")
553 ;; FIXME Fragile!
554 ;; The Emacs and Elisp manual have some text at the
555 ;; start of the detailed menu that is not part of the menu.
556 ;; Other manuals do not.
557 (if (re-search-forward "in one step:" (line-end-position 3) t)
558 (forward-line 1))
559 (insert "</p>\n")
560 (search-forward "</pre></th></tr>")
561 (delete-region (match-beginning 0) (match-end 0))
562 (forward-line -1)
563 (or (looking-at "^$") (error "Parse error 1"))
564 (forward-line -1)
565 (if (looking-at "^$") (error "Parse error 2"))
566 (forward-line -1)
567 (or (looking-at "^$") (error "Parse error 3"))
568 (forward-line 1)
569 (insert "<table class=\"menu\" style=\"float:left\" width=\"100%\">\n\
570 <tr><th colspan=\"2\" align=\"left\" style=\"text-align:left\">\n")
571 (forward-line 1)
572 (insert "</th></tr>")
573 (forward-line 1))
574 ((looking-at ".*</table")
575 (forward-line 1)
576 (setq done t)))))
577 (let (done open-td tag desc)
578 ;; Convert the list that Makeinfo made into a table.
579 (or (search-forward "<ul class=\"menu\">" nil t)
580 ;; FIXME? The following search seems dangerously lax.
581 (search-forward "<ul>"))
582 (replace-match "<table style=\"float:left\" width=\"100%\">")
583 (forward-line 1)
584 (while (not done)
585 (cond
586 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
587 (looking-at "<li>\\(<a.+</a>\\)$"))
588 (setq tag (match-string 1))
589 (setq desc (match-string 2))
590 (replace-match "" t t)
591 (when open-td
592 (save-excursion
593 (forward-char -1)
594 (skip-chars-backward " ")
595 (delete-region (point) (line-end-position))
596 (insert "</td>\n </tr>")))
597 (insert " <tr>\n ")
598 (if table-workaround
599 ;; This works around a Firefox bug in the mono file.
600 (insert "<td bgcolor=\"white\">")
601 (insert "<td>"))
602 (insert tag "</td>\n <td>" (or desc ""))
603 (setq open-td t))
604 ((eq (char-after) ?\n)
605 (delete-char 1)
606 ;; Negate the following `forward-line'.
607 (forward-line -1))
608 ((looking-at "<!-- ")
609 (search-forward "-->"))
610 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
611 (replace-match " </td></tr></table>\n
612 <h3>Detailed Node Listing</h3>\n\n" t t)
613 (search-forward "<p>")
614 ;; FIXME Fragile!
615 ;; The Emacs and Elisp manual have some text at the
616 ;; start of the detailed menu that is not part of the menu.
617 ;; Other manuals do not.
618 (if (looking-at "Here are some other nodes")
619 (search-forward "<p>"))
620 (goto-char (match-beginning 0))
621 (skip-chars-backward "\n ")
622 (setq open-td nil)
623 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
624 ((looking-at "</li></ul>")
625 (replace-match "" t t))
626 ((looking-at "<p>")
627 (replace-match "" t t)
628 (when open-td
629 (insert " </td></tr>")
630 (setq open-td nil))
631 (insert " <tr>
632 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
633 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t)
634 (replace-match " </th></tr>")))
635 ((looking-at "[ \t]*</ul>[ \t]*$")
636 (replace-match
637 (if open-td
638 " </td></tr>\n</table>"
639 "</table>") t t)
640 (setq done t))
642 (if (eobp)
643 (error "Parse error in %s"
644 (file-name-nondirectory buffer-file-name)))
645 (unless open-td
646 (setq done t))))
647 (forward-line 1)))))
650 (defconst make-manuals-dist-output-variables
651 `(("@\\(top_\\)?srcdir@" . ".") ; top_srcdir is wrong, but not used
652 ("^\\(\\(?:texinfo\\|buildinfo\\|emacs\\)dir *=\\).*" . "\\1 .")
653 ("^\\(clean:.*\\)" . "\\1 infoclean")
654 ("@MAKEINFO@" . "makeinfo")
655 ("@MKDIR_P@" . "mkdir -p")
656 ("@INFO_EXT@" . ".info")
657 ("@INFO_OPTS@" . "")
658 ("@SHELL@" . "/bin/bash")
659 ("@prefix@" . "/usr/local")
660 ("@datarootdir@" . "${prefix}/share")
661 ("@datadir@" . "${datarootdir}")
662 ("@PACKAGE_TARNAME@" . "emacs")
663 ("@docdir@" . "${datarootdir}/doc/${PACKAGE_TARNAME}")
664 ("@\\(dvi\\|html\\|pdf\\|ps\\)dir@" . "${docdir}")
665 ("@GZIP_PROG@" . "gzip")
666 ("@INSTALL@" . "install -c")
667 ("@INSTALL_DATA@" . "${INSTALL} -m 644")
668 ("@configure_input@" . "")
669 ("@AM_DEFAULT_VERBOSITY@" . "0")
670 ("@AM_V@" . "${V}")
671 ("@AM_DEFAULT_V@" . "${AM_DEFAULT_VERBOSITY}"))
672 "Alist of (REGEXP . REPLACEMENT) pairs for `make-manuals-dist'.")
674 (defun make-manuals-dist--1 (root type)
675 "Subroutine of `make-manuals-dist'."
676 (let* ((dest (expand-file-name "manual" root))
677 (default-directory (progn (make-directory dest t)
678 (file-name-as-directory dest)))
679 (version (with-temp-buffer
680 (insert-file-contents "../doc/emacs/emacsver.texi")
681 (re-search-forward "@set EMACSVER \\([0-9.]+\\)")
682 (match-string 1)))
683 (stem (format "emacs-%s-%s" (if (equal type "emacs") "manual" type)
684 version))
685 (tarfile (format "%s.tar" stem)))
686 (message "Doing %s..." type)
687 (if (file-directory-p stem)
688 (delete-directory stem t))
689 (make-directory stem)
690 (copy-file "../doc/misc/texinfo.tex" stem)
691 (unless (equal type "emacs")
692 (copy-file "../doc/emacs/emacsver.texi" stem)
693 (copy-file "../doc/emacs/docstyle.texi" stem))
694 (dolist (file (directory-files (format "../doc/%s" type) t))
695 (if (or (string-match-p "\\(\\.texi\\'\\|/README\\'\\)" file)
696 (and (equal type "lispintro")
697 (string-match-p "\\.\\(eps\\|pdf\\)\\'" file)))
698 (copy-file file stem)))
699 (with-temp-buffer
700 (let ((outvars make-manuals-dist-output-variables))
701 (push `("@version@" . ,version) outvars)
702 (insert-file-contents (format "../doc/%s/Makefile.in" type))
703 (dolist (cons outvars)
704 (while (re-search-forward (car cons) nil t)
705 (replace-match (cdr cons) t))
706 (goto-char (point-min))))
707 (let (ats)
708 (while (re-search-forward "@[a-zA-Z_]+@" nil t)
709 (setq ats t)
710 (message "Unexpanded: %s" (match-string 0)))
711 (if ats (error "Unexpanded configure variables in Makefile?")))
712 (write-region nil nil (expand-file-name (format "%s/Makefile" stem))
713 nil 'silent))
714 (call-process "tar" nil nil nil "-cf" tarfile stem)
715 (delete-directory stem t)
716 (message "...created %s" tarfile)))
718 ;; Does anyone actually use these tarfiles?
719 (defun make-manuals-dist (root &optional type)
720 "Make the standalone manual source tarfiles for the Emacs webpage.
721 ROOT should be the root of an Emacs source tree.
722 Interactively with a prefix argument, prompt for TYPE.
723 Optional argument TYPE is type of output (nil means all)."
724 (interactive (let ((root
725 (if noninteractive
726 (or (pop command-line-args-left)
727 default-directory)
728 (read-directory-name "Emacs root directory: "
729 source-directory nil t))))
730 (list root
731 (if current-prefix-arg
732 (completing-read
733 "Type: "
734 '("emacs" "lispref" "lispintro" "misc"))))))
735 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
736 (user-error "%s doesn't seem to be the root of an Emacs source tree" root))
737 (dolist (m '("emacs" "lispref" "lispintro" "misc"))
738 (if (member type (list nil m))
739 (make-manuals-dist--1 root m))))
742 ;; Stuff to check new `defcustom's got :version tags.
743 ;; Adapted from check-declare.el.
745 (defun cusver-find-files (root &optional old)
746 "Find .el files beneath directory ROOT that contain `defcustom's.
747 If optional OLD is non-nil, also include `defvar's."
748 (process-lines find-program root
749 "-name" "*.el"
750 "-exec" grep-program
751 "-l" "-E" (format "^[ \\t]*\\(def%s"
752 (if old "(custom|var)"
753 "custom"
755 "{}" "+"))
757 (defvar cusver-new-version (format "%s.%s" emacs-major-version
758 (1+ emacs-minor-version))
759 "Version number that new `defcustom's should have.")
761 (defun cusver-scan (file &optional old)
762 "Scan FILE for `defcustom' calls.
763 Return a list with elements of the form (VAR . VER),
764 This means that FILE contains a defcustom for variable VAR, with
765 a :version tag having value VER (may be nil).
766 If optional argument OLD is non-nil, also scan for `defvar's."
767 (let ((m (format "Scanning %s..." file))
768 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
769 (if old "\\(custom\\|var\\)" "\\(custom\\|group\\)")))
770 alist var ver form glist grp)
771 (message "%s" m)
772 (with-temp-buffer
773 (insert-file-contents file)
774 ;; FIXME we could theoretically be inside a string.
775 (while (re-search-forward re nil :noerror)
776 (goto-char (match-beginning 1))
777 (if (and (setq form (ignore-errors (read (current-buffer))))
778 (setq var (car-safe (cdr-safe form)))
779 ;; Exclude macros, eg (defcustom ,varname ...).
780 (symbolp var))
781 (progn
782 ;; FIXME It should be cus-test-apropos that does this.
783 (and (not old)
784 (equal "custom" (match-string 2))
785 (not (memq :type form))
786 (display-warning
787 'custom (format-message "Missing type in: `%s'" form)))
788 (setq ver (car (cdr-safe (memq :version form))))
789 (if (equal "group" (match-string 2))
790 ;; Group :version could be old.
791 (if (equal ver cusver-new-version)
792 (setq glist (cons (cons var ver) glist)))
793 ;; If it specifies a group and the whole group has a
794 ;; version. use that.
795 (unless ver
796 (setq grp (car (cdr-safe (memq :group form))))
797 (and grp
798 (setq grp (car (cdr-safe grp))) ; (quote foo) -> foo
799 (setq ver (assq grp glist))))
800 (setq alist (cons (cons var ver) alist))))
801 (if form (format-message "Malformed defcustom: `%s'" form)))))
802 (message "%sdone" m)
803 alist))
805 (defun cusver-scan-cus-start (file)
806 "Scan cus-start.el and return an alist with elements (VAR . VER)."
807 (if (file-readable-p file)
808 (with-temp-buffer
809 (insert-file-contents file)
810 (when (search-forward "(let ((all '(" nil t)
811 (backward-char 1)
812 (let (var ver alist)
813 (dolist (elem (ignore-errors (read (current-buffer))))
814 (when (symbolp (setq var (car-safe elem)))
815 (or (stringp (setq ver (nth 3 elem)))
816 (setq ver nil))
817 (setq alist (cons (cons var ver) alist))))
818 alist)))))
820 (define-button-type 'cusver-xref 'action #'cusver-goto-xref)
822 (defun cusver-goto-xref (button)
823 "Jump to a Lisp file for the BUTTON at point."
824 (let ((file (button-get button 'file))
825 (var (button-get button 'var)))
826 (if (not (file-readable-p file))
827 (message "Cannot read `%s'" file)
828 (with-current-buffer (find-file-noselect file)
829 (goto-char (point-min))
830 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
831 (message "Unable to locate defcustom"))
832 (pop-to-buffer (current-buffer))))))
834 ;; You should probably at least do a grep over the old directory
835 ;; to check the results of this look sensible.
836 ;; TODO Check cus-start if something moved from C to Lisp.
837 ;; TODO Handle renamed things with aliases to the old names.
838 (defun cusver-check (newdir olddir version)
839 "Check that `defcustom's have :version tags where needed.
840 NEWDIR is the current lisp/ directory, OLDDIR is that from the
841 previous release, VERSION is the new version number. A
842 `defcustom' that is only in NEWDIR should have a :version tag.
843 We exclude cases where a `defvar' exists in OLDDIR, since just
844 converting a `defvar' to a `defcustom' does not require
845 a :version bump.
847 Note that a :version tag should also be added if the value of a defcustom
848 changes (in a non-trivial way). This function does not check for that."
849 (interactive (list (read-directory-name "New Lisp directory: " nil nil t)
850 (read-directory-name "Old Lisp directory: " nil nil t)
851 (number-to-string
852 (read-number "New version number: "
853 (string-to-number cusver-new-version)))))
854 (or (file-directory-p (setq newdir (expand-file-name newdir)))
855 (user-error "Directory `%s' not found" newdir))
856 (or (file-directory-p (setq olddir (expand-file-name olddir)))
857 (user-error "Directory `%s' not found" olddir))
858 (setq cusver-new-version version)
859 (let* ((newfiles (progn (message "Finding new files with `defcustom's...")
860 (cusver-find-files newdir)))
861 (oldfiles (progn (message "Finding old files with `defcustom's...")
862 (cusver-find-files olddir t)))
863 (newcus (progn (message "Reading new `defcustom's...")
864 (mapcar
865 (lambda (file)
866 (cons file (cusver-scan file))) newfiles)))
867 oldcus result thisfile file)
868 (message "Reading old `defcustom's...")
869 (dolist (file oldfiles)
870 (setq oldcus (append oldcus (cusver-scan file t))))
871 (setq oldcus (append oldcus (cusver-scan-cus-start
872 (expand-file-name "cus-start.el" olddir))))
873 ;; newcus has elements (FILE (VAR VER) ... ).
874 ;; oldcus just (VAR . VER).
875 (message "Checking for version tags...")
876 (dolist (new newcus)
877 (setq file (car new)
878 thisfile
879 (let (missing var)
880 (dolist (cons (cdr new))
881 (or (cdr cons)
882 (assq (setq var (car cons)) oldcus)
883 (push var missing)))
884 (if missing
885 (cons file missing))))
886 (if thisfile
887 (setq result (cons thisfile result))))
888 (message "Checking for version tags... done")
889 (if (not result)
890 (message "No missing :version tags")
891 (pop-to-buffer "*cusver*")
892 (erase-buffer)
893 (insert (substitute-command-keys
894 "These `defcustom's might be missing :version tags:\n\n"))
895 (dolist (elem result)
896 (let* ((str (file-relative-name (car elem) newdir))
897 (strlen (length str)))
898 (dolist (var (cdr elem))
899 (insert (format "%s: %s\n" str var))
900 (make-text-button (+ (line-beginning-position 0) strlen 2)
901 (line-end-position 0)
902 'file (car elem)
903 'var var
904 'help-echo "Mouse-2: visit this definition"
905 :type 'cusver-xref)))))))
907 (provide 'admin)
909 ;;; admin.el ends here
911 ;; Local Variables:
912 ;; coding: utf-8
913 ;; End: