Function: copyright-fix-years
copyright-fix-years is an autoloaded, interactive and byte-compiled
function defined in copyright.el.gz.
Signature
(copyright-fix-years)
Documentation
Convert 2 digit years to 4 digit years.
Uses heuristic: year >= 50 means 19xx, < 50 means 20xx.
If copyright-year-ranges (which see) is non-nil, also
independently replaces consecutive years with a range.
Probably introduced at or before Emacs version 24.1.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/emacs-lisp/copyright.el.gz
;; FIXME heuristic should be within 50 years of present (cf calendar).
;;;###autoload
(defun copyright-fix-years ()
"Convert 2 digit years to 4 digit years.
Uses heuristic: year >= 50 means 19xx, < 50 means 20xx.
If `copyright-year-ranges' (which see) is non-nil, also
independently replaces consecutive years with a range."
(interactive)
;; TODO there may be multiple copyrights we should fix.
(if (copyright-find-copyright)
(let ((s (match-beginning 3))
(p (make-marker))
;; Not line-beg-pos, so we don't mess up leading whitespace.
(copystart (match-beginning 0))
e last sep year prev-year first-year range-start range-end)
;; In case years are continued over multiple, commented lines.
(goto-char (match-end 1))
(copyright-find-end)
(setq e (copy-marker (1+ (match-end 3))))
(goto-char s)
(while (re-search-forward "[0-9]+" e t)
(set-marker p (point))
(goto-char (match-beginning 0))
(setq year (string-to-number (match-string 0)))
(and (setq sep (char-before))
(/= (char-syntax sep) ?\s)
(not (memq sep '(?- ?–)))
(insert " "))
(when (< year 100)
(insert (if (>= year 50) "19" "20"))
(setq year (+ year (if (>= year 50) 1900 2000))))
(goto-char p)
(when copyright-year-ranges
;; If the previous thing was a range, don't try to tack more on.
;; Ie not 2000-2005 -> 2000-2005-2007
;; TODO should merge into existing range if possible.
(if (memq sep '(?- ?–))
(setq prev-year nil
year nil)
(if (and prev-year (= year (1+ prev-year)))
(setq range-end (point))
(when (and first-year prev-year
(> prev-year first-year))
(goto-char range-end)
(delete-region range-start range-end)
(insert (format "-%d" prev-year))
(goto-char p))
(setq first-year year
range-start (point)))))
(setq prev-year year
last p))
(when last
(when (and copyright-year-ranges
first-year prev-year
(> prev-year first-year))
(goto-char range-end)
(delete-region range-start range-end)
(insert (format "-%d" prev-year)))
(goto-char last)
;; Don't mess up whitespace after the years.
(skip-chars-backward " \t")
(save-restriction
(narrow-to-region copystart (point))
;; This is clearly wrong, eg what about comment markers?
;;; (let ((fill-prefix " "))
;; TODO do not break copyright owner over lines.
(fill-region (point-min) (point-max))))
(set-marker e nil)
(set-marker p nil))
;; Simply reformatting the years is not copyrightable, so it does
;; not seem right to call this. Also it messes with ranges.
;;; (copyright-update nil t))
(message "No copyright message")))