[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/async e8fa5c812c 1/3: async: allow passing of initfile
From: |
ELPA Syncer |
Subject: |
[elpa] externals/async e8fa5c812c 1/3: async: allow passing of initfile to child process (FR#39) |
Date: |
Fri, 14 Oct 2022 18:57:24 -0400 (EDT) |
branch: externals/async
commit e8fa5c812caadbeb827272c1e30b1938f78589d7
Author: Alex Bennée <alex.bennee@linaro.org>
Commit: Alex Bennée <alex.bennee@linaro.org>
async: allow passing of initfile to child process (FR#39)
Sometimes passing all your state setup in the async elisp call can be
painful, especially if the library is being used by another one (in my
case ob-async for org-mode). Luckily we have a method for dealing with
boilerplate setup called an initfile. This allows an initfile to be
specified for all async calls. It does not re-use the existing
initfile as the interactive one is likely too cluttered for a child
process.
---
async.el | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/async.el b/async.el
index 30476e246a..7ce6058137 100644
--- a/async.el
+++ b/async.el
@@ -44,6 +44,13 @@
(defvar async-callback-value-set nil)
(defvar async-current-process nil)
(defvar async--procvar nil)
+(defvar async-child-init nil
+ "Initialisation file for async child Emacs.
+
+If defined this allows for an init file to setup the child Emacs. It
+should not be your normal init.el as that would likely load more
+things that you require. It should limit itself to ensuring paths have
+been setup so any async code can load libraries you expect.")
(defun async-inject-variables
(include-regexp &optional predicate exclude-regexp)
@@ -231,6 +238,20 @@ working directory."
(set (make-local-variable 'async-callback-for-process) t))
proc)))
+(defun async--emacs-program-args (&optional sexp)
+ "Return a list of arguments for invoking the child Emacs."
+ ;; Using `locate-library' ensure we use the right file
+ ;; when the .elc have been deleted.
+ (let ((args (list "-Q" "-l" (locate-library "async"))))
+ (when async-child-init
+ (setq args (append args (list "-l" async-child-init))))
+ (append args (list "-batch" "-f" "async-batch-invoke"
+ (if sexp
+ (with-temp-buffer
+ (async--insert-sexp (list 'quote sexp))
+ (buffer-string))
+ "<none>")))))
+
;;;###autoload
(defun async-start (start-func &optional finish-func)
"Execute START-FUNC (often a lambda) in a subordinate Emacs process.
@@ -283,21 +304,13 @@ returns nil. It can still be useful, however, as an
argument to
;; Subordinate Emacs will send text encoded in UTF-8.
(coding-system-for-read 'utf-8-unix))
(setq async--procvar
- (async-start-process
- "emacs" (file-truename
- (expand-file-name invocation-name
- invocation-directory))
- finish-func
- "-Q" "-l"
- ;; Using `locate-library' ensure we use the right file
- ;; when the .elc have been deleted.
- (locate-library "async")
- "-batch" "-f" "async-batch-invoke"
- (if async-send-over-pipe
- "<none>"
- (with-temp-buffer
- (async--insert-sexp (list 'quote sexp))
- (buffer-string)))))
+ (apply 'async-start-process
+ "emacs" (file-truename
+ (expand-file-name invocation-name
+ invocation-directory))
+ finish-func
+ (async--emacs-program-args (if (not async-send-over-pipe)
sexp))))
+
(if async-send-over-pipe
(async--transmit-sexp async--procvar (list 'quote sexp)))
async--procvar))