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. – T. Verron Oct 13 '16 at 15:17auto-compile
? Also, you should avoid compiling your init file. – Tianxiang Xiong Oct 13 '16 at 16:32init.el
, butpackages
compiles a lot of files (obviously). I sometimes get errors due to this, so I'd like to recompile those files. – GergelyPolonkai Oct 13 '16 at 16:35:)
– T. Verron Oct 13 '16 at 16:35cask
oruse-package
for packages available on the repos, andel-get
for packages which aren't (non-exhaustive list of options). – T. Verron Oct 13 '16 at 16:37use-package
. I don't feel it home ground yet, hence I still carry this burden for a while :) – GergelyPolonkai Oct 13 '16 at 16:46find
, but I think it answers your use case of keeping up-to-date.elc
files. – Dan Oct 13 '16 at 16:56byte-recompile-directory
; yet, I'm curious of an answer for the question for other use cases. – GergelyPolonkai Oct 13 '16 at 17:01byte-recompile-directory
is all you need. And yes, it is recursive. And yes, it won't compile any file that has not yet been compiled (for which there is no*.elc
). – Drew Oct 13 '16 at 20:53.elc
files are portable, unless you have added some compile-time behaviours which are system-specific. – phils Oct 14 '16 at 00:04find(1)
. And in most of those cases things like Projectile is an overkill (or doesn’t even work). – GergelyPolonkai Oct 14 '16 at 08:41