emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* How to handle an inline multiline noweb reference
@ 2018-11-27  9:45 Marcin Borkowski
  2018-11-28  2:08 ` Grant Rettke
  0 siblings, 1 reply; 14+ messages in thread
From: Marcin Borkowski @ 2018-11-27  9:45 UTC (permalink / raw)
  To: Org-Mode mailing list

Hi folks,

I have a multiline source block (a complex sql query).  I'd like it to
be inserted into another (shell) source block, so that I can run psql on
a remote server (via ssh) and execute this query (I cannot access the
database from my machine).

I came up with this:

--8<---------------cut here---------------start------------->8---
#+name: sql_join
#+begin_src sql
  SELECT ... -- complicated, multiline query;
#+end_src

#+name: sql_oneline
#+begin_src elisp :noweb yes
  (replace-regexp-in-string "\n" " " "
<<sql_join>>" t t)
#+end_src

#+begin_src sh :noweb yes :results output verbatim
ssh user@host "psql connector -c '<<sql_oneline()>>'"
#+end_src
--8<---------------cut here---------------end--------------->8---

but it's fairly complicated.  Any better ideas?

TIA,

--
Marcin Borkowski
http://mbork.pl

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

* Re: How to handle an inline multiline noweb reference
  2018-11-27  9:45 How to handle an inline multiline noweb reference Marcin Borkowski
@ 2018-11-28  2:08 ` Grant Rettke
  2018-11-28  2:33   ` Samuel Wales
  2018-11-30 17:23   ` Marcin Borkowski
  0 siblings, 2 replies; 14+ messages in thread
From: Grant Rettke @ 2018-11-28  2:08 UTC (permalink / raw)
  To: mbork; +Cc: Org-mode

On Tue, Nov 27, 2018 at 3:57 AM Marcin Borkowski <mbork@mbork.pl> wrote:
> but it's fairly complicated.  Any better ideas?

What is the part that you think is too complicated?

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  2:08 ` Grant Rettke
@ 2018-11-28  2:33   ` Samuel Wales
  2018-11-28  7:08     ` Eric S Fraga
  2018-11-30 17:23   ` Marcin Borkowski
  1 sibling, 1 reply; 14+ messages in thread
From: Samuel Wales @ 2018-11-28  2:33 UTC (permalink / raw)
  To: Grant Rettke; +Cc: Org-mode

this might be the most ridiculous idea you have ever heard, but does
babel have a concept similar to stdio pipes?  i've often wanted to
just pipe stuff.  dunno if this would help marcin.

the only inter-block communication i am aware of are variables and
noweb inclusion.

[and, unless i am mistaken, one or the other inclusion mechanism
always outputs intermediate lines of text as messages in the
minibuffer, dunno if that can be turned off.]

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  2:33   ` Samuel Wales
@ 2018-11-28  7:08     ` Eric S Fraga
  2018-11-28 17:33       ` Grant Rettke
                         ` (2 more replies)
  0 siblings, 3 replies; 14+ messages in thread
From: Eric S Fraga @ 2018-11-28  7:08 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Org-mode, Grant Rettke

On Tuesday, 27 Nov 2018 at 19:33, Samuel Wales wrote:
> this might be the most ridiculous idea you have ever heard, but does
> babel have a concept similar to stdio pipes?  i've often wanted to
> just pipe stuff.  dunno if this would help marcin.
>
> the only inter-block communication i am aware of are variables and
> noweb inclusion.

Check out the :post option for src blocks.  May be exactly what you
want.
-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  7:08     ` Eric S Fraga
@ 2018-11-28 17:33       ` Grant Rettke
  2018-11-28 22:35       ` Samuel Wales
  2018-11-30 15:20       ` Marcin Borkowski
  2 siblings, 0 replies; 14+ messages in thread
From: Grant Rettke @ 2018-11-28 17:33 UTC (permalink / raw)
  To: Samuel Wales, Org-mode

On Wed, Nov 28, 2018 at 1:08 AM Eric S Fraga <esflists@gmail.com> wrote:
> Check out the :post option for src blocks.  May be exactly what you
> want.

Thanks for sharing that!

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  7:08     ` Eric S Fraga
  2018-11-28 17:33       ` Grant Rettke
