+(defmacro lm-with-file (file &rest body)
+ "Make a buffer with FILE current, and execute BODY.
+If FILE isn't in a buffer, load it in, and kill it after BODY is executed."
+ (let ((filesym (make-symbol "file")))
+ `(save-excursion
+ (let ((,filesym ,file))
+ (if ,filesym (set-buffer (find-file-noselect ,filesym)))
+ (prog1 (progn ,@body)
+ (if (and ,filesym (not (get-buffer-window (current-buffer) t)))
+ (kill-buffer (current-buffer))))))))
+(put 'lm-with-file 'lisp-indent-function 1)
+(put 'lm-with-file 'edebug-form-spec t)
+
+;; Fixme: Probably this should be amalgamated with copyright.el; also
+;; we need a check for ranges in copyright years.
+
+(defun lm-crack-copyright (&optional file)
+ "Return the copyright holder, and a list of copyright years.
+Use the current buffer if FILE is nil.
+Return argument is of the form (\"HOLDER\" \"YEAR1\" ... \"YEARN\")"
+ (lm-with-file file
+ (goto-char (lm-copyright-mark))
+ (let ((holder nil)
+ (years nil)
+ (start (point))
+ (end (line-end-position)))
+ ;; Cope with multi-line copyright `lines'. Assume the second
+ ;; line is indented (with the same commenting style).
+ (save-excursion
+ (beginning-of-line 2)
+ (let ((str (concat (match-string-no-properties 1) "[ \t]+")))
+ (beginning-of-line)
+ (while (looking-at str)
+ (setq end (line-end-position))
+ (beginning-of-line 2))))
+ ;; Make a single line and parse that.
+ (let ((buff (current-buffer)))
+ (with-temp-buffer
+ (insert-buffer-substring buff start end)
+ (goto-char (point-min))
+ (while (re-search-forward "^;+[ \t]+" nil t)
+ (replace-match ""))
+ (goto-char (point-min))
+ (while (re-search-forward " *\n" nil t)
+ (replace-match " "))
+ (goto-char (point-min))
+ (while (re-search-forward "\\([0-9]+\\),? +" nil t)
+ (setq years (cons (match-string-no-properties 1) years)))
+ (if (looking-at ".*$")
+ (setq holder (match-string-no-properties 0)))))
+ (cons holder (nreverse years)))))
+