Update FSF's address.
[bpt/emacs.git] / lisp / emacs-lisp / copyright.el
CommitLineData
3f61a2e7 1;;; copyright.el --- update the copyright notice in current buffer
d501f516 2
3f61a2e7 3;; Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
58142744 4
97b0c634 5;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de, fax (+49 69) 7588-2389
3f61a2e7
KH
6;; Keywords: maint, tools
7
8;; This file is part of GNU Emacs.
9
10;; GNU Emacs is free software; you can redistribute it and/or modify
11;; it under the terms of the GNU General Public License as published by
12;; the Free Software Foundation; either version 2, or (at your option)
13;; any later version.
14
15;; GNU Emacs is distributed in the hope that it will be useful,
16;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;; GNU General Public License for more details.
19
20;; You should have received a copy of the GNU General Public License
b578f267
EN
21;; along with GNU Emacs; see the file COPYING. If not, write to the
22;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23;; Boston, MA 02111-1307, USA.
3f61a2e7
KH
24
25;;; Commentary:
26
27;; Allows updating the copyright year and above mentioned GPL version manually
28;; or when saving a file. Do (add-hook 'write-file-hooks 'copyright-update).
0343b087 29
d46bac56
ER
30;;; Code:
31
3f61a2e7
KH
32(defvar copyright-limit 2000
33 "*Don't try to update copyright beyond this position unless interactive.
34`nil' means to search whole buffer.")
35
36
37(defvar copyright-regexp
a3296f5a 38 "\\(\251\\|[Cc]opyright\\s *:?\\s *(C)\\)\\s *\\([1-9][-0-9, ']*[0-9]+\\) "
3f61a2e7 39 "*What your copyright notice looks like.
a3296f5a 40The second \\( \\) construct must match the years.")
3f61a2e7
KH
41
42
43(defvar copyright-query 'function
44 "*If non-`nil', ask user before changing copyright.
45When this is `function', only ask when called non-interactively.")
46
47
48(defconst copyright-current-year (substring (current-time-string) -4)
0343b087
RM
49 "String representing the current year.")
50
0343b087 51
a7acbbe4 52;; when modifying this, also modify the comment generated by autoinsert.el
3f61a2e7
KH
53(defconst copyright-current-gpl-version "2"
54 "String representing the current version of the GPL or `nil'.")
0343b087 55
3f61a2e7 56(defvar copyright-update t)
9cfd2eeb 57
0343b087 58;;;###autoload
3f61a2e7
KH
59(defun copyright-update (&optional arg)
60 "Update the copyright notice at the beginning of the buffer to indicate
61the current year. If optional prefix ARG is given replace the years in the
62notice rather than adding the current year after them. If necessary and
63`copyright-current-gpl-version' is set, the copying permissions following the
64copyright, if any, are updated as well."
0343b087 65 (interactive "*P")
3f61a2e7
KH
66 (if copyright-update
67 (save-excursion
68 (save-restriction
69 (widen)
70 (goto-char (point-min))
71 (if (re-search-forward copyright-regexp copyright-limit t)
a3296f5a 72 (if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
3f61a2e7
KH
73 (substring copyright-current-year -2))
74 ()
75 (backward-char 1)
76 (if (or (not copyright-query)
77 (and (eq copyright-query 'function)
78 (eq this-command 'copyright-update))
79 (y-or-n-p (if arg
80 (concat "Replace copyright year(s) by "
81 copyright-current-year "? ")
82 (concat "Add " copyright-current-year
83 " to copyright? "))))
84 (if arg
85 (progn
86 (delete-region (match-beginning 1) (match-end 1))
87 (insert copyright-current-year))
88 (setq arg (save-excursion (skip-chars-backward "0-9")))
89 (if (and (eq (% (- (string-to-number
90 copyright-current-year)
91 (string-to-number (buffer-substring
92 (+ (point) arg)
93 (point))))
94 100)
95 1)
96 (or (eq (char-after (+ (point) arg -1)) ?-)
97 (eq (char-after (+ (point) arg -2)) ?-)))
98 (delete-char arg)
99 (insert ", ")
100 (if (eq (char-after (+ (point) arg -3)) ?')
101 (insert ?')))
102 (insert (substring copyright-current-year arg))))))
103 (goto-char (point-min))
104 (and copyright-current-gpl-version
105 ;; match the GPL version comment in .el files, including the
106 ;; bilingual Esperanto one in two-column, and in texinfo.tex
107 (re-search-forward "\\(the Free Software Foundation; either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)version \\([0-9]+\\), or (at"
108 copyright-limit t)
109 (not (string= (buffer-substring (match-beginning 3) (match-end 3))
110 copyright-current-gpl-version))
111 (or (not copyright-query)
112 (and (eq copyright-query 'function)
113 (eq this-command 'copyright-update))
114 (y-or-n-p (concat "Replace GPL version by "
115 copyright-current-gpl-version "? ")))
116 (progn
117 (if (match-end 2)
118 ;; Esperanto bilingual comment in two-column.el
119 (progn
120 (delete-region (match-beginning 2) (match-end 2))
121 (goto-char (match-beginning 2))
122 (insert copyright-current-gpl-version)))
123 (delete-region (match-beginning 3) (match-end 3))
124 (goto-char (match-beginning 3))
125 (insert copyright-current-gpl-version))))
126 (set (make-local-variable 'copyright-update) nil)))
127 ;; If a write-file-hook returns non-nil, the file is presumed to be written.
c810ea90 128 nil)
0343b087 129
d501f516 130
3f61a2e7
KH
131;;;###autoload
132(define-skeleton copyright
133 "Insert a copyright by $ORGANIZATION notice at cursor."
134 "Company: "
135 comment-start
136 "Copyright (C) " copyright-current-year " by "
137 (or (getenv "ORGANIZATION")
138 str)
139 '(if (> (point) copyright-limit)
140 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
141 comment-end)
142
143;; copyright.el ends here