07
Dec
You should byte-compile XYZ
Sure, without much trouble using jhg-cload.el and the following snippet to make compiling a bit smarter: store the .elc in ~/.elc and avoid recompiling, especially if there were errors before. Normally there is no sense to try it again and again:
(require ‘jhg-cload)
(setq load-path (cons "~/.elc" load-path))
(defun jhg-cload-compile (file)
"Compile FILE if it is ok and out of date."
(let* ((file-name (locate-library file))
(path-base (file-name-sans-extension file-name))
(path-el (concat path-base ".el"))
(path-elc-before (concat path-base ".elc"))
(path-elc (concat "~/.elc/"
(file-name-sans-extension
(file-name-nondirectory file-name))
".elc"))
(path-elc-error (concat path-elc "-error")))
(if (and (jhg-cload-oktocompile-p path-base)
(not (file-exists-p path-elc-error)))
(if (file-newer-than-file-p path-el path-elc)
(progn
;; remove the old file — viano and linux disagree over gids
(condition-case nil (make-directory elc-dir) (error nil))
(condition-case nil (delete-file path-elc) (error nil))
(condition-case nil (delete-file path-elc-before) (error nil))
;; set about compiling it
(jhg-cload-msg 1 "cload: compiling ‘%s’…" path-el)
(save-excursion (write-region (point-min) (point-min) path-elc-error))
(byte-compile-file path-el)
(when (file-exists-p path-elc-before)
(rename-file path-elc-before path-elc)
(delete-file path-elc-error)
(jhg-cload-msg 2 "cload: ok ‘%s’" file)))
(jhg-cload-msg 2 "cload: skipping ‘%s’…" file)))))
(setq load-path (cons "~/.elc" load-path))
(defun jhg-cload-compile (file)
"Compile FILE if it is ok and out of date."
(let* ((file-name (locate-library file))
(path-base (file-name-sans-extension file-name))
(path-el (concat path-base ".el"))
(path-elc-before (concat path-base ".elc"))
(path-elc (concat "~/.elc/"
(file-name-sans-extension
(file-name-nondirectory file-name))
".elc"))
(path-elc-error (concat path-elc "-error")))
(if (and (jhg-cload-oktocompile-p path-base)
(not (file-exists-p path-elc-error)))
(if (file-newer-than-file-p path-el path-elc)
(progn
;; remove the old file — viano and linux disagree over gids
(condition-case nil (make-directory elc-dir) (error nil))
(condition-case nil (delete-file path-elc) (error nil))
(condition-case nil (delete-file path-elc-before) (error nil))
;; set about compiling it
(jhg-cload-msg 1 "cload: compiling ‘%s’…" path-el)
(save-excursion (write-region (point-min) (point-min) path-elc-error))
(byte-compile-file path-el)
(when (file-exists-p path-elc-before)
(rename-file path-elc-before path-elc)
(delete-file path-elc-error)
(jhg-cload-msg 2 "cload: ok ‘%s’" file)))
(jhg-cload-msg 2 "cload: skipping ‘%s’…" file)))))

