1

After some search, i don't found example corresponding to my use case.

Writing a research text, i'm interested to mix source blocks code and text with results using inline mode, for example this simple example :

Open a terminal and write git --version returning git version 2.20.1

git version 2.20.1 is the simple result of src_sh[:results value :exports code]{git --version}. But using this command it's impossible to inject text (here the word returning) between the exported code git --version and the result of git -- version evaluation.

Is it possible to reproduce this behaviour using org-mode and org-babel ?

UPDATE 1 :

A short example of behaviour i want to achieve :

Open your terminal and run the command src_sh[exports:code]{git --version} which return $1, go to src_sh[exports: code]{cd /home/xxx/myproject} and count the number of commit using src_sh[exports:code]{git rev-list --all --count && git branch | wc -l } returning $1 commit(s) on $2 branche(s).

2
  • What version of Org mode are you using? M-x org-version will tell you.
    – NickD
    Jan 7 '20 at 18:49
  • Hi Nick, it's 9.3 version
    – reyman64
    Jan 8 '20 at 8:40
2

When I evaluate the inline src block:

src_sh[:results value :exports code]{git --version}

I get the following in my org mode buffer:

src_sh[:results value :exports code]{git --version} {{{results(=git version 2.24.1=)}}}

If you get the same thing, then the only thing you have to do is define a macro that will do what you want:

#+MACRO: results returning $1

When you export, you should get exactly what you want.

UPDATE: For your updated question, I would use src code blocks, not inline ones, but then call them inline. This is not quite what you want, but it is close:

#+MACRO: results $1

* Instructions

Open your terminal and run the command =git --version= which returns
call_gitversion[:exports results](), =cd /home/nick/emacs/emacs= and
count the number of commits using =git rev-list --all --count && git
branch | wc -l= returning call_ncommits[:exports results]() commit(s)
on call_nbranches[:exports results]() branch(es).


* Code                                                    :noexport:
#+name: gitversion
#+begin_src shell :exports none
git --version
#+end_src

#+RESULTS: gitversion
: git version 2.24.1

#+name: ncommits
#+begin_src shell :exports none
cd /home/nick/src/emacs/emacs
git rev-list --all --count
#+end_src

#+RESULTS: ncommits
: 145317

#+name: nbranches
#+begin_src shell :exports none
cd /home/nick/src/emacs/emacs
git branch | wc -l
#+end_src

#+RESULTS: nbranches
: 2

And this was done in a hurry: caveat emptor.

3
  • Thanks for your quick answer @NickD, it works, but syntax is weird if you need to add cut your long text with #+Macro which each time start on a new line, do you think there is a way to simplify/generify this syntax ?
    – reyman64
    Jan 8 '20 at 8:59
  • Sorry, I don't understand what you are saying: maybe edit your question and add an example?
    – NickD
    Jan 8 '20 at 13:16
  • I update with an example of readable syntax i'm interested to obtain
    – reyman64
    Jan 8 '20 at 14:00

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.