emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* per-file (or, really, per buffer) allowing/disallowing code block execution
@ 2022-09-05 23:50 Fedja Beader
  2022-09-06 13:33 ` Ihor Radchenko
  2022-09-06 19:05 ` Greg Minshall
  0 siblings, 2 replies; 20+ messages in thread
From: Fedja Beader @ 2022-09-05 23:50 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

Hello,

Pressing C-c C-c in a code block asks the user whether to
execute that code block or not. This soon becomes annoying.
To remedy this, org-mode provides us the variable
org-confirm-babel-evaluate. But this is not very user friendly.

Additionally, as per documentation, this variable only controls
whether org-mode (babel? Forgive me, I am sort of a new user of
Emacs) will execute the code block without asking, or ask.

What I would like to have, to safely and easily use org-mode
as an interactive notebook, is to not have to overload this
function and to be asked only once per buffer/file whether to:
1) Unconditionally allow executing all code blocks
2) Unconditionally disallow executing all code blocks
3) Ask for every block.

Particularly the second case is the one that cannot be
supported by simply defining org-confirm-babel-evaluate.

This is what I cooked up as a solution, with help and advice
from Ian Eure:


#+BEGIN_SRC elisp
(defvar-local org-babel-code-execute-mode nil)

(defun org-babel-check-confirm-evaluate-wrapper (orig-fun &rest args)
  (pcase org-babel-code-execute-mode
    ("always" t)
    ("never" nil)
    ("query" (apply orig-fun args))
    (- (progn
         (setq
           org-babel-code-execute-mode
           (completing-read ; can also return ""
             "Allow execution of code blocks in this buffer (always, never, query)?"
             '(always never query)
             nil ; predicate
             t ; require match to one of the three options
           )
         )
         (apply orig-fun args)
       )
    )
  )
)

(advice-add 'org-babel-check-confirm-evaluate :around #'org-babel-check-confirm-evaluate-wrapper)
#+END_SRC

I would like this functionality to become part of org-mode
in the future.

Sincerely,
Fedja


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2022-09-23  2:32 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-05 23:50 per-file (or, really, per buffer) allowing/disallowing code block execution Fedja Beader
2022-09-06 13:33 ` Ihor Radchenko
2022-09-06 19:05 ` Greg Minshall
2022-09-07  0:17   ` Steven Harris
2022-09-07  8:49     ` Greg Minshall
2022-09-08  5:53   ` Ihor Radchenko
2022-09-08 12:34     ` Fedja Beader
2022-09-08 17:41       ` tomas
2022-09-09  5:50       ` Ihor Radchenko
2022-09-10  0:19         ` Fedja Beader
2022-09-11  9:10           ` Ihor Radchenko
2022-09-12 13:56             ` Greg Minshall
2022-09-12 20:38               ` Tim Cross
2022-09-13  4:47                 ` Greg Minshall
2022-09-19 18:25               ` Rudolf Adamkovič
2022-09-19 19:28                 ` Greg Minshall
2022-09-21 20:56                   ` Rudolf Adamkovič
2022-09-22 14:17                     ` Max Nikulin
2022-09-23  2:31                       ` Ihor Radchenko
2022-09-19  9:23             ` Fraga, Eric

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).