emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Joseph Novakovich <josephnovakovich@gmail.com>
To: emacs-orgmode@gnu.org
Subject: [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized
Date: Mon, 31 Aug 2020 14:39:08 +0000	[thread overview]
Message-ID: <CAHwqnzH=tRo=_0HYKXOtnmAEdMyHOdFbP1MX76e5wo7URRpiXw@mail.gmail.com> (raw)

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


             reply	other threads:[~2020-09-02 11:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-31 14:39 Joseph Novakovich [this message]
2020-09-04  7:19 ` [PATCH] prevent mangled output in ob-J by allowing sit-time duration to be customized Bastien
2020-09-04 18:02   ` Joseph Novakovich
2020-09-05  6:06     ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHwqnzH=tRo=_0HYKXOtnmAEdMyHOdFbP1MX76e5wo7URRpiXw@mail.gmail.com' \
    --to=josephnovakovich@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).