Mercurial > emacs
annotate lisp/emacs-lisp/copyright.el @ 84916:e41433198a1b
(zone-pgm-rotate): Use `mapc' rather than `mapcar'.
author | Juanma Barranquero <lekktu@gmail.com> |
---|---|
date | Wed, 26 Sep 2007 00:23:11 +0000 |
parents | 729600607616 |
children | a96e5919b08b |
rev | line source |
---|---|
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
1 ;;; copyright.el --- update the copyright notice in current buffer |
657
fec3f9a1e3e5
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
611
diff
changeset
|
2 |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1998, 2001, 2002, 2003, |
75346 | 4 ;; 2004, 2005, 2006, 2007 Free Software Foundation, Inc. |
841 | 5 |
23869 | 6 ;; Author: Daniel Pfeiffer <occitan@esperanto.org> |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
7 ;; Keywords: maint, tools |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
8 |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
9 ;; This file is part of GNU Emacs. |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
718
diff
changeset
|
10 |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
11 ;; GNU Emacs is free software; you can redistribute it and/or modify |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
12 ;; it under the terms of the GNU General Public License as published by |
78217
935157c0b596
Switch license to GPLv3 or later.
Glenn Morris <rgm@gnu.org>
parents:
78100
diff
changeset
|
13 ;; the Free Software Foundation; either version 3, or (at your option) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
14 ;; any later version. |
841 | 15 |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
16 ;; GNU Emacs is distributed in the hope that it will be useful, |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
19 ;; GNU General Public License for more details. |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
20 |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
21 ;; You should have received a copy of the GNU General Public License |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
25 |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
26 ;;; Commentary: |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
27 |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
28 ;; Allows updating the copyright year and above mentioned GPL version manually |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
29 ;; or when saving a file. |
53504
f657faa17ea1
Fix comment to recommend
Simon Josefsson <jas@extundo.com>
parents:
53499
diff
changeset
|
30 ;; Do (add-hook 'before-save-hook 'copyright-update), or use |
f657faa17ea1
Fix comment to recommend
Simon Josefsson <jas@extundo.com>
parents:
53499
diff
changeset
|
31 ;; M-x customize-variable RET before-save-hook RET. |
288 | 32 |
773
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
718
diff
changeset
|
33 ;;; Code: |
9c89fd7ddd41
*** empty log message ***
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
718
diff
changeset
|
34 |
21328 | 35 (defgroup copyright nil |
36 "Update the copyright notice in current buffer." | |
37 :group 'tools) | |
38 | |
39 (defcustom copyright-limit 2000 | |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
40 "Don't try to update copyright beyond this position unless interactive. |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
41 A value of nil means to search whole buffer." |
21328 | 42 :group 'copyright |
43 :type '(choice (integer :tag "Limit") | |
44 (const :tag "No limit"))) | |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
45 |
52286 | 46 ;; The character classes have the Latin-1 version and the Latin-9 |
47 ;; version, which is probably enough. | |
21328 | 48 (defcustom copyright-regexp |
82221 | 49 "\\([]\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\ |
50 \\|[Cc]opyright\\s *:?\\s *[]\\)\ | |
53507 | 51 \\s *\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
52 "What your copyright notice looks like. |
21328 | 53 The second \\( \\) construct must match the years." |
54 :group 'copyright | |
55 :type 'regexp) | |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
56 |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
57 (defcustom copyright-names-regexp "" |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
58 "Regexp matching the names which correspond to the user. |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
59 Only copyright lines where the name matches this regexp will be updated. |
84511
729600607616
(copyright-names-regexp): Doc fix: typo.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82449
diff
changeset
|
60 This allows you to avoid adding years to a copyright notice belonging to |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
61 someone else or to a group for which you do not work." |
82408
50d1581f2548
(copyright-names-regexp): Add custom group.
Richard M. Stallman <rms@gnu.org>
parents:
82221
diff
changeset
|
62 :group 'copyright |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
63 :type 'regexp) |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
64 |
56685
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
65 (defcustom copyright-years-regexp |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
66 "\\(\\s *\\)\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
67 "Match additional copyright notice years. |
56685
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
68 The second \\( \\) construct must match the years." |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
69 :group 'copyright |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
70 :type 'regexp) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
71 |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
72 |
21328 | 73 (defcustom copyright-query 'function |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
74 "If non-nil, ask user before changing copyright. |
21328 | 75 When this is `function', only ask when called non-interactively." |
76 :group 'copyright | |
77 :type '(choice (const :tag "Do not ask") | |
22580
a191ee97be00
(copyright-query): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
21754
diff
changeset
|
78 (const :tag "Ask unless interactive" function) |
a191ee97be00
(copyright-query): Use `other' widget
Andreas Schwab <schwab@suse.de>
parents:
21754
diff
changeset
|
79 (other :tag "Ask" t))) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
80 |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
81 |
14040 | 82 ;; when modifying this, also modify the comment generated by autoinsert.el |
78100
4535acabc388
(copyright-current-gpl-version): Set to 3.
Nick Roberts <nickrob@snap.net.nz>
parents:
75346
diff
changeset
|
83 (defconst copyright-current-gpl-version "3" |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
84 "String representing the current version of the GPL or nil.") |
288 | 85 |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
86 (defvar copyright-update t) |
718 | 87 |
35129
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
88 ;; This is a defvar rather than a defconst, because the year can |
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
89 ;; change during the Emacs session. |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
90 (defvar copyright-current-year (substring (current-time-string) -4) |
35129
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
91 "String representing the current year.") |
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
92 |
82447
7206375cd8a6
(copyright-limit): New defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82445
diff
changeset
|
93 (defsubst copyright-limit () ; re-search-forward BOUND |
82449
786b4b5a733e
(copyright-limit): Fix sense typo in defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82447
diff
changeset
|
94 (and copyright-limit (+ (point) copyright-limit))) |
82447
7206375cd8a6
(copyright-limit): New defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82445
diff
changeset
|
95 |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
96 (defun copyright-update-year (replace noquery) |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
97 (when |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
98 (condition-case err |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
99 (re-search-forward (concat "\\(" copyright-regexp |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
100 "\\)\\([ \t]*\n\\)?.*\\(?:" |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
101 copyright-names-regexp "\\)") |
82447
7206375cd8a6
(copyright-limit): New defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82445
diff
changeset
|
102 (copyright-limit) |
82221 | 103 t) |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
104 ;; In case the regexp is rejected. This is useful because |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
105 ;; copyright-update is typically called from before-save-hook where |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
106 ;; such an error is very inconvenient for the user. |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
107 (error (message "Can't update copyright: %s" err) nil)) |
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
108 (goto-char (match-end 1)) |
56685
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
109 ;; If the years are continued onto multiple lined |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
110 ;; that are marked as comments, skip to the end of the years anyway. |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
111 (while (save-excursion |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
112 (and (eq (following-char) ?,) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
113 (progn (forward-char 1) t) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
114 (progn (skip-chars-forward " \t") (eolp)) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
115 comment-start-skip |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
116 (save-match-data |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
117 (forward-line 1) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
118 (and (looking-at comment-start-skip) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
119 (goto-char (match-end 0)))) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
120 (save-match-data |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
121 (looking-at copyright-years-regexp)))) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
122 (forward-line 1) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
123 (re-search-forward comment-start-skip) |
22f1ac802ffd
(copyright-years-regexp): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
53507
diff
changeset
|
124 (re-search-forward copyright-years-regexp)) |
56706
15d087a81874
(copyright-update-year): Delete code that replaces 20xy with xy.
Luc Teirlinck <teirllm@auburn.edu>
parents:
56685
diff
changeset
|
125 |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
126 ;; Note that `current-time-string' isn't locale-sensitive. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
127 (setq copyright-current-year (substring (current-time-string) -4)) |
81079
506d3398a966
(copyright-names-regexp): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
75346
diff
changeset
|
128 (unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3)) |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
129 (substring copyright-current-year -2)) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
130 (if (or noquery |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
131 (y-or-n-p (if replace |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
132 (concat "Replace copyright year(s) by " |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
133 copyright-current-year "? ") |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
134 (concat "Add " copyright-current-year |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
135 " to copyright? ")))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
136 (if replace |
61330
f6862f0984bc
(copyright-update-year): Replace the right subexpression. Suggested
Lute Kamstra <lute@gnu.org>
parents:
60320
diff
changeset
|
137 (replace-match copyright-current-year t t nil 2) |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
138 (let ((size (save-excursion (skip-chars-backward "0-9")))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
139 (if (and (eq (% (- (string-to-number copyright-current-year) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
140 (string-to-number (buffer-substring |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
141 (+ (point) size) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
142 (point)))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
143 100) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
144 1) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
145 (or (eq (char-after (+ (point) size -1)) ?-) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
146 (eq (char-after (+ (point) size -2)) ?-))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
147 ;; This is a range so just replace the end part. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
148 (delete-char size) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
149 ;; Insert a comma with the preferred number of spaces. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
150 (insert |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
151 (save-excursion |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
152 (if (re-search-backward "[0-9]\\( *, *\\)[0-9]" |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
153 (line-beginning-position) t) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
154 (match-string 1) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
155 ", "))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
156 ;; If people use the '91 '92 '93 scheme, do that as well. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
157 (if (eq (char-after (+ (point) size -3)) ?') |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
158 (insert ?'))) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
159 ;; Finally insert the new year. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
160 (insert (substring copyright-current-year size)))))))) |
35129
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
161 |
288 | 162 ;;;###autoload |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
163 (defun copyright-update (&optional arg interactivep) |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
164 "Update copyright notice at beginning of buffer to indicate the current year. |
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
165 With prefix ARG, replace the years in the notice rather than adding |
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
166 the current year after them. If necessary, and |
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
167 `copyright-current-gpl-version' is set, any copying permissions |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
168 following the copyright are updated as well. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
169 If non-nil, INTERACTIVEP tells the function to behave as when it's called |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
170 interactively." |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
171 (interactive "*P\nd") |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
172 (when (or copyright-update interactivep) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
173 (let ((noquery (or (not copyright-query) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
174 (and (eq copyright-query 'function) interactivep)))) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
175 (save-excursion |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
176 (save-restriction |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
177 (widen) |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
178 (goto-char (point-min)) |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
179 (copyright-update-year arg noquery) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
180 (goto-char (point-min)) |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
181 (and copyright-current-gpl-version |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
182 ;; match the GPL version comment in .el files, including the |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
183 ;; bilingual Esperanto one in two-column, and in texinfo.tex |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
184 (re-search-forward |
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
185 "\\(the Free Software Foundation;\ |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
186 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ |
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
187 version \\([0-9]+\\), or (at" |
82447
7206375cd8a6
(copyright-limit): New defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82445
diff
changeset
|
188 (copyright-limit) t) |
42732
7db08aae2e67
(copyright-regexp): Make (C) optional.
Richard M. Stallman <rms@gnu.org>
parents:
42533
diff
changeset
|
189 (not (string= (match-string 3) copyright-current-gpl-version)) |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
190 (or noquery |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
191 (y-or-n-p (concat "Replace GPL version by " |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
192 copyright-current-gpl-version "? "))) |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
193 (progn |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
194 (if (match-end 2) |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
195 ;; Esperanto bilingual comment in two-column.el |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
196 (replace-match copyright-current-gpl-version t t nil 2)) |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
197 (replace-match copyright-current-gpl-version t t nil 3)))) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
198 (set (make-local-variable 'copyright-update) nil))) |
51564
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
199 ;; If a write-file-hook returns non-nil, the file is presumed to be written. |
09736ff1baa6
(copyright-update-year): New function extracted from copyright-update.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
43169
diff
changeset
|
200 nil)) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
201 |
581 | 202 |
203 ;;;###autoload | |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
204 (defun copyright-fix-years () |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
205 "Convert 2 digit years to 4 digit years. |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
206 Uses heuristic: year >= 50 means 19xx, < 50 means 20xx." |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
207 (interactive) |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
208 (widen) |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
209 (goto-char (point-min)) |
82447
7206375cd8a6
(copyright-limit): New defsubst.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
82445
diff
changeset
|
210 (if (re-search-forward copyright-regexp (copyright-limit) t) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
211 (let ((s (match-beginning 2)) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
212 (e (copy-marker (1+ (match-end 2)))) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
213 (p (make-marker)) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
214 last) |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
215 (goto-char s) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
216 (while (re-search-forward "[0-9]+" e t) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
217 (set-marker p (point)) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
218 (goto-char (match-beginning 0)) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
219 (let ((sep (char-before)) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
220 (year (string-to-number (match-string 0)))) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
221 (when (and sep |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
222 (/= (char-syntax sep) ?\s) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
223 (/= sep ?-)) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
224 (insert " ")) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
225 (when (< year 100) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
226 (insert (if (>= year 50) "19" "20")))) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
227 (goto-char p) |
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
228 (setq last p)) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
229 (when last |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
230 (goto-char last) |
62375
6a8938e81aa7
(copyright-fix-years): Match properly if the first year is 2-digit.
Richard M. Stallman <rms@gnu.org>
parents:
61330
diff
changeset
|
231 ;; Don't mess up whitespace after the years. |
6a8938e81aa7
(copyright-fix-years): Match properly if the first year is 2-digit.
Richard M. Stallman <rms@gnu.org>
parents:
61330
diff
changeset
|
232 (skip-chars-backward " \t") |
6a8938e81aa7
(copyright-fix-years): Match properly if the first year is 2-digit.
Richard M. Stallman <rms@gnu.org>
parents:
61330
diff
changeset
|
233 (save-restriction |
6a8938e81aa7
(copyright-fix-years): Match properly if the first year is 2-digit.
Richard M. Stallman <rms@gnu.org>
parents:
61330
diff
changeset
|
234 (narrow-to-region (point-min) (point)) |
6a8938e81aa7
(copyright-fix-years): Match properly if the first year is 2-digit.
Richard M. Stallman <rms@gnu.org>
parents:
61330
diff
changeset
|
235 (let ((fill-prefix " ")) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
236 (fill-region s last)))) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
237 (set-marker e nil) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
238 (set-marker p nil) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
239 (copyright-update nil t)) |
62508
39dc00cd1f8a
(copyright-fix-years): Make sure all years are fixed. Don't insert a
Lute Kamstra <lute@gnu.org>
parents:
62375
diff
changeset
|
240 (message "No copyright message"))) |
60319
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
241 |
68fb18eab7a7
(copyright-fix-years): New command.
Kim F. Storm <storm@cua.dk>
parents:
56706
diff
changeset
|
242 ;;;###autoload |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
243 (define-skeleton copyright |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
244 "Insert a copyright by $ORGANIZATION notice at cursor." |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
245 "Company: " |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
246 comment-start |
35129
9f38c893ea39
(copyright-current-year): Now a defvar.
Eli Zaretskii <eliz@gnu.org>
parents:
27329
diff
changeset
|
247 "Copyright (C) " `(substring (current-time-string) -4) " by " |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
248 (or (getenv "ORGANIZATION") |
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
249 str) |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
250 '(if (and copyright-limit (> (point) (+ (point-min) copyright-limit))) |
12503
f77164f5bc6b
New name for generalized upd-copyr.el
Karl Heuer <kwzh@gnu.org>
parents:
10510
diff
changeset
|
251 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) |
39764
fb28cd06b2f6
(copyright): Add final \n.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38436
diff
changeset
|
252 comment-end \n) |
288 | 253 |
18383 | 254 (provide 'copyright) |
255 | |
27229 | 256 ;; For the copyright sign: |
257 ;; Local Variables: | |
258 ;; coding: emacs-mule | |
259 ;; End: | |
260 | |
78358
9b7f2e8baaeb
(copyright-update-year, copyright-update, copyright-fix-years, copyright):
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
78217
diff
changeset
|
261 ;; arch-tag: b4991afb-b6b1-4590-bebe-e076d9d4aee8 |
38436
b174db545cfd
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
35129
diff
changeset
|
262 ;;; copyright.el ends here |