X-Git-Url: https://code.delx.au/gnu-emacs/blobdiff_plain/bcbc6fd3d04dbbbba44e98b1a434e6e892059405..d15a6f0af2b45eccda1c67470a842686fb12c4c6:/lisp/emacs-lisp/copyright.el diff --git a/lisp/emacs-lisp/copyright.el b/lisp/emacs-lisp/copyright.el index 8d748291c0..5f5aecea97 100644 --- a/lisp/emacs-lisp/copyright.el +++ b/lisp/emacs-lisp/copyright.el @@ -1,7 +1,7 @@ ;;; 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, 2007 Free Software Foundation, Inc. ;; Author: Daniel Pfeiffer ;; Keywords: maint, tools @@ -20,8 +20,8 @@ ;; 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: @@ -48,12 +48,19 @@ A value of nil means to search whole buffer." (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 *\\([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 :type 'regexp) +(defcustom copyright-years-regexp + "\\(\\s *\\)\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)" + "*Match additional copyright notice years. +The second \\( \\) construct must match the years." + :group 'copyright + :type 'regexp) + (defcustom copyright-query 'function "*If non-nil, ask user before changing copyright. @@ -77,6 +84,23 @@ When this is `function', only ask when called non-interactively." (defun copyright-update-year (replace noquery) (when (re-search-forward copyright-regexp (+ (point) copyright-limit) t) + ;; If the years are continued onto multiple lined + ;; that are marked as comments, skip to the end of the years anyway. + (while (save-excursion + (and (eq (following-char) ?,) + (progn (forward-char 1) t) + (progn (skip-chars-forward " \t") (eolp)) + comment-start-skip + (save-match-data + (forward-line 1) + (and (looking-at comment-start-skip) + (goto-char (match-end 0)))) + (save-match-data + (looking-at copyright-years-regexp)))) + (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)) @@ -88,7 +112,7 @@ When this is `function', only ask when called non-interactively." (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 @@ -100,26 +124,6 @@ When this is `function', only ask when called non-interactively." (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 @@ -173,6 +177,45 @@ version \\([0-9]+\\), or (at" 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."