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