emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: "Charles C. Berry" <ccberry@ucsd.edu>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>
Cc: Aaron Ecay <aaronecay@gmail.com>,
	Andreas Leha <andreas.leha@med.uni-goettingen.de>,
	emacs-orgmode@gnu.org, Ista Zahn <istazahn@gmail.com>,
	mcg <giepen.m@googlemail.com>
Subject: New patches WAS Re: [PATCH] inline src block results can be removed
Date: Mon, 12 Jan 2015 16:48:00 -0800	[thread overview]
Message-ID: <alpine.OSX.2.00.1501121608520.1829@charlessmacbook> (raw)
In-Reply-To: <87zjbqrapy.fsf@nicolasgoaziou.fr>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 3488 bytes --]

On Sun, 16 Nov 2014, Nicolas Goaziou wrote:

> "Charles C. Berry" <ccberry@ucsd.edu> writes:
>
>> For now, I'd be willing to make patches that will allow removal of the
>> inline src block results that do *not* involve these header args:
>>
>> - :file <fn>
>> - :wrap <wrapper>
>> - :results latex html drawer org code
>>
>> which I can do barely touching `org-babel-insert-result' and this
>> simplifies matters a lot.
>
> IMO, we're too much focused on the implementation details. We ought to
> agree on what should be done first. For example, considering
> `org-babel-insert-result' and its RESULT-PARAMS argument, I think the
> following makes sense:
>
>  | Param   | Example output                    |
>  |---------+-----------------------------------|
>  | default | {{{results(42)}}}                 |
>  | file    | {{{results(file:something.pdf)}}} |
>  | list    |                                   |
>  | raw     | 42                                |
>  | drawer  |                                   |
>  | org     | {{{results(src_org{...})}}}        |
>  | html    | {{{results(@@html:...@@)}}}       |
>  | latex   | {{{results(@@latex:...@@)}}}      |
>  | code    | {{{results(src_xxx{...})}}}        |
>
> Basically, it should be possible to remove any kind of result using
> "results" macro, with the exception of "raw".  "list" and "drawer" can
> be ignored since there is no inline equivalent.
>
> Another option for "drawer" is to also use export snippets. So,
> basically, "drawer something" would generate
> {{{results(@@something:...@@)}}}.
>

I'm back online.

I've attached three patches and two files that show the behavior under the 
current master (12 Jan 2015, e0879b03d08bb4acc663084076370482f61e8698) and 
under the patched version.

With the patches, inline source block results can be removed by 
re-executing the source block if they are wrapped in a 
`{{{results(...)}}}' macro. The schema for the RESULT-PARAMS is as 
follows, but see the examples for caveats:

   | Param           | Example output                    |
   |-----------------+-----------------------------------+
   | default/replace | {{{results(=42=)}}}               |
   | list            | \n: - 42\n\n                      |
   | raw             | 42                                |
   | drawer/wrap     | {{{results(42)}}}                 |
   | org             | {{{results(src_org{...})}}}       |
   | html            | {{{results(@@html:...@@)}}}       |
   | latex           | {{{results(@@latex:...@@)}}}      |
   | code            | {{{results(src_emacs-lisp{...})}}}|
   | table           | \n| 42 |\n\n                      |
   |-----------------+-----------------------------------+

where the default is `src_emacs-lisp{42}' and subsequent rows give the 
`:results' arg.

`:file my.pdf' produces `{{{results([[file:/my.pdf]])}}}', although
link style fontification and open on click are lost as a consequence.

Also `:wrap whatknot' does the obvious.

In addition a few bugs have been squashed (as seen in the difference 
between the two example files).

The `results' macro is hard coded to wrap `value' except when list, table, 
or raw is specified as a RESULT-PARAM or when (listp value). And obviously, :file

Users can still customize org-babel-inline-result-wrap, but the macro will 
wrap the around whatever it yields.

HTH,

Chuck

