[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: fix-copyright.el - Automatically update copyright in source files
From: |
Stefan Monnier |
Subject: |
Re: fix-copyright.el - Automatically update copyright in source files |
Date: |
Tue, 17 Jan 2006 23:15:56 -0500 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) |
> Problem is that it will replace first occurence, regardless it is your
> copyright entry or copyright entry for another developer. As I'm
> working on projects with multiple authors, I needed to use
> user-full-name stuff to update my entries only.
> Perhaps patching copyright.el would be more useful but when I wrote
> this I had no time to do so.
I'm using the patch below for that precise reason (I've set
copyright-names-regexp to "Monnier\\|Free Software"). I hope to include
this patch in some future version of copyright.el (probably for Emacs-23
only, tho :-( ).
Stefan
--- orig/lisp/emacs-lisp/copyright.el
+++ mod/lisp/emacs-lisp/copyright.el
@@ -49,6 +49,13 @@
:group 'copyright
:type 'regexp)
+(defcustom copyright-names-regexp ""
+ "Regexp matching the names which correspond to the user.
+Only copyright lines where the name matches this regexp will be updated.
+This allows you to avoid adding yars to a copyright notice belonging to
+someone else or to a group for which you do not work."
+ :type 'regexp)
+
(defcustom copyright-years-regexp
"\\(\\s *\\)\\([1-9]\\([-0-9, ';/*%#\n\t]\\|\\s<\\|\\s>\\)*[0-9]+\\)"
"*Match additional copyright notice years.
@@ -83,7 +90,17 @@
"String representing the current year.")
(defun copyright-update-year (replace noquery)
- (when (re-search-forward copyright-regexp (+ (point) copyright-limit) t)
+ (when
+ (condition-case err
+ (re-search-forward (concat "\\(" copyright-regexp
+ "\\)\\([ \t]*\n\\)?.*\\(?:"
+ copyright-names-regexp "\\)")
+ (+ (point) copyright-limit) t)
+ ;; In case the regexp is rejected. This is useful because
+ ;; copyright-update is typically called from before-save-hook where
+ ;; such an error is very inconvenient for the user.
+ (error (message "Can't update copyright: %s" err) nil))
+ (goto-char (match-end 1))
;; If the years are continued onto multiple lined
;; that are marked as comments, skip to the end of the years anyway.
(while (save-excursion
@@ -94,7 +111,7 @@
(save-match-data
(forward-line 1)
(and (looking-at comment-start-skip)
- (goto-char (match-end 0))))
+ (goto-char (match-end 1))))
(save-match-data
(looking-at copyright-years-regexp))))
(forward-line 1)
@@ -103,7 +120,7 @@
;; 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))
+ (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