1

Is there a way to tell if the current *.elc files were not compiled with the current Emacs?

I am trying to detect an error where emacs is updated, but old .elc files are left in the user elpa directory and they are not compatible.

John Kitchin
  • 11,891
  • 1
  • 20
  • 42

1 Answers1

1

Based on the hint from @Drew about the file header, this seems to work:

(defun elc-consistent-p (elc)
  "Return non-nil if ELC is consistent with current Emacs.
ELC is the path to a .elc file.
That means it was compiled with the same emacs major and minor
version as the current emacs."
  (string= (with-temp-buffer
         (insert-file-contents elc)
         (goto-char (point-min))
         (re-search-forward ";;; in Emacs version \\([0-9]\\{2\\}\\.[0-9]+\\)"
                nil t)
         (match-string 1))
       (format "%s.%s" emacs-major-version emacs-minor-version)))
John Kitchin
  • 11,891
  • 1
  • 20
  • 42