emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [Need Help] Error to evaluate "mpv" command in inline src block
@ 2023-04-30  4:27 stardiviner
  2023-04-30  4:46 ` Ruijie Yu via General discussions about Org-mode.
  2023-04-30 14:52 ` Ihor Radchenko
  0 siblings, 2 replies; 24+ messages in thread
From: stardiviner @ 2023-04-30  4:27 UTC (permalink / raw)
  To: Org-mode

[-- Attachment #1: Type: text/plain, Size: 5687 bytes --]

*** 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/

[-- Attachment #2: Type: text/html, Size: 7497 bytes --]

^ permalink raw reply	[flat|nested] 24+ messages in thread

end of thread, other threads:[~2023-05-03 16:45 UTC | newest]

Thread overview: 24+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-04-30  4:27 [Need Help] Error to evaluate "mpv" command in inline src block stardiviner
2023-04-30  4:46 ` Ruijie Yu via General discussions about Org-mode.
2023-04-30 10:59   ` Christopher M. Miles
2023-04-30 14:52 ` Ihor Radchenko
2023-05-01  3:39   ` Christopher M. Miles
2023-05-01  7:45     ` Ihor Radchenko
2023-05-01 10:46       ` Christopher M. Miles
2023-05-01 11:39         ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively (was: [Need Help] Error to evaluate "mpv" command in inline src block) Ihor Radchenko
2023-05-01 12:50           ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
2023-05-01 13:14             ` Ihor Radchenko
2023-05-01 13:41               ` Christopher M. Miles
2023-05-01 14:20                 ` Ihor Radchenko
2023-05-01 19:06                   ` Christopher M. Miles
2023-05-01 13:08           ` [SOLUTION] a temporary workaround solution using another language like "python" Christopher M. Miles
     [not found]           ` <35881.2693202466$1682946783@news.gmane.org>
2023-05-01 13:35             ` Max Nikulin
2023-05-01 19:01               ` Christopher M. Miles
2023-05-01 19:16                 ` Ihor Radchenko
2023-05-02  4:17                   ` [CLOSED] [ANSWER] " Christopher M. Miles
2023-05-02 20:31           ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively (was: [Need Help] Error to evaluate "mpv" command in inline src block) Matt
2023-05-03 10:41             ` Ihor Radchenko
2023-05-03 11:01               ` ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively Christopher M. Miles
2023-05-03 12:01                 ` Ihor Radchenko
2023-05-03 16:31                   ` Christopher M. Miles
2023-05-01 10:50       ` [Need Help] Error to evaluate "mpv" command in inline src block Christopher M. Miles

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).