Apologies, one last patch. On Sat, May 23, 2020 at 7:02 PM Nick Daly <nick.m.d...@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
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