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