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