1

I have an org file with notes about how to setup my project. One of the notes has some shell scripts, like this:

#+begin_src sh :dir ~/Workspace/MyProject :session cmake-setup
cmake -B build-debug -S . -G Ninja \
  -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_BUILD_TYPE=Debug
#+end_src

I can hit C-c C-c there and execute the shell command. But the problem is that Emacs hangs for 5-10 seconds while that command runs. When it's done I can switch to the cmake-setup buffer and see the output. But I'd like to switch to the shell buffer right away and see the progress. This will be essential when commands take more than a few seconds.

I found ob-async and added the :async header to the source block. It stops freezing emacs, but it ignores the :session header and puts the huge amount of output into my org file.

Is there a way to make my code block execute asynchronously and keep it running in the session?

3
  • 2
    Not sure, but doesn't the ampersand at the end of your shell command help?
    – Arktik
    Commented Mar 20, 2023 at 16:37
  • 1
    You can set the :results silent for the block if you don't want to see a huge output.
    – Arktik
    Commented Mar 20, 2023 at 16:39
  • Oh my, I'm an idiot. Haha. Yes, the & did it. Thank you.
    – Rob N
    Commented Mar 20, 2023 at 16:48

1 Answer 1

1

I guess a slightly belated response, but you can do this at the org-babel level as well. The ob-async package does not support the :session header, but ob-session-async does and it was merged into the standard library as of Org 9.5. So in theory, :async :session cmake-setup should do what you want with Org >= 9.5 even if you don't move your cmake command to the background with &.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.