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