Mercurial > emacs
comparison lisp/emacs-lisp/copyright.el @ 78358:9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Correctly handle the case where copyright-limit is nil.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sun, 29 Jul 2007 20:11:25 +0000 |
parents | 935157c0b596 |
children | b994c6078b25 e126e09e6ac7 |
comparison
equal
deleted
inserted
replaced
78357:fb9000547438 | 78358:9b7f2e8baaeb |
---|---|
35 (defgroup copyright nil | 35 (defgroup copyright nil |
36 "Update the copyright notice in current buffer." | 36 "Update the copyright notice in current buffer." |
37 :group 'tools) | 37 :group 'tools) |
38 | 38 |
39 (defcustom copyright-limit 2000 | 39 (defcustom copyright-limit 2000 |
40 "*Don't try to update copyright beyond this position unless interactive. | 40 "Don't try to update copyright beyond this position unless interactive. |
41 A value of nil means to search whole buffer." | 41 A value of nil means to search whole buffer." |
42 :group 'copyright | 42 :group 'copyright |
43 :type '(choice (integer :tag "Limit") | 43 :type '(choice (integer :tag "Limit") |
44 (const :tag "No limit"))) | 44 (const :tag "No limit"))) |
45 | 45 |
47 ;; version, which is probably enough. | 47 ;; version, which is probably enough. |
48 (defcustom copyright-regexp | 48 (defcustom copyright-regexp |
49 "\\([]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\ | 49 "\\([]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\ |
50 \\|[Cc]opyright\\s *:?\\s *[]\\)\ | 50 \\|[Cc]opyright\\s *:?\\s *[]\\)\ |
51 \\s *\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" | 51 \\s *\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" |
52 "*What your copyright notice looks like. | 52 "What your copyright notice looks like. |
53 The second \\( \\) construct must match the years." | 53 The second \\( \\) construct must match the years." |
54 :group 'copyright | 54 :group 'copyright |
55 :type 'regexp) | 55 :type 'regexp) |
56 | 56 |
57 (defcustom copyright-years-regexp | 57 (defcustom copyright-years-regexp |
58 "\\(\\s *\\)\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" | 58 "\\(\\s *\\)\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" |
59 "*Match additional copyright notice years. | 59 "Match additional copyright notice years. |
60 The second \\( \\) construct must match the years." | 60 The second \\( \\) construct must match the years." |
61 :group 'copyright | 61 :group 'copyright |
62 :type 'regexp) | 62 :type 'regexp) |
63 | 63 |
64 | 64 |
65 (defcustom copyright-query 'function | 65 (defcustom copyright-query 'function |
66 "*If non-nil, ask user before changing copyright. | 66 "If non-nil, ask user before changing copyright. |
67 When this is `function', only ask when called non-interactively." | 67 When this is `function', only ask when called non-interactively." |
68 :group 'copyright | 68 :group 'copyright |
69 :type '(choice (const :tag "Do not ask") | 69 :type '(choice (const :tag "Do not ask") |
70 (const :tag "Ask unless interactive" function) | 70 (const :tag "Ask unless interactive" function) |
71 (other :tag "Ask" t))) | 71 (other :tag "Ask" t))) |
81 ;; change during the Emacs session. | 81 ;; change during the Emacs session. |
82 (defvar copyright-current-year (substring (current-time-string) -4) | 82 (defvar copyright-current-year (substring (current-time-string) -4) |
83 "String representing the current year.") | 83 "String representing the current year.") |
84 | 84 |
85 (defun copyright-update-year (replace noquery) | 85 (defun copyright-update-year (replace noquery) |
86 (when (re-search-forward copyright-regexp (+ (point) copyright-limit) t) | 86 (when (re-search-forward copyright-regexp |
87 (if copyright-limit (+ (point) copyright-limit)) t) | |
87 ;; If the years are continued onto multiple lined | 88 ;; If the years are continued onto multiple lined |
88 ;; that are marked as comments, skip to the end of the years anyway. | 89 ;; that are marked as comments, skip to the end of the years anyway. |
89 (while (save-excursion | 90 (while (save-excursion |
90 (and (eq (following-char) ?,) | 91 (and (eq (following-char) ?,) |
91 (progn (forward-char 1) t) | 92 (progn (forward-char 1) t) |
157 (copyright-update-year arg noquery) | 158 (copyright-update-year arg noquery) |
158 (goto-char (point-min)) | 159 (goto-char (point-min)) |
159 (and copyright-current-gpl-version | 160 (and copyright-current-gpl-version |
160 ;; match the GPL version comment in .el files, including the | 161 ;; match the GPL version comment in .el files, including the |
161 ;; bilingual Esperanto one in two-column, and in texinfo.tex | 162 ;; bilingual Esperanto one in two-column, and in texinfo.tex |
162 (re-search-forward "\\(the Free Software Foundation;\ | 163 (re-search-forward |
164 "\\(the Free Software Foundation;\ | |
163 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ | 165 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ |
164 version \\([0-9]+\\), or (at" | 166 version \\([0-9]+\\), or (at" |
165 (+ (point) copyright-limit) t) | 167 (if copyright-limit (+ (point) copyright-limit)) t) |
166 (not (string= (match-string 3) copyright-current-gpl-version)) | 168 (not (string= (match-string 3) copyright-current-gpl-version)) |
167 (or noquery | 169 (or noquery |
168 (y-or-n-p (concat "Replace GPL version by " | 170 (y-or-n-p (concat "Replace GPL version by " |
169 copyright-current-gpl-version "? "))) | 171 copyright-current-gpl-version "? "))) |
170 (progn | 172 (progn |
182 "Convert 2 digit years to 4 digit years. | 184 "Convert 2 digit years to 4 digit years. |
183 Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." | 185 Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." |
184 (interactive) | 186 (interactive) |
185 (widen) | 187 (widen) |
186 (goto-char (point-min)) | 188 (goto-char (point-min)) |
187 (if (re-search-forward copyright-regexp (+ (point) copyright-limit) t) | 189 (if (re-search-forward copyright-regexp |
190 (if copyright-limit (+ (point) copyright-limit)) t) | |
188 (let ((s (match-beginning 2)) | 191 (let ((s (match-beginning 2)) |
189 (e (copy-marker (1+ (match-end 2)))) | 192 (e (copy-marker (1+ (match-end 2)))) |
190 (p (make-marker)) | 193 (p (make-marker)) |
191 last) | 194 last) |
192 (goto-char s) | 195 (goto-char s) |
222 "Company: " | 225 "Company: " |
223 comment-start | 226 comment-start |
224 "Copyright (C) " `(substring (current-time-string) -4) " by " | 227 "Copyright (C) " `(substring (current-time-string) -4) " by " |
225 (or (getenv "ORGANIZATION") | 228 (or (getenv "ORGANIZATION") |
226 str) | 229 str) |
227 '(if (> (point) (+ (point-min) copyright-limit)) | 230 '(if (and copyright-limit (> (point) (+ (point-min) copyright-limit))) |
228 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) | 231 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) |
229 comment-end \n) | 232 comment-end \n) |
230 | 233 |
231 (provide 'copyright) | 234 (provide 'copyright) |
232 | 235 |
233 ;; For the copyright sign: | 236 ;; For the copyright sign: |
234 ;; Local Variables: | 237 ;; Local Variables: |
235 ;; coding: emacs-mule | 238 ;; coding: emacs-mule |
236 ;; End: | 239 ;; End: |
237 | 240 |
238 ;;; arch-tag: b4991afb-b6b1-4590-bebe-e076d9d4aee8 | 241 ;; arch-tag: b4991afb-b6b1-4590-bebe-e076d9d4aee8 |
239 ;;; copyright.el ends here | 242 ;;; copyright.el ends here |