emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Tom Gillespie <tgbugs@gmail.com>
To: Vladimir Nikishkin <lockywolf@gmail.com>
Cc: Bastien <bzg@gnu.org>, emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: Shouldn't ob-shell's org-babel-expand-src-block prepend the :shebang value?
Date: Thu, 10 Sep 2020 00:10:51 -0700	[thread overview]
Message-ID: <CA+G3_POd5QBswTDmfbz_==CXwzP4RgXryZwL_ntgP8u-0+uqzA@mail.gmail.com> (raw)
In-Reply-To: <CA+A2iZbhCpefdO21agGW=wfNKY4nuYdkTcjO6XsJs8WequhP3A@mail.gmail.com>

Hi Vladimir,
   I have encountered similar issues with wanting to have a racket
#lang line included in a tangled block while also allowing org to know
exactly which #lang it is working with. I haven't found a good
solution. One issue with embedding the shebang when editing a buffer
is that it is very likely to cause confusion because the shebang line
will not actually be included when executing the code, or if it was
included then there is a reasonable possibility that in some cases it
would not be included as the first line due to the addition of a
prologue section. It also becomes necessary to remove the shebang line
from the edit buffer, which means you have to know which shebang lines
were added automatically and which were not. Further, the need to keep
what will be run by org babel in line with what is shown via these
various views makes it seem unlikely that this should be implemented
as default behavior. I have a long email that touches on these issues
in the works for after the 9.4 release, so thank you for providing an
excellent example. It seems like one possible solution for your
workflow would be to advise org-babel-expand-src-block to insert the
shebang. Best,
Tom

On Wed, Sep 9, 2020 at 11:53 PM Vladimir Nikishkin <lockywolf@gmail.com> wrote:
>
> So, my point is the following. A shebang is an almost universally
> accepted way to specify which interpreter should be used for code
> evaluation.
>
> In the ob-core.el, at line 787, the function called
> org-babel-expand-src-block makes a buffer out of the noweb-expanded
> code.
> (I am working with org 20200907)
>
> The sexp is looking like this:
>
> (org-edit-src-code
>      expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))
>
> I suggest replacing this sexp with
>
> (org-edit-src-code
>      (seq-concatenate 'string (or (alist-get :shebang params) "") "\n"
> expanded) (concat "*Org-Babel Preview " (buffer-name) "[ " lang "
> ]*"))
>
> This way the expanded buffer would respect the shebang, and the
> resulting buffer would be saveable as a runnable file.
>
> I suspect that the second branch of the (if) should be left as it is,
> because non-interactive usage probably means that the code will be
> used later as a part of something, and therefore does not need a
> shebang.
>
> Vlad
>
> On Sat, 5 Sep 2020 at 15:13, Bastien <bzg@gnu.org> wrote:
> >
> > Vladimir Nikishkin <lockywolf@gmail.com> writes:
> >
> > > I'll try to do one this week, but I can't submit a patch officially
> > > because of my employer being staunchly against signing the copyright
> > > disclaimer.
> >
> > :/
> >
> > So please just give directions on what to modify and how, and that'd
> > be enough for someone (probably me) to get started.
> >
> > Thanks!
> >
> > --
> >  Bastien
>
>
>
> --
> Yours sincerely, Vladimir Nikishkin
>


  reply	other threads:[~2020-09-10  7:11 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-13  1:03 Shouldn't ob-shell's org-babel-expand-src-block prepend the :shebang value? Vladimir Nikishkin
2020-09-05  5:00 ` Bastien
     [not found]   ` <CA+A2iZbJrNC3Rx5oAvyamBM_BObP8bxyTiFKtzxDrJhqe1MKsQ@mail.gmail.com>
     [not found]     ` <87d030ae7g.fsf@bzg.fr>
2020-09-10  6:52       ` Vladimir Nikishkin
2020-09-10  7:10         ` Tom Gillespie [this message]
2020-09-10  7:29           ` Vladimir Nikishkin
2020-09-10  7:30         ` Tim Cross

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='CA+G3_POd5QBswTDmfbz_==CXwzP4RgXryZwL_ntgP8u-0+uqzA@mail.gmail.com' \
    --to=tgbugs@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=lockywolf@gmail.com \
    /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).