@ 2018-11-28 22:35       ` Samuel Wales
  2018-11-29  6:24         ` Eric S Fraga
  2018-11-30 15:20       ` Marcin Borkowski
  2 siblings, 1 reply; 14+ messages in thread
From: Samuel Wales @ 2018-11-28 22:35 UTC (permalink / raw)
  To: Samuel Wales, Grant Rettke, Org-mode

fyi only: i don't understand the examples or the relevance to pipes.

On 11/28/18, Eric S Fraga <esflists@gmail.com> wrote:
> On Tuesday, 27 Nov 2018 at 19:33, Samuel Wales wrote:
>> this might be the most ridiculous idea you have ever heard, but does
>> babel have a concept similar to stdio pipes?  i've often wanted to
>> just pipe stuff.  dunno if this would help marcin.
>>
>> the only inter-block communication i am aware of are variables and
>> noweb inclusion.
>
> Check out the :post option for src blocks.  May be exactly what you
> want.
> --
> Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442
>


-- 
The Kafka Pandemic: <http://thekafkapandemic.blogspot.com>

The disease DOES progress. MANY people have died from it. And ANYBODY
can get it at any time.

"You’ve really gotta quit this and get moving, because this is murder
by neglect." ---
<http://www.meaction.net/2017/02/03/pwme-people-with-me-are-being-murdered-by-neglect>.

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28 22:35       ` Samuel Wales
@ 2018-11-29  6:24         ` Eric S Fraga
  2018-11-29 22:16           ` Samuel Wales
  0 siblings, 1 reply; 14+ messages in thread
From: Eric S Fraga @ 2018-11-29  6:24 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Org-mode, Grant Rettke

On Wednesday, 28 Nov 2018 at 15:35, Samuel Wales wrote:
> fyi only: i don't understand the examples or the relevance to pipes.

The output (or more generally the results) of one src block is passed directly as input to another using the :post argument.  

See, for instance:

#+begin_src org
  ,#+name: doubleit
  ,#+begin_src octave :results output :var x=[0.1]
  disp(2*x)
  ,#+end_src

  ,#+name: test
  ,#+begin_src octave :post doubleit(x=*this*)
    2*3.14
  ,#+end_src

  ,#+results: test
  :  12.560
#+end_src

HTH,
eric

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442

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

* Re: How to handle an inline multiline noweb reference
  2018-11-29  6:24         ` Eric S Fraga
@ 2018-11-29 22:16           ` Samuel Wales
  2018-11-29 22:18             ` Samuel Wales
  2018-11-30  6:44             ` Eric S Fraga
  0 siblings, 2 replies; 14+ messages in thread
From: Samuel Wales @ 2018-11-29 22:16 UTC (permalink / raw)
  To: Samuel Wales, Grant Rettke, Org-mode

On 11/28/18, Eric S Fraga <esflists@gmail.com> wrote:
> The output (or more generally the results) of one src block is passed
> directly as input to another using the :post argument.

that helps.

i'm not familiar with many languages.  shell and lisp work best for
me, but in this case saying that clarifies.

not sure where *this* comes in.  perhaps it is a variable in the
second block being sent to the first block?

> #+begin_src org
>   ,#+name: doubleit
>   ,#+begin_src octave :results output :var x=[0.1]
>   disp(2*x)
>   ,#+end_src
>
>   ,#+name: test
>   ,#+begin_src octave :post doubleit(x=*this*)
>     2*3.14
>   ,#+end_src
>
>   ,#+results: test
>   :  12.560
> #+end_src
>
> HTH,
> eric
>
> --
> Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442
>


-- 
The Kafka Pandemic: <http://thekafkapandemic.blogspot.com>

The disease DOES progress. MANY people have died from it. And ANYBODY
can get it at any time.

"You’ve really gotta quit this and get moving, because this is murder
by neglect." ---
<http://www.meaction.net/2017/02/03/pwme-people-with-me-are-being-murdered-by-neglect>.

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

* Re: How to handle an inline multiline noweb reference
  2018-11-29 22:16           ` Samuel Wales
@ 2018-11-29 22:18             ` Samuel Wales
  2018-11-30  6:46               ` Eric S Fraga
  2018-11-30  6:44             ` Eric S Fraga
  1 sibling, 1 reply; 14+ messages in thread
From: Samuel Wales @ 2018-11-29 22:18 UTC (permalink / raw)
  To: Samuel Wales, Grant Rettke, Org-mode

it still feels like variables to me.  if you did a shell example with
1000 lines, would those be piped in?  or would the variable contain
1000 lines?  i don't understandt he difference between post and just a
variable.

onte: i am only telling you this to improve documentation if you feel
like it.  i don't need this now.  just want to let you know that it is
not speakign to me.

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

* Re: How to handle an inline multiline noweb reference
  2018-11-29 22:16           ` Samuel Wales
  2018-11-29 22:18             ` Samuel Wales
@ 2018-11-30  6:44             ` Eric S Fraga
  1 sibling, 0 replies; 14+ messages in thread
From: Eric S Fraga @ 2018-11-30  6:44 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Org-mode, Grant Rettke

On Thursday, 29 Nov 2018 at 15:16, Samuel Wales wrote:
> On 11/28/18, Eric S Fraga <esflists@gmail.com> wrote:
>> The output (or more generally the results) of one src block is passed
>> directly as input to another using the :post argument.
>
> that helps.
>
> i'm not familiar with many languages.  shell and lisp work best for
> me, but in this case saying that clarifies.
>
> not sure where *this* comes in.  perhaps it is a variable in the
> second block being sent to the first block?

*this* is replaced by the results of the block that has the :post argument so, in this example, the results (i.e. the output) of the test block are placed in the x variable for the doubleit block.

-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442

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

* Re: How to handle an inline multiline noweb reference
  2018-11-29 22:18             ` Samuel Wales
