* Re: fix-copyright.el - Automatically update copyright in source files
[not found] <87hd84yrkt.fsf@hebus.dyndns.org>
@ 2006-01-16 18:33 ` Reiner Steib
2006-01-17 9:21 ` Benjamin Drieu
0 siblings, 1 reply; 3+ messages in thread
From: Reiner Steib @ 2006-01-16 18:33 UTC (permalink / raw)
On Mon, Jan 16 2006, Benjamin Drieu wrote:
> (defun update-copyright ()
> "Update copyright in current buffer."
What's wrong with `copyright-update'?
,----[ <f1> f copyright-update RET ]
| copyright-update is an interactive compiled Lisp function in `copyright.el'.
| (copyright-update &optional ARG INTERACTIVEP)
|
| Update copyright notice at beginning of buffer to indicate the current year.
`----
/* Copyright (C) 1999 Reiner Steib <reinersteib+from-uce@imap.cc> */
`M-x copyright-update RET' ==>
/* Copyright (C) 1999, 2006 Reiner Steib <reinersteib+from-uce@imap.cc> */
Bye, Reiner.
Crosspost & Followup-To: gnu.emacs.help
--
,,,
(o o)
---ooO-(_)-Ooo--- | PGP key available | http://rsteib.home.pages.de/
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: fix-copyright.el - Automatically update copyright in source files
2006-01-16 18:33 ` fix-copyright.el - Automatically update copyright in source files Reiner Steib
@ 2006-01-17 9:21 ` Benjamin Drieu
2006-01-18 4:15 ` Stefan Monnier
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Drieu @ 2006-01-17 9:21 UTC (permalink / raw)
Reiner Steib <reinersteib+from-uce@imap.cc> writes:
> On Mon, Jan 16 2006, Benjamin Drieu wrote:
>
>> (defun update-copyright ()
>> "Update copyright in current buffer."
>
> What's wrong with `copyright-update'?
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.
Cheers,
Benjamin
--
.''`.
; ;' ; Debian GNU/Linux | Benjamin Drieu
`. `' http://www.debian.org/ | <benj@debian.org>
`-
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: fix-copyright.el - Automatically update copyright in source files
2006-01-17 9:21 ` Benjamin Drieu
@ 2006-01-18 4:15 ` Stefan Monnier
0 siblings, 0 replies; 3+ messages in thread
From: Stefan Monnier @ 2006-01-18 4:15 UTC (permalink / raw)
> 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-01-18 4:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <87hd84yrkt.fsf@hebus.dyndns.org>
2006-01-16 18:33 ` fix-copyright.el - Automatically update copyright in source files Reiner Steib
2006-01-17 9:21 ` Benjamin Drieu
2006-01-18 4:15 ` Stefan Monnier
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).