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 ()
(interactive)
(with-temp-buffer
(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)
(point)))
(end (progn (end-of-line)
(point))))
(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.)
byte-recompile-directory
may save you some trouble.find
, but I think it answers your use case of keeping up-to-date.elc
files.