p.s. The November dates on the patches are a result of using
`git rebase -i' to squash newer commits on top of older ones.

[-- Attachment #2: ob-core.el patch --]
[-- Type: TEXT/PLAIN, Size: 11666 bytes --]

From badc80465860ad63251ae68170cc09daa676b490 Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Thu, 13 Nov 2014 20:45:01 -0800
Subject: [PATCH 1/3] lisp/ob-core.el: Inline source block results are
 replaceable

* lisp/ob-core.el (org-babel-insert-result): Delete any `results'
  macro following current inline src block; insert current value in
  'results' macro possibly wrapping RESULT in an export snippet or
  inline source block first. Protect commas and backslash commas in the
  RESULT with backslashes if the macro form is used.

* lisp/ob-core.el (org-babel-remove-inline-result): Add function to
  delete "{{{results(.*)}}}" macro call of current inline src block.

Inline source block results can be removed by re-executing the source
block if they are wrapped in a `{{{results(...)}}}' macro. The schema
for the RESULT-PARAMS is:

  | Param   | Example output                    |
  |---------+-----------------------------------+
  | default | {{{results(42)}}}                 |
  | file    | {{{results(file:something.pdf)}}} |
  | list    | \n: - 42\n\n                      |
  | raw     | 42                                |
  | drawer  | {{{results(42)}}}                 |
  | org     | {{{results(src_org{...})}}}       |
  | html    | {{{results(@@html:...@@)}}}       |
  | latex   | {{{results(@@latex:...@@)}}}      |
  | code    | {{{results(src_xxx{...})}}}       |
  | table   | \n| 42 |\n\n                      |
  |---------+-----------------------------------+

where the default is `src_emacs{42}' and subsequent rows give the `:results' arg.

The `:wrap something' header arg gives an effect similar to `:results html' or
`:results latex'.

On export, the macro is stripped away before parsing leaving only its contents.

Combining RESULT-PARAMS that use the `results' macro can cause
havoc. Standard source blocks or the `raw' arg should generally be
used for complicated constructions of RESULT-PARAMS, lists, tables,
and/or multi-line RESULTs.
---
 lisp/ob-core.el | 114 +++++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 84 insertions(+), 30 deletions(-)

diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index 93fcb2a..80542ec 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2073,13 +2073,18 @@ If the path of the link is a file path it is expanded using
 (defun org-babel-insert-result
   (result &optional result-params info hash indent lang)
   "Insert RESULT into the current buffer.
-By default RESULT is inserted after the end of the
-current source block.  With optional argument RESULT-PARAMS
-controls insertion of results in the org-mode file.
+By default RESULT is inserted after the end of the current source
+block.  The RESULT of an inline source block usually will be
+wrapped inside a `results' macro and placed on the same line as
+the inline source block. The macro is stripped upon
+export. Multiline and non-scalar RESULTS from inline source
+blocks are fragile and should be avoided. With optional argument
+RESULT-PARAMS controls insertion of results in the org-mode file.
 RESULT-PARAMS can take the following values:
 
 replace - (default option) insert results after the source block
-          replacing any previously inserted results
+          or inline source block replacing any previously
+          inserted results
 
 silent -- no results are inserted into the Org-mode buffer but
           the results are echoed to the minibuffer and are
@@ -2096,8 +2101,9 @@ raw ----- results are added directly to the Org-mode file.  This
           formatted text.
 
 drawer -- results are added directly to the Org-mode file as with
-          \"raw\", but are wrapped in a RESULTS drawer, allowing
-          them to later be replaced or removed automatically.
+          \"raw\", but are wrapped in a RESULTS drawer or results
+          macro, allowing them to later be replaced or removed
+          automatically.
 
 org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
           org\" block depending on whether the current source block is
@@ -2105,13 +2111,15 @@ org ----- results are added inside of a \"src_org{}\" or \"#+BEGIN_SRC
           but Org syntax here will be discarded when exporting the
           file.
 
-html ---- results are added inside of a #+BEGIN_HTML block.  This
-          is a good option if you code block will output html
-          formatted text.
+html ---- results are added inside of a #+BEGIN_HTML block or
+          html export snippet depending on whether the current
+          source block is inline or not.  This is a good option
+          if you code block will output html formatted text.
 
