Re: copyright notice format



On Mon, 2002-12-09 at 07:41, Alan Cox wrote:
> > > (C) <first-year-code-was-published> <author>.
> 
> USSA law is not everywhere law. Unifying 1997.1998.1999 to 1997-1999 is fine.
> 
> > >change the strings every year which is very annoying because it produces
> > >new strings for the translators. Additionally, I think in this case the
> 
> Perl one liner challenge  8)


See attached (X)emacs lisp code to update copyright info when saving a
file.  Not quite one line, but still... might be useful.

I seem to have hacked this from somewhere, because there used to be some
code to update the gpl copyright info if needed.  Perhaps someone will
recognize this and provide a link to the real stuff.

Regards,
Carl

;;--------------------------------------------------------------------------
;; Update Copyright automatically

(defvar copyright-regexp
  "[Cc]opyright *([Cc]) *\\([1-9][-0-9, ']*[0-9]+\\).*"
  "*What your copyright notice looks like.
Must contain \\( \\) construct matching the years.")

(defvar copyright-limit 2000
  "*Don't try to update copyright beyond this position unless interactive.
`nil' means to search whole buffer.")

(defvar copyright-query nil
  "*If non-`nil', ask user before changing copyright.
When this is `function', only ask when called non-interactively.")

(defconst copyright-current-year (substring (current-time-string) -4)
  "String representing the current year.")

(defvar copyright-company-string "<YOUR_ORG_HERE>"
  "*What your company/organization name is.")

(defvar copyright-update t)

(defun cn-update-copyright (&optional arg)
  "My crack at updating copyright info.  If optional prefix ARG is given 
replace the years in the notice rather than adding the current year after 
them."
  (interactive "*P")
  (if copyright-update
      (save-excursion
		(goto-char (point-min))
		(if (re-search-forward copyright-regexp copyright-limit t)
			(if (string= (buffer-substring (- (match-end 1) 2) (match-end 1))
						 (substring copyright-current-year -2))
				(replace-match (concat "Copyright (c) \\1    " 
									   copyright-company-string))
			  (if (or (not copyright-query)
					  (and (eq copyright-query 'function)
						   (eq this-command 'copyright-update))
					  (y-or-n-p (if arg
									(concat "Replace copyright year(s) by "
											copyright-current-year "? ")
								  (concat "Add " copyright-current-year
										  " to copyright? ")))) 
				  (if arg
					  (replace-match (concat "Copyright (c) " 
											 copyright-current-year
											 "    " copyright-company-string))
					(replace-match (concat "Copyright (c) \\1, " 
										   copyright-current-year
										   "    " copyright-company-string)))))))))

(add-hook 'write-file-hooks 'cn-update-copyright)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]