私の Babel ライブラリには、非常に頻繁に順番に呼び出す Org Babel コード ブロックがいくつかあります。
これらの他のコード ブロックを順番に呼び出す Org Babel コード ブロックを作成することは可能ですか?
はい、できます。パラメータが別のブロック実行の結果である :var を使用するだけです。
#+name: clean
#+begin_src ...
...
#+end_src
#+name: plot
#+begin_src :var data=clean
...
#+end_src
はい、それを行う org-babel ファイルがいくつかあります。これを行う1つの方法は次のとおりです。
#+srcname: foo
#+begin_src python :exports code :tangle yes
def foo():
print "I'm foo()"
#+end_src
#+name: bar
#+begin_src python :exports code :tangle yes
def bar():
foo()
print "I'm bar()'"
#+end_src
#+srcname: main
#+begin_src python :exports code :tangle yes
foo()
bar()
#+end_src
この出力は、次のようなファイルです。
def foo():
print "I'm foo()"
def bar():
foo()
print "I'm bar()'"
foo()
bar()
org ファイル内のコードの順序が生成したい順序と異なる場合は、次のように、noweb タグを使用して、必要な順序でコード ファイルを生成できます。
#+name: bar
#+begin_src python :noweb-ref bar :tangle no
def bar():
foo()
print "I'm bar()'"
#+end_src
#+srcname: foo
#+begin_src python :noweb-ref foo :tangle no
def foo():
print "I'm foo()"
#+end_src
#+begin_src python :noweb tangle :tangle yes
<<foo>>
<<bar>>
foo()
bar()
#+end_src
これをもつれの出力は次のとおりです。
def foo():
print "I'm foo()"
def bar():
foo()
print "I'm bar()'"
foo()
bar()