Skip to content

Commit ffde304

Browse files
authored
Merge pull request #73 from stsquad/custom-init
2 parents 0efee62 + fd80540 commit ffde304

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

async.el

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
(defvar async-callback-value-set nil)
5252
(defvar async-current-process nil)
5353
(defvar async--procvar nil)
54+
(defvar async-child-init nil
55+
"Initialisation file for async child Emacs.
56+
57+
If defined this allows for an init file to setup the child Emacs. It
58+
should not be your normal init.el as that would likely load more
59+
things that you require. It should limit itself to ensuring paths have
60+
been setup so any async code can load libraries you expect.")
5461

5562
;; For emacs<29 (only exists in emacs-29+).
5663
(defvar print-symbols-bare)
@@ -310,6 +317,20 @@ Can be one of \"-Q\" or \"-q\".
310317
Default is \"-Q\" but it is sometimes useful to use \"-q\" to have a
311318
enhanced config or some more variables loaded.")
312319

320+
(defun async--emacs-program-args (&optional sexp)
321+
"Return a list of arguments for invoking the child Emacs."
322+
;; Using `locate-library' ensure we use the right file
323+
;; when the .elc have been deleted.
324+
(let ((args (list async-quiet-switch "-l" (locate-library "async"))))
325+
(when async-child-init
326+
(setq args (append args (list "-l" async-child-init))))
327+
(append args (list "-batch" "-f" "async-batch-invoke"
328+
(if sexp
329+
(with-temp-buffer
330+
(async--insert-sexp (list 'quote sexp))
331+
(buffer-string))
332+
"<none>")))))
333+
313334
;;;###autoload
314335
(defun async-start (start-func &optional finish-func)
315336
"Execute START-FUNC (often a lambda) in a subordinate Emacs process.
@@ -373,21 +394,13 @@ returns nil. It can still be useful, however, as an argument to
373394
;; Subordinate Emacs will send text encoded in UTF-8.
374395
(coding-system-for-read 'utf-8-auto))
375396
(setq async--procvar
376-
(async-start-process
377-
"emacs" (file-truename
378-
(expand-file-name invocation-name
379-
invocation-directory))
380-
finish-func
381-
async-quiet-switch "-l"
382-
;; Using `locate-library' ensure we use the right file
383-
;; when the .elc have been deleted.
384-
(locate-library "async")
385-
"-batch" "-f" "async-batch-invoke"
386-
(if async-send-over-pipe
387-
"<none>"
388-
(with-temp-buffer
389-
(async--insert-sexp (list 'quote sexp))
390-
(buffer-string)))))
397+
(apply 'async-start-process
398+
"emacs" (file-truename
399+
(expand-file-name invocation-name
400+
invocation-directory))
401+
finish-func
402+
(async--emacs-program-args (if (not async-send-over-pipe) sexp))))
403+
391404
(if async-send-over-pipe
392405
(async--transmit-sexp async--procvar (list 'quote sexp)))
393406
async--procvar))

0 commit comments

Comments
 (0)