emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized
@ 2020-08-31 14:39 Joseph Novakovich
  2020-09-04  7:19 ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Novakovich @ 2020-08-31 14:39 UTC (permalink / raw)
  To: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

Hello!

The problem is that we read the contents of the output after 0.1
seconds, which, for expensive computations, results in the mangling of
output.  Output from expensive computations gets propagated down to
subsequent code-blocks' outputs, producing a horrible mess.

Joseph

[-- Attachment #2: 0001-ob-J.el-Add-ability-to-customize-sit-duration.patch --]
[-- Type: text/x-patch, Size: 2421 bytes --]

From ee08934a649b4a6c14d8b2ee1c24f849621284a9 Mon Sep 17 00:00:00 2001
From: Joseph Novakovich <josephnovakovich@gmail.com>
Date: Mon, 31 Aug 2020 10:14:15 -0400
Subject: [PATCH] ob-J.el: Add ability to customize sit duration

* lisp/ob-J.el (org-babel-execute:J, org-babel-J-eval-string): Add
customizability.

(org-babel-execute:J): Lookup optional parameter `:sit' to allow one
to wait for a specified amount of time before grabbing the output of
the J subprocess.  Pass this specified value or the previous default
of .1 to `org-babel-J-eval-string'.
(org-babel-eval-string): Pass new argument `sit-time' to `sit-for'
before grabbing output.

The problem is that we read the contents of the output after 0.1
seconds, which, for expensive computations, results in the mangling of
output.  Output from expensive computations gets propagated down to
subsequent code-blocks' outputs, producing a horrible mess.

TINYCHANGE
---
 lisp/ob-J.el | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/lisp/ob-J.el b/lisp/ob-J.el
index c0145211b..f26e82ed9 100644
--- a/lisp/ob-J.el
+++ b/lisp/ob-J.el
@@ -76,6 +76,8 @@ This function is called by `org-babel-execute-src-block'."
   (message "executing J source code block")
   (let* ((processed-params (org-babel-process-params params))
 	 (sessionp (cdr (assq :session params)))
+	 (sit-time (let ((sit (assq :sit params)))
+		     (if sit (cdr sit) .1)))
          (full-body (org-babel-expand-body:J
                      body params processed-params))
 	 (tmp-script-file (org-babel-temp-file "J-src")))
@@ -86,9 +88,9 @@ This function is called by `org-babel-execute-src-block'."
 	   (with-temp-file tmp-script-file
 	     (insert full-body))
 	   (org-babel-eval (format "%s < %s" org-babel-J-command tmp-script-file) ""))
-       (org-babel-J-eval-string full-body)))))
+       (org-babel-J-eval-string full-body sit-time)))))
 
-(defun org-babel-J-eval-string (str)
+(defun org-babel-J-eval-string (str sit-time)
   "Sends STR to the `j-console-cmd' session and executes it."
   (let ((session (j-console-ensure-session)))
     (with-current-buffer (process-buffer session)
@@ -96,7 +98,7 @@ This function is called by `org-babel-execute-src-block'."
       (insert (format "\n%s\n" str))
       (let ((beg (point)))
 	(comint-send-input)
-	(sit-for .1)
+	(sit-for sit-time)
 	(buffer-substring-no-properties
 	 beg (point-max))))))
 
-- 
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized
  2020-08-31 14:39 [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized Joseph Novakovich
@ 2020-09-04  7:19 ` Bastien
  2020-09-04 18:02   ` Joseph Novakovich
  0 siblings, 1 reply; 4+ messages in thread
From: Bastien @ 2020-09-04  7:19 UTC (permalink / raw)
  To: Joseph Novakovich; +Cc: emacs-orgmode

Hi Joseph,

applied on maint (as 7d8247410), thanks.

Would you like to take over ob-J.el maintainance?

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized
  2020-09-04  7:19 ` Bastien
@ 2020-09-04 18:02   ` Joseph Novakovich
  2020-09-05  6:06     ` Bastien
  0 siblings, 1 reply; 4+ messages in thread
From: Joseph Novakovich @ 2020-09-04 18:02 UTC (permalink / raw)
  To: Bastien; +Cc: emacs-orgmode

Hello Bastien,

Sure, I'd be happy to help!

Joseph

On 9/4/20, Bastien <bzg@gnu.org> wrote:
> Hi Joseph,
>
> applied on maint (as 7d8247410), thanks.
>
> Would you like to take over ob-J.el maintainance?
>
> --
>  Bastien
>


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized
  2020-09-04 18:02   ` Joseph Novakovich
@ 2020-09-05  6:06     ` Bastien
  0 siblings, 0 replies; 4+ messages in thread
From: Bastien @ 2020-09-05  6:06 UTC (permalink / raw)
  To: Joseph Novakovich; +Cc: emacs-orgmode

Hi Joseph,

Joseph Novakovich <josephnovakovich@gmail.com> writes:

> Sure, I'd be happy to help!

Thanks!  I added you as the ob-J.el maintainer in 0e580d169.

-- 
 Bastien


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-05  6:07 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-08-31 14:39 [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized Joseph Novakovich
2020-09-04  7:19 ` Bastien
2020-09-04 18:02   ` Joseph Novakovich
2020-09-05  6:06     ` Bastien

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).