1 ;;; copyright.el --- update the copyright notice in current buffer
3 ;; Copyright (C) 1991, 92, 93, 94, 95, 98, 2001 Free Software Foundation, Inc.
5 ;; Author: Daniel Pfeiffer <occitan@esperanto.org>
6 ;; Keywords: maint, tools
8 ;; This file is part of GNU Emacs.
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)
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.
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 the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
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).
32 (defgroup copyright nil
33 "Update the copyright notice in current buffer."
36 (defcustom copyright-limit
2000
37 "*Don't try to update copyright beyond this position unless interactive.
38 A value of nil means to search whole buffer."
40 :type
'(choice (integer :tag
"Limit")
41 (const :tag
"No limit")))
43 ;; Would it be cleaner to specify Latin-1 coding for this file,
44 ;; and not use both unibyte and multibyte copyright symbol characters?
46 (defcustom copyright-regexp
47 "\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\
48 \\|[Cc]opyright\\s *:?\\s *©\\)\
49 \\s *\\([1-9]\\([-0-9, ';\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
50 "*What your copyright notice looks like.
51 The second \\( \\) construct must match the years."
56 (defcustom copyright-query
'function
57 "*If non-nil, ask user before changing copyright.
58 When this is `function', only ask when called non-interactively."
60 :type
'(choice (const :tag
"Do not ask")
61 (const :tag
"Ask unless interactive" function
)
62 (other :tag
"Ask" t
)))
65 ;; when modifying this, also modify the comment generated by autoinsert.el
66 (defconst copyright-current-gpl-version
"2"
67 "String representing the current version of the GPL or nil.")
69 (defvar copyright-update t
)
71 ;; This is a defvar rather than a defconst, because the year can
72 ;; change during the Emacs session.
73 (defvar copyright-current-year
(substring (current-time-string) -
4)
74 "String representing the current year.")
78 (defun copyright-update (&optional arg
)
79 "Update copyright notice at beginning of buffer to indicate the current year.
80 With prefix ARG, replace the years in the notice rather than adding
81 the current year after them. If necessary, and
82 `copyright-current-gpl-version' is set, any copying permissions
83 following the copyright are updated as well."
89 (goto-char (point-min))
90 ;; Note that `current-time-string' isn't locale-sensitive.
91 (setq copyright-current-year
(substring (current-time-string) -
4))
92 (if (re-search-forward copyright-regexp copyright-limit t
)
93 (if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
94 (substring copyright-current-year -
2))
96 (if (or (not copyright-query
)
97 (and (eq copyright-query
'function
)
98 (eq this-command
'copyright-update
))
100 (concat "Replace copyright year(s) by "
101 copyright-current-year
"? ")
102 (concat "Add " copyright-current-year
103 " to copyright? "))))
106 (delete-region (match-beginning 1) (match-end 1))
107 (insert copyright-current-year
))
108 (setq arg
(save-excursion (skip-chars-backward "0-9")))
109 (if (and (eq (%
(- (string-to-number
110 copyright-current-year
)
111 (string-to-number (buffer-substring
116 (or (eq (char-after (+ (point) arg -
1)) ?-
)
117 (eq (char-after (+ (point) arg -
2)) ?-
)))
120 (if (eq (char-after (+ (point) arg -
3)) ?
')
122 (insert (substring copyright-current-year arg
))))))
123 (goto-char (point-min))
124 (and copyright-current-gpl-version
125 ;; match the GPL version comment in .el files, including the
126 ;; bilingual Esperanto one in two-column, and in texinfo.tex
127 (re-search-forward "\\(the Free Software Foundation;\
128 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\
129 version \\([0-9]+\\), or (at"
131 (not (string= (match-string 3) copyright-current-gpl-version
))
132 (or (not copyright-query
)
133 (and (eq copyright-query
'function
)
134 (eq this-command
'copyright-update
))
135 (y-or-n-p (concat "Replace GPL version by "
136 copyright-current-gpl-version
"? ")))
139 ;; Esperanto bilingual comment in two-column.el
141 (delete-region (match-beginning 2) (match-end 2))
142 (goto-char (match-beginning 2))
143 (insert copyright-current-gpl-version
)))
144 (delete-region (match-beginning 3) (match-end 3))
145 (goto-char (match-beginning 3))
146 (insert copyright-current-gpl-version
))))
147 (set (make-local-variable 'copyright-update
) nil
)))
148 ;; If a write-file-hook returns non-nil, the file is presumed to be written.
153 (define-skeleton copyright
154 "Insert a copyright by $ORGANIZATION notice at cursor."
157 "Copyright (C) " `(substring (current-time-string) -
4) " by "
158 (or (getenv "ORGANIZATION")
160 '(if (> (point) copyright-limit
)
161 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
166 ;; For the copyright sign:
171 ;;; copyright.el ends here