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

Re: copyright vs. license

On Thursday 13 January 2005 11:18 am, Thomas Bushnell BSG wrote:
> Ben Pfaff <blp@cs.stanford.edu> writes:
> > Thomas Bushnell BSG <tb@becket.net> writes:
> >
> > [updating copyright years]
> >
> > > I have a handy-dandy emacs lisp frob that will do this automagically
> > > for you if you like.
> >
> > I would like this.

  Slight modification that works more conveniently for me (this is the only
significant chunk of elisp I've tried to write, so may be buggy; it worked
in tests, though):

======= cut here =======
(defconst current-year (substring (current-time-string) -4)
  "String representing the current year.")
(defconst last-year (int-to-string (- (string-to-int current-year) 1))
  "String representing the current year (presuming that the current year is not 1 AD, which hopefully will continue to be the case indefinitely).")
(defvar current-gpl-version "2"
  "String representing the current version of the GPL.")
(defvar copyright-regex "[Cc]opyright\\s *\\(([Cc])\\)?\\(\\s *[0-9]+\\s *\\(-\\s *[0-9]+\\s *\\)?,\\s *\\)*\\s *\\(\\([0-9]+\\)\\s *-\\)?\\s *\\([0-9]+\\)"
  "Regular expression to match common copyright declarations, extracting the final year(s).")
;; Note: paren expr. #5 is the first year of the last dashed pair, if
;; any; paren expr. #6 is the last year.

(defun update-copyright-with-queries ()
  "My version of update-copyright."
      (goto-char (point-min))
      (and (re-search-forward "[i]s free software"
                              nil t)
           (not (eq major-mode 'rmail-mode))
           (let ((limit (point)))
             (goto-char (point-min))
             (re-search-forward copyright-regex
              limit t))
    (let ((final-year (match-string 6))
   (final-range-start (match-string 5)))
      (when (and (not (string= final-year current-year))
   (progn (goto-char (point-min))
          (sit-for 0)
          (y-or-n-p (format "Update copyright (last %s)? " final-year))))
        (if (string= final-year last-year)
     (if final-range-start
    (goto-char (match-end 6))
    (delete-region (match-beginning 6) (match-end 6))
    (insert current-year))
         (goto-char (match-end 6))
         (insert "-")
         (insert current-year)))
     (goto-char (match-end 6))
     (insert ", ")
     (insert current-year))) t))
    (message "Copyright updated to include %s." current-year)
    (if (re-search-forward 
  "; either version \\(.+\\), or (at your option)"
  nil t)
   (goto-char (match-beginning 1))
   (delete-region (point) (match-end 1))
   (insert current-gpl-version)))))))

(setq write-file-hooks (cons 'update-copyright-with-queries write-file-hooks))
====== cut here ========


/------------------- Daniel Burrows <dburrows@debian.org> ------------------\
|           Whom the gods would destroy, they first teach BASIC.            |
\--- News without the $$ -- National Public Radio -- http://www.npr.org ---/

Attachment: pgpQXp1_XIk6j.pgp
Description: PGP signature

Reply to: