all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Christopher M. Miles" <numbchild@gmail.com>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: "Christopher M. Miles" <numbchild@gmail.com>,
	Org-mode <emacs-orgmode@gnu.org>, Matt <matt@excalamus.com>
Subject: Re: ob-shell sessions will send final echo '...' as input key sequence when previous command reads input interactively
Date: Mon, 01 May 2023 21:41:49 +0800	[thread overview]
Message-ID: <m2a5yomahr.fsf@numbchild@gmail.com> (raw)
In-Reply-To: <87y1m86vnj.fsf@localhost>

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


Ihor Radchenko <yantar92@posteo.net> writes:

> "Christopher M. Miles" <numbchild@gmail.com> writes:
>
>> I might consider to use another language like python instead of sh to
>> execute command to play video to get around this issue. I will update
>> here if I success.
>
> All you need to do is getting rid of :async and :session.
> Just use :results none + "&" at the end of mpv command.
> Non-session blocks will not suffer from this problem.

My first version property "EVAL" inline src block indeed don't using
:async and :session. It can play video file.

But I found it will block [Tab] org-cycle expand headline. I don't want
Emacs to be suspended. So I added :async change.

Now I use python `os.system()` to invoke shell command works fine.

Here is my current version:

(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")))
                 ("python" `((:session . ,(make-temp-name "ob-python-inline-async ")) (:async . "yes") (:results . "silent")))
                 (_ '((:results . "none")))))))))))

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

(defvar org-property-eval-templates
  '("src_sh{mpg123 \"path/to/music.mp3\"}"
    "src_python{import os; os.system(\"mpv 'path/to/video.mp4' \")}"))
(org-completing-read-property-construct-function "EVAL" org-property-eval-templates)
(add-to-list 'org-property-set-functions-alist '("EVAL" . org-completing-read-property_eval))

-- 

[ stardiviner ]
I try to make every word tell the meaning that I want to express without misunderstanding.

Blog: https://stardiviner.github.io/
IRC(libera.chat, freenode): stardiviner, Matrix: stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 487 bytes --]

  reply	other threads:[~2023-05-01 15:03 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2a5yomahr.fsf@numbchild@gmail.com \
    --to=numbchild@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=matt@excalamus.com \
    --cc=yantar92@posteo.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.