astahlman / ob-async

Asynchronous src_block execution for org-babel
343 stars 32 forks source link

Feature: Ability to cancel to async requests #29

Open dangirsh opened 6 years ago

dangirsh commented 6 years ago

Maybe there's already a way to do this, but I'm not sure how:

I'd like to be able to cancel the async request for a given block.

I'm unsure how feasible this is, but thought I'd start the discussion.

Thanks for an excellent package!

astahlman commented 6 years ago

This seems doable.

We use async-start [1] to run the org-babel execute function asynchronously [2]. async-start returns the underlying process object, to which we can send a SIGKILL by calling delete-process [3]. We would need to do some bookkeeping to map process objects to src_blocks, since there can be multiple asynchronous processes active simultaneously.

I'm not sure of the best way to present this to the user - maybe the user would have to invoke the cancel function with point on the corresponding src_block? We'd also need to decide whether to clean up the RESULTS block, or to just leave it as-is.

I'd gladly accept a PR if anyone wants to take a shot at it, but let's make sure we agree on the UI aspect, first.

[1] https://github.com/jwiegley/emacs-async/blob/04e1a2c40bef305450389da540ffe7594964e430/async.el#L341 [2] https://github.com/astahlman/ob-async/blob/5984d6172c179528adf9aeba414598604dfb5c9a/ob-async.el#L131 [3] https://www.gnu.org/software/emacs/manual/html_node/elisp/Deleting-Processes.html#Deleting-Processes