aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Monnier2003-06-14 20:11:37 +0000
committerStefan Monnier2003-06-14 20:11:37 +0000
commitf47f53024467c5af8d85e3023ce8da609a4aee8d (patch)
tree1214a34ec329fdf3135ba4a4c0b355e733a33902
parenteffe34908c6874c4026607ce715d58a3fb64a87c (diff)
downloademacs-f47f53024467c5af8d85e3023ce8da609a4aee8d.tar.gz
emacs-f47f53024467c5af8d85e3023ce8da609a4aee8d.zip
(copyright-update-year): New function extracted from copyright-update.
When `arg' is set, replace the year, not the `copyright' text. Ignore `copyright-update = nil' if called interactively. Use "," rather than ", " if that's what was used before. Recognize mixes of 2 and 4 digit years. Use replace-match. (copyright-update): Add interactivep arg. Use it instead of use last-command. Use replace-match. Don't assume (point-min) == 1.
-rw-r--r--lisp/ChangeLog11
-rw-r--r--lisp/emacs-lisp/copyright.el130
2 files changed, 88 insertions, 53 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 33c62e493f5..687a0e326a8 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,5 +1,16 @@
12003-06-14 Stefan Monnier <monnier@cs.yale.edu> 12003-06-14 Stefan Monnier <monnier@cs.yale.edu>
2 2
3 * emacs-lisp/copyright.el (copyright-update-year): New function
4 extracted from copyright-update.
5 When `arg' is set, replace the year, not the `copyright' text.
6 Ignore `copyright-update = nil' if called interactively.
7 Use "," rather than ", " if that's what was used before.
8 Recognize mixes of 2 and 4 digit years.
9 Use replace-match.
10 (copyright-update): Add interactivep arg.
11 Use it instead of use last-command.
12 Use replace-match. Don't assume (point-min) == 1.
13
3 * textmodes/tex-mode.el (tex-compile-commands): 14 * textmodes/tex-mode.el (tex-compile-commands):
4 Handle tex-start-commands like tex-start-tex does. 15 Handle tex-start-commands like tex-start-tex does.
5 16
diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el
index abed05cf902..c2ad007e3a8 100644
--- a/lisp/emacs-lisp/copyright.el
+++ b/lisp/emacs-lisp/copyright.el
@@ -1,6 +1,7 @@
1;;; copyright.el --- update the copyright notice in current buffer 1;;; copyright.el --- update the copyright notice in current buffer
2 2
3;; Copyright (C) 1991, 92, 93, 94, 95, 98, 2001 Free Software Foundation, Inc. 3;; Copyright (C) 1991, 92, 93, 94, 95, 1998, 2001, 2003
4;; Free Software Foundation, Inc.
4 5
5;; Author: Daniel Pfeiffer <occitan@esperanto.org> 6;; Author: Daniel Pfeiffer <occitan@esperanto.org>
6;; Keywords: maint, tools 7;; Keywords: maint, tools
@@ -25,7 +26,8 @@
25;;; Commentary: 26;;; Commentary:
26 27
27;; Allows updating the copyright year and above mentioned GPL version manually 28;; 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). 29;; or when saving a file.
30;; Do (add-hook 'write-file-functions 'copyright-update).
29 31
30;;; Code: 32;;; Code:
31 33
@@ -75,53 +77,82 @@ When this is `function', only ask when called non-interactively."
75(defvar copyright-current-year (substring (current-time-string) -4) 77(defvar copyright-current-year (substring (current-time-string) -4)
76 "String representing the current year.") 78 "String representing the current year.")
77 79
80(defun copyright-update-year (replace noquery)
81 (when (re-search-forward copyright-regexp (+ (point) copyright-limit) t)
82 ;; Note that `current-time-string' isn't locale-sensitive.
83 (setq copyright-current-year (substring (current-time-string) -4))
84 (unless (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
85 (substring copyright-current-year -2))
86 (if (or noquery
87 (y-or-n-p (if replace
88 (concat "Replace copyright year(s) by "
89 copyright-current-year "? ")
90 (concat "Add " copyright-current-year
91 " to copyright? "))))
92 (if replace
93 (replace-match copyright-current-year t t nil 1)
94 (let ((size (save-excursion (skip-chars-backward "0-9"))))
95 (if (and (eq (% (- (string-to-number copyright-current-year)
96 (string-to-number (buffer-substring
97 (+ (point) size)
98 (point))))
99 100)
100 1)
101 (or (eq (char-after (+ (point) size -1)) ?-)
102 (eq (char-after (+ (point) size -2)) ?-)))
103 ;; This is a range so just replace the end part.
104 (delete-char size)
105 ;; Detect if this is using the following shorthand:
106 ;; (C) 1993, 94, 95, 1998, 2000, 01, 02, 2003
107 (if (and
108 ;; Check that the last year was 4-chars and same century.
109 (eq size -4)
110 (equal (buffer-substring (- (point) 4) (- (point) 2))
111 (substring copyright-current-year 0 2))
112 ;; Check that there are 2-char years as well.
113 (save-excursion
114 (re-search-backward "[^0-9][0-9][0-9][^0-9]"
115 (line-beginning-position) t))
116 ;; Make sure we don't remove the first century marker.
117 (save-excursion
118 (forward-char size)
119 (re-search-backward
120 (concat (buffer-substring (point) (+ (point) 2))
121 "[0-9][0-9]")
122 (line-beginning-position) t)))
123 ;; Remove the century marker of the last entry.
124 (delete-region (- (point) 4) (- (point) 2)))
125 ;; Insert a comma with the preferred number of spaces.
126 (insert
127 (save-excursion
128 (if (re-search-backward "[0-9]\\( *, *\\)[0-9]"
129 (line-beginning-position) t)
130 (match-string 1)
131 ", ")))
132 ;; If people use the '91 '92 '93 scheme, do that as well.
133 (if (eq (char-after (+ (point) size -3)) ?')
134 (insert ?')))
135 ;; Finally insert the new year.
136 (insert (substring copyright-current-year size))))))))
78 137
79;;;###autoload 138;;;###autoload
80(defun copyright-update (&optional arg) 139(defun copyright-update (&optional arg interactivep)
81 "Update copyright notice at beginning of buffer to indicate the current year. 140 "Update copyright notice at beginning of buffer to indicate the current year.
82With prefix ARG, replace the years in the notice rather than adding 141With prefix ARG, replace the years in the notice rather than adding
83the current year after them. If necessary, and 142the current year after them. If necessary, and
84`copyright-current-gpl-version' is set, any copying permissions 143`copyright-current-gpl-version' is set, any copying permissions
85following the copyright are updated as well." 144following the copyright are updated as well.
86 (interactive "*P") 145If non-nil, INTERACTIVEP tells the function to behave as when it's called
87 (if copyright-update 146interactively."
147 (interactive "*P\nd")
148 (when (or copyright-update interactivep)
149 (let ((noquery (or (not copyright-query)
150 (and (eq copyright-query 'function) interactivep))))
88 (save-excursion 151 (save-excursion
89 (save-restriction 152 (save-restriction
90 (widen) 153 (widen)
91 (goto-char (point-min)) 154 (goto-char (point-min))
92 ;; Note that `current-time-string' isn't locale-sensitive. 155 (copyright-update-year arg noquery)
93 (setq copyright-current-year (substring (current-time-string) -4))
94 (if (re-search-forward copyright-regexp copyright-limit t)
95 (if (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
96 (substring copyright-current-year -2))
97 ()
98 (if (or (not copyright-query)
99 (and (eq copyright-query 'function)
100 (eq this-command 'copyright-update))
101 (y-or-n-p (if arg
102 (concat "Replace copyright year(s) by "
103 copyright-current-year "? ")
104 (concat "Add " copyright-current-year
105 " to copyright? "))))
106 (if arg
107 (progn
108 (delete-region (match-beginning 1) (match-end 1))
109 (insert copyright-current-year))
110 (setq arg (save-excursion (skip-chars-backward "0-9")))
111 (if (and (eq (% (- (string-to-number
112 copyright-current-year)
113 (string-to-number (buffer-substring
114 (+ (point) arg)
115 (point))))
116 100)
117 1)
118 (or (eq (char-after (+ (point) arg -1)) ?-)
119 (eq (char-after (+ (point) arg -2)) ?-)))
120 (delete-char arg)
121 (insert ", ")
122 (if (eq (char-after (+ (point) arg -3)) ?')
123 (insert ?')))
124 (insert (substring copyright-current-year arg))))))
125 (goto-char (point-min)) 156 (goto-char (point-min))
126 (and copyright-current-gpl-version 157 (and copyright-current-gpl-version
127 ;; match the GPL version comment in .el files, including the 158 ;; match the GPL version comment in .el files, including the
@@ -129,26 +160,19 @@ following the copyright are updated as well."
129 (re-search-forward "\\(the Free Software Foundation;\ 160 (re-search-forward "\\(the Free Software Foundation;\
130 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\ 161 either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\
131version \\([0-9]+\\), or (at" 162version \\([0-9]+\\), or (at"
132 copyright-limit t) 163 (+ (point) copyright-limit) t)
133 (not (string= (match-string 3) copyright-current-gpl-version)) 164 (not (string= (match-string 3) copyright-current-gpl-version))
134 (or (not copyright-query) 165 (or noquery
135 (and (eq copyright-query 'function)
136 (eq this-command 'copyright-update))
137 (y-or-n-p (concat "Replace GPL version by " 166 (y-or-n-p (concat "Replace GPL version by "
138 copyright-current-gpl-version "? "))) 167 copyright-current-gpl-version "? ")))
139 (progn 168 (progn
140 (if (match-end 2) 169 (if (match-end 2)
141 ;; Esperanto bilingual comment in two-column.el 170 ;; Esperanto bilingual comment in two-column.el
142 (progn 171 (replace-match copyright-current-gpl-version t t nil 2))
143 (delete-region (match-beginning 2) (match-end 2)) 172 (replace-match copyright-current-gpl-version t t nil 3))))
144 (goto-char (match-beginning 2))
145 (insert copyright-current-gpl-version)))
146 (delete-region (match-beginning 3) (match-end 3))
147 (goto-char (match-beginning 3))
148 (insert copyright-current-gpl-version))))
149 (set (make-local-variable 'copyright-update) nil))) 173 (set (make-local-variable 'copyright-update) nil)))
150 ;; If a write-file-hook returns non-nil, the file is presumed to be written. 174 ;; If a write-file-hook returns non-nil, the file is presumed to be written.
151 nil) 175 nil))
152 176
153 177
154;;;###autoload 178;;;###autoload
@@ -159,7 +183,7 @@ version \\([0-9]+\\), or (at"
159 "Copyright (C) " `(substring (current-time-string) -4) " by " 183 "Copyright (C) " `(substring (current-time-string) -4) " by "
160 (or (getenv "ORGANIZATION") 184 (or (getenv "ORGANIZATION")
161 str) 185 str)
162 '(if (> (point) copyright-limit) 186 '(if (> (point) (+ (point-min) copyright-limit))
163 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically.")) 187 (message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
164 comment-end \n) 188 comment-end \n)
165 189