(comint-dynamic-complete-as-filename,comint-dynamic-list-filename-completions):
[emacs.git] / admin / admin.el
blob175eb6ded1b42645962501081965d6bbb8c3df1a
1 ;;; admin.el --- utilities for Emacs administration
3 ;; Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
4 ;; Free Software Foundation, Inc.
6 ;; This file is part of GNU Emacs.
8 ;; GNU Emacs is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
11 ;; any later version.
13 ;; GNU Emacs is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
23 ;;; Commentary:
25 ;; add-release-logs Add ``Version X released'' change log entries.
26 ;; set-version Change Emacs version number in source tree.
27 ;; set-copyright Change emacs short copyright string (eg as
28 ;; printed by --version) in source tree.
30 ;;; Code:
32 (defun process-lines (program &rest args)
33 "Execute PROGRAM with ARGS, returning its output as a list of lines.
34 Signal an error if the program returns with a non-zero exit status."
35 (with-temp-buffer
36 (let ((status (apply 'call-process program nil (current-buffer) nil args)))
37 (unless (eq status 0)
38 (error "%s exited with status %s" program status))
39 (goto-char (point-min))
40 (let (lines)
41 (while (not (eobp))
42 (setq lines (cons (buffer-substring-no-properties
43 (line-beginning-position)
44 (line-end-position))
45 lines))
46 (forward-line 1))
47 (nreverse lines)))))
49 (defun add-release-logs (root version)
50 "Add \"Version VERSION released.\" change log entries in ROOT.
51 Root must be the root of an Emacs source tree."
52 (interactive "DEmacs root directory: \nNVersion number: ")
53 (setq root (expand-file-name root))
54 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
55 (error "%s doesn't seem to be the root of an Emacs source tree" root))
56 (require 'add-log)
57 (let* ((logs (process-lines "find" root "-name" "ChangeLog"))
58 (entry (format "%s %s <%s>\n\n\t* Version %s released.\n\n"
59 (funcall add-log-time-format)
60 (or add-log-full-name (user-full-name))
61 (or add-log-mailing-address user-mail-address)
62 version)))
63 (dolist (log logs)
64 (unless (string-match "/gnus/" log)
65 (find-file log)
66 (goto-char (point-min))
67 (insert entry)))))
69 (defun set-version-in-file (root file version rx)
70 (find-file (expand-file-name file root))
71 (goto-char (point-min))
72 (unless (re-search-forward rx nil t)
73 (error "Version not found in %s" file))
74 (replace-match (format "%s" version) nil nil nil 1))
76 (defun set-version (root version)
77 "Set Emacs version to VERSION in relevant files under ROOT.
78 Root must be the root of an Emacs source tree."
79 (interactive "DEmacs root directory: \nsVersion number: ")
80 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
81 (error "%s doesn't seem to be the root of an Emacs source tree" root))
82 (set-version-in-file root "lisp/version.el" version
83 (rx (and "emacs-version" (0+ space)
84 ?\" (submatch (1+ (not (in ?\")))) ?\")))
85 (set-version-in-file root "README" version
86 (rx (and "version" (1+ space)
87 (submatch (1+ (in "0-9."))))))
88 (set-version-in-file root "man/emacs.texi" version
89 (rx (and "EMACSVER" (1+ space)
90 (submatch (1+ (in "0-9."))))))
91 (set-version-in-file root "lispref/elisp.texi" version
92 (rx (and "EMACSVER" (1+ space)
93 (submatch (1+ (in "0-9."))))))
94 (set-version-in-file root "lib-src/makefile.w32-in" version
95 (rx (and "VERSION" (0+ space) "=" (0+ space)
96 (submatch (1+ (in "0-9."))))))
97 ;; nt/emacs.rc also contains the version number, but in an awkward
98 ;; format. It must contain four components, separated by commas, and
99 ;; in two places those commas are followed by space, in two other
100 ;; places they are not.
101 (let* ((version-components (append (split-string version "\\.")
102 '("0" "0")))
103 (comma-version
104 (concat (car version-components) ","
105 (cadr version-components) ","
106 (cadr (cdr version-components)) ","
107 (cadr (cdr (cdr version-components)))))
108 (comma-space-version
109 (concat (car version-components) ", "
110 (cadr version-components) ", "
111 (cadr (cdr version-components)) ", "
112 (cadr (cdr (cdr version-components))))))
113 (set-version-in-file root "nt/emacs.rc" comma-version
114 (rx (and "FILEVERSION" (1+ space)
115 (submatch (1+ (in "0-9,"))))))
116 (set-version-in-file root "nt/emacs.rc" comma-version
117 (rx (and "PRODUCTVERSION" (1+ space)
118 (submatch (1+ (in "0-9,"))))))
119 (set-version-in-file root "nt/emacs.rc" comma-space-version
120 (rx (and "\"FileVersion\"" (0+ space) ?, (0+ space)
121 ?\" (submatch (1+ (in "0-9, "))) "\\0\"")))
122 (set-version-in-file root "nt/emacs.rc" comma-space-version
123 (rx (and "\"ProductVersion\"" (0+ space) ?,
124 (0+ space) ?\" (submatch (1+ (in "0-9, ")))
125 "\\0\"")))
126 ;; Some files in the "mac" subdirectory also contain the version
127 ;; number.
128 (set-version-in-file
129 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
130 version (rx (and "CFBundleShortVersionString" (0+ space) ?= (0+ space) ?\"
131 (submatch (1+ (in "0-9."))))))
132 (set-version-in-file
133 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
134 version (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space) ?\"
135 (submatch (1+ (in "0-9."))))))
136 (set-version-in-file root "mac/src/Emacs.r" (car version-components)
137 (rx (and "GNU Emacs " (submatch (1+ (in "0-9")))
138 " for Mac OS")))
139 (set-version-in-file root "mac/src/Emacs.r" (car version-components)
140 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
141 (0+ space) "/* Major revision in BCD */")))
142 (set-version-in-file root "mac/src/Emacs.r" (cadr version-components)
143 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
144 (0+ space) "/* Minor revision in BCD */")))
145 (set-version-in-file root "mac/src/Emacs.r" (cadr (cdr version-components))
146 (rx (and (submatch (1+ (in "0-9"))) (0+ space) ?\,
147 (0+ space) "/* Non-final release # */")))
148 (set-version-in-file root "mac/src/Emacs.r" version
149 (rx (and (submatch (1+ (in "0-9."))) (0+ space) ?\" ?\,
150 (0+ space) "/* Short version number */")))
151 (set-version-in-file root "mac/src/Emacs.r" version
152 (rx (and "/* Short version number */" (0+ space) ?\"
153 (submatch (1+ (in "0-9."))))))
154 (let* ((third-component (string-to-number (cadr (cdr version-components))))
155 (release (cond ((>= third-component 90) "alpha")
156 ((>= third-component 50) "development")
157 (t "final"))))
158 (set-version-in-file
159 root "mac/src/Emacs.r" release
160 (rx (and (submatch (1+ (in "a-z"))) (0+ space) ?\, (0+ space)
161 "/* development, alpha, beta, or final (release) */"))))))
163 ;; Note this makes some assumptions about form of short copyright.
164 (defun set-copyright (root copyright)
165 "Set Emacs short copyright to COPYRIGHT in relevant files under ROOT.
166 Root must be the root of an Emacs source tree."
167 (interactive (list
168 (read-directory-name "Emacs root directory: " nil nil t)
169 (read-string
170 "Short copyright string: "
171 (format "Copyright (C) %s Free Software Foundation, Inc."
172 (format-time-string "%Y")))))
173 (unless (file-exists-p (expand-file-name "src/emacs.c" root))
174 (error "%s doesn't seem to be the root of an Emacs source tree" root))
175 (set-version-in-file root "lisp/version.el" copyright
176 (rx (and "emacs-copyright" (0+ space)
177 ?\" (submatch (1+ (not (in ?\")))) ?\")))
178 (set-version-in-file root "lib-src/etags.c" copyright
179 (rx (and "emacs_copyright" (0+ (not (in ?\")))
180 ?\" (submatch (1+ (not (in ?\")))) ?\")))
181 (set-version-in-file root "lib-src/rcs2log" copyright
182 (rx (and "Copyright" (0+ space) ?= (0+ space)
183 ?\' (submatch (1+ nonl)))))
184 (set-version-in-file
185 root "mac/Emacs.app/Contents/Resources/English.lproj/InfoPlist.strings"
186 copyright (rx (and "CFBundleGetInfoString" (0+ space) ?= (0+ space) ?\"
187 (1+ anything)
188 (submatch "Copyright" (1+ (not (in ?\")))))))
189 ;; This one is a nuisance, as it needs to be split over two lines.
190 (string-match "\\(.*[0-9]\\{4\\} *\\)\\(.*\\)" copyright)
191 (let ((csign "\\0xa9")
192 (cyear (match-string 1 copyright)) ; "Copyright (C) 2007 "
193 (owner (match-string 2 copyright))) ; "Free Software Foundation, Inc."
194 (set-version-in-file root "mac/src/Emacs.r"
195 (regexp-quote
196 (replace-regexp-in-string "(C)"
197 (regexp-quote csign) cyear))
198 (rx (and
199 (submatch "Copyright" (0+ space) (eval csign)
200 (0+ space) (= 4 num)
201 (0+ (not (in ?\")))) ?\")))
202 (set-version-in-file root "mac/src/Emacs.r" owner
203 (rx (and ?\"
204 (submatch (1+ (not (in ?\"))))
205 ?\" (0+ space)
206 "/* Long version number */")))))
208 ;;; arch-tag: 4ea83636-2293-408b-884e-ad64f22a3bf5
209 ;; admin.el ends here.