Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Hello, Doro Rose writes: > Nicolas Goaziou writes: > >> Fair enough. Could you provide a proper commit message and send the >> patch again? > > Here's the patch. Applied. Thank you. Regards, -- Nicolas Goaziou0x80A93738
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Nicolas Goaziou writes: > Fair enough. Could you provide a proper commit message and send the > patch again? Here's the patch. >From 646d457f8d3e5d38084f44adfacf38a8cc762c30 Mon Sep 17 00:00:00 2001 From: louis 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
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Hello, Doro Rose writes: > Nicolas Goaziou writes: > >> Hello, >> >> Doro Rose 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
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Nicolas Goaziou writes: > Hello, > > Doro Rose 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`.
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Hello, Doro Rose 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
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Nicolas Goaziou 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.
Re: [O] [PATCH]: Fix ob-haskell.el to work with custom ghci prompts
Hello, Doro Rose 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