unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@iro.umontreal.ca>
Cc: Andreas Schwab <schwab@suse.de>,
	nickrob@snap.net.nz, emacs-devel@gnu.org, rms@gnu.org,
	miles@gnu.org
Subject: Re: Adding missing copyright years
Date: Sun, 08 May 2005 22:06:27 -0400	[thread overview]
Message-ID: <8764xti2en.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: <fc339e4a05050818354ca617b2@mail.gmail.com> (Miles Bader's message of "Mon, 9 May 2005 10:35:08 +0900")

>> >       (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

  reply	other threads:[~2005-05-09  2:06 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-05-04 22:04 Adding missing copyright years Richard Stallman
2005-05-05  1:28 ` Kenichi Handa
2005-05-05 19:46   ` Richard Stallman
2005-05-06 23:42     ` Kenichi Handa
2005-05-07 18:35       ` Richard Stallman
2005-05-07 19:15         ` Juanma Barranquero
2005-05-07 23:08           ` Nick Roberts
2005-05-08 16:12             ` Richard Stallman
2005-05-08 16:11           ` Richard Stallman
2005-05-08 21:16             ` Nick Roberts
2005-05-09 21:02               ` Richard Stallman
2005-05-25 22:02                 ` Bill Wohler
2005-05-26  6:00                   ` Richard Stallman
2005-05-26 17:15                     ` Bill Wohler
2005-05-16  7:12         ` Kenichi Handa
2005-05-16 21:20           ` Richard Stallman
2005-05-17  0:50             ` Kenichi Handa
2005-05-05  5:23 ` David Kastrup
2005-05-05 19:46   ` Richard Stallman
2005-05-07  2:24     ` Nick Roberts
2005-05-07  5:29       ` David Kastrup
2005-05-07  6:00         ` Nick Roberts
2005-05-07  9:59         ` Eli Zaretskii
2005-05-07 10:04       ` Eli Zaretskii
2005-05-07 15:07       ` Stefan Monnier
2005-05-07 15:57         ` Luc Teirlinck
2005-05-08  9:03         ` Richard Stallman
2005-05-08  9:22           ` Andreas Schwab
2005-05-09  1:35             ` Miles Bader
2005-05-09  2:06               ` Stefan Monnier [this message]
2005-05-10 21:42         ` Alexander Pohoyda
2005-05-15 22:39           ` Richard Stallman
2005-05-16 15:19             ` Alexander Pohoyda
2005-05-17  4:37               ` Richard Stallman
2005-05-07 18:35       ` Richard Stallman
2005-05-16 20:17     ` Glenn Morris
2005-05-17  4:36       ` Richard Stallman
2005-05-17 22:01         ` Kim F. Storm
2005-05-18  8:02           ` Juanma Barranquero
2005-05-18 17:53             ` Glenn Morris
2005-05-18 18:53               ` Juanma Barranquero
2005-05-18 13:08           ` Richard Stallman
2005-05-18 19:10             ` Thien-Thi Nguyen
2005-05-18 13:15           ` Thien-Thi Nguyen
2005-05-18 13:10       ` Thien-Thi Nguyen
2005-05-18 17:24         ` Glenn Morris
2005-05-20 21:57         ` Richard Stallman
2005-05-21  8:11           ` Thien-Thi Nguyen
2005-05-22  5:22             ` Kenichi Handa
2005-05-18 22:44       ` Richard Stallman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=8764xti2en.fsf-monnier+emacs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=emacs-devel@gnu.org \
    --cc=miles@gnu.org \
    --cc=nickrob@snap.net.nz \
    --cc=rms@gnu.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).