From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Stefan Monnier Newsgroups: gmane.emacs.devel Subject: Re: Adding missing copyright years Date: Sun, 08 May 2005 22:06:27 -0400 Message-ID: <8764xti2en.fsf-monnier+emacs@gnu.org> References: <85mzraqm9k.fsf@lola.goethe.zz> <17020.9976.943092.382629@farnswood.snap.net.nz> <877jibgjnc.fsf-monnier+emacs@gnu.org> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1115604023 28742 80.91.229.2 (9 May 2005 02:00:23 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 9 May 2005 02:00:23 +0000 (UTC) Cc: Andreas Schwab , nickrob@snap.net.nz, emacs-devel@gnu.org, rms@gnu.org, miles@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Mon May 09 04:00:19 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DUxZD-0004TL-CD for ged-emacs-devel@m.gmane.org; Mon, 09 May 2005 04:00:19 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DUxhR-0005xl-TH for ged-emacs-devel@m.gmane.org; Sun, 08 May 2005 22:08:49 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DUxgj-0005sk-Rg for emacs-devel@gnu.org; Sun, 08 May 2005 22:08:05 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DUxgh-0005rE-BE for emacs-devel@gnu.org; Sun, 08 May 2005 22:08:03 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DUxgh-0005r4-6G for emacs-devel@gnu.org; Sun, 08 May 2005 22:08:03 -0400 Original-Received: from [209.226.175.54] (helo=tomts10-srv.bellnexxia.net) by monty-python.gnu.org with esmtp (Exim 4.34) id 1DUxl3-0001f0-FL; Sun, 08 May 2005 22:12:33 -0400 Original-Received: from alfajor ([67.71.32.212]) by tomts10-srv.bellnexxia.net (InterMail vM.5.01.06.10 201-253-122-130-110-20040306) with ESMTP id <20050509020629.TUCF26102.tomts10-srv.bellnexxia.net@alfajor>; Sun, 8 May 2005 22:06:29 -0400 Original-Received: by alfajor (Postfix, from userid 1000) id EE7C2D72FB; Sun, 8 May 2005 22:06:27 -0400 (EDT) Original-To: snogglethorpe@gmail.com In-Reply-To: (Miles Bader's message of "Mon, 9 May 2005 10:35:08 +0900") User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux) X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:36892 X-Report-Spam: http://spam.gmane.org/gmane.emacs.devel:36892 >> > (add-hook 'before-save-hook 'copyright-update) >> >> This is not a problem since you are asked whether you want to update the >> copyright. > Indeed; I use it, and I don't think it's dangerous in the way Richard > suggested (it always leaves the final decision to the user). > However, I can see why some people would not like to use it in its > current form -- it's generally quite stupid, and often mistakenly > thinks the copyright may need updating when the current copyright line > is actually up-to-date. So it tends to ask you whether you want to > update the copyright far more often than it should (for example, it > doesn't understand wrapped copyright lines, and gets confused if there > are multiple copyrights). I haven't seen the problem with wrapped lines, but as far as multiple copyrights goes I use a the local hack below where I can specify a regexp for the copyrights that I'm willing to change (e.g. I don't want my edits to add a year to the copyright of someone else, right?). I've then set copyright-names-regexp to "Monnier\\|Free Software". This way when I edit a file with multiple copyrights, only the relevant line is checked/updated. I've only written it recently (after the feature freeze), which is why I haven't tried to install it. Stefan --- orig/lisp/emacs-lisp/copyright.el +++ mod/lisp/emacs-lisp/copyright.el @@ -54,6 +54,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