[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [PATCH] An amended to the enhance Org babel for scheme blocks
From: |
José L. Doménech |
Subject: |
[O] [PATCH] An amended to the enhance Org babel for scheme blocks |
Date: |
Mon, 17 Jul 2017 19:55:32 +0200 |
User-agent: |
Wanderlust/2.15.9 (Almost Unreal) SEMI-EPG/1.14.7 (Harue) FLIM/1.14.9 (Gojō) APEL/10.8 EasyPG/1.0.0 Emacs/26.0 (x86_64-pc-linux-gnu) MULE/6.0 (HANACHIRUSATO) |
Hello again, I have added a :prologue param to the scheme blocks of babel.
This multiple option prepends all the values in the generated code of the
block.
This patch also includes the previous one that enabled returning a table
when evaluating a scheme block.
A changelog:
Enhance the babel block for scheme.
Allows scheme code blocks to return a table and add a :prologue param
to the scheme blocks. All :prologue params are prepended to the
body of code.
* lisp/ob-scheme.el (org-babel-scheme-null-to): New custom option that
allows to use a empty list to format the table output, initially
assigned to 'hlines.
(org-babel-scheme-table-or-string): New helper function to convert
the return value from the block as a table or a string.
(org-babel-execute-src-block): Changed to allow the return of a
table for the output.
(org-babel-expand-body:scheme) Add :prologue param support.
The patch:
0001-Enhance-the-babel-block-for-scheme.patch
Description: Text document
I hope it will be useful for someone.
José L. Doménech
On Sun, 16 Jul 2017 19:08:02 +0200,
José L. Doménech wrote:
>
> [1 <text/plain; US-ASCII (7bit)>]
> Hello, I have modified 'ob-scheme.el' to be able to return org tables.
>
> This is a quick patch. I hope you find it useful buut I could modify,
> document or write test for it if necesary.
>
> I have already assigned the copyright for Emacs to the FSF.
>
>
> Enhance the scheme babel block output.
>
> Allow scheme code blocks to return a table.
>
> * lisp/ob-scheme.el (org-babel-scheme-null-to): New custom option that
> allows to use a empty list to format the table output, initially assigned
> to 'hlines.
> (org-babel-scheme-table-or-string): New helper function to convert the
> return value from the block as a table or a string.
> (org-babel-execute-src-block): Changed to allow the return of a table for
> the output.
>
> [2 ob-scheme.el.diff <text/plain; US-ASCII (base64)>]
> 1 file changed, 35 insertions(+), 11 deletions(-)
> lisp/ob-scheme.el | 46 +++++++++++++++++++++++++++++++++++-----------
>
> modified lisp/ob-scheme.el
> @@ -51,6 +51,13 @@
> (start end &optional and-go raw nomsg))
> (declare-function geiser-repl-exit "ext:geiser-repl" (&optional arg))
>
> +(defcustom org-babel-scheme-null-to 'hline
> + "Replace `null' in scheme tables with this before returning."
> + :group 'org-babel
> + :version "24.4"
> + :package-version '(Org . "8.0")
> + :type 'symbol)
> +
> (defvar org-babel-default-header-args:scheme '()
> "Default header arguments for scheme code blocks.")
>
> @@ -176,6 +183,18 @@ is true; otherwise returns the last value."
> result))))
> result))
>
> +(defun org-babel-scheme-table-or-string (results)
> + "Convert RESULTS into an appropriate elisp value.
> +If the results look like a list or tuple, then convert them into an
> +Emacs-lisp table, otherwise return the results as a string."
> + (let ((res (org-babel-script-escape results)))
> + (if (listp res)
> + (mapcar (lambda (el) (if (or (eq el '()) (eq el 'null))
> + org-babel-scheme-null-to
> + el))
> + res)
> + res)))
> +
> (defun org-babel-execute:scheme (body params)
> "Execute a block of Scheme code with org-babel.
> This function is called by `org-babel-execute-src-block'"
> @@ -184,7 +203,6 @@ This function is called by `org-babel-execute-src-block'"
> "^ ?\\*\\([^*]+\\)\\*" "\\1"
> (buffer-name source-buffer))))
> (save-excursion
> - (org-babel-reassemble-table
> (let* ((result-type (cdr (assq :result-type params)))
> (impl (or (when (cdr (assq :scheme params))
> (intern (cdr (assq :scheme params))))
> @@ -192,16 +210,22 @@ This function is called by
> `org-babel-execute-src-block'"
> (car geiser-active-implementations)))
> (session (org-babel-scheme-make-session-name
> source-buffer-name (cdr (assq :session params)) impl))
> - (full-body (org-babel-expand-body:scheme body params)))
> - (org-babel-scheme-execute-with-geiser
> - full-body ; code
> - (string= result-type "output") ; output?
> - impl ; implementation
> - (and (not (string= session "none")) session))) ; session
> - (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)))))))
> + (full-body (org-babel-expand-body:scheme body params))
> + (result
> + (org-babel-scheme-execute-with-geiser
> + full-body ; code
> + (string= result-type "output") ; output?
> + impl ; implementation
> + (and (not (string= session "none")) session))) ; session
> + )
> + (let ((table
> + (org-babel-reassemble-table
> + result
> + (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))))))
> + (org-babel-scheme-table-or-string table))))))
>
> (provide 'ob-scheme)
>
> [3 <text/plain; ISO-8859-1 (quoted-printable)>]
>
>
> Best regards:
>
> José L. Doménech
- [O] Enhance Org babel scheme, José L. Doménech, 2017/07/16
- [O] [PATCH] An amended to the enhance Org babel for scheme blocks,
José L. Doménech <=