-latex --- results are added inside of a #+BEGIN_LATEX block.
-          This is a good option if you code block will output
-          latex formatted text.
+latex --- results are added inside of a #+BEGIN_LATEX block or
+          latex export snippet depending on whether the current
+          source block is inline or not.  This is a good option
+          if you code block will output latex formatted text.
 
 code ---- the results are extracted in the syntax of the source
           code of the language being evaluated and are added
@@ -2138,9 +2146,12 @@ code ---- the results are extracted in the syntax of the source
 		(when (or (org-babel-get-inline-src-block-matches)
 			  (org-babel-get-lob-one-liner-matches))
 		  (goto-char (match-end 0))
-		  (insert (if (listp result) "\n" " "))
+		  (insert (if (or (listp result)
+				  (member "list" result-params))
+			      "\n" " "))
 		  (point))))
-	     (existing-result (unless inlinep
+	     (existing-result (if inlinep
+				  (org-babel-remove-inline-result)
 				(org-babel-where-is-src-block-result
 				 t info hash indent)))
 	     (results-switches
@@ -2179,7 +2190,12 @@ code ---- the results are extracted in the syntax of the source
 		 ((member "prepend" result-params)))) ; already there
 	      (setq results-switches
 		    (if results-switches (concat " " results-switches) ""))
-	      (let ((wrap (lambda (start finish &optional no-escape no-newlines)
+	      (let ((wrap (lambda (start finish &optional no-escape no-newlines
+					 inline-start inline-finish)
+			    (when inlinep
+			      (setq start inline-start)
+			      (setq finish inline-finish)
+			      (setq no-newlines t))
 			    (goto-char end)
 			    (insert (concat finish (unless no-newlines "\n")))
 			    (goto-char beg)
@@ -2196,6 +2212,7 @@ code ---- the results are extracted in the syntax of the source
 		 ((null result))
 		 ;; insert a list if preferred
 		 ((member "list" result-params)
+		  (goto-char beg)
 		  (insert
 		   (org-babel-trim
 		    (org-list-to-generic
@@ -2220,6 +2237,19 @@ code ---- the results are extracted in the syntax of the source
 		 ((member "file" result-params)
 		  (when inlinep (goto-char inlinep))
 		  (insert result))
+		 ;; escape commas, e.g. {{{results(a\,b)}}} 
+		 ((and inlinep
+		       (not (member "raw" result-params)))
+		  (goto-char beg)
+		  (insert
+		   ;; Escape commas and preceding backslash per
+		   ;;  (info "(org) Macro replacement").
+		   (replace-regexp-in-string
+		    "\\(\\\\*\\)\\(,\\)"
+		    (lambda (str)
+		      (let ((len (length (match-string 1 str))))
+			(concat (make-string (* 2 (/ len 2)) ?\\) "\\,")))
+		    result nil t)))
 		 (t (goto-char beg) (insert result)))
 		(when (funcall proper-list-p result) (goto-char (org-table-end)))
 		(setq end (point-marker))
@@ -2228,34 +2258,41 @@ code ---- the results are extracted in the syntax of the source
 		 ((assoc :wrap (nth 2 info))
 		  (let ((name (or (cdr (assoc :wrap (nth 2 info))) "RESULTS")))
 		    (funcall wrap (concat "#+BEGIN_" name)
-			     (concat "#+END_" (car (org-split-string name))))))
+			     (concat "#+END_" (car (org-split-string name)))
+			     nil nil (concat "{{{results(@@" name ":") "@@)}}}")))
 		 ((member "html" result-params)
-		  (funcall wrap "#+BEGIN_HTML" "#+END_HTML"))
-		 ((member "latex" result-params)
-		  (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX"))
+		  (funcall wrap "#+BEGIN_HTML" "#+END_HTML" nil nil
+			   "{{{results(@@html:" "@@)}}}"))
+		 ((member "latex" result-params) 
+		  (funcall wrap "#+BEGIN_LaTeX" "#+END_LaTeX" nil nil
+			   "{{{results(@@latex:" "@@)}}}"))
 		 ((member "org" result-params)
 		  (goto-char beg) (if (org-at-table-p) (org-cycle))
-		  (if inlinep
-		      (funcall wrap "src_org{" "}" nil t)
-		      (funcall wrap "#+BEGIN_SRC org" "#+END_SRC")))
+		  (funcall wrap "#+BEGIN_SRC org" "#+END_SRC" nil nil
+			   "{{{results(src_org{" "})}}}"))
 		 ((member "code" result-params)
 		  (let ((lang (or lang "none")))
-		    (if inlinep
-			(funcall wrap (format "src_%s[%s]{" lang results-switches)
-				 "}" nil t)
-			(funcall wrap (format "#+BEGIN_SRC %s%s" lang results-switches)
-				 "#+END_SRC"))))
+		    (funcall wrap (format "#+BEGIN_SRC %s%s" lang results-switches)
+			     "#+END_SRC" nil nil
+			     (format "{{{results(src_%s[%s]{" lang results-switches)
+			     "})}}}")))
 		 ((member "raw" result-params)
 		  (goto-char beg) (if (org-at-table-p) (org-cycle)))
 		 ((or (member "drawer" result-params)
 		      ;; Stay backward compatible with <7.9.2
 		      (member "wrap" result-params))
 		  (goto-char beg) (if (org-at-table-p) (org-cycle))
-		  (funcall wrap ":RESULTS:" ":END:" 'no-escape))
+		  (funcall wrap ":RESULTS:" ":END:" 'no-escape nil
+			   "{{{results(" ")}}}"))
+		 ((and inlinep (member "file" result-params))
+		  (funcall wrap nil nil nil nil "{{{results(" ")}}}"))
 		 ((and (not (funcall proper-list-p result))
 		       (not (member "file" result-params)))
-		  (org-babel-examplify-region beg end results-switches)
-		  (setq end (point)))))
+		  (let ((org-babel-inline-result-wrap
+			 ;; Hard code {{{results(...)}}} on top of customization.
+			 (format "{{{results(%s)}}}" org-babel-inline-result-wrap)))
+		    (org-babel-examplify-region beg end results-switches)
+		    (setq end (point))))))
 	      ;; possibly indent the results to match the #+results line
 	      (when (and (not inlinep) (numberp indent) indent (> indent 0)
 			 ;; in this case `table-align' does the work for us
@@ -2283,6 +2320,23 @@ code ---- the results are extracted in the syntax of the source
 	   (if keep-keyword (1+ (match-end 0)) (1- (match-beginning 0)))
 	   (progn (forward-line 1) (org-babel-result-end))))))))
 
+(defun org-babel-remove-inline-result ()
+  "Remove the result of the current inline-src-block if it is
+  wrapped in a `results' macro and trim extraneous leading whitespace."
+  (let ((el (org-element-context)) post-blank)
+    (when (eq (org-element-type el) 'inline-src-block)
+      (save-excursion
+	(setq post-blank (org-element-property :post-blank el))
+        (goto-char (org-element-property :end el))
+        (setq el (org-element-context))
+        (when (and (eq (org-element-type el) 'macro)
+                   (equal (org-element-property :key el) "results"))
+          (delete-region ; And (only) extra leading whitespace.
+           (- (org-element-property :begin el)
+	      (- post-blank 1))
+           (- (org-element-property :end el)
+	      (org-element-property :post-blank el))))))))
+
 (defun org-babel-remove-result-one-or-many (x)
   "Remove the result of the current source block.
 If called with a prefix argument, remove all result blocks
-- 
1.9.3 (Apple Git-50)


[-- Attachment #3: ob-exp.el patch --]
[-- Type: TEXT/PLAIN, Size: 1321 bytes --]

From afebac8d09a011ba087d858a7dca56f95bc28e69 Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Thu, 13 Nov 2014 20:49:57 -0800
Subject: [PATCH 2/3] ob-exp.el: Enable removal of {{{results(...)}}}

* ob-exp.el (org-babel-do-export): `clean' lambda form removes inline
  results wrapped in `results{{{(' `)}}}' by calling
  `org-babel-remove-inline-result'.
---
 lisp/ob-exp.el | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lisp/ob-exp.el b/lisp/ob-exp.el
index edb889c..afe6cd9 100644
--- a/lisp/ob-exp.el
+++ b/lisp/ob-exp.el
@@ -315,7 +315,9 @@ The function respects the value of the :exports header argument."
   (let ((silently (lambda () (let ((session (cdr (assoc :session (nth 2 info)))))
 			       (when (not (and session (equal "none" session)))
 				 (org-babel-exp-results info type 'silent)))))
-	(clean (lambda () (unless (eq type 'inline) (org-babel-remove-result info)))))
+	(clean (lambda () (if (eq type 'inline)
+			      (org-babel-remove-inline-result info)
+			    (org-babel-remove-result info)))))
     (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
       ('none (funcall silently) (funcall clean) "")
       ('code (funcall silently) (funcall clean) (org-babel-exp-code info type))
-- 
1.9.3 (Apple Git-50)


[-- Attachment #4: ox.el patch --]
[-- Type: TEXT/PLAIN, Size: 969 bytes --]

From 279ff7bc2011bc23e581577ddcc7b209cf7cd0bd Mon Sep 17 00:00:00 2001
From: chasberry <ccberry@ucsd.edu>
Date: Thu, 13 Nov 2014 20:55:36 -0800
Subject: [PATCH 3/3] lisp/ox.el: Enable removable inline src results

* lisp/ox.el: (org-export-as): Treat `results' as an `identity' macro
  with one argument after Babel executes.
---
 lisp/ox.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 8880e10..3d5c7f2 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -2884,7 +2884,8 @@ Return code as a string."
 		;; EMAIL is not a parsed keyword: store it as-is.
 		(cons "email" (or (plist-get info :email) ""))
 		(cons "title"
-		      (org-element-interpret-data (plist-get info :title))))
+		      (org-element-interpret-data (plist-get info :title)))
+		(cons "results" "$1"))
 	  'finalize)
 	 ;; Parse buffer.
 	 (setq tree (org-element-parse-buffer nil visible-only))
-- 
1.9.3 (Apple Git-50)


[-- Attachment #5: master output --]
[-- Type: TEXT/PLAIN, Size: 6067 bytes --]

Demonstrate inline-src block-behavior and the {{{results( )}}} macro.

The `demo' src block sets up an inline-src-block, calls it, then
exports the result. The output is as follows:

- inline-src-block :: inline-src-block with headers and content.
- export backend :: Which backend was used to render the result.
- result :: What the ~*.org~ buffer looks looks like after babel
     executes the inline-src-block.
- exported as :: Show the exported version (starting on the next line). 

* :results replace (default) 

#+name: demo
#+BEGIN_SRC emacs-lisp :var str="replace" bkend="ascii" contents="42"
  (let ((cmd (format "src_emacs-lisp[:results %s]{%s}" str contents)))
    (concat "inline-src-block: " cmd "\nexport backend: " bkend 
            "\nresult: " (with-temp-buffer
                           (insert cmd)
                           (ignore-errors
                            (org-babel-execute-buffer))
                           (buffer-string))
            "\nexported as:\n"
            (ignore-errors
              (org-export-string-as cmd (intern bkend) t))))
#+END_SRC

#+RESULTS: demo
: inline-src-block: src_emacs-lisp[:results replace]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace]{42} =42=
: exported as:
: `42'

#+CALL: demo("replace")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace]{42} =42=
: exported as:
: `42'

* :results html under html backend

#+CALL: demo("html","html")

#+RESULTS:
#+begin_example
inline-src-block: src_emacs-lisp[:results html]{42}
export backend: html
result: src_emacs-lisp[:results html]{42} #+BEGIN_HTML
42#+END_HTML

exported as:
<p>
#+BEGIN<sub>HTML</sub>
42#+END<sub>HTML</sub>
</p>
#+end_example

* :results html under latex backend

#+CALL: demo("html","latex")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results html]{42}
: export backend: latex
: result: src_emacs-lisp[:results html]{42} #+BEGIN_HTML
: 42#+END_HTML
: 
: exported as:
: \#+BEGIN\(_{\text{HTML}}\)
: 42\#+END\(_{\text{HTML}}\)


* :results latex under latex backend

#+CALL: demo("latex","latex")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results latex]{42}
: export backend: latex
: result: src_emacs-lisp[:results latex]{42} #+BEGIN_LaTeX
: 42#+END_LaTeX
: 
: exported as:
: \#+BEGIN\(_{\text{\LaTeX{}}}\)
: 42\#+END\(_{\text{\LaTeX{}}}\)


* :results replace :wrap ascii 

#+CALL: demo("replace :wrap ascii","ascii")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace :wrap ascii]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace :wrap ascii]{42} #+BEGIN_ascii
: 42#+END_ascii
: 
: exported as:
: #+BEGIN_ascii 42#+END_ascii


* :results raw

#+CALL: demo("raw")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results raw]{42}
: export backend: ascii
: result: src_emacs-lisp[:results raw]{42} 42
: exported as:
: 42


* :results drawer

Same as default.

#+CALL: demo("drawer")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results drawer]{42}
: export backend: ascii
: result: src_emacs-lisp[:results drawer]{42} :RESULTS:
: 42:END:
: 
: exported as:
: :RESULTS: 42:END:


* :results org

Code is quoted like this: `42' under ascii backend.

#+CALL: demo("org")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results org]{42}
: export backend: ascii
: result: src_emacs-lisp[:results org]{42} src_org{42}
: exported as:


* :results code

Code is quoted like this: `42' under ascii backend.

#+CALL: demo("code")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results code]{42}
: export backend: ascii
: result: src_emacs-lisp[:results code]{42} src_emacs-lisp[]{42}
: exported as:
: `42'


* :results list

Lists and tables should be avoided for inline-src-blocks, but for
completeness some are listed here.

#+CALL: demo("list")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results list]{42}
: export backend: ascii
: result: s- 42
: : rc_emacs-lisp[:results list]{42} 
: exported as:


* :results table

#+CALL: demo("table")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results table]{42}
: export backend: ascii
: result: src_emacs-lisp[:results table]{42}
: | 42 |
: 
: exported as:
:  42 


* :results replace, proper list as content

Proper lists become tables.

#+CALL: demo(contents="\'(42)")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace]{'(42) }
: export backend: ascii
: result: src_emacs-lisp[:results replace]{'(42) }
: | 42 |
: 
: exported as:
:  42 


* :results replace, proper list as content, latex backend

#+CALL: demo(bkend="latex",contents="\'((42)(43))")

#+RESULTS:
#+begin_example
inline-src-block: src_emacs-lisp[:results replace]{'((42) (43))}
export backend: latex
result: src_emacs-lisp[:results replace]{'((42) (43))}
| 42 |
| 43 |

exported as:
\begin{center}
\begin{tabular}{r}
42\\
43\\
\end{tabular}
\end{center}
#+end_example

* :results list, proper list as content, latex backend

#+CALL: demo(str="list",bkend="latex",contents="\'((42)(43))")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results list]{'((42) (43))}
: export backend: latex
: result: s- (42)
: - (43)
: rc_emacs-lisp[:results list]{'((42) (43))}
: 
: exported as:

* :results html list

Don't mix :results args like this!

#+CALL: demo("html list")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results html list]{42}
: export backend: ascii
: result: s- 42
: #+END_HTML
: rc_emacs-lisp[:results#+BEGIN_HTML
:  html list]{42} 
: exported as:


* :results code, contents as elisp

#+CALL: demo("code",contents="(quote (+ 1 2))")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results code]{(quote (+ 1 2) )}
: export backend: ascii
: result: src_emacs-lisp[:results code]{(quote (+ 1 2) )} src_emacs-lisp[]{(+ 1 2)
: }
: exported as:
: src_emacs-lisp[]{(+ 1 2) }


[-- Attachment #6: patched output --]
[-- Type: TEXT/PLAIN, Size: 5899 bytes --]

Demonstrate inline-src block-behavior and the {{{results( )}}} macro.

The `demo' src block sets up an inline-src-block, calls it, then
exports the result. The output is as follows:

- inline-src-block :: inline-src-block with headers and content.
- export backend :: Which backend was used to render the result.
- result :: What the ~*.org~ buffer looks looks like after babel
     executes the inline-src-block.
- exported as :: Show the exported version (starting on the next line). 

* :results replace (default) 

#+name: demo
#+BEGIN_SRC emacs-lisp :var str="replace" bkend="ascii" contents="42"
  (let ((cmd (format "src_emacs-lisp[:results %s]{%s}" str contents)))
    (concat "inline-src-block: " cmd "\nexport backend: " bkend 
            "\nresult: " (with-temp-buffer
                           (insert cmd)
                           (org-babel-execute-buffer)
                           (buffer-string))
            "\nexported as:\n"
            (org-export-string-as cmd (intern bkend) t)))
#+END_SRC

#+RESULTS: demo
: inline-src-block: src_emacs-lisp[:results replace]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace]{42} {{{results(=42=)}}}
: exported as:
: `42'


#+CALL: demo("replace")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace]{42} {{{results(=42=)}}}
: exported as:
: `42'

* :results html under html backend

#+CALL: demo("html","html")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results html]{42}
: export backend: html
: result: src_emacs-lisp[:results html]{42} {{{results(@@html:42@@)}}}
: exported as:
: <p>
: 42</p>

* :results html under latex backend

#+CALL: demo("html","latex")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results html]{42}
: export backend: latex
: result: src_emacs-lisp[:results html]{42} {{{results(@@html:42@@)}}}
: exported as:

* :results latex under latex backend

#+CALL: demo("latex","latex")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results latex]{42}
: export backend: latex
: result: src_emacs-lisp[:results latex]{42} {{{results(@@latex:42@@)}}}
: exported as:
: 42

* :results replace :wrap ascii 

#+CALL: demo("replace :wrap ascii","ascii")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace :wrap ascii]{42}
: export backend: ascii
: result: src_emacs-lisp[:results replace :wrap ascii]{42} {{{results(@@ascii:42@@)}}}
: exported as:
: 42

* :results raw

#+CALL: demo("raw")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results raw]{42}
: export backend: ascii
: result: src_emacs-lisp[:results raw]{42} 42
: exported as:
: 42

* :results drawer

Same as default.

#+CALL: demo("drawer")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results drawer]{42}
: export backend: ascii
: result: src_emacs-lisp[:results drawer]{42} {{{results(42)}}}
: exported as:
: 42

* :results org

Code is quoted like this: `42' under ascii backend.

#+CALL: demo("org")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results org]{42}
: export backend: ascii
: result: src_emacs-lisp[:results org]{42} {{{results(src_org{42})}}}
: exported as:
: `42'

* :results code

Code is quoted like this: `42' under ascii backend.

#+CALL: demo("code")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results code]{42}
: export backend: ascii
: result: src_emacs-lisp[:results code]{42} {{{results(src_emacs-lisp[]{42})}}}
: exported as:
: `42'

* :results list

Lists and tables should be avoided for inline-src-blocks, but for
completeness some are listed here.

#+CALL: demo("list")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results list]{42}
: export backend: ascii
: result: src_emacs-lisp[:results list]{42}
: : - 42
: 
: exported as:
: ,----
: | - 42
: `----

* :results table

#+CALL: demo("table")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results table]{42}
: export backend: ascii
: result: src_emacs-lisp[:results table]{42}
: | 42 |
: 
: exported as:
:  42 

* :results replace, proper list as content

Proper lists become tables.

#+CALL: demo(contents="\'(42)")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results replace]{'(42) }
: export backend: ascii
: result: src_emacs-lisp[:results replace]{'(42) }
: | 42 |
: 
: exported as:
:  42 

* :results replace, proper list as content, latex backend

#+CALL: demo(bkend="latex",contents="\'((42)(43))")

#+RESULTS:
#+begin_example
inline-src-block: src_emacs-lisp[:results replace]{'((42) (43))}
export backend: latex
result: src_emacs-lisp[:results replace]{'((42) (43))}
| 42 |
| 43 |

exported as:
\begin{center}
\begin{tabular}{r}
42\\
43\\
\end{tabular}
\end{center}
#+end_example

* :results list, proper list as content, latex backend

#+CALL: demo(str="list",bkend="latex",contents="\'((42)(43))")

#+RESULTS:
#+begin_example
inline-src-block: src_emacs-lisp[:results list]{'((42) (43))}
export backend: latex
result: src_emacs-lisp[:results list]{'((42) (43))}
- (42)
- (43)

exported as:
\begin{itemize}
\item (42)
\item (43)
\end{itemize}
#+end_example

* :results html list

Don't mix :results args like this!

#+CALL: demo("html list")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results html list]{42}
: export backend: ascii
: result: src_emacs-lisp[:results html list]{42}
: {{{results(@@html:- 42
: @@)}}}
: exported as:

* :results code, contents as elisp

#+CALL: demo("code",contents="(quote (+ 1 2))")

#+RESULTS:
: inline-src-block: src_emacs-lisp[:results code]{(quote (+ 1 2) )}
: export backend: ascii
: result: src_emacs-lisp[:results code]{(quote (+ 1 2) )} {{{results(src_emacs-lisp[]{(+ 1 2)
: })}}}
: exported as:
: src_emacs-lisp[]{(+ 1 2) }


  parent reply	other threads:[~2015-01-13  0:48 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-12  0:49 [PATCH] inline src block results can be removed Charles C. Berry
2014-11-12  1:10 ` Andreas Leha
2014-11-12  6:58   ` Charles C. Berry
2014-11-12 19:34 ` Aaron Ecay
2014-11-12 23:47   ` Charles C. Berry
2014-11-13 17:48     ` Nicolas Goaziou
2014-11-13 19:06       ` Andreas Leha
2014-11-14 17:43       ` Charles C. Berry
2014-11-14 20:39         ` Nicolas Goaziou
2014-11-14 23:04           ` Aaron Ecay
2014-11-16  0:10             ` Nicolas Goaziou
2014-11-15 20:22           ` Charles C. Berry
2014-11-16 23:23             ` Nicolas Goaziou
2014-11-24  9:48               ` Daniele Pizzolli
2014-11-24 10:18                 ` Andreas Leha
2015-01-13  0:48               ` Charles C. Berry [this message]
2015-01-16 22:41                 ` New patches WAS " Nicolas Goaziou
2015-01-19  3:22                   ` Charles C. Berry
2015-01-19 17:53                     ` Nicolas Goaziou
2015-01-19 19:31                       ` Charles C. Berry
2015-01-20 23:30                         ` Nicolas Goaziou
2015-01-22  3:07                           ` Charles C. Berry
2015-01-22 23:08                             ` Nicolas Goaziou
2015-01-24 22:47                               ` Charles C. Berry
2015-01-25  1:14                                 ` Aaron Ecay
2015-01-25  5:01                                   ` Charles C. Berry
2015-01-29 20:31                               ` Charles C. Berry
2015-01-17  3:22                 ` Aaron Ecay
2015-01-17 22:20                   ` Nicolas Goaziou
2015-01-18 19:13                     ` Aaron Ecay
2015-01-18 22:34                       ` Nicolas Goaziou
2015-01-18 22:55                         ` Aaron Ecay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.OSX.2.00.1501121608520.1829@charlessmacbook \
    --to=ccberry@ucsd.edu \
    --cc=aaronecay@gmail.com \
    --cc=andreas.leha@med.uni-goettingen.de \
    --cc=emacs-orgmode@gnu.org \
    --cc=giepen.m@googlemail.com \
    --cc=istazahn@gmail.com \
    --cc=mail@nicolasgoaziou.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).