emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
@ 2018-06-20 19:36 Henry Blevins
  2018-06-21 16:16 ` Nicolas Goaziou
  2018-06-21 17:56 ` Neil Jerram
  0 siblings, 2 replies; 6+ messages in thread
From: Henry Blevins @ 2018-06-20 19:36 UTC (permalink / raw)
  To: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 325 bytes --]

Currently, scheme babel blocks ignore :results header arguments like
'verbatim' and attempt to format all output as tables. This patch corrects
that and performs the user supplied formatting.

This is my first time contributing a patch, so I apologize if I have made
any mistakes in submitting this.

Regards,

Henry Blevins

[-- Attachment #1.2: Type: text/html, Size: 465 bytes --]

[-- Attachment #2: 0001-ob-scheme.el-Fix-scheme-blocks-ignoring-results-in-f.patch --]
[-- Type: text/x-patch, Size: 1952 bytes --]

From f93f086cbb16926c883a31fe8ad796e0da8bc8f7 Mon Sep 17 00:00:00 2001
From: Henry Blevins <heblevi@gmail.com>
Date: Wed, 20 Jun 2018 14:38:47 -0400
Subject: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in
 formatting

* ob-scheme.el (org-babel-execute:scheme): Process the :result header
argument to conditionally and appropriately format output.

Currently, `org-babel-execute:scheme' ignores the user specified :result header
argument found in the :result-param parameter and process all output as a table.
The fix is to pass the `result' and :result-param to the `org-babel-result-cond'
function to invoke the corresponding formatting.

For example, the following block incorrectly formats its output as a table:

(list 1 2 3)

| 1 | 2 | 3 |

This patch results in the correct behavior:

(list 1 2 3)

: (1 2 3)

Bringing it inline with the result using Emacs lisp:

(list 1 2 3)

: (1 2 3)
---
 lisp/ob-scheme.el | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-scheme.el b/lisp/ob-scheme.el
index 0abac7462..fb7c48bbc 100644
--- a/lisp/ob-scheme.el
+++ b/lisp/ob-scheme.el
@@ -212,6 +212,7 @@ This function is called by `org-babel-execute-src-block'"
 	     (session (org-babel-scheme-make-session-name
 		       source-buffer-name (cdr (assq :session params)) impl))
 	     (full-body (org-babel-expand-body:scheme body params))
+	     (result-params (cdr (assq :result-params params)))
 	     (result
 	      (org-babel-scheme-execute-with-geiser
 	       full-body		       ; code
@@ -225,7 +226,9 @@ This function is called by `org-babel-execute-src-block'"
 				     (cdr (assq :colnames params)))
 		(org-babel-pick-name (cdr (assq :rowname-names params))
 				     (cdr (assq :rownames params))))))
