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