Function: org-babel-load-file
org-babel-load-file is an autoloaded, interactive and byte-compiled
function defined in org.el.gz.
Signature
(org-babel-load-file FILE &optional COMPILE)
Documentation
Load Emacs Lisp source code blocks in the Org FILE.
This function exports the source code using org-babel-tangle
and then loads the resulting file using load-file. With
optional prefix argument COMPILE, the tangled Emacs Lisp file is
byte-compiled before it is loaded.
Key Bindings
Source Code
;; Defined in /usr/src/emacs/lisp/org/org.el.gz
;;;###autoload
(defun org-babel-load-file (file &optional compile)
"Load Emacs Lisp source code blocks in the Org FILE.
This function exports the source code using `org-babel-tangle'
and then loads the resulting file using `load-file'. With
optional prefix argument COMPILE, the tangled Emacs Lisp file is
byte-compiled before it is loaded."
(interactive "fFile to load: \nP")
(let ((tangled-file (concat (file-name-sans-extension file) ".el")))
;; Tangle only if the Elisp file is older than the Org file.
;; Catch the case when the .el file exists while the .org file is missing.
(unless (file-exists-p file)
(error "File to tangle does not exist: %s" file))
(when (file-newer-than-file-p file tangled-file)
(org-babel-tangle-file file
tangled-file
(rx string-start
(or "emacs-lisp" "elisp")
string-end))
;; Make sure that tangled file modification time is
;; updated even when `org-babel-tangle-file' does not make changes.
;; This avoids re-tangling changed FILE where the changes did
;; not affect the tangled code.
(when (file-exists-p tangled-file)
(set-file-times tangled-file)))
(if compile
(progn
(byte-compile-file tangled-file)
(load-file (byte-compile-dest-file tangled-file))
(message "Compiled and loaded %s" tangled-file))
(load-file tangled-file)
(message "Loaded %s" tangled-file))))