;;; copyright.el --- update the copyright notice in current buffer
;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1998, 2001, 2002, 2003,
-;; 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
+;; 2004, 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
;; Keywords: maint, tools
(defcustom copyright-regexp
"\\(©\\|@copyright{}\\|[Cc]opyright\\s *:?\\s *\\(?:(C)\\)?\
\\|[Cc]opyright\\s *:?\\s *©\\)\
-\\s *\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
+\\s *\\(?:[^0-9\n]*\\s *\\)?\
+\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
"What your copyright notice looks like.
The second \\( \\) construct must match the years."
:group 'copyright
(defconst copyright-current-gpl-version "3"
"String representing the current version of the GPL or nil.")
-(defvar copyright-update t)
+(defvar copyright-update t
+ "The function `copyright-update' sets this to nil after updating a buffer.")
;; This is a defvar rather than a defconst, because the year can
;; change during the Emacs session.
(unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
(substring copyright-current-year -2))
(if (or noquery
- (y-or-n-p (if replace
- (concat "Replace copyright year(s) by "
- copyright-current-year "? ")
- (concat "Add " copyright-current-year
- " to copyright? "))))
+ (save-window-excursion
+ (switch-to-buffer (current-buffer))
+ ;; Fixes some point-moving oddness (bug#2209).
+ (save-excursion
+ (y-or-n-p (if replace
+ (concat "Replace copyright year(s) by "
+ copyright-current-year "? ")
+ (concat "Add " copyright-current-year
+ " to copyright? "))))))
(if replace
(replace-match copyright-current-year t t nil 3)
(let ((size (save-excursion (skip-chars-backward "0-9"))))
;;;###autoload
(defun copyright-update (&optional arg interactivep)
- "Update copyright notice at beginning of buffer to indicate the current year.
+ "Update copyright notice to indicate the current year.
With prefix ARG, replace the years in the notice rather than adding
the current year after them. If necessary, and
`copyright-current-gpl-version' is set, any copying permissions
(< (string-to-number (match-string 3))
(string-to-number copyright-current-gpl-version))
(or noquery
- (y-or-n-p (format "Replace GPL version by %s? "
- copyright-current-gpl-version)))
+ (save-match-data
+ (save-window-excursion
+ (switch-to-buffer (current-buffer))
+ (y-or-n-p (format "Replace GPL version by %s? "
+ copyright-current-gpl-version)))))
(progn
(if (match-end 2)
;; Esperanto bilingual comment in two-column.el
nil))
+;; FIXME should be within 50 years of present (cf calendar).
;;;###autoload
(defun copyright-fix-years ()
"Convert 2 digit years to 4 digit years.
(message "Copyright extends beyond `copyright-limit' and won't be updated automatically."))
comment-end \n)
+;;;###autoload
(defun copyright-update-directory (directory match)
"Update copyright notice for all files in DIRECTORY matching MATCH."
- (interactive "DDirectory: \nMFilenames matching: ")
+ (interactive "DDirectory: \nMFilenames matching (regexp): ")
(dolist (file (directory-files directory t match nil))
+ (message "Updating file `%s'" file)
(find-file file)
(let ((copyright-query nil))
(copyright-update))