Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

async: allow passing of initfile to child process (FR#39) #73

Merged
merged 2 commits into from
Oct 14, 2022

Conversation

stsquad
Copy link
Contributor

@stsquad stsquad commented Feb 20, 2017

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.

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.
@jwiegley
Copy link
Owner

@thierryvolpiatto What do you think?

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Feb 21, 2017 via email

@stsquad
Copy link
Contributor Author

stsquad commented Feb 21, 2017

The use-case that I cam across was with ob-sync. It calls async with the following:

(async-start
 `(lambda ()
    ;; TODO: Put this in a function so it can be overidden
    ;; Initialize the new Emacs process with org-babel functions
    (setq exec-path ',exec-path)
    (package-initialize)
    (org-babel-do-load-languages 'org-babel-load-languages ',org-babel-load-languages)
    (,cmd ,body ',params))

And the org-babel-do-load-languages fails in the child because the path isn't setup for all the languages I have defined in org-babel-load-languages in the parent Emacs. However with this patch I set async-child-init to point to a very simple mininit that just sets the paths up. This saves me having to hack the ob-async code to inject the load-path for me which might not always be the solution (it assumes package-initialize solves all the problems).

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Feb 21, 2017 via email

@stsquad
Copy link
Contributor Author

stsquad commented Feb 21, 2017

ob-async is not my package, just one that I'm using. So for me this allows me to work around an assumption it's making by tweaking the child's environment. However you are right I could send a patch upstream to also include load-path in the async environment.

I would envisage async-child-init being used much like a hook used by users to take into account things the 3rd party package didn't consider.

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Feb 21, 2017 via email

@astahlman
Copy link
Contributor

@stsquad Just happened across this thread.

However you are right I could send a patch upstream to also include load-path in the async environment.

I'm the maintainer of ob-async, and I'd happily merge that patch.

@astahlman
Copy link
Contributor

@stsquad I finally got around to creating the patch in ob-async to support a pre-execute hook. I think the merge of astahlman/ob-async#40 would make this request superfluous. Care to review?

@jwiegley
Copy link
Owner

I don't mind having this change, if @thierryvolpiatto agrees.

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Oct 14, 2022 via email

@jwiegley
Copy link
Owner

Well, it is a defvar, so it would only be set at the Emacs Lisp level, and hopefully this will read the docstring before doing so. I don't mind have the capability, though.

@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Oct 14, 2022 via email

@jwiegley
Copy link
Owner

It was my sentence whose English was bad! I don't mind having this capability in the code, i.e., making the feature available to programmers. Since it's not a defcustom, no one will know it's there who doesn't read the source or search for the variable.

@jwiegley jwiegley merged commit ffde304 into jwiegley:master Oct 14, 2022
@thierryvolpiatto
Copy link
Collaborator

thierryvolpiatto commented Oct 15, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants