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