1 ;;; upd-copyr.el --- update the copyright notice in a GNU Emacs elisp file
3 ;; Author: Roland McGrath <roland@gnu.ai.mit.edu>
4 ;; Last-Modified: 03 Jun 1991
6 ;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc.
8 ;;; This program 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 ;;; This program 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 ;;; A copy of the GNU General Public License can be obtained from this
19 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
20 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
25 (defconst current-year
(substring (current-time-string) -
4)
26 "String representing the current year.")
28 (defvar current-gpl-version
"2"
29 "String representing the current version of the GPL.")
32 (defvar replace-copying-with nil
33 "*If non-nil, replace copying notices with this file.")
35 (defvar inhibit-update-copyright nil
36 "If nil, ask the user whether or not to update the copyright notice.
37 If the user has said no, we set this to t locally.")
40 (defun update-copyright (&optional replace ask-upd ask-year
)
41 "Update the copyright notice at the beginning of the buffer
42 to indicate the current year. If optional arg REPLACE is given
43 \(interactively, with prefix arg\) replace the years in the notice
44 rather than adding the current year after them.
45 If `replace-copying-with' is set, the copying permissions following the
46 copyright are replaced as well.
48 If optional third argument ASK is non-nil, the user is prompted for whether
49 or not to update the copyright. If optional third argument ASK-YEAR is
50 non-nil, the user is prompted for whether or not to replace the year rather
56 (goto-char (point-min))
57 ;; Handle abbreviated year lists like "1800, 01, 02, 03".
58 (if (re-search-forward (concat (substring current-year
0 2)
59 "\\([0-9][0-9]\\(,\\s \\)+\\)*"
60 (substring current-year
2))
63 (message "Copyright notice already includes %s." current-year
))
64 (goto-char (point-min))
65 (if (and (not inhibit-update-copyright
)
67 ;; If implicit, narrow it down to things that
68 ;; look like GPL notices.
70 (search-forward "is free software" nil t
)
71 (goto-char (point-min))))
73 "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+"
76 (save-window-excursion
77 (pop-to-buffer (current-buffer))
79 ;; Show the user the copyright.
80 (goto-char (point-min))
82 (or (y-or-n-p "Update copyright? ")
84 (set (make-local-variable
85 'inhibit-update-copyright
) t
)
91 (save-window-excursion
92 (pop-to-buffer (current-buffer))
94 ;; Show the user the copyright.
95 (goto-char (point-min))
97 (y-or-n-p "Replace copyright year? "))))))
99 (delete-region (match-beginning 1) (match-end 1))
101 (insert current-year
)
102 (message "Copyright updated to %s%s."
103 (if replace
"" "include ") current-year
)
104 (if replace-copying-with
105 (let ((case-fold-search t
)
107 (goto-char (point-min))
108 ;; Find the beginning of the copyright.
109 (if (search-forward "copyright" nil t
)
111 ;; Look for a blank line or a line
112 ;; containing only comment chars.
113 (if (re-search-forward "^\\(\\s \\s<\\|\\s>\\)*$" nil t
)
115 (with-output-to-temp-buffer "*Help*"
116 (princ (substitute-command-keys "\
117 I don't know where the copying notice begins.
118 Put point there and hit \\[exit-recursive-edit]."))
121 (or (search-forward "02139, USA." nil t
)
122 (with-output-to-temp-buffer "*Help*"
123 (princ (substitute-command-keys "\
124 I don't know where the copying notice ends.
125 Put point there and hit \\[exit-recursive-edit]."))
127 (delete-region beg
(point))))
128 (insert-file replace-copying-with
))
129 (if (re-search-forward
130 "; either version \\(.+\\), or (at your option)"
133 (goto-char (match-beginning 1))
134 (delete-region (point) (match-end 1))
135 (insert current-gpl-version
))))
137 (error "This buffer contains no copyright notice!"))))))))
140 (defun ask-to-update-copyright ()
141 "If the current buffer contains a copyright notice that is out of date,
142 ask the user if it should be updated with `update-copyright' (which see).
143 Put this on write-file-hooks."
144 (update-copyright nil t t
)
145 ;; Be sure return nil; if a write-file-hook return non-nil,
146 ;; the file is presumed to be already written.
151 ;;; upd-copyr.el ends here