emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Shell SRC blocks under Windows
@ 2022-02-04 20:15 H. Dieter Wilhelm
  2022-02-04 21:45 ` Michael Powe
  0 siblings, 1 reply; 9+ messages in thread
From: H. Dieter Wilhelm @ 2022-02-04 20:15 UTC (permalink / raw)
  To: emacs-orgmode

Hello

I installed the software distribution MSYS2 https://www.msys2.org/.  And
I'd like to call its various shells in org src blocks.  First I tried to
set explicit-shell-file-name but then my LaTeX exports don't work any
longer.

Is is it possible to extend org-mode's src blocks with
org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
can't find examples or the respective lisp files on how to define the
execution functions.

GNU Emacs 28.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30,
cairo version 1.15.10) of 2022-01-14

Org mode version 9.4.6 (9.4.6-13-g4be129-elpaplus @
/home/dieter/.emacs.d/elpa/org-plus-contrib-20210920/)

Thanks a lot

       Dieter
-- 
Best wishes
H. Dieter Wilhelm
Zwingenberg, Germany



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

* Re: Shell SRC blocks under Windows
  2022-02-04 20:15 Shell SRC blocks under Windows H. Dieter Wilhelm
@ 2022-02-04 21:45 ` Michael Powe
  2022-02-05 15:48   ` H. Dieter Wilhelm
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Powe @ 2022-02-04 21:45 UTC (permalink / raw)
  To: emacs-orgmode


On 2/4/2022 15:15, H. Dieter Wilhelm wrote:
> Hello
>
> I installed the software distribution MSYS2 https://www.msys2.org/.  And
> I'd like to call its various shells in org src blocks.  First I tried to
> set explicit-shell-file-name but then my LaTeX exports don't work any
> longer.
>
> Is is it possible to extend org-mode's src blocks with
> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
> can't find examples or the respective lisp files on how to define the
> execution functions.
>
> GNU Emacs 28.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30,
> cairo version 1.15.10) of 2022-01-14
>
> Org mode version 9.4.6 (9.4.6-13-g4be129-elpaplus @
> /home/dieter/.emacs.d/elpa/org-plus-contrib-20210920/)

I'm not aware that I did anything special to get these results, except 
add `(shell . t)` to `org-babel-load-languages`. I mean, it is entirely 
possible that I did, in some other context. I think it's just a matter 
of having bash in your path.


#+begin_src sh :results verbatim

   $SHELL --version

#+end_src

#+RESULTS:
: GNU bash, version 5.1.8(1)-release (x86_64-pc-msys)
: Copyright (C) 2020 Free Software Foundation, Inc.
: License GPLv3+: GNU GPL version 3 or later 
<http://gnu.org/licenses/gpl.html>
:
: This is free software; you are free to change and redistribute it.
: There is NO WARRANTY, to the extent permitted by law.


Thanks.

mp

-- 
"Do not neglect to do good, and to share what you have." - Hebrews 13:16a
Michael Powe
Naugatuck CT USA
powem@ctpowe.net



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

* Re: Shell SRC blocks under Windows
  2022-02-04 21:45 ` Michael Powe
@ 2022-02-05 15:48   ` H. Dieter Wilhelm
  2022-02-05 22:22     ` Matt
  0 siblings, 1 reply; 9+ messages in thread
From: H. Dieter Wilhelm @ 2022-02-05 15:48 UTC (permalink / raw)
  To: Michael Powe; +Cc: emacs-orgmode

Michael Powe <powem@ctpowe.net> writes:

> On 2/4/2022 15:15, H. Dieter Wilhelm wrote:
>> Hello
>>
>> I installed the software distribution MSYS2 https://www.msys2.org/.  And
>> I'd like to call its various shells in org src blocks.  First I tried to
>> set explicit-shell-file-name but then my LaTeX exports don't work any
>> longer.
>>
>> Is is it possible to extend org-mode's src blocks with
>> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
>> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
>> can't find examples or the respective lisp files on how to define the
>> execution functions.
>>
>> GNU Emacs 28.0.91 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.22.30,
>> cairo version 1.15.10) of 2022-01-14
>>
>> Org mode version 9.4.6 (9.4.6-13-g4be129-elpaplus @
>> /home/dieter/.emacs.d/elpa/org-plus-contrib-20210920/)
>
> I'm not aware that I did anything special to get these results, except 
> add `(shell . t)` to `org-babel-load-languages`. I mean, it is entirely 
> possible that I did, in some other context. I think it's just a matter 
> of having bash in your path.

