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