admin.el 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571
  1. ;;; admin.el --- utilities for Emacs administration
  2. ;; Copyright (C) 2001-2012 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. (defun add-release-logs (root version)
  21. "Add \"Version VERSION released.\" change log entries in ROOT.
  22. Root must be the root of an Emacs source tree."
  23. (interactive "DEmacs root directory: \nNVersion number: ")
  24. (setq root (expand-file-name root))
  25. (unless (file-exists-p (expand-file-name "src/emacs.c" root))
  26. (error "%s doesn't seem to be the root of an Emacs source tree" root))
  27. (require 'add-log)
  28. (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
  29. (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
  30. (funcall add-log-time-format)
  31. (or add-log-full-name (user-full-name))
  32. (or add-log-mailing-address user-mail-address)
  33. version)))
  34. (dolist (log logs)
  35. (unless (string-match "/gnus/" log)
  36. (find-file log)
  37. (goto-char (point-min))
  38. (insert entry)))))
  39. (defun set-version-in-file (root file version rx)
  40. (find-file (expand-file-name file root))
  41. (goto-char (point-min))
  42. (unless (re-search-forward rx nil t)
  43. (error "Version not found in %s" file))
  44. (replace-match (format "%s" version) nil nil nil 1))
  45. (defun set-version (root version)
  46. "Set Emacs version to VERSION in relevant files under ROOT.
  47. Root must be the root of an Emacs source tree."
  48. (interactive "DEmacs root directory: \nsVersion number: ")
  49. (unless (file-exists-p (expand-file-name "src/emacs.c" root))
  50. (error "%s doesn't seem to be the root of an Emacs source tree" root))
  51. (set-version-in-file root "README" version
  52. (rx (and "version" (1+ space)
  53. (submatch (1+ (in "0-9."))))))
  54. (set-version-in-file root "configure.in" version
  55. (rx (and "AC_INIT" (1+ (not (in ?,)))
  56. ?, (0+ space)
  57. (submatch (1+ (in "0-9."))))))
  58. (set-version-in-file root "doc/emacs/emacsver.texi" version
  59. (rx (and "EMACSVER" (1+ space)
  60. (submatch (1+ (in "0-9."))))))
  61. (set-version-in-file root "doc/man/emacs.1" version
  62. (rx (and ".TH EMACS" (1+ not-newline)
  63. "GNU Emacs" (1+ space)
  64. (submatch (1+ (in "0-9."))))))
  65. (set-version-in-file root "nt/config.nt" version
  66. (rx (and bol "#" (0+ blank) "define" (1+ blank)
  67. "VERSION" (1+ blank) "\""
  68. (submatch (1+ (in "0-9."))))))
  69. (set-version-in-file root "msdos/sed2v2.inp" version
  70. (rx (and bol "/^#undef " (1+ not-newline)
  71. "define VERSION" (1+ space) "\""
  72. (submatch (1+ (in "0-9."))))))
  73. (set-version-in-file root "nt/makefile.w32-in" version
  74. (rx (and "VERSION" (0+ space) "=" (0+ space)
  75. (submatch (1+ (in "0-9."))))))
  76. ;; nt/emacs.rc also contains the version number, but in an awkward
  77. ;; format. It must contain four components, separated by commas, and
  78. ;; in two places those commas are followed by space, in two other
  79. ;; places they are not.
  80. (let* ((version-components (append (split-string version "\\.")
  81. '("0" "0")))
  82. (comma-version
  83. (concat (car version-components) ","
  84. (cadr version-components) ","
  85. (cadr (cdr version-components)) ","
  86. (cadr (cdr (cdr version-components)))))
  87. (comma-space-version
  88. (concat (car version-components) ", "
  89. (cadr version-components) ", "
  90. (cadr (cdr version-components)) ", "
  91. (cadr (cdr (cdr version-components))))))
  92. (set-version-in-file root "nt/emacs.rc" comma-version
  93. (rx (and "FILEVERSION" (1+ space)
  94. (submatch (1+ (in "0-9,"))))))
  95. (set-version-in-file root "nt/emacs.rc" comma-version
  96. (rx (and "PRODUCTVERSION" (1+ space)
  97. (submatch (1+ (in "0-9,"))))))
  98. (set-version-in-file root "nt/emacs.rc" comma-space-version
  99. (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
  100. ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
  101. (set-version-in-file root "nt/emacs.rc" comma-space-version
  102. (rx (and "\"ProductVersion\"" (0+ space) ?,
  103. (0+ space) ?\" (submatch (1+ (in "0-9, ")))
  104. "\\0\"")))
  105. ;; Likewise for emacsclient.rc
  106. (set-version-in-file root "nt/emacsclient.rc" comma-version
  107. (rx (and "FILEVERSION" (1+ space)
  108. (submatch (1+ (in "0-9,"))))))
  109. (set-version-in-file root "nt/emacsclient.rc" comma-version
  110. (rx (and "PRODUCTVERSION" (1+ space)
  111. (submatch (1+ (in "0-9,"))))))
  112. (set-version-in-file root "nt/emacsclient.rc" comma-space-version
  113. (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
  114. ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
  115. (set-version-in-file root "nt/emacsclient.rc" comma-space-version
  116. (rx (and "\"ProductVersion\"" (0+ space) ?,
  117. (0+ space) ?\" (submatch (1+ (in "0-9, ")))
  118. "\\0\""))))
  119. ;; nextstep.
  120. (set-version-in-file
  121. root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
  122. version (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
  123. (submatch (1+ (in "0-9."))))))
  124. (set-version-in-file
  125. root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
  126. version (rx (and "CFBundleShortVersionString" (1+ not-newline) ?\n
  127. (0+ not-newline) "<string>" (0+ space)
  128. (submatch (1+ (in "0-9."))))))
  129. (set-version-in-file
  130. root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
  131. version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space)
  132. ?\" (0+ space) "Version" (1+ space)
  133. (submatch (1+ (in "0-9."))))))
  134. (set-version-in-file
  135. root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
  136. version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space)
  137. ?\" (0+ space) "Emacs version" (1+ space)
  138. (submatch (1+ (in "0-9."))))))
  139. (set-version-in-file
  140. root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
  141. version (rx (and "ApplicationRelease" (0+ space) ?= (0+ space)
  142. ?\" (0+ space) (submatch (1+ (in "0-9."))))))
  143. (set-version-in-file
  144. root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
  145. version (rx (and "FullVersionID" (0+ space) ?= (0+ space)
  146. ?\" (0+ space) "Emacs" (1+ space)
  147. (submatch (1+ (in "0-9."))))))
  148. (set-version-in-file
  149. root "nextstep/GNUstep/Emacs.base/Resources/Emacs.desktop"
  150. version (rx (and "Version=" (submatch (1+ (in "0-9.")))))))
  151. ;; Note this makes some assumptions about form of short copyright.
  152. (defun set-copyright (root copyright)
  153. "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
  154. Root must be the root of an Emacs source tree."
  155. (interactive (list
  156. (read-directory-name "Emacs root directory: " nil nil t)
  157. (read-string
  158. "Short copyright string: "
  159. (format "Copyright (C) %s Free Software Foundation, Inc."
  160. (format-time-string "%Y")))))
  161. (unless (file-exists-p (expand-file-name "src/emacs.c" root))
  162. (error "%s doesn't seem to be the root of an Emacs source tree" root))
  163. (set-version-in-file root "src/emacs.c" copyright
  164. (rx (and "emacs_copyright" (0+ (not (in ?\")))
  165. ?\" (submatch (1+ (not (in ?\")))) ?\")))
  166. (set-version-in-file root "lib-src/ebrowse.c" copyright
  167. (rx (and "emacs_copyright" (0+ (not (in ?\")))
  168. ?\" (submatch (1+ (not (in ?\")))) ?\")))
  169. (set-version-in-file root "lib-src/etags.c" copyright
  170. (rx (and "emacs_copyright" (0+ (not (in ?\")))
  171. ?\" (submatch (1+ (not (in ?\")))) ?\")))
  172. (set-version-in-file root "lib-src/rcs2log" copyright
  173. (rx (and "Copyright" (0+ space) ?= (0+ space)
  174. ?\' (submatch (1+ nonl)))))
  175. ;; This one is a nuisance, as it needs to be split over two lines.
  176. (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
  177. ;; nextstep.
  178. (set-version-in-file
  179. root "nextstep/Cocoa/Emacs.base/Contents/Info.plist"
  180. copyright (rx (and "CFBundleGetInfoString" (1+ anything) "Emacs" (1+ space)
  181. (1+ (in "0-9.")) (1+ space)
  182. (submatch (1+ (not (in ?\<)))))))
  183. (set-version-in-file
  184. root "nextstep/Cocoa/Emacs.base/Contents/Resources/English.lproj/InfoPlist.strings"
  185. copyright (rx (and "NSHumanReadableCopyright" (0+ space) ?\= (0+ space)
  186. ?\" (submatch (1+ (not (in ?\")))))))
  187. (set-version-in-file
  188. root "nextstep/GNUstep/Emacs.base/Resources/Info-gnustep.plist"
  189. copyright (rx (and "Copyright" (0+ space) ?\= (0+ space)
  190. ?\" (submatch (1+ (not (in ?\")))))))
  191. (when (string-match "\\([0-9]\\{4\\}\\)" copyright)
  192. (setq copyright (match-string 1 copyright))
  193. (dolist (file (directory-files (expand-file-name "etc/refcards" root)
  194. t "\\.tex\\'"))
  195. (unless (string-match "gnus-refcard\\.tex" file)
  196. (set-version-in-file
  197. root file copyright
  198. (concat (if (string-match "ru-refcard\\.tex" file)
  199. "\\\\newcommand{\\\\cyear}\\[0\\]{"
  200. "\\\\def\\\\year{")
  201. "\\([0-9]\\{4\\}\\)}.+%.+copyright year"))))))
  202. ;;; Various bits of magic for generating the web manuals
  203. (defun make-manuals (root)
  204. "Generate the web manuals for the Emacs webpage."
  205. (interactive "DEmacs root directory: ")
  206. (let* ((dest (expand-file-name "manual" root))
  207. (html-node-dir (expand-file-name "html_node" dest))
  208. (html-mono-dir (expand-file-name "html_mono" dest))
  209. (txt-dir (expand-file-name "text" dest))
  210. (dvi-dir (expand-file-name "dvi" dest))
  211. (ps-dir (expand-file-name "ps" dest)))
  212. (when (file-directory-p dest)
  213. (if (y-or-n-p (format "Directory %s exists, delete it first?" dest))
  214. (delete-directory dest t)
  215. (error "Aborted")))
  216. (make-directory dest)
  217. (make-directory html-node-dir)
  218. (make-directory html-mono-dir)
  219. (make-directory txt-dir)
  220. (make-directory dvi-dir)
  221. (make-directory ps-dir)
  222. ;; Emacs manual
  223. (let ((texi (expand-file-name "doc/emacs/emacs.texi" root)))
  224. (manual-html-node texi (expand-file-name "emacs" html-node-dir))
  225. (manual-html-mono texi (expand-file-name "emacs.html" html-mono-dir))
  226. (manual-txt texi (expand-file-name "emacs.txt" txt-dir))
  227. (manual-pdf texi (expand-file-name "emacs.pdf" dest))
  228. (manual-dvi texi (expand-file-name "emacs.dvi" dvi-dir)
  229. (expand-file-name "emacs.ps" ps-dir)))
  230. ;; Lisp manual
  231. (let ((texi (expand-file-name "doc/lispref/elisp.texi" root)))
  232. (manual-html-node texi (expand-file-name "elisp" html-node-dir))
  233. (manual-html-mono texi (expand-file-name "elisp.html" html-mono-dir))
  234. (manual-txt texi (expand-file-name "elisp.txt" txt-dir))
  235. (manual-pdf texi (expand-file-name "elisp.pdf" dest))
  236. (manual-dvi texi (expand-file-name "elisp.dvi" dvi-dir)
  237. (expand-file-name "elisp.ps" ps-dir)))
  238. (message "Manuals created in %s" dest)))
  239. (defconst manual-doctype-string
  240. "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
  241. \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
  242. (defconst manual-meta-string
  243. "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
  244. <link rev=\"made\" href=\"mailto:webmasters@gnu.org\">
  245. <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
  246. <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
  247. <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
  248. (defconst manual-style-string "<style type=\"text/css\">
  249. @import url('/style.css');\n</style>\n")
  250. (defun manual-html-mono (texi-file dest)
  251. "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
  252. This function also edits the HTML files so that they validate as
  253. HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
  254. the @import directive."
  255. (call-process "makeinfo" nil nil nil
  256. "--html" "--no-split" texi-file "-o" dest)
  257. (with-temp-buffer
  258. (insert-file-contents dest)
  259. (setq buffer-file-name dest)
  260. (manual-html-fix-headers)
  261. (manual-html-fix-index-1)
  262. (manual-html-fix-index-2 t)
  263. (manual-html-fix-node-div)
  264. (goto-char (point-max))
  265. (re-search-backward "</body>[\n \t]*</html>")
  266. (insert "</div>\n\n")
  267. (save-buffer)))
  268. (defun manual-html-node (texi-file dir)
  269. "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
  270. This function also edits the HTML files so that they validate as
  271. HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
  272. the @import directive."
  273. (unless (file-exists-p texi-file)
  274. (error "Manual file %s not found" texi-file))
  275. (call-process "makeinfo" nil nil nil
  276. "--html" texi-file "-o" dir)
  277. ;; Loop through the node files, fixing them up.
  278. (dolist (f (directory-files dir nil "\\.html\\'"))
  279. (let (opoint)
  280. (with-temp-buffer
  281. (insert-file-contents (expand-file-name f dir))
  282. (setq buffer-file-name (expand-file-name f dir))
  283. (if (looking-at "<meta http-equiv")
  284. ;; Ignore those HTML files that are just redirects.
  285. (set-buffer-modified-p nil)
  286. (manual-html-fix-headers)
  287. (if (equal f "index.html")
  288. (let (copyright-text)
  289. (manual-html-fix-index-1)
  290. ;; Move copyright notice to the end.
  291. (re-search-forward "[ \t]*<p>Copyright &copy;")
  292. (setq opoint (match-beginning 0))
  293. (re-search-forward "</blockquote>")
  294. (setq copyright-text (buffer-substring opoint (point)))
  295. (delete-region opoint (point))
  296. (manual-html-fix-index-2)
  297. (insert copyright-text "\n</div>\n"))
  298. ;; For normal nodes, give the header div a blue bg.
  299. (manual-html-fix-node-div))
  300. (save-buffer))))))
  301. (defun manual-txt (texi-file dest)
  302. "Run Makeinfo on TEXI-FILE, emitting plaintext output to DEST."
  303. (call-process "makeinfo" nil nil nil
  304. "--plaintext" "--no-split" texi-file "-o" dest)
  305. (shell-command (concat "gzip -c " dest " > " (concat dest ".gz"))))
  306. (defun manual-pdf (texi-file dest)
  307. "Run texi2pdf on TEXI-FILE, emitting plaintext output to DEST."
  308. (call-process "texi2pdf" nil nil nil texi-file "-o" dest))
  309. (defun manual-dvi (texi-file dest ps-dest)
  310. "Run texi2dvi on TEXI-FILE, emitting dvi output to DEST.
  311. Also generate PostScript output in PS-DEST."
  312. (call-process "texi2dvi" nil nil nil texi-file "-o" dest)
  313. (call-process "dvips" nil nil nil dest "-o" ps-dest)
  314. (call-process "gzip" nil nil nil dest)
  315. (call-process "gzip" nil nil nil ps-dest))
  316. (defun manual-html-fix-headers ()
  317. "Fix up HTML headers for the Emacs manual in the current buffer."
  318. (let (opoint)
  319. (insert manual-doctype-string)
  320. (search-forward "<head>\n")
  321. (insert manual-meta-string)
  322. (search-forward "<meta")
  323. (setq opoint (match-beginning 0))
  324. (re-search-forward "<!--")
  325. (goto-char (match-beginning 0))
  326. (delete-region opoint (point))
  327. (insert manual-style-string)
  328. (search-forward "<meta http-equiv=\"Content-Style")
  329. (setq opoint (match-beginning 0))
  330. (search-forward "</head>")
  331. (delete-region opoint (match-beginning 0))))
  332. (defun manual-html-fix-node-div ()
  333. "Fix up HTML \"node\" divs in the current buffer."
  334. (let (opoint div-end)
  335. (while (search-forward "<div class=\"node\">" nil t)
  336. (replace-match
  337. "<div class=\"node\" style=\"background-color:#DDDDFF\">"
  338. t t)
  339. (setq opoint (point))
  340. (re-search-forward "</div>")
  341. (setq div-end (match-beginning 0))
  342. (goto-char opoint)
  343. (if (search-forward "<hr>" div-end 'move)
  344. (replace-match "" t t)))))
  345. (defun manual-html-fix-index-1 ()
  346. (let (opoint)
  347. (re-search-forward "<body>\n\\(<h1 class=\"settitle\\)")
  348. (setq opoint (match-beginning 1))
  349. (search-forward "<h2 class=\"unnumbered")
  350. (goto-char (match-beginning 0))
  351. (delete-region opoint (point))
  352. (insert "<div id=\"content\" class=\"inner\">\n\n")))
  353. (defun manual-html-fix-index-2 (&optional table-workaround)
  354. "Replace the index list in the current buffer with a HTML table."
  355. (let (done open-td tag desc)
  356. ;; Convert the list that Makeinfo made into a table.
  357. (search-forward "<ul class=\"menu\">")
  358. (replace-match "<table style=\"float:left\" width=\"100%\">")
  359. (forward-line 1)
  360. (while (not done)
  361. (cond
  362. ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
  363. (looking-at "<li>\\(<a.+</a>\\)$"))
  364. (setq tag (match-string 1))
  365. (setq desc (match-string 2))
  366. (replace-match "" t t)
  367. (when open-td
  368. (save-excursion
  369. (forward-char -1)
  370. (skip-chars-backward " ")
  371. (delete-region (point) (line-end-position))
  372. (insert "</td>\n </tr>")))
  373. (insert " <tr>\n ")
  374. (if table-workaround
  375. ;; This works around a Firefox bug in the mono file.
  376. (insert "<td bgcolor=\"white\">")
  377. (insert "<td>"))
  378. (insert tag "</td>\n <td>" (or desc ""))
  379. (setq open-td t))
  380. ((eq (char-after) ?\n)
  381. (delete-char 1)
  382. ;; Negate the following `forward-line'.
  383. (forward-line -1))
  384. ((looking-at "<!-- ")
  385. (search-forward "-->"))
  386. ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
  387. (replace-match " </td></tr></table>\n
  388. <h3>Detailed Node Listing</h3>\n\n" t t)
  389. (search-forward "<p>")
  390. (search-forward "<p>")
  391. (goto-char (match-beginning 0))
  392. (skip-chars-backward "\n ")
  393. (setq open-td nil)
  394. (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
  395. ((looking-at "</li></ul>")
  396. (replace-match "" t t))
  397. ((looking-at "<p>")
  398. (replace-match "" t t)
  399. (when open-td
  400. (insert " </td></tr>")
  401. (setq open-td nil))
  402. (insert " <tr>
  403. <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
  404. (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">")
  405. (replace-match " </th></tr>"))
  406. ((looking-at "[ \t]*</ul>[ \t]*$")
  407. (replace-match
  408. (if open-td
  409. " </td></tr>\n</table>"
  410. "</table>") t t)
  411. (setq done t))
  412. (t
  413. (if (eobp)
  414. (error "Parse error in %s" f))
  415. (unless open-td
  416. (setq done t))))
  417. (forward-line 1))))
  418. ;; Stuff to check new defcustoms got :version tags.
  419. ;; Adapted from check-declare.el.
  420. (defun cusver-find-files (root &optional old)
  421. "Find .el files beneath directory ROOT that contain defcustoms.
  422. If optional OLD is non-nil, also include defvars."
  423. (process-lines find-program root
  424. "-name" "*.el"
  425. "-exec" grep-program
  426. "-l" "-E" (format "^[ \\t]*\\(def%s"
  427. (if old "(custom|var)"
  428. "custom"
  429. ))
  430. "{}" "+"))
  431. ;; TODO if a defgroup with a version tag, apply to all customs in that
  432. ;; group (eg for new files).
  433. (defun cusver-scan (file &optional old)
  434. "Scan FILE for `defcustom' calls.
  435. Return a list with elements of the form (VAR . VER),
  436. This means that FILE contains a defcustom for variable VAR, with
  437. a :version tag having value VER (may be nil).
  438. If optional argument OLD is non-nil, also scan for defvars."
  439. (let ((m (format "Scanning %s..." file))
  440. (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
  441. (if old "\\(?:custom\\|var\\)" "custom")))
  442. alist var ver)
  443. (message "%s" m)
  444. (with-temp-buffer
  445. (insert-file-contents file)
  446. ;; FIXME we could theoretically be inside a string.
  447. (while (re-search-forward re nil t)
  448. (goto-char (match-beginning 1))
  449. (if (and (setq form (ignore-errors (read (current-buffer))))
  450. (setq var (car-safe (cdr-safe form)))
  451. ;; Exclude macros, eg (defcustom ,varname ...).
  452. (symbolp var))
  453. (setq ver (car (cdr-safe (memq :version form)))
  454. alist (cons (cons var ver) alist))
  455. (if form (message "Malformed defcustom: `%s'" form)))))
  456. (message "%sdone" m)
  457. alist))
  458. (define-button-type 'cusver-xref 'action #'cusver-goto-xref)
  459. (defun cusver-goto-xref (button)
  460. "Jump to a lisp file for the BUTTON at point."
  461. (let ((file (button-get button 'file))
  462. (var (button-get button 'var)))
  463. (if (not (file-readable-p file))
  464. (message "Cannot read `%s'" file)
  465. (with-current-buffer (find-file-noselect file)
  466. (goto-char (point-min))
  467. (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var) nil t)
  468. (message "Unable to locate defcustom"))
  469. (pop-to-buffer (current-buffer))))))
  470. ;; You should probably at least do a grep over the old directory
  471. ;; to check the results of this look sensible. Eg cus-start if
  472. ;; something moved from C to Lisp.
  473. ;; TODO handle renamed things with aliases to the old names.
  474. ;; What to do about new files? Does everything in there need a :version,
  475. ;; or eg just the defgroup?
  476. (defun cusver-check (newdir olddir)
  477. "Check that defcustoms have :version tags where needed.
  478. NEWDIR is the current lisp/ directory, OLDDIR is that from the previous
  479. release. A defcustom that is only in NEWDIR should have a :version
  480. tag. We exclude cases where a defvar exists in OLDDIR, since
  481. just converting a defvar to a defcustom does not require a :version bump.
  482. Note that a :version tag should also be added if the value of a defcustom
  483. changes (in a non-trivial way). This function does not check for that."
  484. (interactive "DNew Lisp directory: \nDOld Lisp directory: ")
  485. (or (file-directory-p (setq newdir (expand-file-name newdir)))
  486. (error "Directory `%s' not found" newdir))
  487. (or (file-directory-p (setq olddir (expand-file-name olddir)))
  488. (error "Directory `%s' not found" olddir))
  489. (let* ((newfiles (progn (message "Finding new files with defcustoms...")
  490. (cusver-find-files newdir)))
  491. (oldfiles (progn (message "Finding old files with defcustoms...")
  492. (cusver-find-files olddir t)))
  493. (newcus (progn (message "Reading new defcustoms...")
  494. (mapcar
  495. (lambda (file)
  496. (cons file (cusver-scan file))) newfiles)))
  497. oldcus result thisfile)
  498. (message "Reading old defcustoms...")
  499. (dolist (file oldfiles)
  500. (setq oldcus (append oldcus (cusver-scan file t))))
  501. ;; newcus has elements (FILE (VAR VER) ... ).
  502. ;; oldcus just (VAR . VER).
  503. (message "Checking for version tags...")
  504. (dolist (new newcus)
  505. (setq file (car new)
  506. thisfile
  507. (let (missing var)
  508. (dolist (cons (cdr new))
  509. (or (cdr cons)
  510. (assq (setq var (car cons)) oldcus)
  511. (push var missing)))
  512. (if missing
  513. (cons file missing))))
  514. (if thisfile
  515. (setq result (cons thisfile result))))
  516. (message "Checking for version tags... done")
  517. (if (not result)
  518. (message "No missing :version tags")
  519. (pop-to-buffer "*cusver*")
  520. (erase-buffer)
  521. (insert "These defcustoms might be missing :version tags:\n\n")
  522. (dolist (elem result)
  523. (let* ((str (file-relative-name (car elem) newdir))
  524. (strlen (length str)))
  525. (dolist (var (cdr elem))
  526. (insert (format "%s: %s\n" str var))
  527. (make-text-button (+ (line-beginning-position 0) strlen 2)
  528. (line-end-position 0)
  529. 'file (car elem)
  530. 'var var
  531. 'help-echo "Mouse-2: visit this definition"
  532. :type 'cusver-xref)))))))
  533. (provide 'admin)
  534. ;;; admin.el ends here