Function: copyright-update-year

copyright-update-year is a byte-compiled function defined in copyright.el.gz.

Signature

(copyright-update-year REPLACE NOQUERY)

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/copyright.el.gz
(defun copyright-update-year (replace noquery)
  ;; This uses the match-data from copyright-find-copyright/end.
  (goto-char (match-end 1))
  (copyright-find-end)
  (setq copyright-current-year (format-time-string "%Y"))
  (unless (string= (buffer-substring (- (match-end 3) 2) (match-end 3))
		   (substring copyright-current-year -2))
    (if (or noquery
	    (save-window-excursion
              ;; switch-to-buffer might move point when
              ;; switch-to-buffer-preserve-window-point is non-nil.
	      (save-excursion
                (switch-to-buffer (current-buffer))
		(y-or-n-p (if replace
			      (concat "Replace copyright year(s) by "
				      copyright-current-year "? ")
			    (concat "Add " copyright-current-year
				    " to copyright? "))))))
	(if replace
	    (replace-match copyright-current-year t t nil 3)
	  (let ((size (save-excursion (skip-chars-backward "0-9"))))
	    (if (and (eq (% (- (string-to-number copyright-current-year)
			       (string-to-number (buffer-substring
						  (+ (point) size)
						  (point))))
			    100)
			 1)
		     (or (memq (char-after (+ (point) size -1)) '(?- ?–))
			 (memq (char-after (+ (point) size -2)) '(?- ?–))))
		;; This is a range so just replace the end part.
		(delete-char size)
	      ;; Insert a comma with the preferred number of spaces.
	      (insert
	       (save-excursion
		 (if (re-search-backward "[0-9]\\( *, *\\)[0-9]"
					 (line-beginning-position) t)
		     (match-string 1)
		   ", ")))
	      ;; If people use the '91 '92 '93 scheme, do that as well.
	      (if (eq (char-after (+ (point) size -3)) ?')
		  (insert ?')))
	    ;; Finally insert the new year.
	    (insert (substring copyright-current-year size)))))))