1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
|
#+TITLE: Support for :exports options from code blocks
#+startup: showeverything
According to the [[http://orgmode.org/manual/Exporting-code-blocks.html#Exporting-code-blocks][Org mode docs]], it is possible to customize whether
the code block will be exported or not.
* About the ~#+RESULTS:~ block
Using Org Babel features, it is possible to set ~:results output~
to a code block and render the results within a ~#+RESULTS:~ code block:
#+begin_src org
,#+begin_src ruby :results output :exports both
puts "Hello world"
,#+end_src
,#+RESULTS:
: Hello world
#+end_src
One thing about the ~#+RESULTS:~ code blocks, is that they exist in several forms:
1) As an accumulated group of inline examples:
#+begin_src org
,#+begin_src python :results output :exports both
print "like"
print "this"
print "etc..."
,#+end_src
,#+RESULTS:
: like
: this
: etc...
#+end_src
2) As an example code block.
#+begin_src org
,#+begin_src ruby :results output :exports both
10.times {|n| puts n }
,#+end_src
,#+RESULTS:
,#+begin_example
0
1
2
3
4
5
6
7
8
9
,#+end_example
#+end_src
3) Also, in case ~:results output code~ is used, the results would
be a src block of the same language as the original one.
#+begin_src org
,#+begin_src ruby :results output code
counter = 0
10.times { puts "puts '#{counter += 1}'" } # Displayed in first code block
puts counter # Displayed in second code block
,#+end_src
,#+RESULTS:
,#+begin_src ruby
puts '1'
puts '2'
puts '3'
puts '4'
puts '5'
puts '6'
puts '7'
puts '8'
puts '9'
puts '10'
10
,#+end_src
,#+RESULTS:
: 10
#+end_src
* DONE Default options
The default is to export only the code blocks.
The following is an code block written in Emacs Lisp
and its result should not be exported.
#+begin_src emacs-lisp
(message "hello world")
#+end_src
#+RESULTS:
: hello world
The following is a code block written in Python
and its result should not be exported.
#+begin_src python :results output
for i in range(0,12):
print "import this"
#+end_src
#+RESULTS:
#+begin_example
import this
import this
import this
import this
import this
import this
import this
import this
import this
import this
import this
import this
#+end_example
* DONE :exports code
Only the code would be in the output,
the same as when no option is set.
#+begin_src js :exports code :results output
var message = "Hello world!";
console.log(message);
#+end_src
#+RESULTS:
: Hello world!
And as block example too:
#+begin_src js :exports code :results output
var message = "Hello world!";
for (var i = 0; i< 10; i++) {
console.log(message);
}
#+end_src
#+RESULTS:
#+begin_example
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
Hello world!
#+end_example
* DONE :exports none
This omits both the resulting block,
and the code block itself.
#+begin_src python :results output :exports none
print 1 # :P
#+end_src
#+RESULTS:
: 1
This should work as well when using an example block.
#+begin_src python :results output :exports none
for i in range(0,10):
print 1 # :P
#+end_src
#+RESULTS:
#+begin_example
1
1
1
1
1
1
1
1
1
1
#+end_example
* DONE :exports both
#+begin_src ruby :exports both
Math::PI + 1
#+end_src
#+RESULTS:
: 4.14159265358979
Should behave the same when within a block example.
#+begin_src ruby :exports both
hello = <<HELLO
The following is a text
that will contain at least 10 lines or more
so that when C-c C-c is pressed
and Emacs lisp
evals what is inside of the block,
enough lines would be created
such that an example block
would appear underneath the
block that was executed.
This happens after 10 lines by default.
HELLO
#+end_src
#+RESULTS:
#+begin_example
The following is a text
that will contain at least 10 lines or more
so that when C-c C-c is pressed
and Emacs lisp
evals what is inside of the block,
enough lines would be created
such that an example block
would appear underneath the
block that was executed.
This happens after 10 lines by default.
#+end_example
* DONE :exports results
This option can't be completely supported by OrgRuby since
we would have to eval the code block using :lang,
so Org Babel features would have to be implemented as well.
But in case the resulting block is within the Org mode file,
the code block will be omitted and only the results block
would appear.
#+begin_src ruby :exports results
Math::PI
#+end_src
#+RESULTS:
: 3.141592653589793
The same should happen when a block example is used instead:
#+begin_src ruby :results output :exports results
10.times { puts "any string" }
#+end_src
#+RESULTS:
#+begin_example
any string
any string
any string
any string
any string
any string
any string
any string
any string
any string
#+end_example
|