Re: [BUG] obscure error for invalid :exports

2024-03-12 Thread Ihor Radchenko
Max Nikulin  writes:

>> See the attached tentative patch.
>
> Thanks, Ihor. With this patch applied, behavior is improved.

Applied, onto main.
Fixed.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=f08174a45

> Notice however that the *Warnings* buffer may be hidden by export result 
> (e.g. when export to buffer is chosen in the dispatcher).
>
> Almost certainly you already know my opinion (see example of a message 
> link below) that ideally export warnings should be collected with line 
> numbers to a buffer having compilation-minor-mode. Of course, I do not 
> expect that this feature will be implemented as a part of a fix for this 
> bug.

Yes, a better export diagnostics interface (maybe similar to org-lint)
would be nice to have.

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



Re: [BUG] obscure error for invalid :exports

2024-03-10 Thread Max Nikulin

On 08/03/2024 16:46, Ihor Radchenko wrote:

Max Nikulin writes:

Trying to export (to HTML buffer)
  src_elisp[:exports source]{a}
I have got an obscure error
  org-export-as: Wrong type argument: char-or-string-p, nil


See the attached tentative patch.


Thanks, Ihor. With this patch applied, behavior is improved.

Notice however that the *Warnings* buffer may be hidden by export result 
(e.g. when export to buffer is chosen in the dispatcher).


Almost certainly you already know my opinion (see example of a message 
link below) that ideally export warnings should be collected with line 
numbers to a buffer having compilation-minor-mode. Of course, I do not 
expect that this feature will be implemented as a part of a fix for this 
bug.


Max Nikulin. Re: [Syntax discussion] Should we treat src blocks without 
LANG as paragraphs? Sat, 17 Dec 2022 21:47:18 +0700. 
https://list.orgmode.org/tnkkpn$11am$1...@ciao.gmane.io






Re: [BUG] obscure error for invalid :exports

2024-03-08 Thread Ihor Radchenko
Max Nikulin  writes:

> Trying to export (to HTML buffer)
>
>  src_elisp[:exports source]{a}
>
> I have got an obscure error
>
>  org-export-as: Wrong type argument: char-or-string-p, nil
>
> I believe, some meaningful error should be signaled.
>
> I was quite surprised since the following is exported with no error
>
>  #+begin_src elisp :exports source
>a
>  #+end_src

Confirmed.

The behavior on unknown value of :exports header arg is undefined.
We may, however, show a warning in such scenario and avoid throwing
cryptic error.
See the attached tentative patch.

>From 8fcf787ca739008118f9834720ee56d6e190401d Mon Sep 17 00:00:00 2001
Message-ID: <8fcf787ca739008118f9834720ee56d6e190401d.1709891167.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Fri, 8 Mar 2024 12:42:33 +0300
Subject: [PATCH] org-export: Display a warning when the value of :exports
 header arg is invalid

* lisp/ob-exp.el (org-babel-exp-do-export): Display warning when
:exports value is not known.  Document nil return value.
(org-babel-exp-process-buffer): Do not remove code block when
`org-babel-exp-do-export' returns nil.

Reported-by: Max Nikulin 
Link: https://orgmode.org/list/usc9jn$g2r$1...@ciao.gmane.io
---
 lisp/ob-exp.el | 70 +++---
 1 file changed, 43 insertions(+), 27 deletions(-)

diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index aa6091924..af726dc2c 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -218,22 +218,27 @@ (defun org-babel-exp-process-buffer ()
 			 (goto-char begin)
 			 (let ((replacement
 (org-babel-exp-do-export info 'inline)))
-			   (if (equal replacement "")
-			   ;; Replacement code is empty: remove
-			   ;; inline source block, including extra
-			   ;; white space that might have been
-			   ;; created when inserting results.
-			   (delete-region begin
-	  (progn (goto-char end)
-		 (skip-chars-forward " \t")
-		 (point)))
-			 ;; Otherwise: remove inline source block
-			 ;; but preserve following white spaces.
-			 ;; Then insert value.
-			 (unless (string= replacement
-	  (buffer-substring begin end))
-			   (delete-region begin end)
-			   (insert replacement))
+			   (cond
+((equal replacement "")
+			 ;; Replacement code is empty: remove
+			 ;; inline source block, including extra
+			 ;; white space that might have been
+			 ;; created when inserting results.
+			 (delete-region begin
+	(progn (goto-char end)
+		   (skip-chars-forward " \t")
+		   (point
+((not replacement)
+ ;; Replacement code cannot be determined.
+ ;; Leave the code block as is.
+ (goto-char end))
+			;; Otherwise: remove inline source block
+			;; but preserve following white spaces.
+			;; Then insert value.
+((not (string= replacement
+	 (buffer-substring begin end)))
+			 (delete-region begin end)
+			 (insert replacement))
 		  ((or `babel-call `inline-babel-call)
 		   (org-babel-exp-do-export
 			(or (org-babel-lob-get-info element)
@@ -249,21 +254,27 @@ (defun org-babel-exp-process-buffer ()
 			 ;; the object/element, including any extra
 			 ;; white space that might have been created
 			 ;; when including results.
-			 (if (equal rep "")
-			 (delete-region
-			  begin
-			  (progn (goto-char end)
- (if (not (eq type 'babel-call))
-	 (progn (skip-chars-forward " \t")
-		(point))
-   (skip-chars-forward " \r\t\n")
-   (line-beginning-position
+			 (cond
+  ((equal rep "")
+			   (delete-region
+			begin
+			(progn (goto-char end)
+   (if (not (eq type 'babel-call))
+   (progn (skip-chars-forward " \t")
+	  (point))
+ (skip-chars-forward " \r\t\n")
+ (line-beginning-position)
+  ((not rep)
+   ;; Replacement code cannot be determined.
+   ;; Leave the code block as is.
+   (goto-char end))
+  (t
 			   ;; Otherwise, preserve trailing
 			   ;; spaces/newlines and then, insert
 			   ;; replacement string.
 			   (goto-char begin)
 			   (delete-region begin end)
-			   (insert rep
+			   (insert rep)
 		  (`src-block
 		   (let ((match-start (copy-marker (match-beginning 0)))
 			 (ind (org-current-text-indentation)))
@@ -335,6 +346,8 @@ (defun org-babel-exp-do-export (info type  hash)
 TYPE is the code block type: `block', `inline', or `lob'.  HASH is the
 result hash.
 
+Return nil when exported content cannot be determined.
+
 The function respects the value of the :exports header argument."
   (let ((silently (lambda () (let ((session (cdr (assq :session (nth 

[BUG] obscure error for invalid :exports

2024-03-07 Thread Max Nikulin

Hi,

Trying to export (to HTML buffer)

src_elisp[:exports source]{a}

I have got an obscure error

org-export-as: Wrong type argument: char-or-string-p, nil

I believe, some meaningful error should be signaled.

I was quite surprised since the following is exported with no error

#+begin_src elisp :exports source
  a
#+end_src

So source blocks are more liberal in respect to user errors.

`org-lint' warns

 2 low   Unknown value "source" for header ":exports"

Reproducible with Org main HEAD and 9.5.5

Of course, it should be

src_elisp[:exports code]{a}

but I was going to test org-element parser on a more tricky input and by 
mistake typed wrong keyword. It took some time to figure that it is not 
a parser error.