admin.el 32 KB

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