Yes, you are right, when using 

> #+begin_src sh

It seems that I'm also running some bash shell! :-) Previously I was
using the src block in this way:

  #+begin_src shell

and here the shell seems to be com.exe.

But I'm not sure if I'm halfway there with "sh"?  I need to run the
following MSYS2 command AND switch between two arguments (for building
Emacs).

  \MSYS2\msys2_shell.cmd -mingw64

and

  \MSYS2\msys2_shell.cmd -msys.

How could I achieve this within a src block?

Thanks 


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

* Re: Shell SRC blocks under Windows
  2022-02-05 15:48   ` H. Dieter Wilhelm
@ 2022-02-05 22:22     ` Matt
  2022-02-06 15:46       ` Matt
  0 siblings, 1 reply; 9+ messages in thread
From: Matt @ 2022-02-05 22:22 UTC (permalink / raw)
  To: H. Dieter Wilhelm; +Cc: Michael Powe, emacs-orgmode


 ---- On Sat, 05 Feb 2022 10:48:02 -0500 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote ----

 > >> Is is it possible to extend org-mode's src blocks with
 > >> org-babel-shell-names to use either MSYS2 or MinGW shells (instead of
 > >> cmd.exe)?  Unfortunately ob-shell.el doesn't guide me further and I
 > >> can't find examples or the respective lisp files on how to define the
 > >> execution functions.
> 
 > Yes, you are right, when using 
 > 
 > > #+begin_src sh
 > 
 > It seems that I'm also running some bash shell! :
 
Yes, it's likely possible to run those shells. Whether or not it will be straight forward or not depends. It's not clear to me what you're trying to do.

First off,  you're looking in the right place. Unfortunately, ob-shell.el can be a little tricky to read.  All the shells are initialized through the =org-babel-shell-initialize= function. This creates a "org-babel-execute:<lang>" for each of the shells given in the =org-babel-shell-names= variable (where <lang> is given by #+begin_src <lang>) . The default shells are: ("sh" "bash" "zsh" "fish" "csh" "ash" "dash" "ksh" "mksh" "posh").   All  execute calls make their way through the God function =org-babel-sh-evaluate= (note: the "sh" in the function name appears to be cruft from when the ob-shell.el module was called "ob-sh.el"; it is not tied specifically to the sh shell).  Technically, which shell is used to evaluate the block depends on the source block parameters used. There are several possible paths.  Unless something weird is being done, however, the block should be evaluated by <lang>.  It looks like you're using a simple one-off shell, not a session or a shebang, so I'll speak to that.

For #+begin_src sh, the block will we evaluated by whatever  "sh" corresponds to in the environment Emacs is running in.  Under the hood, a call is made to the =shell= command and the =shell-file-name= variable gets set to whatever <lang> the block specifies. The an binding happens in =org-babel-shell-initialize=.  So, open a command line environment that would be used to start Emacs and see what "sh" corresponds to:

which sh

That's the shell used by  #+begin_src sh.  Similarly, whatever "which bash" shows is what  #+begin_src bash uses.

This is why it would be surprising that cmd.exe would be used.  

I know that was a lot.  Depending, it may be as simple as updating the =org-babel-shell-names= and rerunning =org-babel-shell-initialize=.  Check the doc strings on those.  Otherwise, I hope this helps ob-shell.el guide you better.

 > But I'm not sure if I'm halfway there with "sh"?  I need to run the
 > following MSYS2 command AND switch between two arguments (for building
 > Emacs).
 > 
 >   \MSYS2\msys2_shell.cmd -mingw64
 > 
 > and
 > 
 >   \MSYS2\msys2_shell.cmd -msys.
 > 
 > How could I achieve this within a src block?

I'm not sure I follow you here.   Can you please describe what you're trying to do and the system you're using (e.g. Windows, GNU/Linux, Haiku) as well the shell used to run the Emacs instance you're doing this in?


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

* Re: Shell SRC blocks under Windows
  2022-02-05 22:22     ` Matt
