21

I have an org document that contains a lot of source code snippets in it. I want the results of the code to be exported when exporting to Html. On export Emacs asks me if I want to evaluate the code block on my system once for every bit of source code. This is a lot of questions.

Is there any way to stop Emacs for asking for confirmation every time?

The exact message is

"Evaluate this goban code block on your system? (y or n)"

Note goban is the babel language I am exporting. (It is actually an image of a go board).

0

1 Answer 1

23

org-confirm-babel-evaluate can be set to nil to disable confirmation.

From the documentation:

Source code blocks

Source code blocks can be evaluated during export, or when pressing ‘C-c C-c’ in the block. The most important thing to realize here is that Org mode files which contain code snippets are, in a certain sense, like executable files. So you should accept them and load them into Emacs only from trusted sources—just like you would do with a program you install on your computer.

Make sure you know what you are doing before customizing the variables which take off the default security brakes.

-- User Option: org-confirm-babel-evaluate
      When t (the default), the user is asked before every code
      block evaluation.  When ‘nil’, the user is not asked.  When
      set to a function, it is called with two arguments (language
      and body of the code block) and should return t to ask and
      ‘nil’ not to ask.

As suggested by @Emmanuel Goldstein, the :eval header argument can be used for finer control. It can be set to refuse evaluation, ask confirmation, directly evaluate, for each source block.

From the documentation:

The :eval header argument can limit evaluation of specific code blocks. It is useful for protection against evaluating untrusted src code blocks by prompting for a confirmation. This protection is independent of the ‘org-confirm-babel-evaluate’ setting.

  • ‘never or no’ Org will never evaluate this ‘src’ code block.
  • ‘query’ Org prompts the user for permission to evaluate this ‘src’ code block.
  • ‘never-export or no-export’ Org will not evaluate this ‘src’ code block when exporting, yet the user can evaluate this source block interactively.
  • ‘query-export’ Org prompts the user for permission to export this ‘src’ code block.

If :eval header argument is not set for a source block, then Org determines whether to evaluate from the org-confirm-babel-evaluate variable.

8
  • Will this be the same as using eval never-export on the header line of the code? Commented May 22, 2020 at 5:20
  • I don't know what it's supposed to do. Do you have a pointer to documentation?
    – JeanPierre
    Commented May 22, 2020 at 20:03
  • @EmmanuelGoldstein never-export will refuse to evaluate when exporting, while setting org-confirm-babel-evaluate to nil will do it without asking for confirmation.
    – JeanPierre
    Commented May 26, 2020 at 13:42
  • Thanks. All clear now. Commented May 27, 2020 at 2:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.