07 Dec

You should byte-compile XYZ

Thursday December 07th 2006, 11:24 pm
Tags: , ,

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)))))
These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • Reddit

No Comments »

No comments yet.

 

RSS feed for comments on this post. TrackBack Website

Leave a comment

(required)

(required)

Line and paragraph breaks automatic, e-mail address never displayed, HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>