From: "Cook, Malcolm" <MEC@stowers.org>
To: Ihor Radchenko <yantar92@posteo.net>
Cc: Matthew Trzcinski <matt@excalamus.com>, Org-mode <emacs-orgmode@gnu.org>
Subject: RE: org-babel-execute-src-block filters characters from :session *shell* output AND Re: [BUG] conda doesn't work in ob-shell sessions
Date: Wed, 23 Oct 2024 15:49:38 +0000 [thread overview]
Message-ID: <DS7PR20MB46716809EF26589A32E14C0FBE4D2@DS7PR20MB4671.namprd20.prod.outlook.com> (raw)
In-Reply-To: <87le1bc8j3.fsf@localhost>
# -*- org-confirm-babel-evaluate: nil; -*-
Excuse the top-posting. I’m reviving two old-ish threads and felt it best.
I have been struggling with interrelated issues raised in
- https://list.orgmode.org/87jznda90u.fsf@localhost/#t
- https://list.orgmode.org/87le1bc8j3.fsf@localhost/
I expect I am using all the patches offered in addressing these given
my recent build from main. However, in my hands, I find they still
easily allow for mistakes identifying prompts in code block results.
In this demonstration, I am extending the approach to inquiry begun by Jack in
https://list.orgmode.org/87ttzn1mai.fsf@gmail.com/
#+begin_src emacs-lisp
(emacs-version)
#+end_src
#+RESULTS:
: GNU Emacs 31.0.50 (build 1, x86_64-pc-linux-gnu, X toolkit, cairo version 1.15.12, Xaw3d scroll bars)
: of 2024-09-04
#+begin_src emacs-lisp
(org-version nil t)
#+end_src
#+RESULTS:
: Org mode version 9.7.13 (9.7.13-8566bc @ /home/mec/.emacs.d/elpa/org-9.7.13/)
#+begin_src emacs-lisp
(org-babel-do-load-languages
'org-babel-load-languages
'((shell . t)))
#+end_src
#+RESULTS:
Here I define two org code blocks I will use repeatedly below:
#+name:test_filter
#+begin_src shell :session *shell* :results output
printf "a\nb\nc\n>d\n<e\nf>\nggg ggg>\nhhh hhh+\na\n"
#+end_src
#+name:shell_prompt_info
#+begin_src elisp
(with-current-buffer "*shell*"
(format "[comint-prompt-regexp]=[%s]\n[org-babel-comint-prompt-regexp-old]=[%s]" comint-prompt-regexp org-babel-comint-prompt-regexp-old))
#+end_src
#+caption: The results looks good - the output apparently is not confused as being prompt.
#+call: test_filter()
#+RESULTS:
: a
: b
: c
: >d
: <e
: f>
: ggg ggg>
: hhh hhh+
: a
#+caption: take a look at the prompt variables.
#+call:shell_prompt_info()
#+RESULTS:
: [comint-prompt-regexp]=[^org_babel_sh_prompt> *]
: [org-babel-comint-prompt-regexp-old]=[^[^#$%>
: ]*[#$%>] *]
#+caption: check on conda's availabiity & version
#+begin_src shell :session *shell* :results output
conda --version
#+end_src
#+RESULTS:
: conda 24.7.1
#+begin_src shell :session *shell* :results output
conda create --yes --name myenv python=3.9
#+end_src
#+RESULTS:
#+begin_example
... abbreviated...
To activate this environment, use
conda activate myenv
To deactivate an active environment, use
conda deactivate
#+end_example
#+begin_src shell :session *shell* :results output
conda activate myenv
#+end_src
#+RESULTS:
#+begin_src shell :session *shell* :results output
which python
#+end_src
#+RESULTS:
: /n/projects/mec/SRSCHPC2/local/inst/Mambaforge/24.3.0-0/envs/myenv/bin/python
#+caption: alas, the output of test_filter is changed. Some lines are gone missing and some are changed.
#+call: test_filter()
#+RESULTS:
: a
: b
: c
: d
: <e
:
: hhh hhh+
: a
#+caption: Observe the prompts have changed. Perhaps this is related issue?
#+call:shell_prompt_info()
#+RESULTS:
: [comint-prompt-regexp]=[^[^#$%>
: ]*[#$%>] *]
: [org-babel-comint-prompt-regexp-old]=[^org_babel_sh_prompt> *]
#+caption: can we restore by deactivating the environment?
#+begin_src shell :session *shell* :results output
conda deactivate
#+end_src
#+RESULTS:
#+caption: alas, no:
#+call: test_filter()
#+RESULTS:
: a
: b
: c
: d
: <e
:
: hhh hhh+
: a
#+caption: how about by resetting the prompt
#+begin_src shell :session *shell* :results output
PROMPT_COMMAND=;PS1="org_babel_sh_prompt> ";PS2=
#+end_src
#+RESULTS:
#+caption: alas, again, no
#+call: test_filter()
#+RESULTS:
: a
: b
: c
: d
: <e
:
: hhh hhh+
: a
#+caption: perhaps restoring the prompt variables will recover?
#+begin_src elisp
(with-current-buffer "*shell*"
(setq-local comint-prompt-regexp "^org_babel_sh_prompt> *"
org-babel-comint-prompt-regexp-old "[^[^#$%>
]*[#$%>] *"))
#+end_src
#+RESULTS:
: [^[^#$%>
: ]*[#$%>] *
#+caption: YES!
#+call: test_filter()
#+RESULTS:
: a
: b
: c
: >d
: <e
: f>
: ggg ggg>
: hhh hhh+
: a
I'm unsure what change this argues for, but I think it pretty clearly
demonstrates the ongoing issue.
In the above, I am exclusively allowing org/ob/comint to "own" the shell
buffer, and not interact with it, as recommended earlier by Ivor.
I have tried the above after first calling `(shell)` and find
variations on the above occur. I would like to be able to 'share' the
*shell* buffer with org/ob/comint but expect resolving the
non-interactive case should possibly lay foundation.
I would additional like to layer in working with remote shells
(e.g. `:dir "/ssh:me@host:~/`) and have tried but this is just
layering in complexity on the localhost case so I'm backing off for
now.
What else can I report or test?
next prev parent reply other threads:[~2024-10-23 15:50 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-13 14:32 org-babel-execute-src-block filters characters from :session *shell* output Cook, Malcolm
2024-06-14 14:09 ` Ihor Radchenko
2024-06-14 14:29 ` Cook, Malcolm
2024-06-15 13:19 ` Ihor Radchenko
2024-06-16 12:47 ` Max Nikulin
2024-06-17 17:57 ` Ihor Radchenko
2024-06-30 19:05 ` Ihor Radchenko
2024-07-02 19:34 ` Phil
2024-07-02 20:05 ` Ihor Radchenko
2024-07-03 21:07 ` Phil
2024-07-04 11:55 ` Ihor Radchenko
2024-07-06 11:36 ` Max Nikulin
2024-07-06 15:43 ` Ihor Radchenko
2024-07-09 7:54 ` Phil
2024-06-17 15:48 ` Cook, Malcolm
2024-06-17 18:03 ` Ihor Radchenko
2024-06-17 22:40 ` Cook, Malcolm
2024-06-17 23:09 ` Cook, Malcolm
2024-06-19 14:40 ` Ihor Radchenko
2024-06-30 19:08 ` Ihor Radchenko
2024-07-06 11:39 ` Max Nikulin
2024-07-06 11:46 ` Ihor Radchenko
2024-08-05 15:08 ` Ihor Radchenko
2024-10-23 15:49 ` Cook, Malcolm [this message]
2024-10-23 16:52 ` org-babel-execute-src-block filters characters from :session *shell* output AND Re: [BUG] conda doesn't work in ob-shell sessions Cook, Malcolm
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
List information: https://www.orgmode.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=DS7PR20MB46716809EF26589A32E14C0FBE4D2@DS7PR20MB4671.namprd20.prod.outlook.com \
--to=mec@stowers.org \
--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 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).