comparison lisp/emacs-lisp/copyright.el @ 288:5c0f837c0287

Initial revision
author Roland McGrath <roland@gnu.org>
date Mon, 03 Jun 1991 19:54:13 +0000
parents
children 56fa777d299a
comparison
equal deleted inserted replaced
287:1616777eaae5 288:5c0f837c0287
1 ;;; Copyright (C) 1991 Free Software Foundation, Inc.
2 ;;; Written by Roland McGrath
3 ;;;
4 ;;; This program is free software; you can redistribute it and/or modify
5 ;;; it under the terms of the GNU General Public License as published by
6 ;;; the Free Software Foundation; either version 2, or (at your option)
7 ;;; any later version.
8 ;;;
9 ;;; This program is distributed in the hope that it will be useful,
10 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
11 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 ;;; GNU General Public License for more details.
13 ;;;
14 ;;; A copy of the GNU General Public License can be obtained from this
15 ;;; program's author (send electronic mail to roland@ai.mit.edu) or from
16 ;;; the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
17 ;;; 02139, USA.
18
19 (defconst current-year (substring (current-time-string) -4)
20 "String representing the current year.")
21
22 (defvar current-gpl-version "2"
23 "String representing the current version of the GPL.")
24
25 (defvar replace-copying-with nil
26 "*If non-nil, replace copying notices with this file.")
27
28 ;;;###autoload
29 (defun update-copyright (&optional replace)
30 "Update the copyright notice at the beginning of the buffer
31 to indicate the current year. If optional arg REPLACE is given
32 \(interactively, with prefix arg\) replace the years in the notice
33 rather than adding the current year after them.
34 If `replace-copying-with' is set, the copying permissions following the
35 copyright are replaced as well."
36 (interactive "*P")
37 (save-excursion
38 (save-restriction
39 (widen)
40 (goto-char (point-min))
41 (if (search-forward current-year nil t)
42 (message "Copyright notice already includes %s." current-year)
43 (goto-char (point-min))
44 (or (re-search-forward
45 "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+"
46 nil t)
47 (error "This buffer contains no copyright notice!"))
48 (if replace
49 (delete-region (match-beginning 1) (match-end 1))
50 (insert ", "))
51 (insert current-year)
52 (message "Copyright updated to %s%s."
53 (if replace "" "include ") current-year))
54 (if replace-copying-with
55 (let ((case-fold-search t)
56 beg)
57 (goto-char (point-min))
58 ;; Find the beginning of the copyright.
59 (or (search-forward "copyright" nil t)
60 (error "Copyright notice not found!"))
61 ;; Look for a blank line or a line containing only comment chars.
62 (if (re-search-forward "^\\(\\s \\s<\\|\\s>\\)*$" nil t)
63 (forward-line 1)
64 (with-output-to-temp-buffer "*Help*"
65 (princ (substitute-command-keys "\
66 I don't know where the copying notice begins.
67 Put point there and hit \\[exit-recursive-edit]."))
68 (recursive-edit)))
69 (setq beg (point))
70 (or (search-forward "02139, USA." nil t)
71 (with-output-to-temp-buffer "*Help*"
72 (princ (substitute-command-keys "\
73 I don't know where the copying notie ends.
74 Put point there and hit \\[exit-recursive-edit]."))
75 (recursive-edit)))
76 (delete-region beg (point))
77 (insert-file replace-copying-with))
78 (if (re-search-forward "; either version \\(.+\\), or (at your option)"
79 nil t)
80 (progn
81 (goto-char (match-beginning 1))
82 (delete-region (point) (match-end 1))
83 (insert current-gpl-version)))))))
84
85 (provide 'upd-copyr)