Comment fixes.
[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
21;; along with GNU Emacs; see the file COPYING. If not, write to
22;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23
24;;; Commentary:
25
26;; Allows updating the copyright year and above mentioned GPL version manually
27;; or when saving a file. Do (add-hook 'write-file-hooks 'copyright-update).
0343b087 28
d46bac56
ER
29;;; Code:
30
3f61a2e7
KH
31(defvar copyright-limit 2000
32 "*Don't try to update copyright beyond this position unless interactive.
33`nil' means to search whole buffer.")
34
35
36(defvar copyright-regexp
a3296f5a 37 "\\(\251\\|[Cc]opyright\\s *:?\\s *(C)\\)\\s *\\([1-9][-0-9, ']*[0-9]+\\) "
3f61a2e7 38 "*What your copyright notice looks like.
a3296f5a 39The second \\( \\) construct must match the years.")
3f61a2e7
KH
40
41
42(defvar copyright-query 'function
43 "*If non-`nil', ask user before changing copyright.
44When this is `function', only ask when called non-interactively.")
45
46
47(defconst copyright-current-year (substring (current-time-string) -4)
0343b087
RM
48 "String representing the current year.")
49
0343b087 50
a7acbbe4 51;; when modifying this, also modify the comment generated by autoinsert.el
3f61a2e7
KH
52(defconst copyright-current-gpl-version "2"
53 "String representing the current version of the GPL or `nil'.")
0343b087 54
3f61a2e7 55(defvar copyright-update t)
9cfd2eeb 56
0343b087 57;;;###autoload
3f61a2e7
KH
58(defun copyright-update (&optional arg)
59 "Update the copyright notice at the beginning of the buffer to indicate
60the current year. If optional prefix ARG is given replace the years in the
61notice rather than adding the current year after them. If necessary and
62`copyright-current-gpl-version' is set, the copying permissions following the
63copyright, if any, are updated as well."
0343b087 64 (interactive "*P")
3f61a2e7
KH
65 (if copyright-update
66 (save-excursion
67 (save-restriction
68 (widen)
69 (goto-char (point-min))
70 (if (re-search-forward copyright-regexp copyright-limit t)
a3296f5a 71 (if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
3f61a2e7
KH
72 (substring copyright-current-year -2))
73 ()
74 (backward-char 1)
75 (if (or (not copyright-query)
76 (and (eq copyright-query 'function)
77 (eq this-command 'copyright-update))
78 (y-or-n-p (if arg
79 (concat "Replace copyright year(s) by "
80 copyright-current-year "? ")
81 (concat "Add " copyright-current-year
82 " to copyright? "))))
83 (if arg
84 (progn
85 (delete-region (match-beginning 1) (match-end 1))
86 (insert copyright-current-year))
87 (setq arg (save-excursion (skip-chars-backward "0-9")))
88 (if (and (eq (% (- (string-to-number
89 copyright-current-year)
90 (string-to-number (buffer-substring
91 (+ (point) arg)
92 (point))))
93 100)
94 1)
95 (or (eq (char-after (+ (point) arg -1)) ?-)
96 (eq (char-after (+ (point) arg -2)) ?-)))
97 (delete-char arg)
98 (insert ", ")
99 (if (eq (char-after (+ (point) arg -3)) ?')
100 (insert ?')))
101 (insert (substring copyright-current-year arg))))))
102 (goto-char (point-min))
103 (and copyright-current-gpl-version
104 ;; match the GPL version comment in .el files, including the
105 ;; bilingual Esperanto one in two-column, and in texinfo.tex
106 (re-search-forward "\\(the Free Software Foundation; either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)version \\([0-9]+\\), or (at"
107 copyright-limit t)
108 (not (string= (buffer-substring (match-beginning 3) (match-end 3))
109 copyright-current-gpl-version))
110 (or (not copyright-query)
111 (and (eq copyright-query 'function)
112 (eq this-command 'copyright-update))
113 (y-or-n-p (concat "Replace GPL version by "
114 copyright-current-gpl-version "? ")))
115 (progn
116 (if (match-end 2)
117 ;; Esperanto bilingual comment in two-column.el
118 (progn
119 (delete-region (match-beginning 2) (match-end 2))
120 (goto-char (match-beginning 2))
121 (insert copyright-current-gpl-version)))
122 (delete-region (match-beginning 3) (match-end 3))
123 (goto-char (match-beginning 3))
124 (insert copyright-current-gpl-version))))
125 (set (make-local-variable 'copyright-update) nil)))
126 ;; If a write-file-hook returns non-nil, the file is presumed to be written.
c810ea90 127 nil)
0343b087 128
d501f516 129
3f61a2e7
KH
130;;;###autoload
131(define-skeleton copyright
132 "Insert a copyright by $ORGANIZATION notice at cursor."
133 "Company: "
134 comment-start
135 "Copyright (C) " copyright-current-year " by "
136 (or (getenv "ORGANIZATION")
137 str)
138 '(if (> (point) copyright-limit)
139 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
140 comment-end)
141
142;; copyright.el ends here