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 19:02:14 -0500 [thread overview]
Message-ID: <CAM-YhhBoFSf02UDZO0B-qkoaA2DbnJ9Kbb8HcR3ehJzLqPs1Xg@mail.gmail.com> (raw)
In-Reply-To: <87o8qjduhs.fsf@kyleam.com>
[-- Attachment #1: Type: text/plain, Size: 2007 bytes --]
Hi Kyle, thanks for the thoughtful analysis.
On Wed, May 20, 2020 at 12:51 AM Kyle Meyer <kyle@kyleam.com> wrote:
> So it looks like the member call above is returning nil because the
> prompt markers are corrupting the element. If that's the case, it seems
> like the output cleansing should happen upstream of that call.
>
> What do you think?
After a bit of tinkering, I realized there are two things going on
here, only one of which I fully understand:
1. My core functional issue is that =comint-prompt-regexp= isn't set
up to handle the "Prelude| " entries or the repeated prompts. The
other patches I submitted were unnecessary.
2. The =comint-prompt-regexp= gets default values from somewhere I
don't understand and can't find with a quick source grep.
In ob-haskell, we set =comint-prompt-regexp= to the (undefined)
haskell-prompt plus "or optional-lambda":
(defvar haskell-prompt-regexp)
(defun org-babel-execute:haskell (body params) ...
(setq-local comint-prompt-regexp
(concat haskell-prompt-regexp "\\|^λ?> "))))
That causes an evaluation error that prevents the first source block
evaluation but, strangely, that also results in this mess in the
*haskell* buffer on subsequent evaluations:
: "^\\*?[[:upper:]][\\._[:alnum:]]*\\(?:
\\*?[[:upper:]][\\._[:alnum:]]*\\)*\\( λ\\)?> "
=comint-prompt-regexp='s variable documentation calls out much simpler
regexps that do basically the same thing as the one above and handles
the repeated "Prelude| " entries. This one is based off the Canonical
Lisp example:
: "^[^>\n]+\\(> \\)?"
I've attached a patch against git master that results in fewer
undefined variable errors and depends less default-variable magic.
Now, =haskell-prompt-regexp= and =comint-prompt-regexp= are explicitly
set using defaults that can be M-x customized, and the default value
handles the repeated "Prelude| " entries without breaking the original
"λ> " prompt handling.
Thanks,
Nick
[-- Attachment #2: ob-haskell-trim-prelude-3.diff --]
[-- Type: text/x-patch, Size: 988 bytes --]
diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index bea162528..893e4220c 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -56,15 +56,25 @@
(defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
-(defvar haskell-prompt-regexp)
+(defvar haskell-prompt-regexp "^[^>\n]*\\(> \\)?"
+ "Filter out prompts from Haskell interpreters:
+
+GHC:
+
+- '^Prelude> '
+- '^Prelude| Prelude| Prelude> '
+
+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
next prev parent reply other threads:[~2020-05-24 0:02 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-17 19:30 [PATCH] ob-haskell: Line Continuations Mangle Block Output Nick Daly
2020-05-17 20:07 ` Nick Daly
2020-05-20 5:51 ` Kyle Meyer
2020-05-24 0:02 ` Nick Daly [this message]
2020-05-24 2:46 ` Nick Daly
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-YhhBoFSf02UDZO0B-qkoaA2DbnJ9Kbb8HcR3ehJzLqPs1Xg@mail.gmail.com \
--to=nick.m.daly@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=kyle@kyleam.com \
/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).