Commit | Line | Data |
---|---|---|
c810ea90 RM |
1 | ;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc. |
2 | ;;; Written by Roland McGrath. | |
0343b087 RM |
3 | ;;; |
4 | ;;; This program 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 2, or (at your option) | |
7 | ;;; any later version. | |
8 | ;;; | |
9 | ;;; This program is distributed in the hope that it will be useful, | |
10 | ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | ;;; GNU General Public License for more details. | |
13 | ;;; | |
14 | ;;; A copy of the GNU General Public License can be obtained from this | |
15 | ;;; program's author (send electronic mail to roland@ai.mit.edu) or from | |
16 | ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA | |
17 | ;;; 02139, USA. | |
18 | ||
19 | (defconst current-year (substring (current-time-string) -4) | |
20 | "String representing the current year.") | |
21 | ||
22 | (defvar current-gpl-version "2" | |
23 | "String representing the current version of the GPL.") | |
24 | ||
8bfb4482 | 25 | ;;;###autoload |
0343b087 RM |
26 | (defvar replace-copying-with nil |
27 | "*If non-nil, replace copying notices with this file.") | |
28 | ||
29 | ;;;###autoload | |
c810ea90 | 30 | (defun update-copyright (&optional replace ask-upd ask-year) |
0343b087 RM |
31 | "Update the copyright notice at the beginning of the buffer |
32 | to indicate the current year. If optional arg REPLACE is given | |
33 | \(interactively, with prefix arg\) replace the years in the notice | |
34 | rather than adding the current year after them. | |
35 | If `replace-copying-with' is set, the copying permissions following the | |
c810ea90 RM |
36 | copyright are replaced as well. |
37 | ||
38 | If optional third argument ASK is non-nil, the user is prompted for whether | |
39 | or not to update the copyright. If optional third argument ASK-YEAR is | |
40 | non-nil, the user is prompted for whether or not to replace the year rather | |
41 | than adding to it." | |
0343b087 RM |
42 | (interactive "*P") |
43 | (save-excursion | |
44 | (save-restriction | |
45 | (widen) | |
46 | (goto-char (point-min)) | |
47 | (if (search-forward current-year nil t) | |
c810ea90 RM |
48 | (or ask-upd |
49 | (message "Copyright notice already includes %s." current-year)) | |
0343b087 | 50 | (goto-char (point-min)) |
c810ea90 RM |
51 | (if (and (or (not ask-upd) |
52 | ;; If implicit, narrow it down to things that | |
53 | ;; look like GPL notices. | |
54 | (prog1 | |
55 | (search-forward "is free software" nil t) | |
56 | (goto-char (point-min)))) | |
57 | (re-search-forward | |
58 | "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+" | |
59 | nil t) | |
60 | (or (not ask-upd) | |
61 | (save-window-excursion | |
62 | (pop-to-buffer (current-buffer)) | |
63 | (save-excursion | |
64 | ;; Show the user the copyright. | |
65 | (goto-char (point-min)) | |
66 | (sit-for 0) | |
67 | (y-or-n-p "Update copyright? "))))) | |
68 | (progn | |
69 | (setq replace | |
70 | (or replace | |
71 | (and ask-year | |
72 | (save-window-excursion | |
73 | (pop-to-buffer (current-buffer)) | |
74 | (save-excursion | |
75 | ;; Show the user the copyright. | |
76 | (goto-char (point-min)) | |
77 | (sit-for 0) | |
78 | (y-or-n-p "Replace copyright year? ")))))) | |
79 | (if replace | |
80 | (delete-region (match-beginning 1) (match-end 1)) | |
81 | (insert ", ")) | |
82 | (insert current-year) | |
83 | (message "Copyright updated to %s%s." | |
84 | (if replace "" "include ") current-year) | |
2b79d733 JB |
85 | (if replace-copying-with |
86 | (let ((case-fold-search t) | |
87 | beg) | |
88 | (goto-char (point-min)) | |
89 | ;; Find the beginning of the copyright. | |
90 | (if (search-forward "copyright" nil t) | |
91 | (progn | |
92 | ;; Look for a blank line or a line | |
93 | ;; containing only comment chars. | |
94 | (if (re-search-forward "^\\(\\s \\s<\\|\\s>\\)*$" nil t) | |
95 | (forward-line 1) | |
96 | (with-output-to-temp-buffer "*Help*" | |
97 | (princ (substitute-command-keys "\ | |
0343b087 RM |
98 | I don't know where the copying notice begins. |
99 | Put point there and hit \\[exit-recursive-edit].")) | |
2b79d733 JB |
100 | (recursive-edit))) |
101 | (setq beg (point)) | |
102 | (or (search-forward "02139, USA." nil t) | |
103 | (with-output-to-temp-buffer "*Help*" | |
104 | (princ (substitute-command-keys "\ | |
619d1fa0 | 105 | I don't know where the copying notice ends. |
0343b087 | 106 | Put point there and hit \\[exit-recursive-edit].")) |
2b79d733 JB |
107 | (recursive-edit))) |
108 | (delete-region beg (point)))) | |
109 | (insert-file replace-copying-with)) | |
110 | (if (re-search-forward | |
111 | "; either version \\(.+\\), or (at your option)" | |
112 | nil t) | |
113 | (progn | |
114 | (goto-char (match-beginning 1)) | |
115 | (delete-region (point) (match-end 1)) | |
116 | (insert current-gpl-version)))) | |
c810ea90 | 117 | (or ask-upd |
2b79d733 | 118 | (error "This buffer contains no copyright notice!")))))))) |
c810ea90 RM |
119 | |
120 | ;;;###autoload | |
121 | (defun ask-to-update-copyright () | |
122 | "If the current buffer contains a copyright notice that is out of date, | |
123 | ask the user if it should be updated with `update-copyright' (which see). | |
124 | Put this on write-file-hooks." | |
125 | (update-copyright nil t t) | |
126 | ;; Be sure return nil; if a write-file-hook return non-nil, | |
127 | ;; the file is presumed to be already written. | |
128 | nil) | |
0343b087 RM |
129 | |
130 | (provide 'upd-copyr) |