Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Byte-Compiling org-mode files #16

Closed
mattfidler opened this issue Dec 14, 2011 · 2 comments
Closed

Byte-Compiling org-mode files #16

mattfidler opened this issue Dec 14, 2011 · 2 comments

Comments

@mattfidler
Copy link

Eric,

To speed a stable load up, a byte-compile of org-files may be generally useful. I have it in my fork.

(defun starter-kit-load-org (file)
  "Loads Emacs Lisp source code blocks like `org-babel-load-file'.  However, byte-compiles the files as well as tangles them..."
  (flet ((age (file)
              (float-time
               (time-subtract (current-time)
                              (nth 5 (or (file-attributes (file-truename file))
                                         (file-attributes file)))))))
    (let* ((base-name (file-name-sans-extension file))
           (exported-file (concat base-name ".el"))
           (compiled-file (concat base-name ".elc")))
      (unless (and (file-exists-p exported-file)
                   (> (age file) (age exported-file)))
    (message "Trying to Tangle %s" file)
        (condition-case err
        (progn
          (org-babel-tangle-file file exported-file "emacs-lisp")
              (starter-kit-m (format "Tangled %s to %s"
                                      file exported-file)))
          (error (message "Error Tangling %s" file))))
      (when (file-exists-p exported-file)
        (if (and (file-exists-p compiled-file)
                 (> (age exported-file) (age compiled-file)))
            (progn
              (load-file compiled-file)
              (starter-kit-m (format "Loaded %s" compiled-file)))
          (byte-compile-file exported-file t)
          (starter-kit-m (format "Byte-compiled & loaded %s" exported-file))
          ;; Fallback and load source
          (if (file-exists-p compiled-file)
              (set-file-times compiled-file) ; Touch file.
            (load-file exported-file)
            (starter-kit-m (format "Loaded %s since byte-compile failed."
                                   exported-file))))))))
@eschulte
Copy link
Owner

Hi,

Thanks for sharing this function, but I wonder how you use it. Do you call this by hand, or have to replaced starter-kit-load with this function in your fork of the starter kit.

Note that using the current starter kit simply running make in the base of the starter kit directory will byte-compile the starter kit files. I prefer this make-based solution, as it requires a conscious decision to byte-compile the files, and it is external from the Emacs startup process so no extra steps/complexity are added to the booting of Emacs.

@mattfidler
Copy link
Author

You replace org-babel-load with this function.

I prefer this solution since I'm on a most often windows machine.

Also you may wish to use yas/jit to speed up yasnippet load time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants