Re: Fwd: Support compilation of Haskell in org mode babel blocks.
Sorry, I was working on the emacs git repo, which seems to be a bit behind the org mode one. Please find patch attached. On Sat, May 23, 2020 at 4:02 PM Bastien wrote: > Hi Roland, > > Roland Coeurjoly writes: > > > I have done a clean clone and I still don't see a 9.4 section in > > master. > > Is it in another branch? > > It is here in the master branch: > > https://code.orgmode.org/bzg/org-mode/src/master/etc/ORG-NEWS#L13 > > -- > Bastien > From 4d8660eea35ea13809914271562f0ff73507f967 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Sat, 23 May 2020 16:46:26 +0200 Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument * lisp/ob-haskell (org-babel-haskell-compiler): (org-babel-header-args:haskell): new variables. (org-babel-haskell-execute): (org-babel-haskell-interpret): new functions. (org-babel-execute:haskell): use new functions. --- etc/ORG-NEWS | 6 lisp/ob-haskell.el | 80 +++--- 2 files changed, 81 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index f8bddb613..21c5e3d71 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -453,6 +453,12 @@ equations producing inconsistent output. New option ~org-html-equation-reference-format~ sets the command used in HTML export. +*** ob-haskell: add support for compilation with :compile header argument + +By default, Haskell blocks are interpreted. By adding ~:compile yes~ +to a Haskell source block, it will be compiled, executed and +the results will be displayed. + * Version 9.3 ** Incompatible changes diff --git a/lisp/ob-haskell.el b/lisp/ob-haskell.el index bea162528..466344ac0 100644 --- a/lisp/ob-haskell.el +++ b/lisp/ob-haskell.el @@ -23,12 +23,13 @@ ;;; Commentary: -;; Org-Babel support for evaluating haskell source code. This one will -;; be sort of tricky because haskell programs must be compiled before +;; Org Babel support for evaluating Haskell source code. +;; Haskell programs must be compiled before ;; they can be run, but haskell code can also be run through an ;; interactive interpreter. ;; -;; For now lets only allow evaluation using the haskell interpreter. +;; By default we evaluate using the Haskell interpreter. +;; To use the compiler, specify :compile yes in the header. ;;; Requirements: @@ -45,6 +46,7 @@ (declare-function run-haskell "ext:inf-haskell" (&optional arg)) (declare-function inferior-haskell-load-file "ext:inf-haskell" (&optional reload)) +(declare-function org-entry-get "org" (pom property &optional inherit literal-nil)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs")) @@ -58,8 +60,66 @@ (defvar haskell-prompt-regexp) -(defun org-babel-execute:haskell (body params) - "Execute a block of Haskell code." +(defcustom org-babel-haskell-compiler "ghc" + "Command used to compile a Haskell source code file into an executable. +May be either a command in the path, like \"ghc\" +or an absolute path name, like \"/usr/local/bin/ghc\". +The command can include a parameter, such as \"ghc -v\"" + :group 'org-babel + :package-version '(Org "9.4") + :type 'string) + +(defconst org-babel-header-args:haskell '(compile . :any) + "Haskell-specific header arguments.") + +(defun org-babel-haskell-execute (body params) + "This function should only be called by `org-babel-execute:haskell'" + (let* ((tmp-src-file (org-babel-temp-file + "Haskell-src-" +".hs")) + (tmp-bin-file + (org-babel-process-file-name + (org-babel-temp-file "Haskell-bin-" org-babel-exeext))) + (cmdline (cdr (assq :cmdline params))) + (cmdline (if cmdline (concat " " cmdline) "")) + (flags (cdr (assq :flags params))) + (flags (mapconcat #'identity + (if (listp flags) + flags + (list flags)) " ")) + (libs (org-babel-read + (or (cdr (assq :libs params)) + (org-entry-get nil "libs" t)) + nil)) + (libs (mapconcat #'identity + (if (listp libs) libs (list libs)) + " "))) +(with-temp-file tmp-src-file (insert body)) +(org-babel-eval + (format "%s -o %s %s %s %s" + org-babel-haskell-compiler + tmp-bin-file + flags + (org-babel-process-file-name tmp-src-file) + libs) + "") +(let ((results + (org-babel-eval + (concat tmp-bin-file cmdline) ""))) + (when results +(setq results (org-trim (org-remove-indentation results))) +(org-babel-
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
I have done a clean clone and I still don't see a 9.4 section in master. Is it in another branch? On Sat, May 23, 2020 at 7:12 AM Kyle Meyer wrote: > Hi Roland, > > Roland Coeurjoly writes: > > > I added version 9.4 to ORG-NEWS. > > Please tell me if that's OK or I should instead put it in 9.3. > > I don't think you managed to place your patch correctly on top of the > current master (5adfb533c at the time of writing) because ... > > > --- a/etc/ORG-NEWS > > +++ b/etc/ORG-NEWS > > @@ -10,6 +10,15 @@ See the end of the file for license conditions. > > > > Please send Org bug reports to mailto:emacs-orgmode@gnu.org. > > > > +* Version 9.4 > > + > > +** Incompatible changes > > +** New features > > +** New functions > > +** Removed functions and variables > > +** Miscellaneous > > +*** ob-haskell: introduce :compile header argument > > ... ORG-NEWS in master already has a section for 9.4. > > You can correct the situation by fetching and then rebasing onto master. >
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
I added version 9.4 to ORG-NEWS. Please tell me if that's OK or I should instead put it in 9.3. On Fri, May 22, 2020 at 5:30 PM Nicolas Goaziou wrote: > Hello, > > Roland Coeurjoly writes: > > > The assignment process with the FSF is complete. > > Great news! > > Unfortunately, now I cannot your patch anymore. Would you mind rebasing > it on top of master, and add an entry in ORG-NEWS, probably in > "Miscellaneous" function. > > Regards, > > -- > Nicolas Goaziou > From daa91128ae38ffa47831c840b399144dd07c0b4a Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Sat, 25 Apr 2020 20:35:22 +0200 Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument * lisp/ob-haskell (org-babel-haskell-compiler): (org-babel-header-args:haskell): new variables. (org-babel-haskell-execute): (org-babel-haskell-interpret): new functions. (org-babel-execute:haskell): use new functions. --- etc/ORG-NEWS | 9 + lisp/org/ob-haskell.el | 78 +++--- 2 files changed, 82 insertions(+), 5 deletions(-) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index ce08496b20..2ac4315aa4 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -10,6 +10,15 @@ See the end of the file for license conditions. Please send Org bug reports to mailto:emacs-orgmode@gnu.org. +* Version 9.4 + +** Incompatible changes +** New features +** New functions +** Removed functions and variables +** Miscellaneous +*** ob-haskell: introduce :compile header argument + * Version 9.3 ** Incompatible changes diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el index e004a3405e..55989adba1 100644 --- a/lisp/org/ob-haskell.el +++ b/lisp/org/ob-haskell.el @@ -23,12 +23,13 @@ ;;; Commentary: -;; Org-Babel support for evaluating haskell source code. This one will -;; be sort of tricky because haskell programs must be compiled before +;; Org Babel support for evaluating Haskell source code. +;; Haskell programs must be compiled before ;; they can be run, but haskell code can also be run through an ;; interactive interpreter. ;; -;; For now lets only allow evaluation using the haskell interpreter. +;; By default we evaluate using the Haskell interpreter. +;; To use the compiler, specify :compile yes in the header. ;;; Requirements: @@ -47,6 +48,7 @@ (declare-function run-haskell "ext:inf-haskell" (&optional arg)) (declare-function inferior-haskell-load-file "ext:inf-haskell" (&optional reload)) +(declare-function org-entry-get "org" (pom property &optional inherit literal-nil)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs")) @@ -60,8 +62,66 @@ org-babel-haskell-eoe (defvar haskell-prompt-regexp) -(defun org-babel-execute:haskell (body params) - "Execute a block of Haskell code." +(defcustom org-babel-haskell-compiler "ghc" + "Command used to compile a Haskell source code file into an executable. +May be either a command in the path, like \"ghc\" +or an absolute path name, like \"/usr/local/bin/ghc\". +The command can include a parameter, such as \"ghc -v\"" + :group 'org-babel + :package-version '(Org "9.4") + :type 'string) + +(defconst org-babel-header-args:haskell '(compile . :any) + "Haskell-specific header arguments.") + +(defun org-babel-haskell-execute (body params) + "This function should only be called by `org-babel-execute:haskell'" + (let* ((tmp-src-file (org-babel-temp-file + "Haskell-src-" +".hs")) + (tmp-bin-file + (org-babel-process-file-name + (org-babel-temp-file "Haskell-bin-" org-babel-exeext))) + (cmdline (cdr (assq :cmdline params))) + (cmdline (if cmdline (concat " " cmdline) "")) + (flags (cdr (assq :flags params))) + (flags (mapconcat #'identity + (if (listp flags) + flags + (list flags)) " ")) + (libs (org-babel-read + (or (cdr (assq :libs params)) + (org-entry-get nil "libs" t)) + nil)) + (libs (mapconcat #'identity + (if (listp libs) libs (list libs)) + " "))) +(with-temp-file tmp-src-file (insert body)) +(org-babel-eval + (format "%s -o %s %s %s %s" + org-babel-haskell-compiler + tmp-bin-file + flags + (org-babel-process-file-name tmp-src-file) + libs) + "") +(let ((results + (org-babel-eval + (concat tmp-bin-file cmdline) ""))) + (when results +(setq results (org-trim (org-remove-indentation results))) +(org-bab
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
The assignment process with the FSF is complete. Best regards, Roland On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou wrote: > Hello, > > Roland Coeurjoly writes: > > > Please see attached patch. > > Great! > > It seems that this is a patch that needs to be applied on top of the > previous one. Could you merge them into a single patch and send it > again? > > Please let me know when the FSF registers you. > > Regards, > > -- > Nicolas Goaziou >
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
Sorry about that. This attached patch should be good. On Tue, May 5, 2020 at 11:31 PM Nicolas Goaziou wrote: > Hello, > > Roland Coeurjoly writes: > > > Please see attached patch. > > Great! > > It seems that this is a patch that needs to be applied on top of the > previous one. Could you merge them into a single patch and send it > again? > > Please let me know when the FSF registers you. > > Regards, > > -- > Nicolas Goaziou > From 35d637fdad355787ce739d9b42997d3ba781a64f Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Sat, 25 Apr 2020 20:35:22 +0200 Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument * lisp/ob-haskell (org-babel-haskell-compiler): (org-babel-header-args:haskell): new variables. (org-babel-haskell-execute): (org-babel-haskell-interpret): new functions. (org-babel-execute:haskell): use new functions. --- lisp/org/ob-haskell.el | 78 ++ 1 file changed, 73 insertions(+), 5 deletions(-) diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el index e004a34..55989ad 100644 --- a/lisp/org/ob-haskell.el +++ b/lisp/org/ob-haskell.el @@ -23,12 +23,13 @@ ;;; Commentary: -;; Org-Babel support for evaluating haskell source code. This one will -;; be sort of tricky because haskell programs must be compiled before +;; Org Babel support for evaluating Haskell source code. +;; Haskell programs must be compiled before ;; they can be run, but haskell code can also be run through an ;; interactive interpreter. ;; -;; For now lets only allow evaluation using the haskell interpreter. +;; By default we evaluate using the Haskell interpreter. +;; To use the compiler, specify :compile yes in the header. ;;; Requirements: @@ -47,6 +48,7 @@ (declare-function run-haskell "ext:inf-haskell" (&optional arg)) (declare-function inferior-haskell-load-file "ext:inf-haskell" (&optional reload)) +(declare-function org-entry-get "org" (pom property &optional inherit literal-nil)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs")) @@ -60,8 +62,66 @@ org-babel-haskell-eoe (defvar haskell-prompt-regexp) -(defun org-babel-execute:haskell (body params) - "Execute a block of Haskell code." +(defcustom org-babel-haskell-compiler "ghc" + "Command used to compile a Haskell source code file into an executable. +May be either a command in the path, like \"ghc\" +or an absolute path name, like \"/usr/local/bin/ghc\". +The command can include a parameter, such as \"ghc -v\"" + :group 'org-babel + :package-version '(Org "9.4") + :type 'string) + +(defconst org-babel-header-args:haskell '(compile . :any) + "Haskell-specific header arguments.") + +(defun org-babel-haskell-execute (body params) + "This function should only be called by `org-babel-execute:haskell'" + (let* ((tmp-src-file (org-babel-temp-file + "Haskell-src-" +".hs")) + (tmp-bin-file + (org-babel-process-file-name + (org-babel-temp-file "Haskell-bin-" org-babel-exeext))) + (cmdline (cdr (assq :cmdline params))) + (cmdline (if cmdline (concat " " cmdline) "")) + (flags (cdr (assq :flags params))) + (flags (mapconcat #'identity + (if (listp flags) + flags + (list flags)) " ")) + (libs (org-babel-read + (or (cdr (assq :libs params)) + (org-entry-get nil "libs" t)) + nil)) + (libs (mapconcat #'identity + (if (listp libs) libs (list libs)) + " "))) +(with-temp-file tmp-src-file (insert body)) +(org-babel-eval + (format "%s -o %s %s %s %s" + org-babel-haskell-compiler + tmp-bin-file + flags + (org-babel-process-file-name tmp-src-file) + libs) + "") +(let ((results + (org-babel-eval + (concat tmp-bin-file cmdline) ""))) + (when results +(setq results (org-trim (org-remove-indentation results))) +(org-babel-reassemble-table + (org-babel-result-cond (cdr (assq :result-params params)) + (org-babel-read results t) + (let ((tmp-file (org-babel-temp-file "Haskell-"))) + (with-temp-file tmp-file (insert results)) + (org-babel-import-elisp-from-file tmp-file))) + (org-babel-pick-name + (cdr (assq :colname-names params)) (cdr (assq :colnames params))) + (org-babel-pick-name + (cdr (assq :rowname-names params)) (cdr (assq :rownames params + +(defun org-babel-interpret-haskell (body params) (require
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
I have sent the form. Thank you. On Mon, May 4, 2020 at 11:52 PM Nicolas Goaziou wrote: > Roland Coeurjoly writes: > > > I have read the page about signing FSF papers, but I am unclear about how > > to proceed. > > Could you give some pointers? > > Certainly. See > > https://orgmode.org/worg/org-contribute.html#copyright-issues > > You basically need to fill a form and send it to ass...@gnu.org. > > Thank you for considering signing it. >
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
Please see attached patch. Regards. On Mon, May 4, 2020 at 11:50 PM Nicolas Goaziou wrote: > Roland Coeurjoly writes: > > > I am confused about the last point: > > Use a let-binding instead of setq. > > > > If I use: > > > > (let* compile (string= (cdr (assq :compile params)) "yes")) > > I meant: > > (let ((compile (string= "yes" (cdr (assq :compile params) >...) > From 2c05ba85bffac4019432fa461c0e4f75cd24a0f6 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Tue, 5 May 2020 23:09:58 +0200 Subject: [PATCH 1/1] ob-haskell: introduce :compile header argument * lisp/ob-haskell (org-babel-haskell-compiler): (org-babel-header-args:haskell): new variables. (org-babel-haskell-execute): (org-babel-haskell-interpret): new functions. (org-babel-execute:haskell): use new functions. --- lisp/org/ob-haskell.el | 38 -- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el index d32a2f7bc0..55989adba1 100644 --- a/lisp/org/ob-haskell.el +++ b/lisp/org/ob-haskell.el @@ -23,7 +23,7 @@ ;;; Commentary: -;; Org-Babel support for evaluating Haskell source code. +;; Org Babel support for evaluating Haskell source code. ;; Haskell programs must be compiled before ;; they can be run, but haskell code can also be run through an ;; interactive interpreter. @@ -62,19 +62,19 @@ org-babel-haskell-eoe (defvar haskell-prompt-regexp) -(defcustom org-babel-Haskell-compiler "ghc" +(defcustom org-babel-haskell-compiler "ghc" "Command used to compile a Haskell source code file into an executable. -May be either a command in the path, like ghc -or an absolute path name, like /usr/local/bin/ghc -parameter may be used, like ghc -v" +May be either a command in the path, like \"ghc\" +or an absolute path name, like \"/usr/local/bin/ghc\". +The command can include a parameter, such as \"ghc -v\"" :group 'org-babel - :version "27.0" + :package-version '(Org "9.4") :type 'string) -(defconst org-babel-header-args:haskell '((compile . :any)) +(defconst org-babel-header-args:haskell '(compile . :any) "Haskell-specific header arguments.") -(defun org-babel-Haskell-execute (body params) +(defun org-babel-haskell-execute (body params) "This function should only be called by `org-babel-execute:haskell'" (let* ((tmp-src-file (org-babel-temp-file "Haskell-src-" @@ -85,8 +85,10 @@ org-babel-Haskell-execute (cmdline (cdr (assq :cmdline params))) (cmdline (if cmdline (concat " " cmdline) "")) (flags (cdr (assq :flags params))) - (flags (mapconcat 'identity - (if (listp flags) flags (list flags)) " ")) + (flags (mapconcat #'identity + (if (listp flags) + flags + (list flags)) " ")) (libs (org-babel-read (or (cdr (assq :libs params)) (org-entry-get nil "libs" t)) @@ -97,11 +99,12 @@ org-babel-Haskell-execute (with-temp-file tmp-src-file (insert body)) (org-babel-eval (format "%s -o %s %s %s %s" - org-babel-Haskell-compiler + org-babel-haskell-compiler tmp-bin-file flags (org-babel-process-file-name tmp-src-file) - libs) "") + libs) + "") (let ((results (org-babel-eval (concat tmp-bin-file cmdline) ""))) @@ -116,10 +119,9 @@ org-babel-Haskell-execute (org-babel-pick-name (cdr (assq :colname-names params)) (cdr (assq :colnames params))) (org-babel-pick-name - (cdr (assq :rowname-names params)) (cdr (assq :rownames params) - ))) + (cdr (assq :rowname-names params)) (cdr (assq :rownames params -(defun org-babel-interpret-Haskell (body params) +(defun org-babel-interpret-haskell (body params) (require 'inf-haskell) (add-hook 'inferior-haskell-hook (lambda () @@ -157,10 +159,10 @@ org-babel-interpret-Haskell (defun org-babel-execute:haskell (body params) "Execute a block of Haskell code." - (setq compile (string= (cdr (assq :compile params)) "yes")) + (let ((compile (string= "yes" (cdr (assq :compile params) (if (not compile) - (org-babel-interpret-Haskell body params) -(org-babel-Haskell-execute body params))) + (org-babel-interpret-haskell body params) +(org-babel-haskell-execute body params (defun org-babel-haskell-initiate-session (&optional _session _params) "Initiate a haskell session. -- 2.20.1
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
I am confused about the last point: Use a let-binding instead of setq. If I use: (let* compile (string= (cdr (assq :compile params)) "yes")) I get the following error: ob-haskell.el:158:1: Error: Wrong type argument: listp, compile If I leave with set: (setq compile (string= (cdr (assq :compile params)) "yes")) I get the following warnings: ob-haskell.el:161:12: Warning: assignment to free variable ‘compile’ ob-haskell.el:161:12: Warning: reference to free variable ‘compile’ Upon searching the web, I find a relevant this relevant post <https://emacs.stackexchange.com/questions/21245/dealing-with-warning-assignment-to-free-variable-when-certain-libraries-can-b>, whose conclusion (if I understand it correctly) is that we could live with those warning raised by setq. Apart from this issue I am ready to submit a fixed patch. What do you recommend? On Mon, May 4, 2020 at 5:26 PM Nicolas Goaziou wrote: > Hello, > > Roland Coeurjoly writes: > > > From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001 > > From: Roland Coeurjoly > > Date: Sat, 25 Apr 2020 20:35:22 +0200 > > Subject: [PATCH] Add Haskell specific header argument compile, to compile > > instead of interpret the body of source block > > Thank you! > > Could you rewrite the commit message so that it is on par with our > conventions? > > It could be something like: > > ob-haskell: introduce :compile header argument > > * lisp/ob-haskell (org-babel-haskell-compiler): > (org-babel-header-args:haskell): new variables. > (org-babel-haskell-execute): > (org-babel-haskell-interpret): new functions. > (org-babel-execute:haskell): use new functions. > > > -;; Org-Babel support for evaluating haskell source code. This one will > > -;; be sort of tricky because haskell programs must be compiled before > > +;; Org-Babel support for evaluating Haskell source code. > > +;; Haskell programs must be compiled before > > "Org Babel" would be even better, while you're changing this line. > > > +(defcustom org-babel-Haskell-compiler "ghc" > > No need to capitalize Haskell here. > > > + "Command used to compile a Haskell source code file into an > executable. > > +May be either a command in the path, like ghc > > like "ghc" > > > +or an absolute path name, like /usr/local/bin/ghc > > like "/usr/local/bin/ghc". > > > +parameter may be used, like ghc -v" > > The command can include a parameter, such as "ghc -v". > > > + :group 'org-babel > > + :version "27.0" > > It should be :package-version '(Org "9.4") instead. > > > + :type 'string) > > + > > +(defconst org-babel-header-args:haskell '((compile . :any)) > > + "Haskell-specific header arguments.") > > + > > +(defun org-babel-Haskell-execute (body params) > > + "This function should only be called by `org-babel-execute:haskell'" > > + (let* ((tmp-src-file (org-babel-temp-file > > + "Haskell-src-" > > +".hs")) > > Indentation seems a bit off. > > > + (tmp-bin-file > > + (org-babel-process-file-name > > + (org-babel-temp-file "Haskell-bin-" org-babel-exeext))) > > + (cmdline (cdr (assq :cmdline params))) > > + (cmdline (if cmdline (concat " " cmdline) "")) > > + (flags (cdr (assq :flags params))) > > + (flags (mapconcat 'identity > > Nitpick: #'identity > > > +(if (listp flags) flags (list flags)) " ")) > > + (libs (org-babel-read > > + (or (cdr (assq :libs params)) > > + (org-entry-get nil "libs" t)) > > + nil)) > > Ditto, mind the indentation. > > > + (libs (mapconcat #'identity > > + (if (listp libs) libs (list libs)) > > + " "))) > > +(with-temp-file tmp-src-file (insert body)) > > +(org-babel-eval > > + (format "%s -o %s %s %s %s" > > + org-babel-Haskell-compiler > > + tmp-bin-file > > + flags > > + (org-babel-process-file-name tmp-src-file) > > + libs) "") > > Please move the empty string below. > > > +(let ((results > > +(org-babel-eval > > + (concat tmp-bin-file cmdline) ""))) > > + (when results > > +(se
Re: Babel Haskell. Print all results when header has :results output
No, I haven't yet. As it is required to firm them for the other patch, I am willing to firm them but unsure how to proceed. Please advise. On Mon, May 4, 2020, 17:01 Nicolas Goaziou wrote: > Hello, > > Roland Coeurjoly writes: > > > Right now, when executing the following source block > > > > #+begin_src haskell :results output > > [1..10] > > "hello" == "hello" > >#+end_src > > > > I get the following output: > > > > #+RESULTS: > >: True > > > > Whereas (for me) the desired result would be > > > > #+RESULTS: > >: [1,2,3,4,5,6,7,8,9,10] > >: True > > > > I created the attached patch that achieves the desired result. > > I added a proper commit message and applied your patch. Thank you! > > Have you signed FSF papers? If you haven't, you need to add TINYCHANGE > cookie in your commit messages (and consider signing them, of course!). > > Regards, > > -- > Nicolas Goaziou >
Re: Fwd: Support compilation of Haskell in org mode babel blocks.
I have read the page about signing FSF papers, but I am unclear about how to proceed. Could you give some pointers? Thank you. On Mon, May 4, 2020 at 5:29 PM Nicolas Goaziou wrote: > Roland Coeurjoly writes: > > > lisp/org/ob-haskell.el | 76 +++--- > > 1 file changed, 71 insertions(+), 5 deletions(-) > > I forgot to say a change of this size requires you to sign FSF papers. > Please consider doing so if that's not already the case. > > Thank you. >
Babel Haskell. Print all results when header has :results output
Right now, when executing the following source block #+begin_src haskell :results output [1..10] "hello" == "hello" #+end_src I get the following output: #+RESULTS: : True Whereas (for me) the desired result would be #+RESULTS: : [1,2,3,4,5,6,7,8,9,10] : True I created the attached patch that achieves the desired result. Please notice that the default behaviour (without :results output) remains unchanged. From 0e7d2ac22a028507eaf5ecc85623b62572ee3de8 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Tue, 28 Apr 2020 18:06:50 +0200 Subject: [PATCH] Print all results --- lisp/org/ob-haskell.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el index d32a2f7bc0..e5ef0999e0 100644 --- a/lisp/org/ob-haskell.el +++ b/lisp/org/ob-haskell.el @@ -145,7 +145,7 @@ org-babel-interpret-Haskell (org-babel-reassemble-table (let ((result (pcase result-type - (`output (mapconcat #'identity (reverse (cdr results)) "\n")) + (`output (mapconcat #'identity (reverse results) "\n")) (`value (car results) (org-babel-result-cond (cdr (assq :result-params params)) result (org-babel-script-escape result))) -- 2.20.1
Fwd: Support compilation of Haskell in org mode babel blocks.
-- Forwarded message - From: Roland Coeurjoly Date: Sat, Apr 25, 2020 at 9:04 PM Subject: Support compilation of Haskell in org mode babel blocks. To: Haskell code can be both compiled (for example with ghc), or interpreted (with ghci). Until now, org babel had only support for interpretation. Haskell is weird in that some code for the interpreter cannot be compiled and viceversa. For example, in ghci (the interpreter) you are required to use let to declare functions <https://stackoverflow.com/questions/28927716/org-babel-for-haskell-not-works-of-eval-haskell-block/40920873> . In this patch I add support for compilation with the header argument :compile yes. The function to compile haskell is almost a copy paste of the C funcion in ob-C.el. By default I retain the original behavior, i.e. interpreting the block. I have tested this patch in emacs-27.0.91. It is my first patch to GNU Emacs and I am a newbie with both elisp and haskell. From 091f470a278561a60fac1ee3ee658f6823bc2503 Mon Sep 17 00:00:00 2001 From: Roland Coeurjoly Date: Sat, 25 Apr 2020 20:35:22 +0200 Subject: [PATCH] Add Haskell specific header argument compile, to compile instead of interpret the body of source block --- lisp/org/ob-haskell.el | 76 +++--- 1 file changed, 71 insertions(+), 5 deletions(-) diff --git a/lisp/org/ob-haskell.el b/lisp/org/ob-haskell.el index e004a3405e..d32a2f7bc0 100644 --- a/lisp/org/ob-haskell.el +++ b/lisp/org/ob-haskell.el @@ -23,12 +23,13 @@ ;;; Commentary: -;; Org-Babel support for evaluating haskell source code. This one will -;; be sort of tricky because haskell programs must be compiled before +;; Org-Babel support for evaluating Haskell source code. +;; Haskell programs must be compiled before ;; they can be run, but haskell code can also be run through an ;; interactive interpreter. ;; -;; For now lets only allow evaluation using the haskell interpreter. +;; By default we evaluate using the Haskell interpreter. +;; To use the compiler, specify :compile yes in the header. ;;; Requirements: @@ -47,6 +48,7 @@ (declare-function run-haskell "ext:inf-haskell" (&optional arg)) (declare-function inferior-haskell-load-file "ext:inf-haskell" (&optional reload)) +(declare-function org-entry-get "org" (pom property &optional inherit literal-nil)) (defvar org-babel-tangle-lang-exts) (add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs")) @@ -60,8 +62,64 @@ org-babel-haskell-eoe (defvar haskell-prompt-regexp) -(defun org-babel-execute:haskell (body params) - "Execute a block of Haskell code." +(defcustom org-babel-Haskell-compiler "ghc" + "Command used to compile a Haskell source code file into an executable. +May be either a command in the path, like ghc +or an absolute path name, like /usr/local/bin/ghc +parameter may be used, like ghc -v" + :group 'org-babel + :version "27.0" + :type 'string) + +(defconst org-babel-header-args:haskell '((compile . :any)) + "Haskell-specific header arguments.") + +(defun org-babel-Haskell-execute (body params) + "This function should only be called by `org-babel-execute:haskell'" + (let* ((tmp-src-file (org-babel-temp-file + "Haskell-src-" +".hs")) + (tmp-bin-file + (org-babel-process-file-name + (org-babel-temp-file "Haskell-bin-" org-babel-exeext))) + (cmdline (cdr (assq :cmdline params))) + (cmdline (if cmdline (concat " " cmdline) "")) + (flags (cdr (assq :flags params))) + (flags (mapconcat 'identity + (if (listp flags) flags (list flags)) " ")) + (libs (org-babel-read + (or (cdr (assq :libs params)) + (org-entry-get nil "libs" t)) + nil)) + (libs (mapconcat #'identity + (if (listp libs) libs (list libs)) + " "))) +(with-temp-file tmp-src-file (insert body)) +(org-babel-eval + (format "%s -o %s %s %s %s" + org-babel-Haskell-compiler + tmp-bin-file + flags + (org-babel-process-file-name tmp-src-file) + libs) "") +(let ((results + (org-babel-eval + (concat tmp-bin-file cmdline) ""))) + (when results +(setq results (org-trim (org-remove-indentation results))) +(org-babel-reassemble-table + (org-babel-result-cond (cdr (assq :result-params params)) + (org-babel-read results t) + (let ((tmp-file (org-babel-temp-file "Haskell-"))) + (with-temp-file tmp-file (insert results)) + (org-babel-import-elisp-from-file tmp-file))) + (org-babel-pick-name + (cdr (assq :colname-names params)) (cdr (assq :colnames params))) +
[O] Bug: Exporting dash to html gives hexadecimal code [8.2.10 (release_8.2.10 @ /usr/share/emacs/24.5/lisp/org/)]
I publish (M+x org-publish-project) the following to html: #+OPTIONS: toc:nil num:nil #+BEGIN_EXPORT html --- layout: post title: "A beginner's Emacs config" subtitle: "First steps into the Emacs universe" tags: [hacking, emacs] category: blog --- #+END_EXPORT I get the following: — layout: post title: "A beginner's Emacs config" subtitle: "First steps into the Emacs universe" tags: [hacking, emacs] category: blog — I expect the following: --- layout: post title: "A beginner's Emacs config" subtitle: "First steps into the Emacs universe" tags: [hacking, emacs] category: blog --- I learn that — is the hexadecimal code for a dash (-). As a result of the previously described behaviour, my blog doesn't display the html. Like a all. Emacs : GNU Emacs 24.5.1 (x86_64-pc-linux-gnu, GTK+ Version 3.18.9) of 2017-09-20 on lcy01-07, modified by Debian Package: Org-mode version 8.2.10 (release_8.2.10 @ /usr/share/emacs/24.5/lisp/org/) current state: == (setq org-tab-first-hook '(org-hide-block-toggle-maybe org-src-native-tab-command-maybe org-babel-hide-result-toggle-maybe org-babel-header-arg-expand) org-speed-command-hook '(org-speed-command-default-hook org-babel-speed-command-hook) org-occur-hook '(org-first-headline-recenter) org-export-show-temporary-export-buffer nil org-metaup-hook '(org-babel-load-in-session-maybe) org-html-format-drawer-function '(lambda (name contents) contents) org-latex-format-inlinetask-function 'ignore org-confirm-shell-link-function 'yes-or-no-p org-ascii-format-inlinetask-function 'org-ascii-format-inlinetask-default org-latex-format-headline-function 'org-latex-format-headline-default-function org-after-todo-state-change-hook '(org-clock-out-if-current) org-latex-format-drawer-function '(lambda (name contents) contents) org-src-mode-hook '(org-src-babel-configure-edit-buffer org-src-mode-configure-edit-buffer) org-agenda-before-write-hook '(org-agenda-add-entry-text) org-babel-pre-tangle-hook '(save-buffer) org-mode-hook '(#[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-show-block-all append local] 5] #[nil "\300\301\302\303\304$\207" [org-add-hook change-major-mode-hook org-babel-show-result-all append local] 5] org-babel-result-hide-spec org-babel-hide-all-hashes) org-ascii-format-drawer-function '(lambda (name contents width) contents) org-ctrl-c-ctrl-c-hook '(org-babel-hash-at-point org-babel-execute-safely-maybe) org-cycle-hook '(org-cycle-hide-archived-subtrees org-cycle-hide-drawers org-cycle-hide-inline-tasks org-cycle-show-empty-lines org-optimize-window-after-visibility-change) org-confirm-elisp-link-function 'yes-or-no-p org-metadown-hook '(org-babel-pop-to-session-maybe) org-html-format-headline-function 'ignore org-html-format-inlinetask-function 'ignore org-clock-out-hook '(org-clock-remove-empty-clock-drawer) org-publish-project-alist '(("https://rcoeurjoly.github.io/posts"; :base-directory "~/RCoeurjoly.github.io/_org/posts" :base-extension "org" :publishing-directory "~/RCoeurjoly.github.io/_posts" :recursive t :publishing-function org-html-publish-to-html :headline-levels 4 :html-extension "html" :body-only t) ) )