Re: [PATCH] Async evaluation in ob-shell

2023-03-18 Thread Ihor Radchenko
Matt  writes:

> Way back in https://list.orgmode.org/87sfeyc7qr.fsf@localhost/, we had this 
> exchange:
>
>   On Mon, 20 Feb 2023 11:24:52 +  Ihor Radchenko  wrote --- 
>> Matt  writes:
>>
>> > +(defun ob-shell-async-chunk-callback (string)
>> > +  "Filter applied to results before insertion.
>> > +See `org-babel-comint-async-chunk-callback'."
>> > +  (replace-regexp-in-string (concat org-babel-sh-prompt "*") "" string))
>>
>  > Why not using `comint-prompt-regexp'?
>
> I switched out `org-babel-sh-prompt'  with `comint-prompt-regexp' so that the 
> expression looks like:
>
> +(defun ob-shell-async-chunk-callback (string)
> +  "Filter applied to results before insertion.
> +See `org-babel-comint-async-chunk-callback'."
> +  (replace-regexp-in-string comint-prompt-regexp "" string))
>
> This causes the new test `test-ob-shell/session-async-evaluation' to fail, as 
> you pointed out: https://list.orgmode.org/87bkl96g6e.fsf@localhost/
>
> The test fails when we switch out the prompt in the callback because 
> `comint-prompt-regexp' has two spaces in it.  The second space causes a 
> prompt to not be filtered (by the callback).  The output becomes ": 1\n: 2\n: 
> org_babel_sh_prompt>\n" instead of  ": 1\n: 2\n" .  This looks like a bug in 
> the `comint-prompt-regexp''.

No, this looks like a bug in comint.el. ob-shell correctly sets
PROMPT to be org-babel-sh-prompt, which is "org_babel_sh_prompt> ", with
space! The fact that the comint output does not, in fact, contain space
is wrong.

We can probably remove the space in org-babel-sh-prompt to work around
this (likely, Emacs) bug.

> It could be that `test-ob-shell/session-async-evaluation' doesn't test 
> correctly, but it looks right to me (I could certainly be mistaken).  
> Therefore, I see only two options to fix it: remove a space from the concat 
> expression (which I did in my latest patch) or remove a space from 
> `org-babel-sh-prompt'.

Removing space from the concat expression in plain wrong, as Max
explained. 

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



Re: [PATCH] ox-odt: Prevent auto-formatting in export buffers

2023-03-18 Thread Ihor Radchenko
David Lukes  writes:

> * lisp/ox-odt.el (org-odt-template, org-odt--export-wrap):
> `write-region' instead of `save-buffer'.
>
> `write-file' and `save-buffer' trigger major mode changes, which leads
> to various mode-related hooks being run.  This is undesirable: running
> these on generated files is wasted time and computation, and it can even
> lead to hard to track data corruption when auto-formatting hooks are
> involved.  One such case is the 2006 version of the tidy program which
> ships with stock macOS and can corrupt multi-byte UTF-8 codepoints in
> HTML and ODT (via XML) exports.  And even recent versions of tidy can
> re-arrange whitespace in the exported documents in unwanted ways.

See the attached patch where I applied the idea across Org, where it
made sense. Note that I did not alter `org-odt--export-wrap' because
`save-buffer' there is applied only when XML files are opened as buffers
in Emacs, presumably manually. Interactive `save-buffer' makes sense
then. (Though maybe that code is not needed at all, IDK)

Please let me know if there are any objections.

>From 8d8884bb6be0ba7cb7f9662f067d42b53393e92e Mon Sep 17 00:00:00 2001
Message-Id: <8d8884bb6be0ba7cb7f9662f067d42b53393e92e.1679139580.git.yanta...@posteo.net>
From: Ihor Radchenko 
Date: Sat, 18 Mar 2023 12:34:17 +0100
Subject: [PATCH] Prefer `write-region' to `save-file'

* lisp/ob-haskell.el (org-babel-haskell-export-to-lhs): Use
non-interactive `insert-file-contents' + `write-region' to avoid
triggering various interactive hooks.  Ensure that temp files are
always deleted.
* lisp/org-agenda.el (org-agenda-write):
* lisp/org-table.el: Simplify code using `write-region'.
* lisp/ox-odt.el (org-odt-template): Use `insert-file-contents' +
`write-region' instead of `find-file-noselect' that may trigger
various hooks.  The new approach makes `revert-buffer' not
necessary (and do not trigger `revert-buffer' hooks).  Also, the
problem with backups will no longer exists.

Original idea: https://list.orgmode.org/orgmode/20221002035931.12191-1-dafydd.lu...@gmail.com/
---
 lisp/ob-haskell.el | 41 
 lisp/org-agenda.el |  9 ++
 lisp/org-table.el  | 10 ++
 lisp/ox-odt.el | 78 --
 4 files changed, 59 insertions(+), 79 deletions(-)

diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index 2b1441c2a..3e64c1657 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -255,26 +255,27 @@ (defun org-babel-haskell-export-to-lhs (&optional arg)
t t)
 (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
 (save-excursion
-  ;; export to latex w/org and save as .lhs
-  (require 'ox-latex)
-  (find-file tmp-org-file)
-  ;; Ensure we do not clutter kill ring with incomplete results.
-  (let (org-export-copy-to-kill-ring)
-	(org-export-to-file 'latex tmp-tex-file))
-  (kill-buffer nil)
-  (delete-file tmp-org-file)
-  (find-file tmp-tex-file)
-  (goto-char (point-min)) (forward-line 2)
-  (insert "%include polycode.fmt\n")
-  ;; ensure all \begin/end{code} statements start at the first column
-  (while (re-search-forward "^[ \t]+begin{code}[^\000]+end{code}" nil t)
-(replace-match (save-match-data (org-remove-indentation (match-string 0)))
-   t t))
-  (setq contents (buffer-string))
-  (save-buffer) (kill-buffer nil))
-(delete-file tmp-tex-file)
-;; save org exported latex to a .lhs file
-(with-temp-file lhs-file (insert contents))
+  (unwind-protect
+  (with-temp-buffer
+;; Export to latex w/org and save as .lhs
+(require 'ox-latex)
+(insert-file-contents tmp-org-file)
+;; Ensure we do not clutter kill ring with incomplete results.
+(let (org-export-copy-to-kill-ring)
+	  (org-export-to-file 'latex tmp-tex-file)))
+(delete-file tmp-org-file))
+  (unwind-protect
+  (with-temp-buffer
+(insert-file-contents tmp-tex-file)
+(goto-char (point-min)) (forward-line 2)
+(insert "%include polycode.fmt\n")
+;; ensure all \begin/end{code} statements start at the first column
+(while (re-search-forward "^[ \t]+begin{code}[^\000]+end{code}" nil t)
+  (replace-match (save-match-data (org-remove-indentation (match-string 0)))
+ t t))
+;; save org exported latex to a .lhs file
+(write-region nil nil lhs-file))
+(delete-file tmp-tex-file)))
 (if (not arg)
 (find-file lhs-file)
   ;; process .lhs file with lhs2tex
diff --git a/lisp/org-agenda.el b/lisp/org-agenda.el
index 3da0967f0..859a80c47 100644
--- a/lisp/org-agenda.el
+++ b/lisp/org-agenda.el
@@ -3667,13 +3667,8 @@ (defun org-agenda-write (file &optional open nosettings agenda-bufname)
 	"ox-icalendar" (file))
 	

Re: [PATCH v4] lisp/ob-screen.el: Support ~:var~ header args for babel blocks

2023-03-18 Thread Ihor Radchenko
Max Nikulin  writes:

> Ken, you wrote that you have other patches for ob-screen.el. Do you plan 
> to sent them?

For context, Ken is the maintainer of ob-screen.
It is up to him is this feature is useful for ob-screen, with your
additions.

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



Re: [BUG] citations incorrectly exported to pandoc [9.6.1 (9.6.1-??-fe92a3ced ]

2023-03-18 Thread Ihor Radchenko
Eric Rauchway  writes:

> This error occurs when using the org exporter to create a docx or
> latex-pdf file via pandoc, i.e., C-c C-e p X or C-c C-e p l.
>
> It does _not_ occur when using the org exporter to create a latex file
> without pandoc, i.e., C-c C-e l o does not produce the error.

Thanks for reporting, but the described problem appears to be with
ox-pandoc. Note that ox-pandoc is a third-party package, which is not a
part of Org.

You may consider contacting the current ox-pandoc maintainers at
https://github.com/emacsorphanage/ox-pandoc/
But do not expect much - the package is abandoned.

Alternatively, you can customize `org-odt-preferred-output-format' and
make ox-odt export to docx.

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



Re: [PATCH v2] org-manual.org: $n$-th is not math

2023-03-18 Thread Ihor Radchenko
Max Nikulin  writes:

> Subject: [PATCH v2] org-manual.org: $n$-th is not math

Applied, onto main.

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



Re: [SUGGESTION] separate ob-clojure.el into Clojure part ob-clojure.el and ClojureScript part ob-clojurescript.el

2023-03-18 Thread Ihor Radchenko
stardiviner  writes:

> For now, ob-clojure.el contains lot of code for ClojureScript. Only some
> code has same functionality. Like CIDER backend. In the future,
> ClojureScript part code will increase and different. So I suggest
> separate them into two source code files.
>
> WDYT?

The only downside is that people might need to
(require 'ob-clojurescript)
I am thinking if ob-core.el should try to automatically guess the
correct library to be loaded.

Otherwise, I am neutral towards this split.

Up to Daniel.

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