Some copyright.el updates.
* lisp/emacs-lisp/copyright.el (copyright-find-copyright): New function, split out from copyright-update-year. (copyright-update): Don't mess with the GPL version if we don't own the copyright. Update license regexp, and remove no longer needed Esperanto stuff.
This commit is contained in:
parent
e7c1dca85c
commit
0412a5a4de
2 changed files with 112 additions and 97 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2011-01-22 Glenn Morris <rgm@gnu.org>
|
||||||
|
|
||||||
|
* emacs-lisp/copyright.el (copyright-find-copyright): New function,
|
||||||
|
split out from copyright-update-year.
|
||||||
|
(copyright-update): Don't mess with the GPL version if we don't own the
|
||||||
|
copyright. Update license regexp, and remove no longer needed
|
||||||
|
Esperanto stuff.
|
||||||
|
|
||||||
2011-01-22 Chong Yidong <cyd@stupidchicken.com>
|
2011-01-22 Chong Yidong <cyd@stupidchicken.com>
|
||||||
|
|
||||||
* vc/diff.el (diff-sentinel): Doc fix (Bug#7682).
|
* vc/diff.el (diff-sentinel): Doc fix (Bug#7682).
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
;;; copyright.el --- update the copyright notice in current buffer
|
;;; copyright.el --- update the copyright notice in current buffer
|
||||||
|
|
||||||
;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1998, 2001, 2002, 2003,
|
;; Copyright (C) 1991, 1992, 1993, 1994, 1995, 1998, 2001, 2002, 2003,
|
||||||
;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
|
;; 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
|
||||||
|
;; Free Software Foundation, Inc.
|
||||||
|
|
||||||
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
|
;; Author: Daniel Pfeiffer <occitan@esperanto.org>
|
||||||
;; Keywords: maint, tools
|
;; Keywords: maint, tools
|
||||||
|
@ -120,78 +121,83 @@ When this is `function', only ask when called non-interactively."
|
||||||
(< (point) (- (point-max) copyright-limit))
|
(< (point) (- (point-max) copyright-limit))
|
||||||
(> (point) (+ (point-min) copyright-limit)))))
|
(> (point) (+ (point-min) copyright-limit)))))
|
||||||
|
|
||||||
(defun copyright-update-year (replace noquery)
|
(defun copyright-find-copyright ()
|
||||||
(when
|
"Return non-nil if a copyright header suitable for updating is found.
|
||||||
(condition-case err
|
The header must match `copyright-regexp' and `copyright-names-regexp', if set.
|
||||||
;; (1) Need the extra \\( \\) around copyright-regexp because we
|
This function sets the match-data that `copyright-update-year' uses."
|
||||||
;; goto (match-end 1) below. See note (2) below.
|
(condition-case err
|
||||||
(copyright-re-search (concat "\\(" copyright-regexp
|
;; (1) Need the extra \\( \\) around copyright-regexp because we
|
||||||
"\\)\\([ \t]*\n\\)?.*\\(?:"
|
;; goto (match-end 1) below. See note (2) below.
|
||||||
copyright-names-regexp "\\)")
|
(copyright-re-search (concat "\\(" copyright-regexp
|
||||||
(copyright-limit)
|
"\\)\\([ \t]*\n\\)?.*\\(?:"
|
||||||
t)
|
copyright-names-regexp "\\)")
|
||||||
;; In case the regexp is rejected. This is useful because
|
(copyright-limit)
|
||||||
;; copyright-update is typically called from before-save-hook where
|
t)
|
||||||
;; such an error is very inconvenient for the user.
|
;; In case the regexp is rejected. This is useful because
|
||||||
(error (message "Can't update copyright: %s" err) nil))
|
;; copyright-update is typically called from before-save-hook where
|
||||||
(goto-char (match-end 1))
|
;; such an error is very inconvenient for the user.
|
||||||
;; If the years are continued onto multiple lines
|
(error (message "Can't update copyright: %s" err) nil)))
|
||||||
;; 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))))
|
|
||||||
(looking-at-p copyright-years-regexp)))
|
|
||||||
(forward-line 1)
|
|
||||||
(re-search-forward comment-start-skip)
|
|
||||||
;; (2) Need the extra \\( \\) so that the years are subexp 3, as
|
|
||||||
;; they are at note (1) above.
|
|
||||||
(re-search-forward (format "\\(%s\\)" copyright-years-regexp)))
|
|
||||||
|
|
||||||
;; Note that `current-time-string' isn't locale-sensitive.
|
(defun copyright-update-year (replace noquery)
|
||||||
(setq copyright-current-year (substring (current-time-string) -4))
|
;; This uses the match-data from copyright-find-copyright.
|
||||||
(unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
|
(goto-char (match-end 1))
|
||||||
(substring copyright-current-year -2))
|
;; If the years are continued onto multiple lines
|
||||||
(if (or noquery
|
;; that are marked as comments, skip to the end of the years anyway.
|
||||||
(save-window-excursion
|
(while (save-excursion
|
||||||
(switch-to-buffer (current-buffer))
|
(and (eq (following-char) ?,)
|
||||||
;; Fixes some point-moving oddness (bug#2209).
|
(progn (forward-char 1) t)
|
||||||
(save-excursion
|
(progn (skip-chars-forward " \t") (eolp))
|
||||||
(y-or-n-p (if replace
|
comment-start-skip
|
||||||
(concat "Replace copyright year(s) by "
|
(save-match-data
|
||||||
copyright-current-year "? ")
|
(forward-line 1)
|
||||||
(concat "Add " copyright-current-year
|
(and (looking-at comment-start-skip)
|
||||||
" to copyright? "))))))
|
(goto-char (match-end 0))))
|
||||||
(if replace
|
(looking-at-p copyright-years-regexp)))
|
||||||
(replace-match copyright-current-year t t nil 3)
|
(forward-line 1)
|
||||||
(let ((size (save-excursion (skip-chars-backward "0-9"))))
|
(re-search-forward comment-start-skip)
|
||||||
(if (and (eq (% (- (string-to-number copyright-current-year)
|
;; (2) Need the extra \\( \\) so that the years are subexp 3, as
|
||||||
(string-to-number (buffer-substring
|
;; they are at note (1) above.
|
||||||
(+ (point) size)
|
(re-search-forward (format "\\(%s\\)" copyright-years-regexp)))
|
||||||
(point))))
|
|
||||||
100)
|
;; Note that `current-time-string' isn't locale-sensitive.
|
||||||
1)
|
(setq copyright-current-year (substring (current-time-string) -4))
|
||||||
(or (eq (char-after (+ (point) size -1)) ?-)
|
(unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
|
||||||
(eq (char-after (+ (point) size -2)) ?-)))
|
(substring copyright-current-year -2))
|
||||||
;; This is a range so just replace the end part.
|
(if (or noquery
|
||||||
(delete-char size)
|
(save-window-excursion
|
||||||
;; Insert a comma with the preferred number of spaces.
|
(switch-to-buffer (current-buffer))
|
||||||
(insert
|
;; Fixes some point-moving oddness (bug#2209).
|
||||||
(save-excursion
|
(save-excursion
|
||||||
(if (re-search-backward "[0-9]\\( *, *\\)[0-9]"
|
(y-or-n-p (if replace
|
||||||
(line-beginning-position) t)
|
(concat "Replace copyright year(s) by "
|
||||||
(match-string 1)
|
copyright-current-year "? ")
|
||||||
", ")))
|
(concat "Add " copyright-current-year
|
||||||
;; If people use the '91 '92 '93 scheme, do that as well.
|
" to copyright? "))))))
|
||||||
(if (eq (char-after (+ (point) size -3)) ?')
|
(if replace
|
||||||
(insert ?')))
|
(replace-match copyright-current-year t t nil 3)
|
||||||
;; Finally insert the new year.
|
(let ((size (save-excursion (skip-chars-backward "0-9"))))
|
||||||
(insert (substring copyright-current-year size))))))))
|
(if (and (eq (% (- (string-to-number copyright-current-year)
|
||||||
|
(string-to-number (buffer-substring
|
||||||
|
(+ (point) size)
|
||||||
|
(point))))
|
||||||
|
100)
|
||||||
|
1)
|
||||||
|
(or (eq (char-after (+ (point) size -1)) ?-)
|
||||||
|
(eq (char-after (+ (point) size -2)) ?-)))
|
||||||
|
;; This is a range so just replace the end part.
|
||||||
|
(delete-char size)
|
||||||
|
;; Insert a comma with the preferred number of spaces.
|
||||||
|
(insert
|
||||||
|
(save-excursion
|
||||||
|
(if (re-search-backward "[0-9]\\( *, *\\)[0-9]"
|
||||||
|
(line-beginning-position) t)
|
||||||
|
(match-string 1)
|
||||||
|
", ")))
|
||||||
|
;; If people use the '91 '92 '93 scheme, do that as well.
|
||||||
|
(if (eq (char-after (+ (point) size -3)) ?')
|
||||||
|
(insert ?')))
|
||||||
|
;; Finally insert the new year.
|
||||||
|
(insert (substring copyright-current-year size)))))))
|
||||||
|
|
||||||
;;;###autoload
|
;;;###autoload
|
||||||
(defun copyright-update (&optional arg interactivep)
|
(defun copyright-update (&optional arg interactivep)
|
||||||
|
@ -210,31 +216,32 @@ interactively."
|
||||||
(save-restriction
|
(save-restriction
|
||||||
(widen)
|
(widen)
|
||||||
(goto-char (copyright-start-point))
|
(goto-char (copyright-start-point))
|
||||||
(copyright-update-year arg noquery)
|
;; If names-regexp doesn't match, we should not mess with
|
||||||
(goto-char (copyright-start-point))
|
;; the years _or_ the GPL version.
|
||||||
(and copyright-current-gpl-version
|
(when (copyright-find-copyright)
|
||||||
;; match the GPL version comment in .el files, including the
|
(copyright-update-year arg noquery)
|
||||||
;; bilingual Esperanto one in two-column, and in texinfo.tex
|
(goto-char (copyright-start-point))
|
||||||
(copyright-re-search
|
(and copyright-current-gpl-version
|
||||||
"\\(the Free Software Foundation;\
|
;; Match the GPL version comment in .el files.
|
||||||
either \\|; a\\^u eldono \\([0-9]+\\)a, ? a\\^u (la\\^u via \\)\
|
;; This is sensitive to line-breaks. :(
|
||||||
version \\([0-9]+\\), or (at"
|
(copyright-re-search
|
||||||
(copyright-limit) t)
|
"the Free Software Foundation[,;\n].*either version \
|
||||||
;; Don't update if the file is already using a more recent
|
\\([0-9]+\\)\\(?: of the License\\)?, or[ \n].*any later version"
|
||||||
;; version than the "current" one.
|
(copyright-limit) t)
|
||||||
(< (string-to-number (match-string 3))
|
;; Don't update if the file is already using a more recent
|
||||||
(string-to-number copyright-current-gpl-version))
|
;; version than the "current" one.
|
||||||
(or noquery
|
(< (string-to-number (match-string 1))
|
||||||
(save-match-data
|
(string-to-number copyright-current-gpl-version))
|
||||||
(save-window-excursion
|
(or noquery
|
||||||
(switch-to-buffer (current-buffer))
|
(save-match-data
|
||||||
(y-or-n-p (format "Replace GPL version by %s? "
|
(goto-char (match-end 1))
|
||||||
copyright-current-gpl-version)))))
|
(save-window-excursion
|
||||||
(progn
|
(switch-to-buffer (current-buffer))
|
||||||
(if (match-end 2)
|
(y-or-n-p
|
||||||
;; Esperanto bilingual comment in two-column.el
|
(format "Replace GPL version %s with version %s? "
|
||||||
(replace-match copyright-current-gpl-version t t nil 2))
|
(match-string-no-properties 1)
|
||||||
(replace-match copyright-current-gpl-version t t nil 3))))
|
copyright-current-gpl-version)))))
|
||||||
|
(replace-match copyright-current-gpl-version t t nil 1))))
|
||||||
(set (make-local-variable 'copyright-update) nil)))
|
(set (make-local-variable 'copyright-update) nil)))
|
||||||
;; If a write-file-hook returns non-nil, the file is presumed to be written.
|
;; If a write-file-hook returns non-nil, the file is presumed to be written.
|
||||||
nil))
|
nil))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue