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

Re: copyright vs. license

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.

;; When we save a file with a GPL copyright, prompt to suggest
;; modifying the notice to contain the most recent GPL version and
;; include the current year.
(defconst current-year (substring (current-time-string) -4)
  "String representing the current year.")
(defvar current-gpl-version "2"
  "String representing the current version of the GPL.")
(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))
	      "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+"
	      limit t))
	   (progn (forward-word -1)
		  (not (looking-at current-year)))
	   (progn (goto-char (point-min))
		  (sit-for 0)
		  (y-or-n-p "Update copyright? "))
	   (let ((replace (y-or-n-p "Replace year? ")))
	     (or (re-search-forward
		  "[Cc]opyright[^0-9]*\\(\\([-, \t]*\\([0-9]+\\)\\)\\)+"
		  nil t)
		 (error "This buffer contains no copyright notice!"))
	     (if replace
		 (delete-region (match-beginning 1) (match-end 1))
	       (insert ", "))
	     (insert current-year)
	     (message "Copyright updated to %s%s."
		      (if replace "" "include ") 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))

Reply to: