annotate lisp/emacs-lisp/copyright.el @ 718:2011f5e67975

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