emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
@ 2017-11-06  6:53 Doro Rose
  2017-11-16 21:04 ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Doro Rose @ 2017-11-06  6:53 UTC (permalink / raw)
  To: emacs-orgmode

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

Hi,

I noticed that ob-haskell.el doesn't support custom ghci prompts at present.
Custom ghci prompts such as "λ>" are quite popular in the haskell community, see for example

https://stackoverflow.com/questions/42081379/how-to-set-up-org-babel-for-haskell-with-stack

Could you have a look at the following patch and see, wether that would work in general, wrt. coding standars etc.
Obviously it works on my system, but I'm not an experienced elisp programmer, so I guess there might be  room for
improvement. 


[-- Attachment #2: ob-haskell.el diff --]
[-- Type: text/x-patch, Size: 1139 bytes --]

diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index cc78bec33..361b2b9ce 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -59,14 +59,23 @@
 
 (defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
 
+(defvar haskell-prompt-regexp)
+
 (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 "\\|^λ?> "))))
   (let* ((session (cdr (assq :session params)))
          (result-type (cdr (assq :result-type params)))
          (full-body (org-babel-expand-body:generic
 		     body params
 		     (org-babel-variable-assignments:haskell params)))
          (session (org-babel-haskell-initiate-session session params))
+	 (comint-preoutput-filter-functions
+	       (cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
          (raw (org-babel-comint-with-output
 		  (session org-babel-haskell-eoe t full-body)
                 (insert (org-trim full-body))

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-06  6:53 [PATCH]: Fix ob-haskell.el to work with custom ghci prompts Doro Rose
@ 2017-11-16 21:04 ` Nicolas Goaziou
  2017-11-16 22:22   ` Doro Rose
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2017-11-16 21:04 UTC (permalink / raw)
  To: Doro Rose; +Cc: emacs-orgmode

Hello,

Doro Rose <doroerose@gmail.com> writes:

> I noticed that ob-haskell.el doesn't support custom ghci prompts at present.
> Custom ghci prompts such as "λ>" are quite popular in the haskell community, see for example
>
> https://stackoverflow.com/questions/42081379/how-to-set-up-org-babel-for-haskell-with-stack
>
> Could you have a look at the following patch and see, wether that would work in general, wrt. coding standars etc.
> Obviously it works on my system, but I'm not an experienced elisp programmer, so I guess there might be  room for
> improvement.

Thank you.

> +  (require 'inf-haskell)
> +  (add-hook 'inferior-haskell-hook
> +            (lambda ()
> +              (setq-local comint-prompt-regexp
> +                          (concat haskell-prompt-regexp "\\|^λ?> "))))

Doesn't this kind of configuration ultimately belongs to the user? Org
is not supposed to mess with `haskell-prompt-regexp' in the current
buffer, IMO.

>    (let* ((session (cdr (assq :session params)))
>           (result-type (cdr (assq :result-type params)))
>           (full-body (org-babel-expand-body:generic
>  		     body params
>  		     (org-babel-variable-assignments:haskell params)))
>           (session (org-babel-haskell-initiate-session session params))
> +	 (comint-preoutput-filter-functions
> +	       (cons 'ansi-color-filter-apply comint-preoutput-filter-functions))

Ditto.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-16 21:04 ` Nicolas Goaziou
@ 2017-11-16 22:22   ` Doro Rose
  2017-11-17 22:14     ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Doro Rose @ 2017-11-16 22:22 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Doesn't this kind of configuration ultimately belongs to the user? Org
> is not supposed to mess with `haskell-prompt-regexp' in the current
> buffer, IMO."Doesn't this kind of configuration ultimately belongs to the user? Org

I figured, since I'm only adding another regexp to an existing regexp, no harm is done, as all else stays equal, i.e. all previously
valid matches are still valid.

>> +	 (comint-preoutput-filter-functions
>> +	       (cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
>
> Ditto.

Adding  `ansi-color-filter-apply' only ensures that color escape sequences are handled properly.

In summary, yes I'm accessing user settings but in a rather noninvasive way. Unfortunately I can't think of a more elegant way
to do this.

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-16 22:22   ` Doro Rose
@ 2017-11-17 22:14     ` Nicolas Goaziou
  2017-11-18 11:12       ` Doro Rose
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2017-11-17 22:14 UTC (permalink / raw)
  To: Doro Rose; +Cc: emacs-orgmode

Hello,

Doro Rose <doroerose@gmail.com> writes:

> In summary, yes I'm accessing user settings but in a rather
> noninvasive way. Unfortunately I can't think of a more elegant way to
> do this.

Let's put it differently then. Isn't it the job of the user, who changed
their prompt, to configure properly "inf-haskell" library? I don't get
why it should be a task for "ob-haskell".

This is a genuine question: I don't use Haskell at all.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-17 22:14     ` Nicolas Goaziou
@ 2017-11-18 11:12       ` Doro Rose
  2017-11-29 20:21         ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Doro Rose @ 2017-11-18 11:12 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Hello,
>
> Doro Rose <doroerose@gmail.com> writes:
>
>> In summary, yes I'm accessing user settings but in a rather
>> noninvasive way. Unfortunately I can't think of a more elegant way to
>> do this.
>
> Let's put it differently then. Isn't it the job of the user, who changed
> their prompt, to configure properly "inf-haskell" library? I don't get
> why it should be a task for "ob-haskell".
>
> This is a genuine question: I don't use Haskell at all.
>
> Regards,

Well the "inf-haskell" library is fine as it is, i.e. the code sent to its buffer
is evaluated correctly in the corresponding buffer.
The problem occurs when sending code  to that buffer via org-babel, since
the interpreter output isn't parsed correctly in `org-babel-comint-with-output`.

As an org-babel user my expectation would be for that to just work out of the
box. -> Without having to figure out that I need to set internal variables defined in
"inf-haskell" or that I need  to add `ansi-color-filter-apply` to
`comint-preoutput-filter-functions`.

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-18 11:12       ` Doro Rose
@ 2017-11-29 20:21         ` Nicolas Goaziou
  2017-12-02 21:25           ` Doro Rose
  0 siblings, 1 reply; 8+ messages in thread
From: Nicolas Goaziou @ 2017-11-29 20:21 UTC (permalink / raw)
  To: Doro Rose; +Cc: emacs-orgmode

Hello,

Doro Rose <doroerose@gmail.com> writes:

> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Hello,
>>
>> Doro Rose <doroerose@gmail.com> writes:
>>
>>> In summary, yes I'm accessing user settings but in a rather
>>> noninvasive way. Unfortunately I can't think of a more elegant way to
>>> do this.
>>
>> Let's put it differently then. Isn't it the job of the user, who changed
>> their prompt, to configure properly "inf-haskell" library? I don't get
>> why it should be a task for "ob-haskell".
>>
>> This is a genuine question: I don't use Haskell at all.
>>
>> Regards,
>
> Well the "inf-haskell" library is fine as it is, i.e. the code sent to its buffer
> is evaluated correctly in the corresponding buffer.
> The problem occurs when sending code  to that buffer via org-babel, since
> the interpreter output isn't parsed correctly in `org-babel-comint-with-output`.
>
> As an org-babel user my expectation would be for that to just work out of the
> box. -> Without having to figure out that I need to set internal variables defined in
> "inf-haskell" or that I need  to add `ansi-color-filter-apply` to
> `comint-preoutput-filter-functions`.

Fair enough. Could you provide a proper commit message and send the
patch again?

Thank you.

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-11-29 20:21         ` Nicolas Goaziou
@ 2017-12-02 21:25           ` Doro Rose
  2017-12-11 14:14             ` Nicolas Goaziou
  0 siblings, 1 reply; 8+ messages in thread
From: Doro Rose @ 2017-12-02 21:25 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

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

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:

> Fair enough. Could you provide a proper commit message and send the
> patch again?

Here's the patch.


[-- Attachment #2: ob-haskell.el patch --]
[-- Type: text/x-patch, Size: 2220 bytes --]

From 646d457f8d3e5d38084f44adfacf38a8cc762c30 Mon Sep 17 00:00:00 2001
From: louis <doro.rose@live.de>
Date: Sat, 2 Dec 2017 21:21:39 +0100
Subject: [PATCH] ob-haskell.el: Fix ob-haskell.el to work with custom ghci
 prompts
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* lisp/ob-haskell.el (haskell-prompt-regexp):  Define defvar
`haskell-prompt-regexp`.  This variable will override the variable set by
inf-haskell, when `org-babel-execute:haskell` is called.
(org-babel-execute:haskell):  Make sure that
`comint-prompt-regexp` is set appropriately to enable  correct parsing
of "λ"-prompts.  Set `comint-preoutput-filter-functions` appropriately to
enable correct parsing of coloured ghci prompts.

The problem was that code sent back from the inf-haskell buffer to
 org-babel wasn't parsed correctly in `org-babel-comint-with-output`.
 This occured when the user uses the commonly used "λ"-prompt.

TINYCHANGE
---
 lisp/ob-haskell.el | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el
index cc78bec33..faf976b2d 100644
--- a/lisp/ob-haskell.el
+++ b/lisp/ob-haskell.el
@@ -59,14 +59,23 @@
 
 (defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")
 
+(defvar haskell-prompt-regexp)
+
 (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 "\\|^λ?> "))))
   (let* ((session (cdr (assq :session params)))
          (result-type (cdr (assq :result-type params)))
          (full-body (org-babel-expand-body:generic
 		     body params
 		     (org-babel-variable-assignments:haskell params)))
          (session (org-babel-haskell-initiate-session session params))
+       	 (comint-preoutput-filter-functions
+	       (cons 'ansi-color-filter-apply comint-preoutput-filter-functions))
          (raw (org-babel-comint-with-output
 		  (session org-babel-haskell-eoe t full-body)
                 (insert (org-trim full-body))
-- 
2.14.2


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

* Re: [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
  2017-12-02 21:25           ` Doro Rose
@ 2017-12-11 14:14             ` Nicolas Goaziou
  0 siblings, 0 replies; 8+ messages in thread
From: Nicolas Goaziou @ 2017-12-11 14:14 UTC (permalink / raw)
  To: Doro Rose; +Cc: emacs-orgmode

Hello,

Doro Rose <doroerose@gmail.com> writes:

> Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
>
>> Fair enough. Could you provide a proper commit message and send the
>> patch again?
>
> Here's the patch.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou                                                0x80A93738

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

end of thread, other threads:[~2017-12-11 14:14 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-06  6:53 [PATCH]: Fix ob-haskell.el to work with custom ghci prompts Doro Rose
2017-11-16 21:04 ` Nicolas Goaziou
2017-11-16 22:22   ` Doro Rose
2017-11-17 22:14     ` Nicolas Goaziou
2017-11-18 11:12       ` Doro Rose
2017-11-29 20:21         ` Nicolas Goaziou
2017-12-02 21:25           ` Doro Rose
2017-12-11 14:14             ` Nicolas Goaziou

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).