emacs - 如何在 emacs org 文件中引用调用 block 的结果?

标签 emacs org-mode literate-programming org-babel

我正在使用 emacs org 模式进行可重复的研究。我无法将调用结果链接到代码块。作为我正在尝试做的一个最小示例:

* Functions
#+name: f1
#+begin_src elisp :var x=7
  (+ x x)
#+end_src

#+name: f2
#+begin_src elisp :var x=7
  (+ x 2)
#+end_src

* Data
#+name: intermediate
#+call: f1(x=5)

#+RESULTS: intermediate
: 10

#+call: f2(x=intermediate)

当我调用 f2 ,它失败了,因为 xnil .如果我从 f1 上的通话中删除姓名,然后 f2 工作,但如果我更改 f1 的参数,结果不会保持同步.

如何告诉 org 模式我想查看函数调用的结果,而无需在每次计算结果时手动重命名?

最佳答案

您可以使用Noweb 来实现您想要的。 Data 下计算中的引用语法标题:

* Functions
...

* Data
#+name: intermediate
#+BEGIN_SRC elisp :noweb yes
<<f1(x=5)>>
#+END_SRC

#+BEGIN_SRC elisp :noweb yes
<<f2(x=intermediate)>>
#+END_SRC

来自 manual (强调我的):

The "noweb" ... Literate Programming system allows named blocks of code to be referenced by using the familiar Noweb syntax:


<<code-block-name>>

When a code block is tangled or evaluated, whether or not "noweb" references are expanded depends upon the value of the :noweb header argument. If :noweb yes, then a Noweb reference is expanded before evaluation. [...]

It is possible to include the results of a code block rather than the body. This is done by appending parentheses to the code block name which may optionally contain arguments to the code block as shown below.


<<code-block-name(optional arguments)>>

通过此设置,您可以更改 x 的值你要传递给 f1并成功重新导出/重新评估,而无需修改其他任何内容。

关于emacs - 如何在 emacs org 文件中引用调用 block 的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24144961/

相关文章:

emacs - 在 Emacs 中将行拆分为字段

Emacs:是否可以将一个特定窗口设置为始终用作 "other window"?

emacs - elisp如何检查是否按下了Shift键

encryption - MS Windows 中的 Emacs 组织文件加密

haskell - LHS 和 Markdown : Codeblocks

emacs - 在议程 View 中匹配属性

emacs - 如何强制 Org-mode 在另一个框架中打开链接?

c - 为什么这个 org-babel c 片段没有产生输出?

haskell - 将 literate Haskell (.lhs) 转换为 Haskell (.hs)

emacs - 组织议程缓冲区不再显示议程项目