1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001-2013 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/>.
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.
29 (defvar add-log-time-format
) ; in add-log
31 ;; Does this information need to be in every ChangeLog, as opposed to
32 ;; just the top-level one? Only if you allow changes the same
33 ;; day as the release.
34 ;; http://lists.gnu.org/archive/html/emacs-devel/2013-03/msg00161.html
35 (defun add-release-logs (root version
&optional date
)
36 "Add \"Version VERSION released.\" change log entries in ROOT.
37 Root must be the root of an Emacs source tree.
38 Optional argument DATE is the release date, default today."
39 (interactive (list (read-directory-name "Emacs root directory: ")
40 (read-string "Version number: "
41 (format "%s.%s" emacs-major-version
43 (read-string "Release date: "
44 (progn (require 'add-log
)
45 (let ((add-log-time-zone-rule t
))
46 (funcall add-log-time-format
))))))
47 (setq root
(expand-file-name root
))
48 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
49 (error "%s doesn't seem to be the root of an Emacs source tree" root
))
51 (or date
(setq date
(let ((add-log-time-zone-rule t
))
52 (funcall add-log-time-format
))))
53 (let* ((logs (process-lines "find" root
"-name" "ChangeLog"))
54 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
56 (or add-log-full-name
(user-full-name))
57 (or add-log-mailing-address user-mail-address
)
61 (goto-char (point-min))
64 (defun set-version-in-file (root file version rx
)
65 (find-file (expand-file-name file root
))
66 (goto-char (point-min))
67 (unless (re-search-forward rx nil t
)
68 (error "Version not found in %s" file
))
69 (replace-match (format "%s" version
) nil nil nil
1))
71 (defun set-version (root version
)
72 "Set Emacs version to VERSION in relevant files under ROOT.
73 Root must be the root of an Emacs source tree."
74 (interactive "DEmacs root directory: \nsVersion number: ")
75 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
76 (error "%s doesn't seem to be the root of an Emacs source tree" root
))
77 (set-version-in-file root
"README" version
78 (rx (and "version" (1+ space
)
79 (submatch (1+ (in "0-9."))))))
80 (set-version-in-file root
"configure.ac" version
81 (rx (and "AC_INIT" (1+ (not (in ?
,)))
83 (submatch (1+ (in "0-9."))))))
84 (set-version-in-file root
"doc/emacs/emacsver.texi" version
85 (rx (and "EMACSVER" (1+ space
)
86 (submatch (1+ (in "0-9."))))))
87 (set-version-in-file root
"doc/man/emacs.1" version
88 (rx (and ".TH EMACS" (1+ not-newline
)
89 "GNU Emacs" (1+ space
)
90 (submatch (1+ (in "0-9."))))))
91 (set-version-in-file root
"nt/config.nt" version
92 (rx (and bol
"#" (0+ blank
) "define" (1+ blank
)
93 "VERSION" (1+ blank
) "\""
94 (submatch (1+ (in "0-9."))))))
95 (set-version-in-file root
"msdos/sed2v2.inp" version
96 (rx (and bol
"/^#undef " (1+ not-newline
)
97 "define VERSION" (1+ space
) "\""
98 (submatch (1+ (in "0-9."))))))
99 (set-version-in-file root
"nt/makefile.w32-in" version
100 (rx (and "VERSION" (0+ space
) "=" (0+ space
)
101 (submatch (1+ (in "0-9."))))))
102 ;; nt/emacs.rc also contains the version number, but in an awkward
103 ;; format. It must contain four components, separated by commas, and
104 ;; in two places those commas are followed by space, in two other
105 ;; places they are not.
106 (let* ((version-components (append (split-string version
"\\.")
109 (concat (car version-components
) ","
110 (cadr version-components
) ","
111 (cadr (cdr version-components
)) ","
112 (cadr (cdr (cdr version-components
)))))
114 (concat (car version-components
) ", "
115 (cadr version-components
) ", "
116 (cadr (cdr version-components
)) ", "
117 (cadr (cdr (cdr version-components
))))))
118 (set-version-in-file root
"nt/emacs.rc" comma-version
119 (rx (and "FILEVERSION" (1+ space
)
120 (submatch (1+ (in "0-9,"))))))
121 (set-version-in-file root
"nt/emacs.rc" comma-version
122 (rx (and "PRODUCTVERSION" (1+ space
)
123 (submatch (1+ (in "0-9,"))))))
124 (set-version-in-file root
"nt/emacs.rc" comma-space-version
125 (rx (and "\"FileVersion\"" (0+ space
) ?
, (0+ space
)
126 ?
\" (submatch (1+ (in "0-9, "))) "\\0\"")))
127 (set-version-in-file root
"nt/emacs.rc" comma-space-version
128 (rx (and "\"ProductVersion\"" (0+ space
) ?
,
129 (0+ space
) ?
\" (submatch (1+ (in "0-9, ")))
131 ;; Likewise for emacsclient.rc
132 (set-version-in-file root
"nt/emacsclient.rc" comma-version
133 (rx (and "FILEVERSION" (1+ space
)
134 (submatch (1+ (in "0-9,"))))))
135 (set-version-in-file root
"nt/emacsclient.rc" comma-version
136 (rx (and "PRODUCTVERSION" (1+ space
)
137 (submatch (1+ (in "0-9,"))))))
138 (set-version-in-file root
"nt/emacsclient.rc" comma-space-version
139 (rx (and "\"FileVersion\"" (0+ space
) ?
, (0+ space
)
140 ?
\" (submatch (1+ (in "0-9, "))) "\\0\"")))
141 (set-version-in-file root
"nt/emacsclient.rc" comma-space-version
142 (rx (and "\"ProductVersion\"" (0+ space
) ?
,
143 (0+ space
) ?
\" (submatch (1+ (in "0-9, ")))
145 ;; Major version only.
146 (when (string-match "\\([0-9]\\{2,\\}\\)" version
)
147 (setq version
(match-string 1 version
))
148 (set-version-in-file root
"src/msdos.c" version
149 (rx (and "Vwindow_system_version" (1+ not-newline
)
150 ?\
( (submatch (1+ (in "0-9"))) ?\
))))
151 (set-version-in-file root
"etc/refcards/ru-refcard.tex" version
152 "\\\\newcommand{\\\\versionemacs}\\[0\\]\
153 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs")
154 (set-version-in-file root
"etc/refcards/emacsver.tex" version
155 "\\\\def\\\\versionemacs\
156 {\\([0-9]\\{2,\\}\\)}.+%.+version of Emacs"))))
159 ;; Note this makes some assumptions about form of short copyright.
160 (defun set-copyright (root copyright
)
161 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
162 Root must be the root of an Emacs source tree."
164 (read-directory-name "Emacs root directory: " nil nil t
)
166 "Short copyright string: "
167 (format "Copyright (C) %s Free Software Foundation, Inc."
168 (format-time-string "%Y")))))
169 (unless (file-exists-p (expand-file-name "src/emacs.c" root
))
170 (error "%s doesn't seem to be the root of an Emacs source tree" root
))
171 (set-version-in-file root
"configure.ac" copyright
172 (rx (and bol
"copyright" (0+ (not (in ?
\")))
173 ?
\" (submatch (1+ (not (in ?
\")))) ?
\")))
174 (set-version-in-file root
"msdos/sed2v2.inp" copyright
175 (rx (and bol
"/^#undef " (1+ not-newline
)
176 "define COPYRIGHT" (1+ space
)
177 ?
\" (submatch (1+ (not (in ?
\")))) ?
\")))
178 (set-version-in-file root
"nt/config.nt" copyright
179 (rx (and bol
"#" (0+ blank
) "define" (1+ blank
)
180 "COPYRIGHT" (1+ blank
)
181 ?
\" (submatch (1+ (not (in ?
\")))) ?
\")))
182 (set-version-in-file root
"lib-src/rcs2log" copyright
183 (rx (and "Copyright" (0+ space
) ?
= (0+ space
)
184 ?
\' (submatch (1+ nonl
)))))
185 (when (string-match "\\([0-9]\\{4\\}\\)" copyright
)
186 (setq copyright
(match-string 1 copyright
))
187 (set-version-in-file root
"etc/refcards/ru-refcard.tex" copyright
188 "\\\\newcommand{\\\\cyear}\\[0\\]\
189 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")
190 (set-version-in-file root
"etc/refcards/emacsver.tex" copyright
192 {\\([0-9]\\{4\\}\\)}.+%.+copyright year")))
194 ;;; Various bits of magic for generating the web manuals
196 (defun manual-misc-manuals (root)
197 "Return doc/misc manuals as list of strings."
198 ;; Similar to `make -C doc/misc echo-info', but works if unconfigured,
199 ;; and for INFO_TARGETS rather than INFO_INSTALL.
201 (insert-file-contents (expand-file-name "doc/misc/Makefile.in" root
))
202 ;; Should really use expanded value of INFO_TARGETS.
203 (search-forward "INFO_COMMON = ")
204 (let ((start (point)))
206 (while (and (looking-back "\\\\")
207 (zerop (forward-line 1)))
209 (append (split-string (replace-regexp-in-string
210 "\\(\\\\\\|\\.info\\)" ""
211 (buffer-substring start
(point))))
214 (defun make-manuals (root &optional type
)
215 "Generate the web manuals for the Emacs webpage.
216 Interactively with a prefix argument, prompt for TYPE.
217 Optional argument TYPE is type of output (nil means all)."
218 (interactive (let ((root (read-directory-name "Emacs root directory: "
219 source-directory nil t
)))
221 (if current-prefix-arg
227 (dolist (i '("emacs" "elisp" "eintr") res
)
228 (dolist (j '("" "-mono" "-node" "-ps" "-pdf"))
229 (push (concat i j
) res
))))
230 (manual-misc-manuals root
)))))))
231 (let* ((dest (expand-file-name "manual" root
))
232 (html-node-dir (expand-file-name "html_node" dest
))
233 (html-mono-dir (expand-file-name "html_mono" dest
))
234 (ps-dir (expand-file-name "ps" dest
))
235 (pdf-dir (expand-file-name "pdf" dest
))
236 (emacs (expand-file-name "doc/emacs/emacs.texi" root
))
237 (elisp (expand-file-name "doc/lispref/elisp.texi" root
))
238 (eintr (expand-file-name "doc/lispintro/emacs-lisp-intro.texi" root
))
239 (misc (manual-misc-manuals root
)))
240 ;; TODO this makes it non-continuable.
241 ;; Instead, delete the individual dest directory each time.
242 (when (file-directory-p dest
)
243 (if (y-or-n-p (format "Directory %s exists, delete it first? " dest
))
244 (delete-directory dest t
)
245 (user-error "Aborted")))
246 (if (member type
'(nil "emacs" "emacs-node"))
247 (manual-html-node emacs
(expand-file-name "emacs" html-node-dir
)))
248 (if (member type
'(nil "emacs" "emacs-mono"))
249 (manual-html-mono emacs
(expand-file-name "emacs.html" html-mono-dir
)))
250 (if (member type
'(nil "emacs" "emacs-pdf" "pdf"))
251 (manual-pdf emacs
(expand-file-name "emacs.pdf" pdf-dir
)))
252 (if (member type
'(nil "emacs" "emacs-ps" "ps"))
253 (manual-ps emacs
(expand-file-name "emacs.ps" ps-dir
)))
254 (if (member type
'(nil "elisp" "elisp-node"))
255 (manual-html-node elisp
(expand-file-name "elisp" html-node-dir
)))
256 (if (member type
'(nil "elisp" "elisp-mono"))
257 (manual-html-mono elisp
(expand-file-name "elisp.html" html-mono-dir
)))
258 (if (member type
'(nil "elisp" "elisp-pdf" "pdf"))
259 (manual-pdf elisp
(expand-file-name "elisp.pdf" pdf-dir
)))
260 (if (member type
'(nil "elisp" "elisp-ps" "ps"))
261 (manual-ps elisp
(expand-file-name "elisp.ps" ps-dir
)))
262 (if (member type
'(nil "eintr" "eintr-node"))
263 (manual-html-node eintr
(expand-file-name "eintr" html-node-dir
)))
264 (if (member type
'(nil "eintr" "eintr-node"))
265 (manual-html-mono eintr
(expand-file-name "eintr.html" html-mono-dir
)))
266 (if (member type
'(nil "eintr" "eintr-pdf" "pdf"))
267 (manual-pdf eintr
(expand-file-name "eintr.pdf" pdf-dir
)))
268 (if (member type
'(nil "eintr" "eintr-ps" "ps"))
269 (manual-ps eintr
(expand-file-name "eintr.ps" ps-dir
)))
271 (dolist (manual misc
)
272 (if (member type
`(nil ,manual
"misc"))
273 (manual-misc-html manual root html-node-dir html-mono-dir
)))
274 (message "Manuals created in %s" dest
)))
276 (defconst manual-doctype-string
277 "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"
278 \"http://www.w3.org/TR/html4/loose.dtd\">\n\n")
280 (defconst manual-meta-string
281 "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\">
282 <link rev=\"made\" href=\"mailto:webmasters@gnu.org\">
283 <link rel=\"icon\" type=\"image/png\" href=\"/graphics/gnu-head-mini.png\">
284 <meta name=\"ICBM\" content=\"42.256233,-71.006581\">
285 <meta name=\"DC.title\" content=\"gnu.org\">\n\n")
287 (defconst manual-style-string
"<style type=\"text/css\">
288 @import url('/software/emacs/manual.css');\n</style>\n")
290 (defun manual-misc-html (name root html-node-dir html-mono-dir
)
291 ;; Hack to deal with the cases where .texi creates a different .info.
292 ;; Blech. TODO Why not just rename the .texi (or .info) files?
293 (let* ((texiname (cond ((equal name
"ccmode") "cc-mode")
295 (texi (expand-file-name (format "doc/misc/%s.texi" texiname
) root
)))
296 (manual-html-node texi
(expand-file-name name html-node-dir
))
297 (manual-html-mono texi
(expand-file-name (concat name
".html")
300 (defun manual-html-mono (texi-file dest
)
301 "Run Makeinfo on TEXI-FILE, emitting mono HTML output to DEST.
302 This function also edits the HTML files so that they validate as
303 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
304 the @import directive."
305 (make-directory (or (file-name-directory dest
) ".") t
)
306 (call-process "makeinfo" nil nil nil
308 "-I" (expand-file-name "../emacs"
309 (file-name-directory texi-file
))
310 "-I" (expand-file-name "../misc"
311 (file-name-directory texi-file
))
312 "--html" "--no-split" texi-file
"-o" dest
)
314 (insert-file-contents dest
)
315 (setq buffer-file-name dest
)
316 (manual-html-fix-headers)
317 (manual-html-fix-index-1)
318 (manual-html-fix-index-2 t
)
319 (manual-html-fix-node-div)
320 (goto-char (point-max))
321 (re-search-backward "</body>[\n \t]*</html>")
322 (insert "</div>\n\n")
325 (defun manual-html-node (texi-file dir
)
326 "Run Makeinfo on TEXI-FILE, emitting per-node HTML output to DIR.
327 This function also edits the HTML files so that they validate as
328 HTML 4.01 Transitional, and pulls in the gnu.org stylesheet using
329 the @import directive."
330 (unless (file-exists-p texi-file
)
331 (error "Manual file %s not found" texi-file
))
332 (make-directory dir t
)
333 (call-process "makeinfo" nil nil nil
335 "-I" (expand-file-name "../emacs"
336 (file-name-directory texi-file
))
337 "-I" (expand-file-name "../misc"
338 (file-name-directory texi-file
))
339 "--html" texi-file
"-o" dir
)
340 ;; Loop through the node files, fixing them up.
341 (dolist (f (directory-files dir nil
"\\.html\\'"))
344 (insert-file-contents (expand-file-name f dir
))
345 (setq buffer-file-name
(expand-file-name f dir
))
346 (if (looking-at "<meta http-equiv")
347 ;; Ignore those HTML files that are just redirects.
348 (set-buffer-modified-p nil
)
349 (manual-html-fix-headers)
350 (if (equal f
"index.html")
351 (let (copyright-text)
352 (manual-html-fix-index-1)
353 ;; Move copyright notice to the end.
354 (when (re-search-forward "[ \t]*<p>Copyright ©" nil t
)
355 (setq opoint
(match-beginning 0))
356 (re-search-forward "</blockquote>")
357 (setq copyright-text
(buffer-substring opoint
(point)))
358 (delete-region opoint
(point)))
359 (manual-html-fix-index-2)
361 (insert copyright-text
))
362 (insert "\n</div>\n"))
363 ;; For normal nodes, give the header div a blue bg.
364 (manual-html-fix-node-div))
367 (defun manual-pdf (texi-file dest
)
368 "Run texi2pdf on TEXI-FILE, emitting pdf output to DEST."
369 (make-directory (or (file-name-directory dest
) ".") t
)
370 (let ((default-directory (file-name-directory texi-file
)))
371 (call-process "texi2pdf" nil nil nil
372 "-I" "../emacs" "-I" "../misc"
373 texi-file
"-o" dest
)))
375 (defun manual-ps (texi-file dest
)
376 "Generate a PostScript version of TEXI-FILE as DEST."
377 (make-directory (or (file-name-directory dest
) ".") t
)
378 (let ((dvi-dest (concat (file-name-sans-extension dest
) ".dvi"))
379 (default-directory (file-name-directory texi-file
)))
380 (call-process "texi2dvi" nil nil nil
381 "-I" "../emacs" "-I" "../misc"
382 texi-file
"-o" dvi-dest
)
383 (call-process "dvips" nil nil nil dvi-dest
"-o" dest
)
384 (delete-file dvi-dest
)
385 (call-process "gzip" nil nil nil dest
)))
387 (defun manual-html-fix-headers ()
388 "Fix up HTML headers for the Emacs manual in the current buffer."
390 (insert manual-doctype-string
)
391 (search-forward "<head>\n")
392 (insert manual-meta-string
)
393 (search-forward "<meta")
394 (setq opoint
(match-beginning 0))
395 (re-search-forward "<!--")
396 (goto-char (match-beginning 0))
397 (delete-region opoint
(point))
398 (insert manual-style-string
)
399 (search-forward "<meta http-equiv=\"Content-Style")
400 (setq opoint
(match-beginning 0))
401 (search-forward "</head>")
402 (delete-region opoint
(match-beginning 0))))
404 (defun manual-html-fix-node-div ()
405 "Fix up HTML \"node\" divs in the current buffer."
406 (let (opoint div-end
)
407 (while (search-forward "<div class=\"node\">" nil t
)
409 "<div class=\"node\" style=\"background-color:#DDDDFF\">"
411 (setq opoint
(point))
412 (re-search-forward "</div>")
413 (setq div-end
(match-beginning 0))
415 (if (search-forward "<hr>" div-end
'move
)
416 (replace-match "" t t
)))))
418 (defun manual-html-fix-index-1 ()
420 (re-search-forward "<body>\n")
421 (setq opoint
(match-end 0))
422 (search-forward "<h2 class=\"")
423 (goto-char (match-beginning 0))
424 (delete-region opoint
(point))
425 (insert "<div id=\"content\" class=\"inner\">\n\n")))
427 (defun manual-html-fix-index-2 (&optional table-workaround
)
428 "Replace the index list in the current buffer with a HTML table."
429 (let (done open-td tag desc
)
430 ;; Convert the list that Makeinfo made into a table.
431 (or (search-forward "<ul class=\"menu\">" nil t
)
432 (search-forward "<ul>"))
433 (replace-match "<table style=\"float:left\" width=\"100%\">")
437 ((or (looking-at "<li>\\(<a.+</a>\\):[ \t]+\\(.*\\)$")
438 (looking-at "<li>\\(<a.+</a>\\)$"))
439 (setq tag
(match-string 1))
440 (setq desc
(match-string 2))
441 (replace-match "" t t
)
445 (skip-chars-backward " ")
446 (delete-region (point) (line-end-position))
447 (insert "</td>\n </tr>")))
450 ;; This works around a Firefox bug in the mono file.
451 (insert "<td bgcolor=\"white\">")
453 (insert tag
"</td>\n <td>" (or desc
""))
455 ((eq (char-after) ?
\n)
457 ;; Negate the following `forward-line'.
459 ((looking-at "<!-- ")
460 (search-forward "-->"))
461 ((looking-at "<p>[- ]*The Detailed Node Listing[- \n]*")
462 (replace-match " </td></tr></table>\n
463 <h3>Detailed Node Listing</h3>\n\n" t t
)
464 (search-forward "<p>")
465 (search-forward "<p>" nil t
)
466 (goto-char (match-beginning 0))
467 (skip-chars-backward "\n ")
469 (insert "</p>\n\n<table style=\"float:left\" width=\"100%\">"))
470 ((looking-at "</li></ul>")
471 (replace-match "" t t
))
473 (replace-match "" t t
)
475 (insert " </td></tr>")
478 <th colspan=\"2\" align=\"left\" style=\"text-align:left\">")
479 (if (re-search-forward "</p>[ \t\n]*<ul class=\"menu\">" nil t
)
480 (replace-match " </th></tr>")))
481 ((looking-at "[ \t]*</ul>[ \t]*$")
484 " </td></tr>\n</table>"
489 (error "Parse error in %s"
490 (file-name-nondirectory buffer-file-name
)))
496 ;; Stuff to check new defcustoms got :version tags.
497 ;; Adapted from check-declare.el.
499 (defun cusver-find-files (root &optional old
)
500 "Find .el files beneath directory ROOT that contain defcustoms.
501 If optional OLD is non-nil, also include defvars."
502 (process-lines find-program root
505 "-l" "-E" (format "^[ \\t]*\\(def%s"
506 (if old
"(custom|var)"
511 (defvar cusver-new-version
(format "%s.%s" emacs-major-version
512 (1+ emacs-minor-version
))
513 "Version number that new defcustoms should have.")
515 (defun cusver-scan (file &optional old
)
516 "Scan FILE for `defcustom' calls.
517 Return a list with elements of the form (VAR . VER),
518 This means that FILE contains a defcustom for variable VAR, with
519 a :version tag having value VER (may be nil).
520 If optional argument OLD is non-nil, also scan for defvars."
521 (let ((m (format "Scanning %s..." file
))
522 (re (format "^[ \t]*\\((def%s\\)[ \t\n]"
523 (if old
"\\(custom\\|var\\)" "\\(custom\\|group\\)")))
524 alist var ver form glist grp
)
527 (insert-file-contents file
)
528 ;; FIXME we could theoretically be inside a string.
529 (while (re-search-forward re nil t
)
530 (goto-char (match-beginning 1))
531 (if (and (setq form
(ignore-errors (read (current-buffer))))
532 (setq var
(car-safe (cdr-safe form
)))
533 ;; Exclude macros, eg (defcustom ,varname ...).
536 (setq ver
(car (cdr-safe (memq :version form
))))
537 (if (equal "group" (match-string 2))
538 ;; Group :version could be old.
539 (if (equal ver cusver-new-version
)
540 (setq glist
(cons (cons var ver
) glist
)))
541 ;; If it specifies a group and the whole group has a
542 ;; version. use that.
544 (setq grp
(car (cdr-safe (memq :group form
))))
546 (setq grp
(car (cdr-safe grp
))) ; (quote foo) -> foo
547 (setq ver
(assq grp glist
))))
548 (setq alist
(cons (cons var ver
) alist
))))
549 (if form
(message "Malformed defcustom: `%s'" form
)))))
553 (defun cusver-scan-cus-start (file)
554 "Scan cus-start.el and return an alist with elements (VAR . VER)."
555 (if (file-readable-p file
)
557 (insert-file-contents file
)
558 (when (search-forward "(let ((all '(" nil t
)
561 (dolist (elem (ignore-errors (read (current-buffer))))
562 (when (symbolp (setq var
(car-safe elem
)))
563 (or (stringp (setq ver
(nth 3 elem
)))
565 (setq alist
(cons (cons var ver
) alist
))))
568 (define-button-type 'cusver-xref
'action
#'cusver-goto-xref
)
570 (defun cusver-goto-xref (button)
571 "Jump to a lisp file for the BUTTON at point."
572 (let ((file (button-get button
'file
))
573 (var (button-get button
'var
)))
574 (if (not (file-readable-p file
))
575 (message "Cannot read `%s'" file
)
576 (with-current-buffer (find-file-noselect file
)
577 (goto-char (point-min))
578 (or (re-search-forward (format "^[ \t]*(defcustom[ \t]*%s" var
) nil t
)
579 (message "Unable to locate defcustom"))
580 (pop-to-buffer (current-buffer))))))
582 ;; You should probably at least do a grep over the old directory
583 ;; to check the results of this look sensible.
584 ;; TODO Check cus-start if something moved from C to Lisp.
585 ;; TODO Handle renamed things with aliases to the old names.
586 (defun cusver-check (newdir olddir version
)
587 "Check that defcustoms have :version tags where needed.
588 NEWDIR is the current lisp/ directory, OLDDIR is that from the previous
589 release. A defcustom that is only in NEWDIR should have a :version
590 tag. We exclude cases where a defvar exists in OLDDIR, since
591 just converting a defvar to a defcustom does not require a :version bump.
593 Note that a :version tag should also be added if the value of a defcustom
594 changes (in a non-trivial way). This function does not check for that."
595 (interactive (list (read-directory-name "New Lisp directory: ")
596 (read-directory-name "Old Lisp directory: ")
598 (read-number "New version number: "
599 (string-to-number cusver-new-version
)))))
600 (or (file-directory-p (setq newdir
(expand-file-name newdir
)))
601 (error "Directory `%s' not found" newdir
))
602 (or (file-directory-p (setq olddir
(expand-file-name olddir
)))
603 (error "Directory `%s' not found" olddir
))
604 (setq cusver-new-version version
)
605 (let* ((newfiles (progn (message "Finding new files with defcustoms...")
606 (cusver-find-files newdir
)))
607 (oldfiles (progn (message "Finding old files with defcustoms...")
608 (cusver-find-files olddir t
)))
609 (newcus (progn (message "Reading new defcustoms...")
612 (cons file
(cusver-scan file
))) newfiles
)))
613 oldcus result thisfile file
)
614 (message "Reading old defcustoms...")
615 (dolist (file oldfiles
)
616 (setq oldcus
(append oldcus
(cusver-scan file t
))))
617 (setq oldcus
(append oldcus
(cusver-scan-cus-start
618 (expand-file-name "cus-start.el" olddir
))))
619 ;; newcus has elements (FILE (VAR VER) ... ).
620 ;; oldcus just (VAR . VER).
621 (message "Checking for version tags...")
626 (dolist (cons (cdr new
))
628 (assq (setq var
(car cons
)) oldcus
)
631 (cons file missing
))))
633 (setq result
(cons thisfile result
))))
634 (message "Checking for version tags... done")
636 (message "No missing :version tags")
637 (pop-to-buffer "*cusver*")
639 (insert "These defcustoms might be missing :version tags:\n\n")
640 (dolist (elem result
)
641 (let* ((str (file-relative-name (car elem
) newdir
))
642 (strlen (length str
)))
643 (dolist (var (cdr elem
))
644 (insert (format "%s: %s\n" str var
))
645 (make-text-button (+ (line-beginning-position 0) strlen
2)
646 (line-end-position 0)
649 'help-echo
"Mouse-2: visit this definition"
650 :type
'cusver-xref
)))))))
654 ;;; admin.el ends here