Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-17 Thread Ihor Radchenko
Gerard Vermeulen  writes:

>> (setq org-babel-default-header-args:text '((:eval . "no")))
>> 
>> to your config.
>
> Is it possible to make org-lint recognize those settings?
>
> I have the kludge
>
> (defun org-babel-execute:text (_body _params)
>"NO-OP to silence warnings." nil)
>
> in my config to silence "Unknown source block language" warnings.

You can hide all the warnings from a certain checker by pressing "i" in
the org-lint report.

If necessary, we may add some customizations to org-lint that will allow
customizing which checkers to use.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-17 Thread Gerard Vermeulen




On 16.03.2024 12:48, Ihor Radchenko wrote:


Yes. You can add

#+property: header-args:text :eval no

on top of your Org file or add

(setq org-babel-default-header-args:text '((:eval . "no")))

to your config.


Is it possible to make org-lint recognize those settings?

I have the kludge

(defun org-babel-execute:text (_body _params)
  "NO-OP to silence warnings." nil)

in my config to silence "Unknown source block language" warnings.

Regards -- Gerard




Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-16 Thread Damien Cassou
Ihor Radchenko  writes:
> Yes. You can add
> #+property: header-args:text :eval no
> on top of your Org file or add
> (setq org-babel-default-header-args:text '((:eval . "no")))
> to your config.

org is amazing!

Thank you very much for all your work.

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-16 Thread Ihor Radchenko
Damien Cassou  writes:

> If I understand correctly, you are saying that it is better to let the
> command crash as soon as possible instead of letting it execute
> potentially problematic code because some previous block has not been
> executed. I think it makes perfect sense. I'm now convinced that my
> patch is not desirable. Feel free to close the issue.

Yup, you understand correctly.
Although, we previously discussed a similar issue with bibtex
blocks in https://list.orgmode.org/87ilvnx29d@kyleam.com/, but the
proposed approach to solve the issue was different.

> Just because I didn't know it exists. Thank you for telling me. I have
> now added it to all my code blocks generating non-executable results
> using the :wrap keyword like this:
>
> #+name: show-tree
> #+begin_src sh :exports both :results output drawer :tangle yes :wrap 
> "SRC text :eval no"
> echo foo
> #+end_src
> 
> #+RESULTS: show-tree
> #+begin_SRC text :eval no
> foo
> #+end_SRC
>
> It works very well, thanks! Would you say this is how you would have
> done it as well or is there a better way?

Yes. You can add

#+property: header-args:text :eval no

on top of your Org file or add

(setq org-babel-default-header-args:text '((:eval . "no")))

to your config.

See https://orgmode.org/manual/Using-Header-Arguments.html

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-16 Thread Damien Cassou
Hi Ihor,

Ihor Radchenko  writes:
> For example, consider
>
> #+begin_src bash
> mkdir foo
> #+end_src
>
> #+begin_src emacs-lisp
> (write-file "foo/result")
> #+end_src
>
> The second block relies upon side effects of the first block.
> However, if ob-shell is not loaded, with your patch, the side effect
> will not happen.  One can construct more nasty examples when not
> executing prior block leads to unexpected or even damaging results.


If I understand correctly, you are saying that it is better to let the
command crash as soon as possible instead of letting it execute
potentially problematic code because some previous block has not been
executed. I think it makes perfect sense. I'm now convinced that my
patch is not desirable. Feel free to close the issue.


> Why not simply adding :eval no header argument?


Just because I didn't know it exists. Thank you for telling me. I have
now added it to all my code blocks generating non-executable results
using the :wrap keyword like this:

#+name: show-tree
#+begin_src sh :exports both :results output drawer :tangle yes :wrap "SRC 
text :eval no"
echo foo
#+end_src

#+RESULTS: show-tree
#+begin_SRC text :eval no
foo
#+end_SRC

It works very well, thanks! Would you say this is how you would have
done it as well or is there a better way?

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-12 Thread Ihor Radchenko
Damien Cassou  writes:

> Ihor Radchenko  writes:
>> Thanks for the patch, but it is not obvious that skipping src blocks
>> that cannot be executed is always a good idea.  Consider, for example,
>> that some blocks are used as input for other blocks. Then, failing to
>> execute them means that other blocks may have unpredictable side
>> effects.
>
>
> I don't understand your position. Without this patch, executing
> `org-babel-execute-buffer' will just crash if a block can't be
> executed. What problem can skipping those could cause?

For example, consider

#+begin_src bash
mkdir foo
#+end_src

#+begin_src emacs-lisp
(write-file "foo/result")
#+end_src

The second block relies upon side effects of the first block.
However, if ob-shell is not loaded, with your patch, the side effect
will not happen.

One can construct more nasty examples when not executing prior block
leads to unexpected or even damaging results.

>> May you please provide a concrete use-case when skipping some src code
>> blocks is desired?
>
> I use text-mode blocks to represent output of bash scripts as in:
>
> #+name: repo-test-check
> #+begin_src sh :exports both :results output raw :wrap SRC text
>   git log --oneline
> #+end_src
> 
> #+RESULTS: repo-test-check
> #+begin_SRC text
> cfd2b (HEAD -> main) Empty
> #+end_SRC
>
> The second block can't be executed because no
> `org-babel-execute:text` function exists.

Why not simply adding :eval no header argument?

The problem with testing that `org-babel-execute:' function exists
is that we cannot distinguish between languages that cannot and should
not be executed and babel backends that are not loaded for some reason.

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-12 Thread Damien Cassou
Hi Ihor,

Ihor Radchenko  writes:
> Thanks for the patch, but it is not obvious that skipping src blocks
> that cannot be executed is always a good idea.  Consider, for example,
> that some blocks are used as input for other blocks. Then, failing to
> execute them means that other blocks may have unpredictable side
> effects.


I don't understand your position. Without this patch, executing
`org-babel-execute-buffer' will just crash if a block can't be
executed. What problem can skipping those could cause?


> May you please provide a concrete use-case when skipping some src code
> blocks is desired?

I use text-mode blocks to represent output of bash scripts as in:

#+name: repo-test-check
#+begin_src sh :exports both :results output raw :wrap SRC text
  git log --oneline
#+end_src

#+RESULTS: repo-test-check
#+begin_SRC text
cfd2b (HEAD -> main) Empty
#+end_SRC

The second block can't be executed because no
`org-babel-execute:text` function exists.

Best

-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill



Re: [BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-12 Thread Ihor Radchenko
Damien Cassou  writes:

> The command `org-babel-execute-buffer' tries to execute all source code
> blocks of the current buffer. When it encounters a block that is not
> executable the command crashes. The attached patch makes the command ignore
> non-executable blocks and move on.
> ...
> -(org-babel-execute-src-block arg)
> +(let* ((info (org-babel-get-src-block-info))
> +   (lang (nth 0 info))
> +   (cmd (intern (concat "org-babel-execute:" lang
> +  (when (fboundp cmd)
> +(org-babel-execute-src-block arg)))

Thanks for the patch, but it is not obvious that skipping src blocks
that cannot be executed is always a good idea.
Consider, for example, that some blocks are used as input for other
blocks. Then, failing to execute them means that other blocks may have
unpredictable side effects.

May you please provide a concrete use-case when skipping some src code
blocks is desired?

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[BUG] [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks [9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)]

2024-03-08 Thread Damien Cassou


Remember to cover the basics, that is, what you expected to happen and
what in fact did happen.  You don't know how to make a good report?  See

 https://orgmode.org/manual/Feedback.html#Feedback

Your bug report will be posted to the Org mailing list.


The command `org-babel-execute-buffer' tries to execute all source code
blocks of the current buffer. When it encounters a block that is not
executable the command crashes. The attached patch makes the command ignore
non-executable blocks and move on.

Emacs  : GNU Emacs 29.2 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.41, 
cairo version 1.18.0)
Package: Org mode version 9.6.20 ( @ /home/cassou/.emacs.d/lib/org/lisp/)
-- 
Damien Cassou

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill
>From 0879a7f4b855465a9cb1532293726a9a3d7d7c75 Mon Sep 17 00:00:00 2001
From: Damien Cassou 
Date: Sat, 9 Mar 2024 08:35:44 +0100
Subject: [PATCH] org-babel-execute-buffer: Prevent executing non-code blocks

* lisp/ob-core.el (org-babel-execute-buffer): Guard against evaluating
non-code blocks.
---
 lisp/ob-core.el | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index bfeac257b..ca7afcdc5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -1417,7 +1417,11 @@ (defun org-babel-execute-buffer ( arg)
   (if (org-element-type-p
(org-element-context) '(babel-call inline-babel-call))
   (org-babel-lob-execute-maybe)
-(org-babel-execute-src-block arg)
+(let* ((info (org-babel-get-src-block-info))
+   (lang (nth 0 info))
+   (cmd (intern (concat "org-babel-execute:" lang
+  (when (fboundp cmd)
+(org-babel-execute-src-block arg)))
 
 ;;;###autoload
 (defun org-babel-execute-subtree ( arg)
-- 
2.43.1