1 ;;; copyright.el --- update the copyright notice in current buffer
3 ;; Copyright (C) 1991, 1992-1995, 1998 Free Software Foundation, Inc.
5 ;; Author: Daniel.Pfeiffer@Informatik.START.dbp.de
6 ;; fax (+49 69) 7588-2389
7 ;; Keywords: maint, tools
9 ;; This file is part of GNU Emacs.
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)
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.
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.
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).
33 (defgroup copyright nil
34 "Update the copyright notice in current buffer."
37 (defcustom copyright-limit 2000
38 "*Don't try to update copyright beyond this position unless interactive.
39 `nil' means to search whole buffer."
41 :type '(choice (integer :tag "Limit")
42 (const :tag "No limit")))
45 (defcustom copyright-regexp
46 "\\([
\81©\251]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *(C)\
47 \\|[Cc]opyright\\s *:?\\s *[
\81©\251]\\)\
48 \\s *\\([1-9][-0-9, ']*[0-9]+\\) "
49 "*What your copyright notice looks like.
50 The second \\( \\) construct must match the years."
55 (defcustom copyright-query 'function
56 "*If non-`nil', ask user before changing copyright.
57 When this is `function', only ask when called non-interactively."
59 :type '(choice (const :tag "Do not ask")
61 (const :tag "Ask unless interactive" function)))
64 (defconst copyright-current-year (substring (current-time-string) -4)
65 "String representing the current year.")
68 ;; when modifying this, also modify the comment generated by autoinsert.el
69 (defconst copyright-current-gpl-version "2"
70 "String representing the current version of the GPL or `nil'.")
72 (defvar copyright-update t)
75 (defun copyright-update (&optional arg)
76 "Update the copyright notice at the beginning of the buffer to indicate
77 the current year. If optional prefix ARG is given replace the years in the
78 notice rather than adding the current year after them. If necessary and
79 `copyright-current-gpl-version' is set, the copying permissions following the
80 copyright, if any, are updated as well."
86 (goto-char (point-min))
87 (if (re-search-forward copyright-regexp copyright-limit t)
88 (if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
89 (substring copyright-current-year -2))
92 (if (or (not copyright-query)
93 (and (eq copyright-query 'function)
94 (eq this-command 'copyright-update))
96 (concat "Replace copyright year(s) by "
97 copyright-current-year "? ")
98 (concat "Add " copyright-current-year
102 (delete-region (match-beginning 1) (match-end 1))
103 (insert copyright-current-year))
104 (setq arg (save-excursion (skip-chars-backward "0-9")))
105 (if (and (eq (% (- (string-to-number
106 copyright-current-year)
107 (string-to-number (buffer-substring
112 (or (eq (char-after (+ (point) arg -1)) ?-)
113 (eq (char-after (+ (point) arg -2)) ?-)))
116 (if (eq (char-after (+ (point) arg -3)) ?')
118 (insert (substring copyright-current-year arg))))))
119 (goto-char (point-min))
120 (and copyright-current-gpl-version
121 ;; match the GPL version comment in .el files, including the
122 ;; bilingual Esperanto one in two-column, and in texinfo.tex
123 (re-search-forward "\\(the Free Software Foundation; either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)version \\([0-9]+\\), or (at"
125 (not (string= (buffer-substring (match-beginning 3) (match-end 3))
126 copyright-current-gpl-version))
127 (or (not copyright-query)
128 (and (eq copyright-query 'function)
129 (eq this-command 'copyright-update))
130 (y-or-n-p (concat "Replace GPL version by "
131 copyright-current-gpl-version "? ")))
134 ;; Esperanto bilingual comment in two-column.el
136 (delete-region (match-beginning 2) (match-end 2))
137 (goto-char (match-beginning 2))
138 (insert copyright-current-gpl-version)))
139 (delete-region (match-beginning 3) (match-end 3))
140 (goto-char (match-beginning 3))
141 (insert copyright-current-gpl-version))))
142 (set (make-local-variable 'copyright-update) nil)))
143 ;; If a write-file-hook returns non-nil, the file is presumed to be written.
148 (define-skeleton copyright
149 "Insert a copyright by $ORGANIZATION notice at cursor."
152 "Copyright (C) " copyright-current-year " by "
153 (or (getenv "ORGANIZATION")
155 '(if (> (point) copyright-limit)
156 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
161 ;; copyright.el ends here