emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[QUESTION] How to use `make-thread` to run org-babel-execute-src-block?


From: Christopher Miles
Subject: [QUESTION] How to use `make-thread` to run org-babel-execute-src-block?
Date: Mon, 1 Feb 2021 05:05:07 +0000

<#secure method=pgpmime mode=sign>

I have following code snippet config:

(defun org-property-eval-on-cycle-expand (&optional state)
  "Evaluate Org inline source block in property value on headline cycle expand."
  (when (memq state '(children subtree))
    (if-let ((inline-src-block (org-entry-get nil "EVAL" nil)))
        (with-temp-buffer
          (insert inline-src-block)
          (goto-char (point-min))
          (require 'ob-async nil t)
          (setq-local org-babel-default-inline-header-args
                      '((:results . "silent") (:async . t)))
          (let* ((context (org-element-context))
                 (src-block-info (org-babel-get-src-block-info nil context))
                 (type (org-element-type context)))
            (when (eq type 'inline-src-block)
              ;; TODO use `make-thread'
              ;; ob-async: advice `org-babel-execute-src-block:async' on ‘org-babel-execute-src-block
              (org-babel-execute-src-block nil src-block-info)))))))

(add-hook 'org-cycle-hook #'org-property-eval-on-cycle-expand)

I use upper config in bellowing case to auto play video when I expand headline.

* eval inline src code block
  :PROPERTIES:
  :EVAL: src_sh{mpv "video.mp4"}
  :END:

As upper code snippet marked TODO comment. Because I'm using ob-async. So the org-babel-execute-src-block is async by default with ob-async's advice. I want to get rip of it. Using make-thread, I tried to use (make-thread FUNCTION) (the FUNCTION is a wrapper of org-babel-execute-src-block) but it will block current Emacs instance. How to make it async without blocking current Emacs?

Hope someone can help me. Thank you in advance.

Attachment: ATT00001.txt
Description: ATT00001.txt


reply via email to

[Prev in Thread] Current Thread [Next in Thread]