emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Daly <nick.m.daly@gmail.com>
To: Kyle Meyer <kyle@kyleam.com>
Cc: Org Mode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] ob-haskell: Line Continuations Mangle Block Output
Date: Sat, 23 May 2020 21:46:55 -0500	[thread overview]
Message-ID: <CAM-YhhC9EXUBq7-u1Rx=yamO6qf6mELrkqpPsEH=qpUKCyPZ5g@mail.gmail.com> (raw)
In-Reply-To: <CAM-YhhBoFSf02UDZO0B-qkoaA2DbnJ9Kbb8HcR3ehJzLqPs1Xg@mail.gmail.com>

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

Apologies, one last patch.

On Sat, May 23, 2020 at 7:02 PM Nick Daly <nick.m.daly@gmail.com> wrote:
> : "^\\*?[[:upper:]][\\._[:alnum:]]*\\(?:
> \\*?[[:upper:]][\\._[:alnum:]]*\\)*\\( λ\\)?> "
>
> =comint-prompt-regexp='s variable documentation calls out much simpler
> regexps
>
> : "^[^>]+\\(> \\)?"

This simplified patch breaks one case that I'd forgotten about: the
true one-liner, where the output displays before the "Prelude> "
prompt even appears.

#+BEGIN_SRC haskell
scanl (+) 0 [1,2,3,4]
#+END_SRC

#+BEGIN_EXAMPLE
Prelude> scanl (+) 0 [1,2,3,4]
"org-babel-haskell-eoe"
[0,1,3,6,10]
Prelude> "org-babel-haskell-eoe"
Prelude>
#+END_EXAMPLE

This latest patch updates the original (more complicated) regexp that
works with this out-of-order output.  This should display the expected
result in all known cases:

One liners:

#+BEGIN_SRC haskell
scanl (+) 0 [1,2,3,4]
#+END_SRC

#+RESULTS:
| 0 | 1 | 3 | 6 | 10 |

Silent multi-line blocks:

#+BEGIN_SRC haskell :results silent
:{
flip' :: (a -> b -> c) -> (b -> a -> c)
flip' f = \x y -> f y x
:}
#+END_SRC

Multi-line blocks with value results:

#+BEGIN_SRC haskell
:{
sum' :: (Num a) => [a] -> a
sum' xs = foldl (\ acc x -> acc + x) 0 xs
:}
sum' [1,2,3,4] == 10
#+END_SRC

#+RESULTS:
: True

Multi-line blocks with output results:

#+BEGIN_SRC haskell :results output
:{
sum' :: (Num a) => [a] -> a
sum' xs = foldl (\ acc x -> acc + x) 0 xs
:}
print "hi"
#+END_SRC

#+RESULTS:
:
: hi

Thanks again for your time,
Nick

[-- Attachment #2: ob-haskell-trim-prelude-4.diff --]
[-- Type: text/x-patch, Size: 1116 bytes --]

diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index bea162528..6ac34f2f5 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -56,15 +56,27 @@
 
 (defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
 
-(defvar haskell-prompt-regexp)
+(defvar haskell-prompt-regexp "^\\(\\*?[[:upper:]][\\._[:alnum:]]*\\(?: \\*?[[:upper:]][\\._[:alnum:]]*\\)*\\( λ\\)?[|>] \\)*"
+  "Filter out prompts from Haskell interpreters:
+
+GHC:
+
+- 'output
+   ^Prelude> EOE'
+- '^Prelude> output EOE'
+- '^Prelude| Prelude| Prelude> output EOE'
+
+Unknown Interpreter:
+
+- '^> '
+- '^λ> '")
 
 (defun org-babel-execute:haskell (body params)
   "Execute a block of Haskell code."
   (require 'inf-haskell)
   (add-hook 'inferior-haskell-hook
             (lambda ()
-              (setq-local comint-prompt-regexp
-                          (concat haskell-prompt-regexp "\\|^λ?> "))))
+              (setq-local comint-prompt-regexp haskell-prompt-regexp)))
   (let* ((session (cdr (assq :session params)))
          (result-type (cdr (assq :result-type params)))
          (full-body (org-babel-expand-body:generic

  reply	other threads:[~2020-05-24  2:47 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-17 19:30 Nick Daly
2020-05-17 20:07 ` Nick Daly
2020-05-20  5:51   ` Kyle Meyer
2020-05-24  0:02     ` Nick Daly
2020-05-24  2:46       ` Nick Daly [this message]
2020-05-26  0:05         ` Kyle Meyer
2020-05-31 17:00           ` Nick Daly
2020-05-26  0:02       ` Kyle Meyer

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='CAM-YhhC9EXUBq7-u1Rx=yamO6qf6mELrkqpPsEH=qpUKCyPZ5g@mail.gmail.com' \
    --to=nick.m.daly@gmail.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=kyle@kyleam.com \
    --subject='Re: [PATCH] ob-haskell: Line Continuations Mangle Block Output' \
    /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

Code repositories for project(s) associated with this 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).