How do I prevent org-mode from executing all of the babel source blocks?

天大地大妈咪最大 提交于 2019-12-03 12:29:53

问题


I have an org file with lots of babel source blocks in it that only need to be re-executed when the code is changed.

How do I prevent org from executing all of the blocks during export? In other words, set them all to manual execution only?

I would prefer a single global option rather than having to edit each block individually.


回答1:


The variable org-export-babel-evaluate, if set to nil, will prevent any code from being evaluated as part of the export process. This way, only the results inserted by way of manual execution will be exported.

You can define it, and others, as a file variable by placing the following comment line at the top of your org file:

# -*- org-export-babel-evaluate: nil -*-




回答2:


You can set the cache to yes (see http://orgmode.org/manual/cache.html). This can also be set a property line in the file to act globally. #+Property: header-args :cache yes just make sure to C-c C-c on that line to activate the property.




回答3:


Setting the variable org-export-babel-evaluate to nil will avoid code evaluation, but it will also cause all source block header arguments to be ignored This means that code blocks with the argument :exports none or :exports results will end up in the export. This caught me off guard.

The alternative is to use the header argument :eval never-export on a file basis and then remove that line when re-running the source code:

#+PROPERTY: header-args :eval never-export

See the docstring for org-babel-evaluate:

Switch controlling code evaluation and header processing during export. When set to nil no code will be evaluated as part of the export process and no header arguments will be obeyed. Users who wish to avoid evaluating code on export should use the header argument ‘:eval never-export’.




回答4:


After placing the following:

# -*- org-export-use-babel: nil;-*-

at the top of the file, and executing C-c C-c, It didn't work for me. The variable's value is not set accordingly.

But the following:

#+BIND: org-export-use-babel nil

with an application of C-c C-c works as expected.

I found the answer here: http://joelmccracken.github.io/entries/org-mode-specifying-document-variables-and-keywords/

There are probably some changes in emacs 25, which I'm using.



来源:https://stackoverflow.com/questions/29952543/how-do-i-prevent-org-mode-from-executing-all-of-the-babel-source-blocks

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!