@ 2018-11-30  6:46               ` Eric S Fraga
  0 siblings, 0 replies; 14+ messages in thread
From: Eric S Fraga @ 2018-11-30  6:46 UTC (permalink / raw)
  To: Samuel Wales; +Cc: Org-mode, Grant Rettke

On Thursday, 29 Nov 2018 at 15:18, Samuel Wales wrote:
> it still feels like variables to me.  

I agree.  It's not the *same* as a pipe but does meet some of the requirements for some use cases...  I think expecting behaviour like pipes is possibly too much given the single threaded nature of much of emacs?
-- 
Eric S Fraga via Emacs 27.0.50, Org release_9.1.14-1035-gfeb442

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  7:08     ` Eric S Fraga
  2018-11-28 17:33       ` Grant Rettke
  2018-11-28 22:35       ` Samuel Wales
@ 2018-11-30 15:20       ` Marcin Borkowski
  2 siblings, 0 replies; 14+ messages in thread
From: Marcin Borkowski @ 2018-11-30 15:20 UTC (permalink / raw)
  To: Eric S Fraga; +Cc: Org-mode, Grant Rettke


On 2018-11-28, at 08:08, Eric S Fraga <esflists@gmail.com> wrote:

> On Tuesday, 27 Nov 2018 at 19:33, Samuel Wales wrote:
>> this might be the most ridiculous idea you have ever heard, but does
>> babel have a concept similar to stdio pipes?  i've often wanted to
>> just pipe stuff.  dunno if this would help marcin.
>>
>> the only inter-block communication i am aware of are variables and
>> noweb inclusion.
>
> Check out the :post option for src blocks.  May be exactly what you
> want.

Thanks, this looks *very* promising!

Best,

-- 
Marcin Borkowski
http://mbork.pl

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

* Re: How to handle an inline multiline noweb reference
  2018-11-28  2:08 ` Grant Rettke
  2018-11-28  2:33   ` Samuel Wales
@ 2018-11-30 17:23   ` Marcin Borkowski
  2018-12-02  3:59     ` Grant Rettke
  1 sibling, 1 reply; 14+ messages in thread
From: Marcin Borkowski @ 2018-11-30 17:23 UTC (permalink / raw)
  To: Grant Rettke; +Cc: Org-mode


On 2018-11-28, at 03:08, Grant Rettke <gcr@wisdomandwonder.com> wrote:

> On Tue, Nov 27, 2018 at 3:57 AM Marcin Borkowski <mbork@mbork.pl> wrote:
>> but it's fairly complicated.  Any better ideas?
>
> What is the part that you think is too complicated?

I hoped that I could somehow skip the "manually replace newlines with
spaces" step.

Best,

--
Marcin Borkowski
http://mbork.pl

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

* Re: How to handle an inline multiline noweb reference
  2018-11-30 17:23   ` Marcin Borkowski
@ 2018-12-02  3:59     ` Grant Rettke
  0 siblings, 0 replies; 14+ messages in thread
From: Grant Rettke @ 2018-12-02  3:59 UTC (permalink / raw)
  To: mbork; +Cc: Org-mode

On Fri, Nov 30, 2018 at 11:25 AM Marcin Borkowski <mbork@mbork.pl> wrote:
> On 2018-11-28, at 03:08, Grant Rettke <gcr@wisdomandwonder.com> wrote:
> > On Tue, Nov 27, 2018 at 3:57 AM Marcin Borkowski <mbork@mbork.pl> wrote:
> >> but it's fairly complicated.  Any better ideas?
> >
> > What is the part that you think is too complicated?
>
> I hoped that I could somehow skip the "manually replace newlines with
> spaces" step.

Thank you for explaining!

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

end of thread, other threads:[~2018-12-02  4:00 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-27  9:45 How to handle an inline multiline noweb reference Marcin Borkowski
2018-11-28  2:08 ` Grant Rettke
2018-11-28  2:33   ` Samuel Wales
2018-11-28  7:08     ` Eric S Fraga
2018-11-28 17:33       ` Grant Rettke
2018-11-28 22:35       ` Samuel Wales
2018-11-29  6:24         ` Eric S Fraga
2018-11-29 22:16           ` Samuel Wales
2018-11-29 22:18             ` Samuel Wales
2018-11-30  6:46               ` Eric S Fraga
2018-11-30  6:44             ` Eric S Fraga
2018-11-30 15:20       ` Marcin Borkowski
2018-11-30 17:23   ` Marcin Borkowski
2018-12-02  3:59     ` Grant Rettke

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