问题描述
目标
我想使用 org-export
和 org-babel
生成文档。文档中的代码用于 (org-babel
) 生成输出的一部分,例如示例计算。
我还想从命令行运行这些导出(作为构建文件的一部分)。
已执行代码中的错误应停止导出并发出错误信号。否则代码中的错误将不会被构建过程注意到,并且生成的文档将包含错误或空白点(其中有没有输出)。
由于某些块取决于环境(例如,运行 shell 脚本、连接到 Internet 等),因此很可能会出现错误/故障,需要检测和处理。
示例
以下示例可以通过 org-org-export-as-org
导出。
代码
#+TITLE: Test Export
* No error: works
A shell script without errors works.
#+begin_src bash :exports results :results output
echo This will be exported as result
#+end_src
* Errors are ignored in export
Each of the following errors should stop the export with an error.
** Python Exception
#+begin_src python :exports results :results output
raise Exception("please stop")
#+end_src
** Python Syntax Error
#+begin_src python :exports results :results output
this is a Syntax error
#+end_src
** Shell Exit Code 1
#+begin_src bash :exports results :results output
echo Hello there
echo Hello there to stderr >&2
exit 1
#+end_src
预期
另外:从脚本运行应该会出错,退出代码为 != 0
如果我通过脚本 (emacs -batch file.org -f org-org-export-to-org --kill
) 运行导出,我希望 emacs 以退出代码 != 0 退出。
实际结果
导出运行并产生以下输出。从 cli 运行导出不会以错误代码退出。
# Created 2020-12-21 Mon 10:48
#+TITLE: Test Export
#+AUTHOR: Jens
* No error: works
A shell script without errors works.
#+results:
: This will be exported as result
* Errors are ignored in export
Each of the following errors should stop the export with an error.
** Python Exception
#+results:
** Python Syntax Error
#+results:
** Shell Exit Code 1
#+results:
环境
- Linux
-
org-version
9.5 - GNU Emacs 27.1(内部版本 1,x86_64-pc-linux-gnu,GTK+ 版本 3.24.23,开罗版本 1.16.0)
我尝试了什么
- 阅读文档(Exporting、org-babel ref card)
- 探究
lisp
代码(但不多) - 谷歌
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)