0

When <> expands to multiple line and I wrote like this

some-string <<noweb ref>>

then it expands like

some-string line1-from-noweb-ref some-string line2-from-noweb-ref some-string line3-from-noweb-ref

Is there a way to avoid this?

  • What are you trying to avoid exactly? The behaviour you describe is normal. Do you want some-string to appear only on the first line? Or not at all? A minimal reproducible example would help clarify this. – Tyler Nov 9 '17 at 14:32
2

I think you're asking how to prefix only the first line of the noweb block. It will probably depend on the language your using, but I came up with this hack for bash:

#+NAME: example
#+BEGIN_SRC text
 please echo this line
 date ## but not this one
 cd test ## this one
 ls -l ## or this one  
#+END_SRC

Bad source code block, echo prepended to very line:

#+BEGIN_SRC bash :noweb yes :results verbatim
  echo <<example>>
#+END_SRC

#+RESULTS:
: please echo this line
: date
: cd test
: ls -l
: 

Good source code block, echo prepended to the first line only, the rest
are executed:

#+BEGIN_SRC bash :noweb yes :results verbatim
  echo \
  <<example>>
#+END_SRC

 #+RESULTS:
 : please echo this line
 : Thu Nov  9 10:22:32 EST 2017
 : total 0
 : -rw-r--r-- 1 tws tws 0 Nov  9 09:44 one
 : -rw-r--r-- 1 tws tws 0 Nov  9 09:44 three
 : -rw-r--r-- 1 tws tws 0 Nov  9 09:44 two
  • Thank you! Seems like a solution. But why do you think is "The behaviour you describe is normal. " ? For me <<>> looks like usual inline macros. Well, don't you wait that for example in JS somestring ${nowebref()} do the same - multiply somestring as many as nowebref() will return rows ? – Dima Fomin Nov 10 '17 at 9:26
  • 1
    I only mean that according to the orgmode manual, the designed behaviour is for some-string to be prepended to each line. I don't have an opinion on whether this is the best behaviour, but it is the intended behaviour of the orgmode authors – Tyler Nov 10 '17 at 18:41
  • Ahh, I see now! I should better RTFM :) By the way, inspired with such behaviour I am trying one trick with <<>> but stuck again. May be you could see with one eye? It's here emacs.stackexchange.com/questions/36832/… – Dima Fomin Nov 12 '17 at 18:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.