Re: Executing Org Code Block w/o Confirmation?
John W Higgins <[email protected]> Mon, 20 Jul 2026 21:14:14 -0700
| Newsgroups | gmane.emacs.help |
|---|---|
| Message-ID | <CAPhAwGz_fbHo4Rrf60ij-U=4GX3StcKB_w5aKLDCfm-vB55Qaw@mail.gmail.com> |
On Mon, Jul 20, 2026 at 7:58=E2=80=AFPM Brendan Leber <brendan@brendanleber=
.com>
wrote:
> Greetings!
>
> Generally I want confirmation before executing code blocks in org-mode
> files. However, there are
> some that are non-destructive and I would like those to just execute.
> Reading the manual and info
> pages it seems I can disable confirmation for executing every code block,
> or disable confirmation on
> a language by language basis. Is there a way to disable the confirmation
> for a block like shown
> below?
>
> #+begin_src sh :eval yes
> curl --insecure --silent -X 'GET' \
> 'https://10.10.11.154/api/v1/foo/bar' \
> -H 'accept: application/json' \
> -H 'Authorization: apikey=3Dsekrit'
> #+end_src
>
>
I was just working on something like this myself yesterday - it's probably
on the ugly side - but this is what I use for stopping certain sql
statements from auto-running while allowing "safe: true" as an override -
obviously you would replace safe with eval
(defun my-org-confirm-babel-evaluate (lang body)
"Respect safe: header for confirmation."
(let* ((info (org-babel-get-src-block-info 'light))
(headers (nth 2 info))
(safe (alist-get 'safe: headers)))
(cond
;; If :safe is "true", respect it
((string=3D "true" safe) nil)
;; For SQL: confirm only for dangerous commands
((string=3D lang "sql")
(string-match-p
(regexp-opt '("DROP" "DELETE" "UPDATE" "ALTER" "CREATE" "INSERT"
"TRUNCATE") 'words)
(upcase body)))
;; For other languages: always confirm
(t t)
)))
(setq org-confirm-babel-evaluate 'my-org-confirm-babel-evaluate)