-	  (org-babel-scheme--table-or-string table))))))
+	  (org-babel-result-cond result-params
+	    result
+	    (org-babel-scheme--table-or-string table)))))))
 
 (provide 'ob-scheme)
 
-- 
2.17.0


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

* Re: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
  2018-06-20 19:36 [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting Henry Blevins
@ 2018-06-21 16:16 ` Nicolas Goaziou
  2018-06-21 19:05   ` Henry Blevins
  2018-06-21 17:56 ` Neil Jerram
  1 sibling, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2018-06-21 16:16 UTC (permalink / raw)
  To: Henry Blevins; +Cc: emacs-orgmode

Hello,

Henry Blevins <heblevi@gmail.com> writes:

> Currently, scheme babel blocks ignore :results header arguments like
> 'verbatim' and attempt to format all output as tables. This patch corrects
> that and performs the user supplied formatting.
>
> This is my first time contributing a patch, so I apologize if I have made
> any mistakes in submitting this.

Thank you.

If you haven't signed FSF papers yet, you need to add "TINYCHANGE" at
the end of your commit message.

Also, would you mind adding a couple of tests in "test-ob-scheme.el"?

Regards,

-- 
Nicolas Goaziou

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

* Re: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
  2018-06-20 19:36 [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting Henry Blevins
  2018-06-21 16:16 ` Nicolas Goaziou
@ 2018-06-21 17:56 ` Neil Jerram
  2018-06-21 18:44   ` Henry Blevins
  1 sibling, 1 reply; 6+ messages in thread
From: Neil Jerram @ 2018-06-21 17:56 UTC (permalink / raw)
  To: Henry Blevins, emacs-orgmode

Henry Blevins <heblevi@gmail.com> writes:

> Currently, scheme babel blocks ignore :results header arguments like
> 'verbatim' and attempt to format all output as tables. This patch corrects
> that and performs the user supplied formatting.
>
> This is my first time contributing a patch, so I apologize if I have made
> any mistakes in submitting this.

Thanks for working on this Henry; as a fellow ob-scheme user, I
appreciate it.

> Currently, `org-babel-execute:scheme' ignores the user specified :result header
> argument found in the :result-param parameter and process all output as a table.
> The fix is to pass the `result' and :result-param to the `org-babel-result-cond'
> function to invoke the corresponding formatting.
>
> For example, the following block incorrectly formats its output as a table:
>
> (list 1 2 3)
>
> | 1 | 2 | 3 |
>
> This patch results in the correct behavior:
>
> (list 1 2 3)
>
> : (1 2 3)
>
> Bringing it inline with the result using Emacs lisp:
>
> (list 1 2 3)
>
> : (1 2 3)

But if I want the table output

| 1 | 2 | 3 |

will there still be a way to get it?  (I'm sure I have org files that
need this!)

Regards,
   Neil

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

* Re: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
  2018-06-21 17:56 ` Neil Jerram
@ 2018-06-21 18:44   ` Henry Blevins
  0 siblings, 0 replies; 6+ messages in thread
From: Henry Blevins @ 2018-06-21 18:44 UTC (permalink / raw)
  To: Neil Jerram; +Cc: emacs-orgmode

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

Neil Jerram <neil@ossau.homelinux.net> writes:

> But if I want the table output
>
> | 1 | 2 | 3 |
>
> will there still be a way to get it? (I'm sure I have org files that
> need this!)

This patch will not affect any of your existing org files unless you have
specified you want the block to output as 'verbatim', 'scalar' or
otherwise. For
all org source blocks the default is to process the output as a table if it
is
in a suitable format, so the following would still occur:

#+BEGIN_SRC scheme
  (list 1 2 3)
#+END_SRC

#+RESULTS:
| 1 | 2 | 3 |

Additionally, you can always specify the output be processed as a table by
specifying it in the ':results' header argument.

#+BEGIN_SRC scheme :results table
  (list 1 2 3)
#+END_SRC

#+RESULTS:
| 1 | 2 | 3 |

The other defined options for result formatting can be found here
https://orgmode.org/manual/results.html.

[-- Attachment #2: Type: text/html, Size: 2169 bytes --]

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

* Re: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
  2018-06-21 16:16 ` Nicolas Goaziou
@ 2018-06-21 19:05   ` Henry Blevins
  2018-06-21 20:02     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Henry Blevins @ 2018-06-21 19:05 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode


[-- Attachment #1.1: Type: text/plain, Size: 337 bytes --]

Nicolas,

Attached is the patch adding tests for verbatim and list result types.

> If you haven't signed FSF papers yet, you need to add "TINYCHANGE" at
> the end of your commit message.

I have signed FSF papers. I know these are small enough changes not to
require
 that and can add "TINYCHANGE" if you would prefer.

Regards,

Henry

[-- Attachment #1.2: Type: text/html, Size: 1301 bytes --]

[-- Attachment #2: 0002-test-ob-scheme.el-Add-tests-for-scheme-result-types.patch --]
[-- Type: text/x-patch, Size: 1433 bytes --]

From 564661f586501dd235f2dad6ece45d0100dc21a9 Mon Sep 17 00:00:00 2001
From: Henry Blevins <heblevi@gmail.com>
Date: Thu, 21 Jun 2018 14:56:48 -0400
Subject: [PATCH 2/2] test-ob-scheme.el: Add tests for scheme result types

* test-ob-scheme.el (test-ob-scheme/verbatim, test-ob-scheme/list):
  Add tests for scheme source block output specify the results as
  'verbatim' or 'list'.
---
 testing/lisp/test-ob-scheme.el | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/testing/lisp/test-ob-scheme.el b/testing/lisp/test-ob-scheme.el
index a3406d309..a47649436 100644
--- a/testing/lisp/test-ob-scheme.el
+++ b/testing/lisp/test-ob-scheme.el
@@ -39,6 +39,34 @@
 	   (org-babel-execute-maybe)
 	   (buffer-string))))
 
+(ert-deftest test-ob-scheme/verbatim ()
+  "Test verbatim output."
+  (equal "#+begin_src scheme
+'(1 2 3)
+#+end_src
+
+#+RESULTS:
+: (1 2 3)
+"
+	 (org-test-with-temp-text "#+begin_src scheme :results verbatim\n'(1 2 3)\n#+end_src"
+	   (org-babel-execute-maybe)
+	   (buffer-string))))
+
+(ert-deftest test-ob-scheme/list ()
+  "Test list output."
+  (equal "#+begin_src scheme :results list
+'(1 2 3)
+#+end_src
+
+#+RESULTS:
+- 1
+- 2
+- 3
+"
+	 (org-test-with-temp-text "#+begin_src scheme :results list\n'(1 2 3)\n#+end_src"
+	   (org-babel-execute-maybe)
+	   (buffer-string))))
+
 (ert-deftest test-ob-scheme/prologue ()
   "Test :prologue parameter."
   (should
-- 
2.17.1


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

* Re: [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting
  2018-06-21 19:05   ` Henry Blevins
@ 2018-06-21 20:02     ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2018-06-21 20:02 UTC (permalink / raw)
  To: Henry Blevins; +Cc: emacs-orgmode

Hello,

Henry Blevins <heblevi@gmail.com> writes:

> Attached is the patch adding tests for verbatim and list result types.

Applied both patches. Thank you.

> I have signed FSF papers.

Great. I added you to the list of contributors.

> I know these are small enough changes not to require that and can add
> "TINYCHANGE" if you would prefer.

That is not necessary.

Regards,

-- 
Nicolas Goaziou

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

end of thread, other threads:[~2018-06-21 20:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-20 19:36 [PATCH] ob-scheme.el: Fix scheme blocks ignoring :results in formatting Henry Blevins
2018-06-21 16:16 ` Nicolas Goaziou
2018-06-21 19:05   ` Henry Blevins
2018-06-21 20:02     ` Nicolas Goaziou
2018-06-21 17:56 ` Neil Jerram
2018-06-21 18:44   ` Henry Blevins

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