|
@@ -179,6 +179,33 @@ Stars are put in group 1 and the trimmed body in group 2.")
|
|
|
(intern (concat "org-babel-expand-body:" lang)))))))
|
|
|
org-babel-load-languages))
|
|
|
|
|
|
+;;;###autoload
|
|
|
+(defun org-babel-load-file (file &optional compile)
|
|
|
+ "Load Emacs Lisp source code blocks in the Org-mode FILE.
|
|
|
+This function exports the source code using `org-babel-tangle'
|
|
|
+and then loads the resulting file using `load-file'. With prefix
|
|
|
+arg (noninteractively: 2nd arg) COMPILE the tangled Emacs Lisp
|
|
|
+file to byte-code before it is loaded."
|
|
|
+ (interactive "fFile to load: \nP")
|
|
|
+ (require 'ob-core)
|
|
|
+ (let* ((age (lambda (file)
|
|
|
+ (float-time
|
|
|
+ (time-subtract (current-time)
|
|
|
+ (nth 5 (or (file-attributes (file-truename file))
|
|
|
+ (file-attributes file)))))))
|
|
|
+ (base-name (file-name-sans-extension file))
|
|
|
+ (exported-file (concat base-name ".el")))
|
|
|
+ ;; tangle if the org-mode file is newer than the elisp file
|
|
|
+ (unless (and (file-exists-p exported-file)
|
|
|
+ (> (funcall age file) (funcall age exported-file)))
|
|
|
+ (org-babel-tangle-file file exported-file "emacs-lisp"))
|
|
|
+ (message "%s %s"
|
|
|
+ (if compile
|
|
|
+ (progn (byte-compile-file exported-file 'load)
|
|
|
+ "Compiled and loaded")
|
|
|
+ (progn (load-file exported-file) "Loaded"))
|
|
|
+ exported-file)))
|
|
|
+
|
|
|
(defcustom org-babel-load-languages '((emacs-lisp . t))
|
|
|
"Languages which can be evaluated in Org-mode buffers.
|
|
|
This list can be used to load support for any of the languages
|