aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoland McGrath1992-03-16 06:13:09 +0000
committerRoland McGrath1992-03-16 06:13:09 +0000
commitc810ea9018c06c2ad81c4273df097426abbc6e30 (patch)
tree890dc7ac222f4a4031b79bd7cbe572eadcdb436d
parent9fd54390a89770213570801cb8dc37d738c0ab4b (diff)
downloademacs-c810ea9018c06c2ad81c4273df097426abbc6e30.tar.gz
emacs-c810ea9018c06c2ad81c4273df097426abbc6e30.zip
*** empty log message ***
-rw-r--r--lisp/emacs-lisp/copyright.el127
1 files changed, 86 insertions, 41 deletions
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index f79eaee2acf..3d4d74cf6de 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -1,5 +1,5 @@
1;;; Copyright (C) 1991 Free Software Foundation, Inc. 1;;; Copyright (C) 1991, 1992 Free Software Foundation, Inc.
2;;; Written by Roland McGrath 2;;; Written by Roland McGrath.
3;;; 3;;;
4;;; This program is free software; you can redistribute it and/or modify 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 5;;; it under the terms of the GNU General Public License as published by
@@ -27,60 +27,105 @@
27 "*If non-nil, replace copying notices with this file.") 27 "*If non-nil, replace copying notices with this file.")
28 28
29;;;###autoload 29;;;###autoload
30(defun update-copyright (&optional replace) 30(defun update-copyright (&optional replace ask-upd ask-year)
31 "Update the copyright notice at the beginning of the buffer 31 "Update the copyright notice at the beginning of the buffer
32to indicate the current year. If optional arg REPLACE is given 32to indicate the current year. If optional arg REPLACE is given
33\(interactively, with prefix arg\) replace the years in the notice 33\(interactively, with prefix arg\) replace the years in the notice
34rather than adding the current year after them. 34rather than adding the current year after them.
35If `replace-copying-with' is set, the copying permissions following the 35If `replace-copying-with' is set, the copying permissions following the
36copyright are replaced as well." 36copyright are replaced as well.
37
38If optional third argument ASK is non-nil, the user is prompted for whether
39or not to update the copyright. If optional third argument ASK-YEAR is
40non-nil, the user is prompted for whether or not to replace the year rather
41than adding to it."
37 (interactive "*P") 42 (interactive "*P")
38 (save-excursion 43 (save-excursion
39 (save-restriction 44 (save-restriction
40 (widen) 45 (widen)
41 (goto-char (point-min)) 46 (goto-char (point-min))
42 (if (search-forward current-year nil t) 47 (if (search-forward current-year nil t)
43 (message "Copyright notice already includes %s." current-year) 48 (or ask-upd
49 (message "Copyright notice already includes %s." current-year))
44 (goto-char (point-min)) 50 (goto-char (point-min))
45 (or (re-search-forward 51 (if (and (or (not ask-upd)
46 "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+" 52 ;; If implicit, narrow it down to things that
47 nil t) 53 ;; look like GPL notices.
48 (error "This buffer contains no copyright notice!")) 54 (prog1
49 (if replace 55 (search-forward "is free software" nil t)
50 (delete-region (match-beginning 1) (match-end 1)) 56 (goto-char (point-min))))
51 (insert ", ")) 57 (re-search-forward
52 (insert current-year) 58 "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+"
53 (message "Copyright updated to %s%s." 59 nil t)
54 (if replace "" "include ") current-year)) 60 (or (not ask-upd)
55 (if replace-copying-with 61 (save-window-excursion
56 (let ((case-fold-search t) 62 (pop-to-buffer (current-buffer))
57 beg) 63 (save-excursion
58 (goto-char (point-min)) 64 ;; Show the user the copyright.
59 ;; Find the beginning of the copyright. 65 (goto-char (point-min))
60 (or (search-forward "copyright" nil t) 66 (sit-for 0)
61 (error "Copyright notice not found!")) 67 (y-or-n-p "Update copyright? ")))))
62 ;; Look for a blank line or a line containing only comment chars. 68 (progn
63 (if (re-search-forward "^\\(\\s \\s<\\|\\s>\\)*$" nil t) 69 (setq replace
64 (forward-line 1) 70 (or replace
65 (with-output-to-temp-buffer "*Help*" 71 (and ask-year
66 (princ (substitute-command-keys "\ 72 (save-window-excursion
73 (pop-to-buffer (current-buffer))
74 (save-excursion
75 ;; Show the user the copyright.
76 (goto-char (point-min))
77 (sit-for 0)
78 (y-or-n-p "Replace copyright year? "))))))
79 (if replace
80 (delete-region (match-beginning 1) (match-end 1))
81 (insert ", "))
82 (insert current-year)
83 (message "Copyright updated to %s%s."
84 (if replace "" "include ") current-year)
85 (if replace-copying-with
86 (let ((case-fold-search t)
87 beg)
88 (goto-char (point-min))
89 ;; Find the beginning of the copyright.
90 (if (search-forward "copyright" nil t)
91 (progn
92 ;; Look for a blank line or a line
93 ;; containing only comment chars.
94 (if (re-search-forward "^\\(\\s \\s<\\|\\s>\\)*$"
95 nil t)
96 (forward-line 1)
97 (with-output-to-temp-buffer "*Help*"
98 (princ (substitute-command-keys "\
67I don't know where the copying notice begins. 99I don't know where the copying notice begins.
68Put point there and hit \\[exit-recursive-edit].")) 100Put point there and hit \\[exit-recursive-edit]."))
69 (recursive-edit))) 101 (recursive-edit)))
70 (setq beg (point)) 102 (setq beg (point))
71 (or (search-forward "02139, USA." nil t) 103 (or (search-forward "02139, USA." nil t)
72 (with-output-to-temp-buffer "*Help*" 104 (with-output-to-temp-buffer "*Help*"
73 (princ (substitute-command-keys "\ 105 (princ (substitute-command-keys "\
74I don't know where the copying notice ends. 106I don't know where the copying notice ends.
75Put point there and hit \\[exit-recursive-edit].")) 107Put point there and hit \\[exit-recursive-edit]."))
76 (recursive-edit))) 108 (recursive-edit)))
77 (delete-region beg (point)) 109 (delete-region beg (point))))
78 (insert-file replace-copying-with)) 110 (insert-file replace-copying-with))
79 (if (re-search-forward "; either version \\(.+\\), or (at your option)" 111 (if (re-search-forward
80 nil t) 112 "; either version \\(.+\\), or (at your option)"
81 (progn 113 nil t)
82 (goto-char (match-beginning 1)) 114 (progn
83 (delete-region (point) (match-end 1)) 115 (goto-char (match-beginning 1))
84 (insert current-gpl-version))))))) 116 (delete-region (point) (match-end 1))
117 (insert current-gpl-version)))))
118 (or ask-upd
119 (error "This buffer contains no copyright notice!")))))))
120
121;;;###autoload
122(defun ask-to-update-copyright ()
123 "If the current buffer contains a copyright notice that is out of date,
124ask the user if it should be updated with `update-copyright' (which see).
125Put this on write-file-hooks."
126 (update-copyright nil t t)
127 ;; Be sure return nil; if a write-file-hook return non-nil,
128 ;; the file is presumed to be already written.
129 nil)
85 130
86(provide 'upd-copyr) 131(provide 'upd-copyr)