emacs-orgmode
[Top][All Lists]
Advanced

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

[Need Help] Error to evaluate "mpv" command in inline src block


From: stardiviner
Subject: [Need Help] Error to evaluate "mpv" command in inline src block
Date: Sun, 30 Apr 2023 12:27:30 +0800

*** Reproduce and experience log

I have Emacs Org mode config like bellowing to auto evaluate inline src block when Org headline cycle expanded.

#+begin_src emacs-lisp
;;; auto evaluate inline source block in property "EVAL".

(defcustom org-property-eval-keyword "EVAL"
  "A property keyword for evaluate code."
  :type 'string
  :safe #'stringp
  :group 'org)

(add-to-list 'org-default-properties org-property-eval-keyword)

(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 org-property-eval-keyword nil)))
        (with-temp-buffer
          (insert inline-src-block)
          (goto-char (point-min))
          (let* ((context (org-element-context))
                 (lang (org-element-property :language context))
                 (type (org-element-type context))
                 (src-block-info (org-babel-get-src-block-info nil context)))
            (when (eq type 'inline-src-block)
              (org-babel-execute-src-block
               nil src-block-info
               (pcase lang
                 ("sh" `((:session . ,(make-temp-name " *ob-sh-inline-async (sh) ")) (:async . "yes") (:results . "silent")))
                 ("shell" `((:session . ,(make-temp-name " *ob-sh-inline-async (shell) ")) (:async . "yes") (:results . "silent")))
                 ("bash" `((:session . ,(make-temp-name " *ob-sh-inline-async (bash) ")) (:async . "yes") (:results . "silent")))
                 ("zsh" `((:session . ,(make-temp-name " *ob-sh-inline-async (zsh) ")) (:async . "yes") (:results . "silent")))
                 (_ '((:results . "none")))))))))))

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

I have example Org file like bellowing.

Here is the testing Org content:

#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE:     [2021-05-13 Thu 20:09]
:Douban:   https://movie.douban.com/subject/35350794/
:DIR:      枕刀歌
:EVAL:     src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
:END:
#+end_src

When I press Tab key to expand upper headline. I check the inline src block session buffer, here is the output:

#+begin_example
bash-5.2$ bash-5.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo 'ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"
echo 'ob_comint_async_shell_end_d1cc7563-be0c-4ed0-a4c2-d1b545333983'
ob_comint_async_shell_start_d1cc7563-be0c-4ed0-a4c2-d1b545333983
org_babel_sh_prompt> =[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key '''.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'y'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'h'.
[input] No key binding found for key 'n'.
[input] No key binding found for key 'c'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'a'.
[input] No key binding found for key 'c'.
[input] No key binding found for key '-'.
[input] No key binding found for key 'b'.
[input] No key binding found for key '''.

Resuming playback. This behavior can be disabled with --no-resume-playback.

     Video --vid=1 (*) (h264 1920x1080 25.000fps)
 (+) Audio --aid=1 (*) (aac 2ch 48000Hz)
AO: [coreaudio] 48000Hz stereo 2ch floatp
Mute: yes



  C-c C-c>
Saving state.

Exiting... (Quit)
org_babel_sh_prompt> echo $SHELL
/bin/zsh
org_babel_sh_prompt>
#+end_example

Then I try to replace the "mpv" shell command with another command without need to invoke desktop GUI. Like bellowing Org content:

#+begin_src org
,* 《枕刀歌》
:PROPERTIES:
:DATE:     [2021-05-13 Thu 20:09]
:Douban:   https://movie.douban.com/subject/35350794/
:DIR:      枕刀歌
:EVAL:     src_sh{sleep 10; echo "done"}
:END:
#+end_src

It evaluated fine.

#+begin_example
sh-3.2$ sh-3.2$ PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
org_babel_sh_prompt> echo 'ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
sleep 10; echo "done"
echo 'ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5'
ob_comint_async_shell_start_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt> done
org_babel_sh_prompt> ob_comint_async_shell_end_ca48d711-c1d3-4ec3-8e9b-072f76fc86d5
org_babel_sh_prompt>
#+end_example

Even I testing using content directly instead of in "EVAL" property like bellowing:

#+begin_src org
Test src_sh{pwd} {{{results(=/Users/stardiviner/Org/Wiki/ACG/Anime/Anime Videos=)}}}
#+end_src

It works fine.

But I failed to execute mpv command:

#+begin_src org
Test src_sh{mpv "枕刀歌/《枕刀歌》SE05 江海阔 歌谣哼唱.mp4"}
#+end_src

I don't understand where get wrong. And what's the reason.

[stardiviner]           <Hack this world!>      GPG key ID: 47C32433
IRC(freeenode): stardiviner                     Twitter:  @numbchild
Key fingerprint = 9BAA 92BC CDDD B9EF 3B36  CB99 B8C4 B8E5 47C3 2433
Blog: http://stardiviner.github.io/

reply via email to

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