@ 2022-02-06 15:46       ` Matt
  2022-02-06 17:51         ` H. Dieter Wilhelm
  0 siblings, 1 reply; 9+ messages in thread
From: Matt @ 2022-02-06 15:46 UTC (permalink / raw)
  To: H. Dieter Wilhelm; +Cc: emacs-orgmode


 ---- On Sat, 05 Feb 2022 17:22:29 -0500 Matt <matt@excalamus.com> wrote ----

 >  > But I'm not sure if I'm halfway there with "sh"?  I need to run the
 >  > following MSYS2 command AND switch between two arguments (for building
 >  > Emacs).
 >  > 
 >  >   \MSYS2\msys2_shell.cmd -mingw64
 >  > 
 >  > and
 >  > 
 >  >   \MSYS2\msys2_shell.cmd -msys.
 >  > 
 >  > How could I achieve this within a src block?
 > 
 > I'm not sure I follow you here.   Can you please describe what you're trying to do and the system you're using (e.g. Windows, GNU/Linux, Haiku) as well the shell used to run the Emacs instance you're doing this in?
 > 
Excuse me.  Obviously you're using Windows.  :)


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

* Re: Shell SRC blocks under Windows
  2022-02-06 15:46       ` Matt
@ 2022-02-06 17:51         ` H. Dieter Wilhelm
  2022-02-07 12:57           ` Matt
  0 siblings, 1 reply; 9+ messages in thread
From: H. Dieter Wilhelm @ 2022-02-06 17:51 UTC (permalink / raw)
  To: Matt; +Cc: emacs-orgmode

Matt <matt@excalamus.com> writes:

>  ---- On Sat, 05 Feb 2022 17:22:29 -0500 Matt <matt@excalamus.com> wrote ----
>
>  >  > But I'm not sure if I'm halfway there with "sh"?  I need to run the
>  >  > following MSYS2 command AND switch between two arguments (for building
>  >  > Emacs).
>  >  > 
>  >  >   \MSYS2\msys2_shell.cmd -mingw64
>  >  > 
>  >  > and
>  >  > 
>  >  >   \MSYS2\msys2_shell.cmd -msys.
>  >  > 
>  >  > How could I achieve this within a src block?
>  > 
>  > I'm not sure I follow you here.  Can you please describe what
>  > you're trying to do and the system you're using (e.g. Windows,
>  > GNU/Linux, Haiku) as well the shell used to run the Emacs instance
>  > you're doing this in?
>  > 
> Excuse me.  Obviously you're using Windows.  :)

Yes I have to, but please don't mind, thank you for your interest. :-)


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

* Re: Shell SRC blocks under Windows
  2022-02-06 17:51         ` H. Dieter Wilhelm
@ 2022-02-07 12:57           ` Matt
  2022-02-08  9:47             ` H. Dieter Wilhelm
  0 siblings, 1 reply; 9+ messages in thread
From: Matt @ 2022-02-07 12:57 UTC (permalink / raw)
  To: H. Dieter Wilhelm; +Cc: emacs-orgmode


 ---- On Sun, 06 Feb 2022 12:51:49 -0500 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote ----
 > Matt <matt@excalamus.com> writes:
 > 
 > >  ---- On Sat, 05 Feb 2022 17:22:29 -0500 Matt <matt@excalamus.com> wrote ----
 > >
 > >  >  > But I'm not sure if I'm halfway there with "sh"?  I need to run the
 > >  >  > following MSYS2 command AND switch between two arguments (for building
 > >  >  > Emacs).
 > >  >  > 
 > >  >  >   \MSYS2\msys2_shell.cmd -mingw64
 > >  >  > 
 > >  >  > and
 > >  >  > 
 > >  >  >   \MSYS2\msys2_shell.cmd -msys.
 > >  >  > 
 > >  >  > How could I achieve this within a src block?
 > >  > 
 > >  > I'm not sure I follow you here.  Can you please describe what
 > >  > you're trying to do and the system you're using (e.g. Windows,
 > >  > GNU/Linux, Haiku) as well the shell used to run the Emacs instance
 > >  > you're doing this in?
 > >  > 
 > > Excuse me.  Obviously you're using Windows.  :)
 > 
 > Yes I have to, but please don't mind, thank you for your interest. :-)
 > 
 
