;;; copyright.el --- update the copyright notice in current buffer
-;; Copyright (C) 1991, 92, 93, 94, 95, 1998, 2001, 2003, 2004
-;; Free Software Foundation, Inc.
+;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1998, 2001, 2002, 2003,
+;; 2004, 2005, 2006 Free Software Foundation, Inc.
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
;; Keywords: maint, tools
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
(forward-line 1)
(re-search-forward comment-start-skip)
(re-search-forward copyright-years-regexp))
-
+
;; Note that `current-time-string' isn't locale-sensitive.
(setq copyright-current-year (substring (current-time-string) -4))
(unless (string= (buffer-substring (- (match-end 2) 2) (match-end 2))
(concat "Add " copyright-current-year
" to copyright? "))))
(if replace
- (replace-match copyright-current-year t t nil 1)
+ (replace-match copyright-current-year t t nil 2)
(let ((size (save-excursion (skip-chars-backward "0-9"))))
(if (and (eq (% (- (string-to-number copyright-current-year)
(string-to-number (buffer-substring
(eq (char-after (+ (point) size -2)) ?-)))
;; This is a range so just replace the end part.
(delete-char size)
- ;; Detect if this is using the following shorthand:
- ;; (C) 1993, 94, 95, 1998, 2000, 01, 02, 2003
- (if (and
- ;; Check that the last year was 4-chars and same century.
- (eq size -4)
- (equal (buffer-substring (- (point) 4) (- (point) 2))
- (substring copyright-current-year 0 2))
- ;; Check that there are 2-char years as well.
- (save-excursion
- (re-search-backward "[^0-9][0-9][0-9][^0-9]"
- (line-beginning-position) t))
- ;; Make sure we don't remove the first century marker.
- (save-excursion
- (forward-char size)
- (re-search-backward
- (concat (buffer-substring (point) (+ (point) 2))
- "[0-9][0-9]")
- (line-beginning-position) t)))
- ;; Remove the century marker of the last entry.
- (delete-region (- (point) 4) (- (point) 2)))
;; Insert a comma with the preferred number of spaces.
(insert
(save-excursion
nil))
+;;;###autoload
+(defun copyright-fix-years ()
+ "Convert 2 digit years to 4 digit years.
+Uses heuristic: year >= 50 means 19xx, < 50 means 20xx."
+ (interactive)
+ (widen)
+ (goto-char (point-min))
+ (if (re-search-forward copyright-regexp (+ (point) copyright-limit) t)
+ (let ((s (match-beginning 2))
+ (e (copy-marker (1+ (match-end 2))))
+ (p (make-marker))
+ last)
+ (goto-char s)
+ (while (re-search-forward "[0-9]+" e t)
+ (set-marker p (point))
+ (goto-char (match-beginning 0))
+ (let ((sep (char-before))
+ (year (string-to-number (match-string 0))))
+ (when (and sep
+ (/= (char-syntax sep) ?\s)
+ (/= sep ?-))
+ (insert " "))
+ (when (< year 100)
+ (insert (if (>= year 50) "19" "20"))))
+ (goto-char p)
+ (setq last p))
+ (when last
+ (goto-char last)
+ ;; Don't mess up whitespace after the years.
+ (skip-chars-backward " \t")
+ (save-restriction
+ (narrow-to-region (point-min) (point))
+ (let ((fill-prefix " "))
+ (fill-region s last))))
+ (set-marker e nil)
+ (set-marker p nil)
+ (copyright-update nil t))
+ (message "No copyright message")))
+
;;;###autoload
(define-skeleton copyright
"Insert a copyright by $ORGANIZATION notice at cursor."