[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



Re: [BUG] ob-shell async incorrect table and value results

2024-03-08 Thread Matt


  On Fri, 08 Mar 2024 10:25:09 +0100  Ihor Radchenko  wrote --- 

 > Confirmed.
 > This is because `ob-shell-async-chunk-callback' never returns a list.
 > 
 > In `org-babel-sh-evaluate', there is a part that is responsible for
 > detecting the result type:
 > 
 > (when (and results value-is-exit-status)
 >   (setq results (car (reverse (split-string results "\n" t)
 > (when results
 >   (let ((result-params (cdr (assq :result-params params
 > (org-babel-result-cond result-params
 >   results
 >   (let ((tmp-file (org-babel-temp-file "sh-")))
 > (with-temp-file tmp-file (insert results))
 > (org-babel-import-elisp-from-file tmp-file)
 > 
 > This part is skipped for :async results.
 
Thanks for looking at it.  I'm still working on "[BUG] Prompt appears in async 
shell results" 
(https://list.orgmode.org/18dbc1f273c.11687295c1395973.3345700621594100...@excalamus.com/T/#u)
 and will circle back to this when that's done.

--
Matt Trzcinski
Emacs Org contributor (ob-shell)
Learn more about Org mode at https://orgmode.org
Support Org development at https://liberapay.com/org-mode





ob-haskell and changing executables?

2024-03-08 Thread Laurence von Bottorff
I'm on Debian 12 and I just started using Haskell's ghcup tools, leaving
the stack tools behind, as advised these days. ghcup puts executables for
Haskell such as ghc, ghci (REPL), cabal, etc. in its ~/.ghcup/bin
directory. Next, to stop using the stack tools that have executables in
/usr/bin/ you must change your PATH to go to ~/.ghcup/bin first. But when I
try a Babel code block, ob-haskell seems to have the /usr/bin versions
hardwired somewhere and calls up the old ghci REPL. Searching through Emacs
Customize Haskell was confusing and my init only had one relevant entry
anyway, which didn't help when I changed it.

In the /usr/bin directory the Haskell execs are linked to just one specific
version. In my case /usr/bin contained symbolic links ghc -> ghc-9.0.2 and
ghci -> ghci-9.0.2. This is not great, since Haskell in the wild is
project-based, i.e., differing versions of the ghc compiler can be used in
different projects, as well as wildly diverging libraries and packages per
project. Obviously Babel can't easily take advantage of this, but Haskell
does allow "system-wide" library installs.

My solution was to simply delete the symlinks in /usr/bin and create new
ones to the ghcup tools, e.g., ghc -> ~/.ghcup/bin/ghc etc. So now it works
properly and calls up the new ghcup ghci when I do a Haskell Babel block,
but this is a kludge. No elisp master, I can't find where this /usr/bin
address is hardwired. If you've gotten this far you probably know more
about the Haskell Babel situation than you ever wanted to, but maybe you
can sniff out where this hardwire is happening.

-- 
⨽
Lawrence Bottorff
Grand Marais, MN, USA
borg...@gmail.com


Re: [BUG] Org-Agenda leaves frame around [9.7-pre (release_9.6.8-785-g72bbf8.dirty @ /home/bidar/.local/private/etc/emacs/lib/org/lisp/)]

2024-03-08 Thread Björn Bidar
Ihor Radchenko  writes:

> Ihor Radchenko  writes:
>
>>> 0. emacs -Q
>>> 1. Paste this into the scratch buffer:
>>> (setq org-agenda-window-setup 'other-frame)
>>> (setq pop-up-frames t)
>>> 2. Eval
>>> 3. Org-agenda
>>
>> This is now expected.
>> We changed Org agenda to respect user settings, including
>> `pop-up-frames' setting.
>> ...
>
> Oops. I missed that the problem is not with a new frame with agenda
> commands, but with the frame not being closed.
>
> Fixed, on main.
> https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=fef873b1c

I noticed that `org-insert-structure-template' and possibly others are
also affected

Is a new bug needed or this one enough?



Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Juan Manuel Macías
Juan Manuel Macías  escribió:

> Ok, I think you and Maxim are right. This is a clear bug. I hope it
> was fixed in the last commit.

Now:

  (org-export-string-as "Alpha@Beta{" 'latex t))

==> Alpha@Beta\{

  (org-export-string-as "Alpha@Beta{gamma}" 'latex t))

==> Alpha\Beta{gamma}

--
Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño 
editorial y ortotipografía



Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Juan Manuel Macías
Ihor Radchenko writes:

> Juan Manuel Macías  writes:
>
>>>   Debugger entered--Lisp error: (wrong-type-argument
>>>   number-or-marker-p nil)
>>
>> Maybe in that case you could add a zero width space character.
>>
>> In any case, if someone has reasons to write "Alpha@Beta{" they may also
>> have reasons to write "Alpha_Beta":
>
> 1. Parser must not throw errors on text files. Ever. Any text file is a
>valid Org file.
> 2. We should demand paired {...}, as we do for latex fragments,
>emphasis, inline export snippets, and all other container objects.

Ok, I think you and Maxim are right. This is a clear bug. I hope it
was fixed in the last commit.


-- 
Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño 
editorial y ortotipografía




Re: Subject: cannot export asynchronously because of org-fold-core--update-buffer-folds

2024-03-08 Thread Pedro Andres Aranda Gutierrez
Hi,

I’m very interested on how your document header looks like. Can you please send 
mee a file with your header
and a couple of dummy slides? I’m not able to reproduce the problem…

Thx, /PA


> El 7 mar 2024, a las 10:42, Alan Schmitt  
> escribió:
> 
> Hi Pedro,
> 
> On 2024-03-07 10:03, Pedro Andres Aranda Gutierrez  writes:
> 
>> could you please try to add
>> 
>> #+LATEX_CLASS: beamer
>> #+LATEX_CLASS_OPTIONS: [presentation,aspectratio=169]
>> 
>> instead of
>> 
>> (require 'ox-latex)
>> 
>> (add-to-list 'org-latex-classes
>> '("my-beamer"
>>   "\\documentclass\[presentation,aspectratio=169\]\{beamer\}
>> [NO-DEFAULT-PACKAGES]"
>>   ("\\section\{%s\}" . "\\section*\{%s\}")
>>   ("\\subsection\{%s\}" . "\\subsection*\{%s\}")
>>   ("\\subsubsection\{%s\}" . "\\subsubsection*\{%s\}")))
>> 
>> and see if that makes any difference?
> 
> Thank you for the suggestion. I tried this and it does not help, I have
> the same error. I do not know how to debug it since the error happens in
> compiled code whose origin is not given…
> 
> The surprising part is that the problematic function was introduced very
> recently
> (https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=87c9f9b5db2e14fe0c5254105b7b90b01bbf8d61)
> but it seems to be used in the asynchronous export that does not load
> any package, so there I should be using the orgmode version shipped with
> emacs…
> 
> Alan




Re: naming: Re: Experimental public branch for inline special blocks

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

> Ihor, I see you intention, however I reserve my vote for some new unique 
> word, preferably a single one.

That's fine. I do not insist on my preferences about naming. Rather see
it as a minor issue that can be resolved at any moment after we
implement the functionality. Maybe using a proper poll.

Let's register that we have some disagreement here. To be resolved
before we finalize things.

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



Re: naming: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Max Nikulin

On 08/03/2024 12:26, Samuel Wales wrote:

cannot follow discussion but is the role and scope of the proposed
semantics settled and agreed upon by those who do?


I think, there are enough issues with the proposed feature to discuss. 
Notice "naming" added to the message subject with hope to facilitate 
tracking of specific aspects.


Ihor, I see you intention, however I reserve my vote for some new unique 
word, preferably a single one.






Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Ihor Radchenko
Juan Manuel Macías  writes:

>>   Debugger entered--Lisp error: (wrong-type-argument
>>   number-or-marker-p nil)
>
> Maybe in that case you could add a zero width space character.
>
> In any case, if someone has reasons to write "Alpha@Beta{" they may also
> have reasons to write "Alpha_Beta":

1. Parser must not throw errors on text files. Ever. Any text file is a
   valid Org file.
2. We should demand paired {...}, as we do for latex fragments,
   emphasis, inline export snippets, and all other container objects.

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



Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Max Nikulin

On 08/03/2024 22:44, Juan Manuel Macías wrote:

Max Nikulin writes:


   (org-export-string-as "Alpha@Beta{"
   'html
   '(:export-options (body-only)))
   "\nAlpha{\n"

   (org-export-string-as "Alpha@Beta["
   'html
   '(:export-options (body-only)))
   Debugger entered--Lisp error: (wrong-type-argument
   number-or-marker-p nil)


Maybe in that case you could add a zero width space character.

In any case, if someone has reasons to write "Alpha@Beta{" they may also
have reasons to write "Alpha_Beta":

(org-export-string-as "Alpha_beta"
   'html
   '(:export-options (body-only)))

Alphabeta


From my point of view it is a pitfall with Org syntax, but parser works 
as it should.


On the other hand if there is no closing bracket then it is not an 
inline special block, so this part of document should be considered as 
text (unless some other objects are recognized).


Currently Org parser does not signal errors even for invalid input.




Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Juan Manuel Macías
Max Nikulin writes:

>   (org-export-string-as "Alpha@Beta{"
>   'html
>   '(:export-options (body-only)))
>   "\nAlpha{\n"
>
>   (org-export-string-as "Alpha@Beta["
>   'html
>   '(:export-options (body-only)))
>   Debugger entered--Lisp error: (wrong-type-argument
>   number-or-marker-p nil)

Maybe in that case you could add a zero width space character.

In any case, if someone has reasons to write "Alpha@Beta{" they may also
have reasons to write "Alpha_Beta":

(org-export-string-as "Alpha_beta"
  'html
  '(:export-options (body-only)))


Alphabeta


-- 
Juan Manuel Macías -- Composición tipográfica, tratamiento de datos, diseño 
editorial y ortotipografía




Re: [DISCUSSION] Add "Recent News" to orgmode.org

2024-03-08 Thread Bastien Guerry
Ihor Radchenko  writes:

> Something like the attached maybe.

Thanks! Applied: https://git.sr.ht/~bzg/woof/commit/177ea5b1

-- 
 Bastien Guerry



Re: Pending contents in org documents (Re: Asynchronous blocks for everything (was Re: ...))

2024-03-08 Thread Bruno Barbier


Hi Ihor,

Ihor Radchenko  writes:

> Thanks!
> I have some minor concerns about implementation, but you clearly
> demonstrated the things can be working in general.

Thanks!

> While reading the library header and `org-pending' docstring (btw, it
> should probably be a separate library, not a part of org-macs),

I was feeling more and more like squatting the wrong file :-)

Would "lisp/org-pending.el" be OK ?  Or do you see a better place/name ?


> I felt confused about terminology and also had déjà vu's about what
> org-pending does.

> More or less, org-pending implements Elisp asynchronous process control,
> but the processes are associated with region, not the whole buffer.
> Hence, I feel that we should adopt terminology similar to the existing
> terminology for processes - process filters, process sentinels, sending
> signals to processes, etc. And similar API.

The current `org-pending' doesn't know what a process is, or a thread.
The job of org-pending is only to let Emacs know that a given region
will be updated at some point later (much like what
`org-edit-src-code' does, when a source block is being edited
manually).

I've re-read the Elisp manual about asynchronous processes.  The only
thing that seemed obvious to me, was to replace "feedbacks-handler"
with "sentinel".  I also tried to simplify things and use REGION
instead of CONTENT where it make sense.  Thanks.

Do you see something else ?



> Also, I am not sure if I like the idea of exposing raw PINFO alist and
> mutating it. In particular, I have doubts about mutating CONTENT.
> What we might do instead is implement PINFO as struct with custom
> accessors/setters.

I went for this simple alist because it's more flexible (easy to add new
bindings) and less code than using a struct.  And Org already uses lists
like this (params, info, etc.).  Mutating CONTENT (or other essential
data) would be a very bad idea indeed; but it's like that for pretty
much everything with elisp.

I'm OK to rewrite it using a cl-defstruct (to be honnest, I just
flipped a coin to decide between a struct or an alist :) ).

I'll push my new version after relocating everything into its own
file. Let me know if lisp/org-pending.el is OK.

Thanks.

Bruno



Re: false positives: Re: Experimental public branch for inline special blocks

2024-03-08 Thread Max Nikulin

On 08/03/2024 01:21, Juan Manuel Macías wrote:

Ihor Radchenko escribió:


I am wondering if @@[...]{...} would be better than @_...
It should be slightly easier to type.


Anyway, in the last commit I replaced _ with @. Let's see how it goes...
Now the anonymous variant is @@[...]{...}.


Unfortunately the issue, I have reported, has not fixed. I admit, the 
examples have become more contrived


  (org-export-string-as "Alpha@Beta{"
  'html
  '(:export-options (body-only)))
  "\nAlpha{\n"

  (org-export-string-as "Alpha@Beta["
  'html
  '(:export-options (body-only)))
  Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p 
nil)





Re: Emacs slow-down

2024-03-08 Thread Fraga, Eric
On Friday,  8 Mar 2024 at 07:54, Pedro Andres Aranda Gutierrez wrote:
> In this case, one of the root causes for my insufferable
> slowdown was not org-mode but jinx (the spell checker). 

I turned jinx off as well.  The other culprit, for me, was wc-mode.  I
now count words explicitly when needed and use flyspell-buffer also
manually.

But I still see some lagging every now and again and keep
investigating...

-- 
: Eric S Fraga, with org release_9.6.19-1215-g67d937 in Emacs 30.0.50


Re: Warn about shell-expansion in the docstring of org-latex-to-html-convert-command

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

>>> It should be more reliable to pass fragment to command stdin. It can be
>>> done if %i is missed in `org-latex-to-html-convert-command'.
>> 
>> I agree that it will be more reliable to shell-escape argument.
>> However, I am concerned that escaping may break certain uses like
>> 
>> somecommand << EOF
>> %i
>> EOF
>> 
>> In the above scenario, escaping will break things.
>
> It is unsafe to use such command. Variable expansion, etc. is performed 
> inside here document blocks. Try
>
> cat << EOF
> \[f(i), \text{where $i \ne 10$}\]
> EOF

I did non know this. Thanks for the info.

> That is why I proposed to use stdin in the case of missed %i.
>
> `org-latex-to-html-convert-command' should be set to something like
> "latexmlc --profile=math --preload=siunitx.sty - 2>/dev/null"
> this case.

I decided not to introduce stdin. User can always use echo %i | ... instead.

>> That's why I prefer to add a new replacement, not change the meaning of
>> %i. We might even remove %i from the docstring, keeping support in the
>> code for backwards-compatibility.
>
> What you calls backward compatibility is actually a means to get strange 
> results in the case of complex math. It is better to force users to 
> update configuration (I hope, it actually will not be necessary) and to 
> ensure safe command without pitfalls related to missed parts of equations.

Agree.
This breaking change cannot be avoided, unfortunately.
Even stripping quotes is unreliable when we use the example from
docstring: 'literal:%i'. So, we have to bite the bullet.

>> test2.html is rendered *incorrectly* as in the attached screenshot.
>
> Looks like missed  inside 
> ...

Exporting Org document using

(setq org-html-with-latex 'html)
(setq org-latex-to-html-convert-command "latexmlc 'literal:%i' --profile=math 
--preload=siunitx.sty 2>/dev/null")

renders just fine, so these caveats appear to be terminal-specific. Not
our problem.

Attaching tentative patch that fixes the problem.

>From 34e5e14260cf895b32f13ed8f4c2e50684f91baf Mon Sep 17 00:00:00 2001
Message-ID: <34e5e14260cf895b32f13ed8f4c2e50684f91baf.1709896570.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Fri, 8 Mar 2024 14:05:12 +0300
Subject: [PATCH] org-latex-to-mathml/html-convert-command: Prevent shell
 expansion

* lisp/org.el (org-create-math-formula):
(org-format-latex-as-html): Shell-quote LaTeX fragment text when
replacing %i placeholder.  This prevents shell expansion of
$... and similar constructs inside the code.
(org-latex-to-mathml-convert-command):
(org-latex-to-html-convert-command): Update the docstring.
* etc/ORG-NEWS (~org-latex-to-mathml-convert-command~ and
~org-latex-to-html-convert-command~ shell-escape LaTeX code): Announce
the breaking change.

Reported-by: Max Nikulin 
Link: https://orgmode.org/list/735645dd-1ddf-4579-a6dd-2700f3e83...@gmail.com
---
 etc/ORG-NEWS | 10 ++
 lisp/org.el  | 17 ++---
 2 files changed, 16 insertions(+), 11 deletions(-)

diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS
index abe62daaf..9f628bc10 100644
--- a/etc/ORG-NEWS
+++ b/etc/ORG-NEWS
@@ -13,6 +13,16 @@ Please send Org bug reports to mailto:emacs-orgmode@gnu.org.
 
 * Version 9.7 (not released yet)
 ** Important announcements and breaking changes
+*** ~org-latex-to-mathml-convert-command~ and ~org-latex-to-html-convert-command~ shell-escape LaTeX code
+
+Previously, ~org-latex-to-mathml-convert-command~ and
+~org-latex-to-html-convert-command~ replaced %i placeholders with raw
+LaTeX fragment text, potentially triggered shell-expansion.
+
+Now, the %i placeholders are shell-escaped to prevent shell expansion - this will prevent.
+
+The existing customizations that assume no shell-escaping must be updated.
+
 *** When ~org-link-file-path-type~ is a function, its argument is now a filename as it is read by ~org-insert-link~; not an absolute path
 
 Previously, when ~org-link-file-path-type~ is set to a function, the
diff --git a/lisp/org.el b/lisp/org.el
index 33d90506b..a00d50c51 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -3246,7 +3246,7 @@ (defcustom org-latex-to-mathml-convert-command nil
 %j: Executable file in fully expanded form as specified by
 `org-latex-to-mathml-jar-file'.
 %I: Input LaTeX file in fully expanded form.
-%i: The latex fragment to be converted.
+%i: Shell-escaped LaTeX fragment to be converted.
 %o: Output MathML file.
 
 This command is used by `org-create-math-formula'.
@@ -3255,7 +3255,7 @@ (defcustom org-latex-to-mathml-convert-command nil
 \"java -jar %j -unicode -force -df %o %I\".
 
 When using LaTeXML set this option to
-\"latexmlmath \"%i\" --presentationmathml=%o\"."
+\"latexmlmath %i --presentationmathml=%o\"."
   :group 'org-latex
   :version "24.1"
   :type '(choice
@@ -3268,15 +3268,10 @@ (defcustom org-latex-to-html-convert-command nil
 directly replace the LaTeX fragment in the resulting HTML.
 Replace format-specifiers in the command as noted below and use
 

Re: Provide sane default for the @direntry

2024-03-08 Thread Ihor Radchenko
Stefan Monnier  writes:

> I fixed those three issues (I still get test failures, but I get the
> same with or without my patch ).

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

If you are getting failures on make test, please report them.
There should not be any, normally.

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



Re: [DISCUSSION] Add "Recent News" to orgmode.org

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

> +;; Display the latest first.
> +resources (reverse (sort resources))

* (sort-by :date resources)

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



Re: [DISCUSSION] Add "Recent News" to orgmode.org

2024-03-08 Thread Ihor Radchenko
Bastien Guerry  writes:

>> Also, it looks like https://tracker.orgmode.org/index.org does not sort
>> links by date. It would be nice if top 5 links were also the most recent.
>
> Yes, indeed. I'll see when I can hack on this. Help from Clojure
> hackers is welcome here: https://git.sr.ht/~bzg/woof

Something like the attached maybe.

>From 2e170f073ae258d27680baf16f8db1aa2dcf9b78 Mon Sep 17 00:00:00 2001
Message-ID: <2e170f073ae258d27680baf16f8db1aa2dcf9b78.1709893748.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Fri, 8 Mar 2024 13:28:12 +0300
Subject: [PATCH] src/bzg/data.clj (get-data): Sort list of entries by date
 (latest first)

Link: https://orgmode.org/list/87wmqdxmds@bzg.fr
---
 src/bzg/data.clj | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/bzg/data.clj b/src/bzg/data.clj
index 99ab66d..333dd6a 100644
--- a/src/bzg/data.clj
+++ b/src/bzg/data.clj
@@ -74,6 +74,8 @@
 :requests (fetch/requests source-id search)
 :patches  (fetch/patches source-id search)
 :news (fetch/news source-id search))
+;; Display the latest first.
+resources (reverse (sort resources))
 headers   (condp = format
 "rss"  {"Content-Type" "application/xml"}
 "md"   {"Content-Type" "text/plain; charset=utf-8"}
-- 
2.43.0


-- 
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-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 

Re: [BUG] ob-shell async incorrect table and value results

2024-03-08 Thread Ihor Radchenko
Matt  writes:

> #+name: sync table
> #+begin_src sh :session *test* :results table
> echo "hello world"
> #+end_src
>
> #+RESULTS:
> | hello world |
>
> #+name: async table
> #+begin_src sh :session *test* :results table :async t
> echo "hello world"
> #+end_src
>
> #+RESULTS:
> : hello world

Confirmed.
This is because `ob-shell-async-chunk-callback' never returns a list.

In `org-babel-sh-evaluate', there is a part that is responsible for
detecting the result type:

(when (and results value-is-exit-status)
  (setq results (car (reverse (split-string results "\n" t)
(when results
  (let ((result-params (cdr (assq :result-params params
(org-babel-result-cond result-params
  results
  (let ((tmp-file (org-babel-temp-file "sh-")))
(with-temp-file tmp-file (insert results))
(org-babel-import-elisp-from-file tmp-file)

This part is skipped for :async results.

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



Re: Provide sane default for the @direntry

2024-03-08 Thread Stefan Monnier
> Thanks!
> Unfortunately, the patch causes some tests (make test) to fail.
> Looks like export to temporary buffer is broken (temporary buffer does
> not have a filename):
>
> 2 unexpected results:
>FAILED  test-ox-texinfo/end-to-end-inline  stringp
>FAILED  test-ox-texinfo/end-to-end-sanity-check-displayed  stringp
[...]
> ^^ stray newline.
[...]
> This is under Org 9.6 header, while should be under Org 9.7 (not yet
> released).

I fixed those three issues (I still get test failures, but I get the
same with or without my patch ).


Stefan
>From 11a40ce47b104609c003c7b9d871db1f2f26be67 Mon Sep 17 00:00:00 2001
From: Stefan Monnier 
Date: Tue, 5 Mar 2024 14:11:19 -0500
Subject: [PATCH 1/2] lisp/ox-texinfo.el: Remove redundant `:group`s

---
 lisp/ox-texinfo.el | 21 +
 1 file changed, 1 insertion(+), 20 deletions(-)

diff --git a/lisp/ox-texinfo.el b/lisp/ox-texinfo.el
index bd01effaa6..d74ed50033 100644
--- a/lisp/ox-texinfo.el
+++ b/lisp/ox-texinfo.el
@@ -147,12 +147,10 @@
   "Default document encoding for Texinfo output.
 
 If nil it will default to `buffer-file-coding-system'."
-  :group 'org-export-texinfo
   :type 'coding-system)
 
 (defcustom org-texinfo-default-class "info"
   "The default Texinfo class."
-  :group 'org-export-texinfo
   :type '(string :tag "Texinfo class"))
 
 (defcustom org-texinfo-classes
@@ -205,7 +203,6 @@ The sectioning structure of the class is given by the elements
 following the header string.  For each sectioning level, a number
 of strings is specified.  A %s formatter is mandatory in each
 section string and will be replaced by the title of the section."
-  :group 'org-export-texinfo
   :version "27.1"
   :package-version '(Org . "9.2")
   :type '(repeat
@@ -233,7 +230,6 @@ TEXT  the main headline text (string).
 TAGS  the tags as a list of strings (list of strings or nil).
 
 The function result will be used in the section format string."
-  :group 'org-export-texinfo
   :type 'function
   :version "26.1"
   :package-version '(Org . "8.3"))
@@ -244,38 +240,32 @@ The function result will be used in the section format string."
   "Column at which to start the description in the node listings.
 If a node title is greater than this length, the description will
 be placed after the end of the title."
-  :group 'org-export-texinfo
   :type 'integer)
 
  Timestamps
 
 (defcustom org-texinfo-active-timestamp-format "@emph{%s}"
   "A printf format string to be applied to active timestamps."
-  :group 'org-export-texinfo
   :type 'string)
 
 (defcustom org-texinfo-inactive-timestamp-format "@emph{%s}"
   "A printf format string to be applied to inactive timestamps."
-  :group 'org-export-texinfo
   :type 'string)
 
 (defcustom org-texinfo-diary-timestamp-format "@emph{%s}"
   "A printf format string to be applied to diary timestamps."
-  :group 'org-export-texinfo
   :type 'string)
 
  Links
 
 (defcustom org-texinfo-link-with-unknown-path-format "@indicateurl{%s}"
   "Format string for links with unknown path type."
-  :group 'org-export-texinfo
   :type 'string)
 
  Tables
 
 (defcustom org-texinfo-tables-verbatim nil
   "When non-nil, tables are exported verbatim."
-  :group 'org-export-texinfo
   :type 'boolean)
 
 (defcustom org-texinfo-table-scientific-notation nil
@@ -285,7 +275,6 @@ The format should have \"%s\" twice, for mantissa and exponent
 \(i.e. \"%stimes10^{%s}\").
 
 When nil, no transformation is made."
-  :group 'org-export-texinfo
   :type '(choice
 	  (string :tag "Format string")
 	  (const :tag "No formatting" nil)))
@@ -297,7 +286,6 @@ This should an indicating command, e.g., \"@code\", \"@kbd\" or
 \"@samp\".
 
 It can be overridden locally using the \":indic\" attribute."
-  :group 'org-export-texinfo
   :type 'string
   :version "26.1"
   :package-version '(Org . "9.1")
@@ -323,7 +311,6 @@ to typeset and protects special characters.
 
 When no association is found for a given markup, text is returned
 as-is."
-  :group 'org-export-texinfo
   :version "26.1"
   :package-version '(Org . "9.1")
   :type 'alist
@@ -341,7 +328,6 @@ The function must accept two parameters:
 The function should return the string to be exported.
 
 The default function simply returns the value of CONTENTS."
-  :group 'org-export-texinfo
   :version "24.4"
   :package-version '(Org . "8.2")
   :type 'function)
@@ -361,7 +347,6 @@ The function must accept six parameters:
   CONTENTS  the contents of the inlinetask, as a string.
 
 The function should return the string to be exported."
-  :group 'org-export-texinfo
   :type 'function)
 
  LaTeX
@@ -374,7 +359,6 @@ fragments as Texinfo \"@displaymath\" and \"@math\" commands
 respectively.  Alternatively, when set to `detect', the exporter
 does so only if the installed version of Texinfo supports the
 necessary commands."
-  :group 'org-export-texinfo
   :package-version '(Org . "9.6")
   :type '(choice
   (const :tag "Detect" detect)
@@ -391,7 +375,6 @@