I don't mind. I had asked about the system to help troubleshoot yet that info was clearly given in the thread title.  :)

 You said you weren't sure if you're halfway there with "sh".  Is that feeling resolved for you?


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

* Re: Shell SRC blocks under Windows
  2022-02-07 12:57           ` Matt
@ 2022-02-08  9:47             ` H. Dieter Wilhelm
  2022-02-08 22:48               ` Matt
  0 siblings, 1 reply; 9+ messages in thread
From: H. Dieter Wilhelm @ 2022-02-08  9:47 UTC (permalink / raw)
  To: Matt; +Cc: emacs-orgmode

Matt <matt@excalamus.com> writes:

>  ---- On Sun, 06 Feb 2022 12:51:49 -0500 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote ----
>  > Matt <matt@excalamus.com> writes:
>  > 
>  > >  ---- On Sat, 05 Feb 2022 17:22:29 -0500 Matt <matt@excalamus.com> wrote ----
>  > >
>  > >  >  > But I'm not sure if I'm halfway there with "sh"?  I need to run the
>  > >  >  > following MSYS2 command AND switch between two arguments (for building
>  > >  >  > Emacs).
>  > >  >  > 
>  > >  >  >   \MSYS2\msys2_shell.cmd -mingw64
>  > >  >  > 
>  > >  >  > and
>  > >  >  > 
>  > >  >  >   \MSYS2\msys2_shell.cmd -msys.
>  > >  >  > 
>  > >  >  > How could I achieve this within a src block?
>  > >  > 
>  > >  > I'm not sure I follow you here.  Can you please describe what
>  > >  > you're trying to do and the system you're using (e.g. Windows,
>  > >  > GNU/Linux, Haiku) as well the shell used to run the Emacs instance
>  > >  > you're doing this in?
>  > >  > 
>  > > Excuse me.  Obviously you're using Windows.  :)
>  > 
>  > Yes I have to, but please don't mind, thank you for your interest. :-)
>  > 
>  
> I don't mind. I had asked about the system to help troubleshoot yet
> that info was clearly given in the thread title.  :)
>
>  You said you weren't sure if you're halfway there with "sh".  Is that
>  feeling resolved for you?

Not yet, I'm still grappling with your message
<17ecbfb46e9.e16df906236239.6523271905911672361@excalamus.com> and
ob-shell.el.  I'll come back to you when I'm through.

Thanks a lot for your interest.

       Dieter
-- 
Best wishes
H. Dieter Wilhelm
Zwingenberg, Germany


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

* Re: Shell SRC blocks under Windows
  2022-02-08  9:47             ` H. Dieter Wilhelm
@ 2022-02-08 22:48               ` Matt
  0 siblings, 0 replies; 9+ messages in thread
From: Matt @ 2022-02-08 22:48 UTC (permalink / raw)
  To: H. Dieter Wilhelm; +Cc: emacs-orgmode


 ---- On Tue, 08 Feb 2022 04:47:04 -0500 H. Dieter Wilhelm <dieter@duenenhof-wilhelm.de> wrote ----

 > Not yet, I'm still grappling with your message
 > <17ecbfb46e9.e16df906236239.6523271905911672361@excalamus.com> and
 > ob-shell.el.  I'll come back to you when I'm through.

Okay, feel free to let me know if something I wrote is unclear or to ask any questions.


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

end of thread, other threads:[~2022-02-08 22:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-04 20:15 Shell SRC blocks under Windows H. Dieter Wilhelm
2022-02-04 21:45 ` Michael Powe
2022-02-05 15:48   ` H. Dieter Wilhelm
2022-02-05 22:22     ` Matt
2022-02-06 15:46       ` Matt
2022-02-06 17:51         ` H. Dieter Wilhelm
2022-02-07 12:57           ` Matt
2022-02-08  9:47             ` H. Dieter Wilhelm
2022-02-08 22:48               ` Matt

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).