As I move all my emacs.d between my machines using Git, and, obviously, I don’t version control byte-compiled files (*.elc), I sometimes get into a situation when my .el files are newer then the corresponding .elc files.

Right now I construct a find(1) command using find-cmd, to find all .elc files, check if they are older then their .el counterpart, and byte-compile them if so.

(defun recompile-stale-elcs ()

    (setq-local default-directory user-emacs-directory)

    (let ((find-command (find-cmd '(prune (name ".git"))
                                  '(name "*.elc"))))

      (shell-command find-command t t))

    (goto-char (point-min))
    (setq more-lines t)

    (while more-lines
      (let ((start (progn (beginning-of-line)
            (end (progn (end-of-line)
        (let ((el (buffer-substring start (- end 1)))
              (elc (buffer-substring start end)))

          (if (file-newer-than-file-p el elc)
              (byte-compile-file (buffer-substring start (- end 1))))))
      (setq more-lines (= 0 (forward-line 1))))))

Is there a way to change that find-cmd call to pure Elisp?

Of course, if there is any other solution for the base problem, I’m open to hear that (probably in comment/chat.)

(Also, I was in doubt when selecting tags for this question. Please add some more relevant ones if such exist.)

  • 1
    byte-recompile-directory may save you some trouble.
    – T. Verron
    Oct 13, 2016 at 15:17
  • Am i right to assume it is recursive? The problem usually comes up with ELPA/MELPA packages, of which all has a separate directory. Oct 13, 2016 at 15:27
  • The doc says that it is.
    – T. Verron
    Oct 13, 2016 at 15:51
  • @T.Verron The docstring says subdirectories are processed but does not say explicitely this applies recursively. Looking at the code, it seems it does, though.
    – JeanPierre
    Oct 13, 2016 at 15:51
  • 2
    Can I avoid outdated byte-compiled elisp files? doesn't answer the specific question about an elisp equivalent of find, but I think it answers your use case of keeping up-to-date .elc files.
    – Dan
    Oct 13, 2016 at 16:56


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.