branch: elpa/org-auto-tangle
commit b4e7abc019179df473ecddf0af80561ddad8fc58
Merge: 56e7afc35e4 e6ebda99dae
Author: knottedbrain <[email protected]>
Commit: GitHub <[email protected]>
Merge pull request #29 from llcc/master
Add support for loading files in async tangle process
---
README.org | 10 ++++++++++
org-auto-tangle.el | 23 ++++++++++++++++++++++-
2 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/README.org b/README.org
index 41b80c13d52..9a4f77f9640 100644
--- a/README.org
+++ b/README.org
@@ -60,6 +60,16 @@ line without removing any ~vars~ list.
#+auto_tangle: vars:load-path nil
#+end_src
+Each listed file in =org-auto-tangle-with-files= will be loaded inside the
asynchronous
+Emacs process *before* tangling begins. This is useful for setting up
additional
+libraries, paths, or environment variables.
+
+#+begin_src emacs-lisp
+(setq org-auto-tangle-with-files
+ '("~/.emacs.d/my-env.el"
+ "~/.emacs.d/project-hooks.el"))
+#+end_src
+
* Babel Auto Tangle Safelist
Add a list of files to the safelist to autotangle with noweb evaluation
#+begin_src emacs-lisp
diff --git a/org-auto-tangle.el b/org-auto-tangle.el
index ae5e9b5e0a2..c0db04fc0cc 100644
--- a/org-auto-tangle.el
+++ b/org-auto-tangle.el
@@ -111,6 +111,19 @@ DEFAULT.")
:tag "Org Auto Tangle"
:group 'org-babel)
+(defcustom org-auto-tangle-with-files nil
+ "Lisp files to be loaded in the async tangling process.
+
+Can be a string (a single file path) or a list of file paths.
+Each file will be `load-file`'d in the asynchronous subprocess
+before tangling starts. Useful for loading custom libraries or
+initializing environment variables."
+ :group 'org-auto-tangle
+ :type '(choice
+ (const :tag "None" nil)
+ (file :tag "Single file")
+ (repeat (file :tag "Multiple files"))))
+
(defcustom org-auto-tangle-with-vars nil
"Non-nil means pass VARS variables to the async tangling process.
@@ -162,9 +175,17 @@ Assume buffer is in Org mode. Narrowing, if any, is
ignored."
org-babel-pre-tangle-hook
org-babel-post-tangle-hook)
with-vars)))
- (evaluate (not (member file org-auto-tangle-babel-safelist))))
+ (evaluate (not (member file org-auto-tangle-babel-safelist)))
+ (with-files org-auto-tangle-with-files))
(lambda ()
(require 'org)
+ (when with-files
+ (dolist (f (if (listp with-files)
+ with-files
+ (list with-files)))
+ (when (and (stringp f) (file-exists-p f))
+ (ignore-errors
+ (load-file f)))))
(let ((start-time (current-time))
(non-essential t)
(org-confirm-babel-evaluate evaluate))