ob-async icon indicating copy to clipboard operation
ob-async copied to clipboard

make sure (current-buffer) is not #<killed buffer>

Open stardiviner opened this issue 3 years ago • 6 comments

When ob-async execute source block in a temp buffer with with-temp-buffer. Like this:

(with-temp-buffer
(insert "<source block>")
(goto-char (point-min))
(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)
                   ;; ob-async: `org-babel-execute-src-block:async'
                   (org-babel-execute-src-block nil src-block-info)))

I use this implement extension to auto evaluate org inline source block which defined in org property named "EVAL" like this:

*** 《春风十里,不如你》 Spring Breeze Ten Miles 2017
    :PROPERTIES:
    :EVAL:     src_sh{mpv ~/Org/Beauty/周冬雨/春风十里不如你/《春风十里不如你》虐心片段\ 心疼小红把七年青春都给了秋水.flv}
    :END:

stardiviner avatar Oct 16 '20 04:10 stardiviner

Seems the CI build check timeout?

stardiviner avatar Oct 17 '20 01:10 stardiviner

This patch seems break ob-async function. Somebody have any idea to improve it?

stardiviner avatar Oct 25 '20 07:10 stardiviner

Gentle ping ...

stardiviner avatar Nov 07 '20 01:11 stardiviner

Hi, I've only just started looking at this repository, and it's not entirely clear to me what you're trying to do with this commit - I've taken the with-temp-buffer example, changed the "< source block >" string so it actually calls a subprocess, but don't run into any errors. Can you give clearer instructions to reproduce the problem you're seeing?

spacebat avatar Nov 12 '20 21:11 spacebat

Here is my config code try to auto execute Org Mode "EVAL" property's value.

;;; auto evaluate inline source block in property "EVAL".

(defcustom org-property-eval-keywords-list '("EVAL")
  "A list of property keywords for evaluate code."
  :type 'list
  :safe #'listp
  :group 'org)

(dolist (prop org-property-eval-keywords-list)
  (add-to-list 'org-default-properties prop))

(defun org-property-eval-code (&optional state)
  "Evaluate Org inline source block in property value."
  (when (memq state '(children subtree))
    ;; TODO: detect property keywords in `org-property-eval-keywords-list'.
    ;; (require 'seq nil t)
    ;; (seq-intersection ... org-property-eval-keywords-list)
    (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)
              (org-babel-execute-src-block nil nil src-block-info))))))) ; <----- HERE

(add-hook 'org-cycle-hook #'org-property-eval-code)

Here is the "EVAL" property value looks like:

*** Spring Breeze Ten Miles 2017
    :PROPERTIES:
    :EVAL:     src_sh{mpv "/path/to/a/media/music.mp3"}
    :END:

My Org startup is all folded. So when I put point on this header, and press [TAB] to expand it, with my upper config, Emacs will use ob-async to auto play it. After play music command exit, it will raise warning message:

error in process sentinel: save-current-buffer: Selecting deleted buffer
error in process sentinel: Selecting deleted buffer

stardiviner avatar Nov 12 '20 23:11 stardiviner

I force pushed commit which really fixed my issue, no error message error in process sentinel: save-current-buffer: Selecting deleted buffer now.

@astahlman, can you review my PR?

stardiviner avatar Jan 10 '21 08:01 stardiviner