|
51 | 51 | (defvar async-callback-value-set nil)
|
52 | 52 | (defvar async-current-process nil)
|
53 | 53 | (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.") |
54 | 61 |
|
55 | 62 | ;; For emacs<29 (only exists in emacs-29+).
|
56 | 63 | (defvar print-symbols-bare)
|
@@ -310,6 +317,20 @@ Can be one of \"-Q\" or \"-q\".
|
310 | 317 | Default is \"-Q\" but it is sometimes useful to use \"-q\" to have a
|
311 | 318 | enhanced config or some more variables loaded.")
|
312 | 319 |
|
| 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 | + |
313 | 334 | ;;;###autoload
|
314 | 335 | (defun async-start (start-func &optional finish-func)
|
315 | 336 | "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
|
373 | 394 | ;; Subordinate Emacs will send text encoded in UTF-8.
|
374 | 395 | (coding-system-for-read 'utf-8-auto))
|
375 | 396 | (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 | + |
391 | 404 | (if async-send-over-pipe
|
392 | 405 | (async--transmit-sexp async--procvar (list 'quote sexp)))
|
393 | 406 | async--procvar))
|
|
0 commit comments