Interesting in OrgMode version 9+
Is there a way to reference and evaluate code block from other org file and to use it's result in main code block in current org file?
Or maybe just to include code block from other org file to current code block to compose last one as
#+BEGIN_SRS lang :noweb yes
<<reusable-part1>>
<<current-buffer-specific-part>>
<<reusable-part2>>
#+END_SRS
and be possible to C-c C-c it.
I think that Library of Babel is the best way to reuse code across org-mode files.
For any user to add code to the library, first save the code in regular ‘src’ code blocks of an Org file, and then load the Org file with org-babel-lob-ingest, which is bound to C-c C-v i
To be more explicit, lets say that you have a simple code like this one:
#+NAME: simpleShExample
#+BEGIN_SRC sh :var x="default X" :var y="default Y" :export none
echo "Var: $x, $y"
#+END_SRC
This code can be reused with:
#+CALL: simpleShExample(y="My y")
which prints:
Var: default X, My y
Now if you save your code in an org file, for instance simpleShExample.org
then you can reuse it in any other org files by loading it with this lisp command:
(org-babel-lob-ingest "path/to/simpleShExample.org")
Note that you can do that once in your emacs init file.
You can check the list of all the source code blocks you have ingested by inspecting the org-babel-library-of-babel variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With