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