#+TITLE: Org-mode Scraps #+OPTIONS: num:nil ^:nil #+STYLE: * scraps :PROPERTIES: :ID: 96eaa17f-f1b6-4958-acb1-e271045fdfa2 :DATE: 2011-09-03 :END: ** pretty printed source code block result set the value #+begin_src lisp :results silent (defvar foo '(defun square (x) (* x x))) #+end_src #+begin_src lisp :results output pp code foo #+end_src #+RESULTS: #+BEGIN_SRC lisp (DEFUN SQUARE (X) (* X X)) #+END_SRC ** prologue and epilogue in R code blocks #+headers: :epilogue "})" #+headers: :prologue "local({" #+begin_src R :results output :session cat("Test") #+end_src ** export header argument dependent on backend #+name: export-hdr-arg-backend-dep #+begin_src emacs-lisp (message "do stuff") #+end_src #+call: export-hdr-arg-backend-dep() :exports (if (eq org-export-current-backend 'beamer) "none" "results") ** parenthesis in prologue and epilogue #+begin_src R :prologue "local({" :epilogue "})" qwerty <- "test"; #+end_src #+RESULTS: ** call line caching #+name: call-line-caching-example #+begin_src emacs-lisp :var bar="baz" (sit-for 1) (message "bar=%S" bar) #+end_src #+RESULTS: call-line-caching-example : bar="baz" This does not return immediately, because the block must execute. #+call: call-line-caching-example("quxxx") #+RESULTS: : bar="quxxx" This returns immediately thanks to the cached result. #+name: call-line-caching-called #+call: call-line-caching-example("qux") :cache yes #+RESULTS[1df20b5a51c3c710b11d7d9cac7272a66a85990f]: call-line-caching-called : bar="qux" ** valid inline function names #+name: w/o-spaces #+begin_src sh echo no space #+end_src - call_space () - call_w/o-spaces() =no space= ** quoted lines between block and result #+begin_src sh :cache yes date #+end_src #+label: foo #+RESULTS[767d8ce04ce746568cd0f3f1f8f621a3583b93c5]: : Fri Dec 13 15:05:38 MST 2013 ** literal example #+NAME: literal-example #+BEGIN_EXAMPLE A literal example on two lines #+END_EXAMPLE #+NAME: read-literal-example #+BEGIN_SRC emacs-lisp :var x=literal-example (concatenate 'string x " for me.") #+END_SRC #+RESULTS: read-literal-example : A literal example : on two lines : for me. ** shell history, alias and environment variables #+BEGIN_SRC sh :session :results output echo $SHELL echo $HOME source ~/.bashrc alias | wc env | wc history | wc #+END_SRC #+RESULTS: : /bin/zsh : /home/eschulte : 0 0 0 : 28 28 715 : 0 0 0 #+BEGIN_SRC sh :session :results output echo $SHELL echo $HOME source ~/.alia source ~/.bashrc alias | wc env | wc history | wc #+END_SRC #+RESULTS: : /bin/zsh : /home/eschulte : 19 99 814 : 28 28 715 : 0 0 0 ** C undefined behavior #+begin_src C int i=0; printf("%d %d %d %d\n", ++i, ++i, ++i, ++i); #+end_src #+RESULTS: : 4 4 4 4 #+begin_src C int i=0; printf("%d %d %d %d\n", i++, i++, i++, i++); #+end_src #+RESULTS: : 3 2 1 0 #+begin_src C void p(int a, int b, int c, int d){ printf("%d %d %d %d\n", a, b, c, d); } int i=0; p(i++, i++, ++i, ++i); #+end_src #+RESULTS: : 3 2 4 4 #+begin_src C++ :includes '("") int i=0; std::cout << i++ << " " << i++ << " " << ++i << " " << ++i; #+end_src #+RESULTS: : 3 2 4 4 ** header arguments on call lines :PROPERTIES: :DATE: 2011-09-11 :END: #+name: simple-example #+begin_src emacs-lisp "the result" #+end_src #+call: simple-example() #+name: simple-example() : the result #+call: simple-example() :results raw #+name: simple-example() the result ** removing result with a silent header argument :PROPERTIES: :DATE: 2011-09-07 :END: evaluating the following code block will remove the related result. #+begin_src sh :results silent date +%Y-%m-%d #+end_src #+name: : 2011-09-07 ** leading commas in code blocks :PROPERTIES: :DATE: 2011-09-06 :END: #+begin_src r :exports code a <- c(1 , 2 , 3) #+end_src #+begin_src org :exports code ,this one will have commas removed ,#+begin_src R , a <- c(1 , , 2 , , 3) ,#+end_src #+end_src ** silent results in org but not in export :PROPERTIES: :DATE: 2011-09-06 :END: The results of the following code block will not be inserted during interactive evaluation but will during export. #+begin_src sh :results (if org-current-export-file "replace" "silent") :exports both echo "I want to see this in HTML/PDF, but not in Org" #+end_src ** demarcation of indented blocks :PROPERTIES: :DATE: 2011-09-04 :END: Demarcating a block with the point part-way in a line should indent the remainder of the line in the second block. #+begin_src sh echo 1 echo 2 echo 3 echo 4 #+end_src becomes #+begin_src sh :results silent :session something echo 1 echo 2 echo #+end_src #+begin_src sh :results silent :session something 3 echo 4 #+end_src ** returning file type to inline call line :PROPERTIES: :DATE: 2011-09-04 :END: Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec hendrerit tempor tellus. Donec pretium posuere tellus. Proin quam nisl, tincidunt et, mattis eget, convallis nec, purus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Nulla posuere. Donec vitae dolor. Nullam tristique diam non turpis. call_nothing_to_something()[:results file] [[file:something.txt]] Cras placerat accumsan nulla. Nullam rutrum. Nam vestibulum accumsan nisl. #+name: nothing_to_something #+begin_src sh :file something.txt echo nothing #+end_src ** simple gnuplot plotting of Org-mode tables :PROPERTIES: :DATE: 2011-09-01 :END: #+tblname: gnuplot-testing | x | y | |---+----| | 1 | 2 | | 2 | 4 | | 3 | 6 | | 4 | 8 | | 5 | 10 | | 6 | 12 | | 7 | 14 | | 8 | 16 | #+begin_src gnuplot :var data=gnuplot-testing :file output.eps set term postscript set title "test" set auto x set style data histogram set style fill solid border -1 set boxwidth 0.9 plot data using 2:xtic(1) #+end_src ** simple indexing :PROPERTIES: :DATE: 2011-09-01 :END: #+name: list-o-numbers | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | #+begin_src sh :var column=list-o-numbers[,0] echo $column #+end_src #+name: : 1 4 7 ** convert results to all string :PROPERTIES: :DATE: 2011-08-29 :END: #+name: hetero-table #+begin_src emacs-lisp '((1 2 3 4) ("a" "b" "c" "d")) #+end_src #+name: all-to-string #+begin_src emacs-lisp :var tbl='() (defun all-to-string (tbl) (if (listp tbl) (mapcar #'all-to-string tbl) (if (stringp tbl) tbl (format "%s" tbl)))) (all-to-string tbl) #+end_src #+begin_src emacs-lisp :var tbl=hetero-table (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl) #+end_src #+name: | nil | nil | nil | nil | | t | t | t | t | #+begin_src emacs-lisp :var tbl=all-to-string(hetero-table) (mapcar (lambda (row) (mapcar (lambda (cell) (stringp cell)) row)) tbl) #+end_src #+name: | t | t | t | t | | t | t | t | t | ** simple short R block :PROPERTIES: :DATE: 2011-08-29 :END: #+BEGIN_SRC R c(1,23,54,5) #+END_SRC #+name: | 1 | | 23 | | 54 | | 5 | ** two blocks and a table :PROPERTIES: :DATE: 2011-08-28 :END: #+name: stuff #+begin_src sh echo 1 echo 2 echo 3 #+end_src #+name: last-of-stuff #+begin_src sh :var input=stuff echo "$input" |tail -1 #+end_src | one | | two | | 3 | #+TBLFM: @3$1='(sbe last-of-stuff) ** inheriting the file property :PROPERTIES: :FILE: something.png :DATE: 2011-08-23 :END: #+begin_src ditaa +-----------------------------+ | | | +-----+ | | | | +---------+ | | | | | | | | +-----+ | | | | | | | | file | | | | inheritance +---------+ | | | +-----------------------------+ #+end_src #+name: [[file:something.png]] ** a table with tags :PROPERTIES: :DATE: 2011-08-23 :END: #+TBLNAME: sandbox :noexport: | 1 | 2 | 3 | | 4 | org-babel | 6 | #+begin_src emacs-lisp :var table=sandbox (message "%S" table) #+end_src #+name: : ((1 2 3) (4 "org-babel" 6)) ** shell script output not in table :PROPERTIES: :DATE: 2011-08-21 :END: #+begin_src sh :results scalar echo 1 echo 2 echo 3 #+end_src #+name: : 1 : 2 : 3 ** inline code block and downstream src blocks :PROPERTIES: :DATE: 2011-08-21 :END: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA something src_sh{echo eric} CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC #+begin_src sh echo schulte #+end_src EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE *** with R :PROPERTIES: :DATE: 2011-08-21 :END: AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA blah blah src_R[:results output]{cat(rnorm(2))} CCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC #+begin_src R :eval never :exports none 1+2 a <- b + c xyz #+end_src DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD ** updating a table :PROPERTIES: :DATE: 2011-08-19 :END: #+name: this-is-another-table | 0 | 0 | 0 | | 0 | 0 | 0 | | 0 | 0 | 0 | #+name: this-is-another-table #+begin_src emacs-lisp :var table=this-is-another-table (setf (nth 1 table) '(2 2 2)) table #+end_src ** space around exported code blocks :PROPERTIES: :DATE: 2011-08-19 :END: try evaluating the following blocks, then removing their results with M-x `org-babel-remove-result' Verbiage to begin the paragraph #+begin_src sh echo eric #+end_src and verbiage to end the same paragraph. #+begin_src sh echo 1 echo 2 #+end_src and verbiage to end the same paragraph. ** simple ditaa block :PROPERTIES: :DATE: 2011-08-19 :END: #+begin_src ditaa :file work-flow.png +-------+ +--------+ | | | | | Org |------------>| Tex | | | | | +-------+ +--------+ #+end_src #+name: [[file:work-flow.png]] ** replacing a table :PROPERTIES: :DATE: 2011-08-19 :END: #+name: this-is-the-table | 1 | 4 | 7 | | 2 | 5 | 8 | | 3 | 6 | 9 | #+name: this-is-the-table #+begin_src emacs-lisp :var table=this-is-the-table (mapcar (lambda (row) (mapcar (lambda (cell) (* cell 2)) row)) table) #+end_src ** ruby code block :PROPERTIES: :DATE: 2011-08-19 :END: #+begin_src ruby 1+2 #+end_src #+name: : 3 ** bug with undefined function copy-seq :PROPERTIES: :DATE: 2011-08-05 :END: #+begin_src R :session :exports both 1:10 #+end_src ** tangle before evaluating a code block :PROPERTIES: :DATE: 2011-08-05 :END: #+begin_src sh :var TANGLED=(org-babel-tangle) :tangle no wc $TANGLED #+end_src #+name: : 2 2 11 it.sh #+begin_src sh :tangle it.sh echo TEST #+end_src ** plot results with org-plot :PROPERTIES: :DATE: 2011-08-02 :END: #+name: disk-usage #+begin_src sh :exports both df #+end_src #+PLOT: title:"Disk Usage" ind:6 deps:(5) type:2d with:histograms set:"yrange [0:100]" #+name: disk-usage | Filesystem | 1K-blocks | Used | Available | Use% | Mounted | on | | /dev/sda6 | 28835836 | 8447712 | 18923344 | 31% | / | | | none | 2997072 | 676 | 2996396 | 1% | /dev | | | none | 3006056 | 0 | 3006056 | 0% | /dev/shm | | | none | 3006056 | 96 | 3005960 | 1% | /var/run | | | none | 3006056 | 0 | 3006056 | 0% | /var/lock | | | /dev/sda7 | 144176824 | 72225604 | 64627420 | 53% | /home | | ** premature truncation of emacs-lisp results :PROPERTIES: :DATE: 2011-07-28 :END: #+begin_src emacs-lisp '(nil nil nil nil) #+end_src #+name: : (nil nil nil nil) ** non-defined code blocks can still tangle :PROPERTIES: :DATE: 2011-07-28 :END: #+begin_src text :tangle somewhere.txt This will still tangle out to a file, and it opens in text mode, which may be nice. #+end_src ** expand noweb refs :PROPERTIES: :DATE: 2011-07-25 :END: #+name: def-something #+begin_src sh SOMETHING=nothing #+end_src #+begin_src sh <> echo $SOMETHING #+end_src ** returning file names -- interpreted as lists :PROPERTIES: :DATE: 2011-07-21 :END: #+begin_src sh :results scalar echo "[[file:./cv.cls]]" #+end_src #+name: : [[file:./cv.cls]] #+begin_src sh :results org echo "[[file:./cv.cls]]" #+end_src #+name: #+BEGIN_ORG [[file:\./cv\.cls]] #+END_ORG ** java code block :PROPERTIES: :DATE: 2011-07-19 :END: #+begin_src java :classname myfirstjavaprog class myfirstjavaprog { public static void main(String args[]) { System.out.println("Hello World!"); } } #+end_src #+name: : Hello World! ** exporting a ditaa example :PROPERTIES: :DATE: 2011-07-19 :END: #+begin_src ditaa :file blue.png :cmdline -r /---------------\ | test | | {cBLU} | \---------------/ #+end_src #+name: [[file:blue.png]] ** including noweb refs w/o last newline :PROPERTIES: :DATE: 2011-07-19 :END: #+begin_src sh :noweb yes <> |\ <> #+end_src #+name: my-name #+begin_src sh echo "eric schulte" #+end_src #+name: capitalize-name #+begin_src sh sed 's/^e/E/;s/ s/ S/' #+end_src ** simple sbe example :PROPERTIES: :DATE: 2011-07-10 :END: | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 3.5 | #+TBLFM: @7$1='(sbe mean (lst @1..@6)) #+name: mean #+begin_src emacs-lisp :var lst=() (let ((num (car lst)) (nums (cdr lst))) (/ (float (+ num (apply #'+ nums))) (1+ (length nums)))) #+end_src ** eval never :PROPERTIES: :DATE: 2011-07-10 :END: #+begin_src emacs-lisp :eval (if org-export-current-backend "never" "yes") :exports results (message "launch missles") #+end_src #+name: : launch missles ** indexing into a list variable :PROPERTIES: :DATE: 2011-07-06 :END: #+begin_src emacs-lisp :var lst='(0 1 2) (first lst) #+end_src #+name: : 0 or as a noweb reference #+name: external-list - 0 - 1 - 2 #+begin_src sh :noweb yes echo <> #+end_src #+name: : 0 ** data alias for resname :PROPERTIES: :DATE: 2011-07-05 :END: #+name: blah : blahcontent #+begin_src emacs-lisp :var it=blah it #+end_src #+name: : blahcontent ** define a block with a name for noweb expansion :PROPERTIES: :tangle: yes :noweb: yes :DATE: 2011-07-01 :END: #+name: simple(something="something") #+begin_src emacs-lisp something #+end_src another block including the first block #+begin_src emacs-lisp <> #+end_src ** find a resource by global id :PROPERTIES: :DATE: 2011-07-01 :END: #+begin_src emacs-lisp :var it=990f3218-6fce-44fb-bd0c-5f6076c0dadc it #+end_src #+name: : : here it is *** I'm the resource :PROPERTIES: :ID: 990f3218-6fce-44fb-bd0c-5f6076c0dadc :DATE: 2011-07-01 :END: here it is ** longtable label and attr lines on code block results :PROPERTIES: :DATE: 2011-06-29 :END: #+name: faz #+begin_src emacs-lisp :exports results '((foo foo) (bar baz)) #+end_src #+LABEL: Foo #+name: faz | foo | foo | | bar | baz | ** another test :PROPERTIES: :DATE: 2011-06-29 :END: #+name: square #+begin_src emacs-lisp :var it=0 (* it it) #+end_src Here is a call_square(it=4), stuck in the middle of some prose. Here is another 25^2=call_square(it=25). ** multiple variables :PROPERTIES: :DATE: 2011-06-27 :END: Should work call_concat(1, 2, 3) =123= in order. #+name: concat #+begin_src emacs-lisp :var a=0 :var b=0 :var c=0 (format "%S%S%S" a b c) #+end_src Should be positive call_lob-minus(4, 3) =1= by order. ** un-named variables :PROPERTIES: :DATE: 2011-06-27 :END: #+name: square #+begin_src emacs-lisp :var it=0 (* it it) #+end_src #+call: square(8) first we can name the argument with call_square(it=4) =16= then we can pass the argument unnamed with call_square(4) =16= #+name: minus #+begin_src emacs-lisp :var a=0 :var b=0 (- a b) #+end_src To ensure that these arguments are passed in the correct order we can use the following call_minus(8, 4) =-4= ** inline call line :PROPERTIES: :DATE: 2011-06-27 :END: #+name: double #+begin_src emacs-lisp :var it=0 (* 2 it) #+end_src This is the number src_sh[:var it=double(it=1)]{echo $it} in the middle The following exports as a normal call line #+call: double(it=1) Now here is an inline call call_double(it=1) stuck in the middle of some prose. This one should not be exported =call_double(it=2)= because it is quoted. Finally this next one should export, even though it starts a line call_double(it=3) because sometimes inline blocks fold with a paragraph. And, a call with raw results call_double(4)[:results raw] should not have quoted results. ** text and graphics from R :PROPERTIES: :DATE: 2011-06-24 :END: #+begin_src R :results output :session print(seq(1,10)) #+end_src #+begin_src R :file example.png :results graphics :session plot(seq(1,10)) #+end_src #+name: [[file:example.png]] ** large code in inline blocks :PROPERTIES: :DATE: 2011-06-22 :END: #+name: big-block #+begin_src emacs-lisp :exports none "something complex" #+end_src Here is some text with src_emacs-lisp[:var it=big-block]{it} in the middle. ** clojure =:results scalar= :PROPERTIES: :DATE: 2011-06-21 :END: #+begin_src clojure :results scalar '(1 2 3) #+end_src ** expand variable during tangling :PROPERTIES: :tangle: yes :DATE: 2011-06-20 :END: #+begin_src sh :var VER=(vc-working-revision (buffer-file-name)) echo $VER #+end_src ** python session :PROPERTIES: :DATE: 2011-06-19 :END: #+begin_src python :results output :session mypy x = 1 for i in range(1,5): x = x + i print x print "I throw an error" #+end_src #+name: : : ... ... ... 2 : 4 : 7 : 11 : I throw an error #+begin_src python :results output :session print y #+end_src #+name: : Traceback (most recent call last): : File "", line 1, in : NameError: name 'y' is not defined ** scalar emacs lisp results :PROPERTIES: :DATE: 2011-06-19 :END: #+begin_src emacs-lisp :results scalar '(1 2 3) #+end_src #+name: : (1 2 3) ** named code block export :PROPERTIES: :DATE: 2011-06-13 :END: This has a name which is not exported. #+name: rand(n) #+begin_src R runif(n) #+end_src ** continued code blocks :PROPERTIES: :tangle: yes :comments: yes :DATE: 2011-06-10 :END: #+name: foo #+begin_src emacs-lisp (message "foo:%S" 1) #+end_src #+begin_src emacs-lisp (message "un-named") #+end_src #+name: bar #+begin_src emacs-lisp (message "bar:%S" 1) #+end_src #+name: foo #+begin_src emacs-lisp (message "foo:%S" 2) #+end_src #+name: bar #+begin_src emacs-lisp (message "bar:%S" 2) #+end_src #+begin_src emacs-lisp :tangle no :results silent (with-temp-buffer (insert-file-contents "scraps.el") (eval-buffer)) #+end_src ** ruby with xmpfilter :PROPERTIES: :DATE: 2011-06-10 :END: #+begin_src ruby :results xmp code 2 + 2 # => 3.times{ puts :hello } #+end_src #+name: #+BEGIN_SRC ruby 2 + 2 # => 4 3.times{ puts :hello } # >> hello # >> hello # >> hello #+END_SRC ** tangle test :PROPERTIES: :DATE: 2011-06-10 :END: #+begin_src R :tangle test.R :shebang #!/bin/cat :padline no This is a test #+end_src ** quick testing new session code :PROPERTIES: :DATE: 2011-06-06 :END: #+begin_src sh :session test :results output echo foo #+end_src #+name: : foo #+begin_src ruby :results output :session simple puts "foo" #+end_src #+name: : foo ** =:file= and python :PROPERTIES: :DATE: 2011-06-06 :END: #+begin_src python :file /tmp/test.png return 1 #+end_src #+name: [[file:/tmp/test.png]] ** simple shell :PROPERTIES: :DATE: 2011-06-06 :END: #+begin_src sh sleep 10 && ls #+end_src #+name: | _config.yml | | data | | development.org | | elsevier | | index.org | | paper | | publish.org | | scraps | | scraps.html | | scraps.org | | scraps.tex | #+begin_src ruby :session eric puts [1..4] #+end_src #+name: : nil ** testing new data names :PROPERTIES: :DATE: 2011-06-02 :END: #+name: simple-123 : 123 #+begin_src emacs-lisp :var simple=simple-123 :exports both (* simple 2) #+end_src results data my data is results #+name: : 246 ** default directory examples in lisp :PROPERTIES: :DATE: 2011-06-01 :END: #+begin_src lisp *default-pathname-defaults* #+end_src #+begin_src sh pwd #+end_src #+begin_src lisp :dir *default-pathname-defaults* #+end_src #+name: : #P"" ** lisp body with multiple forms :PROPERTIES: :DATE: 2011-05-31 :END: #+begin_src lisp :results value (format t "~&eric") (+ 1 2) #+end_src #+name: : 3 ** example =#+call= line expansion :PROPERTIES: :DATE: 2011-05-27 :END: this code block peeks inside of the `params' variable which is used by babel during code block evaluation #+name: callee #+begin_src emacs-lisp ;; this is cheating and shouldn't be done in user code :) (or (cdr (assoc :foo params)) 'unset) #+end_src this code block evaluates to the following, #+name: callee : unset this call line, #+call: callee[:foo bar]() :results org expands into the following which is evaluated as a normal code block by Babel. #+begin_src emacs-lisp :var results=callee[:foo bar]() :results org results #+end_src this code block evaluates to the following, #+name: #+BEGIN_ORG nothing #+END_ORG ** awk example :PROPERTIES: :DATE: 2011-05-26 :END: #+name: simple-table | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | #+begin_src awk :stdin simple-table {print $1} #+end_src #+name: | 1 | | 4 | | 7 | ** passing values through to STDIN of shell code blocks :PROPERTIES: :DATE: 2011-05-26 :END: #+name: square-table | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | #+name: first-col #+begin_src sh :stdin square-table awk '{print $1}' #+end_src #+begin_src sh :stdin first-col sed 's/4/middle/g' #+end_src #+name: | 1 | | middle | | 7 | ** don't match end_src inside of a block :PROPERTIES: :DATE: 2011-05-14 :END: #+name: the_issue #+begin_src sh :results output echo '#+end_src' #+end_src #+name: the_issue : #+end_src block ** append tables :PROPERTIES: :DATE: 2011-05-14 :END: #+name: table-names - first-table - second-table - third-table #+name: first-table | a | 1 | | b | 2 | #+name: second-table | c | 3 | | d | 4 | #+name: third-table | e | 5 | | f | 6 | #+begin_src emacs-lisp :var table-names=table-names (mapcar #'org-babel-ref-resolve table-names) #+end_src #+name: | (a 1) | (b 2) | | (c 3) | (d 4) | | (e 5) | (f 6) | ** new names for results :PROPERTIES: :DATE: 2011-05-06 :END: #+name: simple : 1 #+begin_src emacs-lisp :var data=simple data #+end_src #+name: : 1 changing the variable used to label data #+begin_src emacs-lisp :results silent (setq org-babel-result-fmt "^[ \t]*#\\+\\(TBLNAME\\|RESNAME\\|RESULTS\\|DATA\\):[ \t]*%s[ \t]*$") #+end_src #+name: not-so-simple : 2 #+begin_src emacs-lisp :var data=not-so-simple data #+end_src #+name: : 2 ** ocaml :PROPERTIES: :DATE: 2011-05-06 :END: #+begin_src ocaml [3;2;3] @ [3;2;3;4;5];; #+end_src #+name: | 3 | 2 | 3 | 3 | 2 | 3 | 4 | 5 | ** simple latex verbatim wrap example :PROPERTIES: :DATE: 2011-05-05 :END: #+begin_src emacs-lisp :results silent (setq org-export-latex-verbatim-wrap '("{\\scriptsize\n\\begin{verbatim}\n" . "\\end{verbatim}\n}\n")) #+end_src #+begin_src sh echo eric schulte echo another #+end_src ** inserting complicated results :PROPERTIES: :DATE: 2011-05-05 :END: #+begin_src emacs-lisp :results scalar ((lambda (result) (condition-case nil (read result) (error result))) "(:return (:ok \"{:model #, :v #, :z nil}\") 13)") #+end_src #+name: | :return | (:ok {:model #, :v #, :z nil}) | 13 | ** automatic org-mode formatting :PROPERTIES: :DATE: 2011-04-27 :END: #+name: raw-results #+begin_src sh :results output tabular echo "| 1 |" echo "| 2 |" #+end_src #+begin_src emacs-lisp :var in=raw-results (stringp in) #+end_src #+name: : t ** units in R plot :PROPERTIES: :DATE: 2011-04-21 :END: #+begin_src R :results graphics :file test.png :width 8 :height 8 :res 200 :units cm x <- -10:10 y <- x^2 plot(x, y, type="l", col="red", lty=1) #+end_src #+name: [[file:test.png]] ** Ocaml appending blocks :PROPERTIES: :DATE: 2011-04-19 :END: block #+begin_src ocaml [|1;2;3|];; #+end_src #+name: | 1 | 2 | 3 | ** simple Oz example :PROPERTIES: :DATE: 2011-04-19 :END: #+begin_src oz :results output {Browse 'Hello'} #+end_src ** complex numbers in tables and python, reference in table formula :PROPERTIES: :DATE: 2011-04-13 :END: #+name: parameter-variation(data=0) #+begin_src python :result values return 'text' #+end_src |---------------------------------------| | "(0.0331901438056,0.000535222885197)" | | "(0.0333434157791,0.000537930174356)" | | "(0.0345727512157,0.000559346040457)" | | "(0.0353146483908,0.000571501584524)" | | "(0.0355522909393,0.000574387067408)" | | "(0.0356575682336,0.000574851263615)" | | "(0.0357806926897,0.000575051685084)" | |---------------------------------------| | text | #+TBLFM: @8$1='(sbe parameter-variation (nums @1$1..@7$1)) | '(1 2 3 4) | |------------| | 4 | #+TBLFM: @2$1='(sbe quote (it @1$1)) | (1 2 3 4) | |-----------| | #ERROR | #+TBLFM: @2$1='(sbe quote (it @1$1)) *** using vectors to represent complex number is lisp :PROPERTIES: :DATE: 2011-04-15 :END: | [1 2] | |------------------| | real:1 complex:2 | #+TBLFM: @2$1='(sbe real (it @1$1)) #+name: real(it='()) #+begin_src emacs-lisp (format "real:%d complex:%d" (aref it 0) (aref it 1)) #+end_src *** reference the table in a table formula :PROPERTIES: :DATE: 2011-04-13 :END: #+name: complex-data |-------------------------------------| | (0.0331901438056,0.000535222885197) | |-------------------------------------| | 4 | #+TBLFM: @2$1='(sbe quote (it "complex-data")) *** externally referencing the table :PROPERTIES: :DATE: 2011-04-13 :END: #+name: complex-data |-------------------------------------| | (0.0331901438056,0.000535222885197) | | (0.0333434157791,0.000537930174356) | | (0.0345727512157,0.000559346040457) | | (0.0353146483908,0.000571501584524) | | (0.0355522909393,0.000574387067408) | | (0.0356575682336,0.000574851263615) | | (0.0357806926897,0.000575051685084) | #+TBLFM: @8$1='(sbe parameter-variation (nums @1$1..@7$1)) #+begin_src python :var data=complex-data return data #+end_src #+name: | (0.0331901438056,0.000535222885197) | | (0.0333434157791,0.000537930174356) | | (0.0345727512157,0.000559346040457) | | (0.0353146483908,0.000571501584524) | | (0.0355522909393,0.000574387067408) | | (0.0356575682336,0.000574851263615) | | (0.0357806926897,0.000575051685084) | ** emacs-lisp printing with output to string :PROPERTIES: :DATE: 2011-04-10 :END: #+begin_src emacs-lisp :results output (let ((dog (sqrt 2)) (cat 7)) (print (format "%s %f" "Dog: " (eval dog))) (print (format "%s %d" "Cat: " (eval cat)) nil) (print "Fish.")) #+end_src #+name: : : "Dog: 1.414214" : : "Cat: 7" : : "Fish." #+begin_src emacs-lisp (let ((dog (sqrt 2)) (cat 7)) `((dog ,dog) (cat ,cat) (fish))) #+end_src #+name: | dog | 1.4142135623730951 | | cat | 7 | | fish | | ** headers in R tables during export :PROPERTIES: :DATE: 2011-04-04 :END: #+TBLNAME: Chuah07 | condition | Mean.offer | |-----------+------------| | 1.MMM | 48.49 | | 2.MMU | 42.59 | | 3.MUM | 44.87 | | 4.UMU | 46.43 | | 5.UUM | 44.15 | | 6.UUU | 43.80 | | MAL | 46.28 | | UK | 44.1 | | All | 45.29 | #+headers: :var data=Chuah07 #+begin_src R :results output :exports both :cache yes str(data) #+end_src #+name[135a7f73839b69d118780ca29a64c3840601f7b9]: : 'data.frame': 9 obs. of 2 variables: : $ condition : chr "1.MMM" "2.MMU" "3.MUM" "4.UMU" ... : $ Mean.offer: num 48.5 42.6 44.9 46.4 44.1 ... eric ** session associated with R block :PROPERTIES: :DATE: 2011-04-02 :END: #+begin_src R :session *chris* x <- 1 y <- 2 y-x #+end_src #+name: : 1 ** detangling example :PROPERTIES: :tangle: yes :comments: yes :shebang: #!/bin/sh :ID: 7a22cf71-6be3-4fca-a700-4c8be8237303 :DATE: 2011-04-01 :END: #+name: sh-for-tangling #+begin_src sh echo "this is the `sh-for-tangling' code block" num=`expr 1 + 1` echo "the value of num is $num" #+end_src #+begin_src sh echo "this is an unnamed code block" #+end_src ** vc-log :PROPERTIES: :DATE: 2011-04-01 :END: A version control log of this file. The =vc-log= code block lives in the library of babel. #+call: vc-log() :exports results ** CL example :PROPERTIES: :DATE: 2011-04-01 :END: #+begin_src lisp (defun range (n &optional m) "Return the numbers in range." (loop for num from (if m n 0) to (if m m (- n 1)) collect num)) (mapcar #'list (mapcar #'1+ (range 10))) #+end_src #+name: | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | ** tangling out vc information :PROPERTIES: :DATE: 2011-04-01 :END: #+headers: :var STATE=(vc-state (or (buffer-file-name) org-current-export-file)) #+headers: :var REV=(vc-working-revision (or (buffer-file-name) org-current-export-file)) #+begin_src sh :tangle yes rm -rf ./R rm -f ./spreadSim.sub REVISION=$REV.$STATE tar -xf nsa.$REVISION.tar.gz $HOME/R/R/R-2.12.0/bin/Rscript --vanilla -e "source('./R/generateLatinHypercubeScenarios.R'); doIt()" for SCENARIO in ./R/scenarios/*.R; do export SCENARIO=${SCENARIO#./R/scenarios/} qsub nsa.sub done #+end_src ** grabbing the current buffer during export :PROPERTIES: :DATE: 2011-04-01 :END: Eric #+begin_src emacs-lisp :var buf=(buffer-file-name (current-buffer)) :exports both (message "buffer %S!" buf) #+end_src #+begin_src sh :exports results :results output git log -1 #+end_src ** colnames with call lines :PROPERTIES: :DATE: 2011-03-29 :END: #+TBLNAME: data | x | parameter | value | |---+-----------+-------| | 0 | heat | 30 | | 1 | heat | 30 | #+name: func5 #+begin_src R :var name=data :var a="one" :colnames yes names(name) #+end_src #+name: func5 | x | |-----------| | x | | parameter | | value | #+call: func5(name=data, a="two") :colnames yes #+name: func5(name=data, a="two") | x | |-----------| | x | | parameter | | value | ** caching on export :PROPERTIES: :DATE: 2011-03-23 :END: #+name: testcache #+begin_src R :cache yes :exports results dat <- matrix(runif(12), 3, 4) print(dat) #+end_src #+name[e7b83e61596da84f85c5a24e61569576c802f9a2]: testcache | 0.590091332094744 | 0.101750465808436 | 0.487125408137217 | 0.92315583024174 | | 0.483292032498866 | 0.427640072302893 | 0.974636133294553 | 0.995571716455743 | | 0.60190233332105 | 0.122638279106468 | 0.437959408387542 | 0.015639441087842 | ** conflicting header arguments :PROPERTIES: :DATE: 2011-03-14 :END: code block #+name: conflict-block #+begin_src sh :exports results :results silent echo eric #+end_src call line #+call: conflict-block() :exports results #+name: conflict-block() : eric ** macros during tangling :PROPERTIES: :ID: d2ff9d6f-b413-4072-91a9-3ae8aa32032c :DATE: 2011-03-14 :END: First, add macro expansion to the new `org-babel-tangle-body-hook'. #+begin_src emacs-lisp :results silent (add-hook 'org-babel-tangle-body-hook (lambda () (org-export-preprocess-apply-macros))) #+end_src Then define the macro. Note: you may need to export the buffer before tangling so that the macro definition is noticed and processed by Org-mode. #+MACRO: CONFIG_PARAM01 45 Then on both export and tangling the macro in the following code block will be replaced. #+begin_src sh :tangle yes echo org-mode set CONFIG_PARAMETER to: {{{CONFIG_PARAM01}}} #+end_src ** looks like a pipe in a table :PROPERTIES: :DATE: 2011-03-07 :END: #+name: clean #+begin_src emacs-lisp :var in="" (flet ((clean (in) (if (listp in) (mapcar #'clean in) (if (stringp in) (replace-regexp-in-string "¦" "|" in) in)))) (clean in)) #+end_src #+name: regexps | first | (a¦b) | | second | (1¦2) | #+begin_src perl :var a=clean(in=regexps)[0,1] :var b=clean(in=regexps)[1,1] $a; $b; #+end_src #+name: : (1|2) ** eval results as a list :PROPERTIES: :DATE: 2011-03-06 :END: #+begin_src python :results value return "(mapcar (lambda (el) (+ 1 el)) '(1 2))" #+end_src #+name: | 2 | 3 | #+begin_src python :results value return "[1, 2]" #+end_src #+name: | 1 | 2 | #+begin_src python :results value return [1, 2] #+end_src #+name: | 1 | 2 | #+begin_src python :results value return "%r" % "[1 2]" #+end_src #+name: : [1 2] ** export of inline R code :PROPERTIES: :DATE: 2011-03-03 :END: Here I test inline code evaluation in R. #+begin_src R :session *R* x <- 100 #+end_src #+name: : 100 Now I want to export the value of x, which should be src_R[:session *R*]{x} . Did the number 100 show up at the end of the previous sentence on export? ** simple mysql :PROPERTIES: :DATE: 2011-03-03 :END: #+begin_src sql :engine mysql show tables; #+end_src ** leading/trailing spaces :PROPERTIES: :DATE: 2011-03-02 :END: #+name: spaces-wrapped-string - " pass through with space " #+begin_src emacs-lisp :var res=spaces-wrapped-string[0] res #+end_src #+name: : pass through with space ** results org raw wrap :PROPERTIES: :DATE: 2011-03-02 :END: #+begin_src sh :results output org :exports none cat <> #+end_src #+name[e2c9e6c2f84563b590a765502057d92463e50182]: test_sleep | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | ** source block names in current buffer :PROPERTIES: :DATE: 2011-02-26 :END: #+begin_src emacs-lisp :results list (org-babel-src-block-names) #+end_src ** simple python block :PROPERTIES: :DATE: 2011-02-26 :END: #+begin_src python :return foo foo = 8 foo += 1 #+end_src #+name: : 9 ** sh return a list of elements with spaces :PROPERTIES: :DATE: 2011-02-26 :END: #+begin_src sh :results list echo "eric schulte" echo "dan davison" echo "seb vauban" #+end_src #+name: - ("eric" "schulte") - ("dan" "davison") - ("seb" "vauban") #+begin_src sh :results scalar echo "eric schulte" echo "dan davison" echo "seb vauban" #+end_src #+name: : eric schulte : dan davison : seb vauban ** calc variables inside of parenthesis :PROPERTIES: :DATE: 2011-02-22 :END: #+BEGIN_SRC calc :var testvar=9000 testvar - 200 #+END_SRC #+name: : 8800 #+BEGIN_SRC calc :var testvar=9000 (testvar - 200) 800 #+END_SRC #+name: : 7040000 ** new lists :PROPERTIES: :DATE: 2011-02-21 :END: *** results embedded inside of a list :PROPERTIES: :DATE: 2011-02-22 :END: 1. this has results #+name: something-in-a-list : foo 2. and this doesn't work #+begin_src emacs-lisp :var data=something-in-a-list data #+end_src #+name: : foo *** reading and writing :PROPERTIES: :DATE: 2011-02-22 :END: #+name: simple-list - 1 - two - 3 - four #+name: simple-list #+begin_src emacs-lisp :var lst=simple-list :results list (reverse lst) #+end_src ** catch the file name during export :PROPERTIES: :DATE: 2011-02-21 :END: #+begin_src emacs-lisp :var file-name=(buffer-file-name) :exports both file-name #+end_src ** export of inline code blocks which are silent :PROPERTIES: :DATE: 2011-02-20 :END: #+begin_src emacs-lisp :results silent (setf org-babel-default-inline-header-args '((:session . "none") (:results . (if (boundp 'org-current-export-file) "replace" "silent")) (:exports . "results"))) #+end_src Here is an inline code block src_sh{echo 8} <- there ** mentions of file names in file contents :PROPERTIES: :DATE: 2011-02-20 :END: directory to search #+name: graph-dir : graph-dir list all files in dir #+name: graph-files #+begin_src sh :results vector :var dir=graph-dir find $dir -type f -exec basename {} \; #+end_src #+name: graph-files | other | | dan | | eric | | seb | association of files with mentions #+name: graph-associations #+begin_src sh :var dir=graph-dir :var files=graph-files for i in $files; do for j in `grep -l -r $i $dir`;do echo $i, `basename $j` done done #+end_src #+name: graph-associations | other | eric | | other | seb | | dan | eric | | eric | seb | | seb | dan | graphing with dot #+name: to-dot #+begin_src sh :var associations=graph-associations :results scalar echo "$associations"|awk '{print $1, "->", $2}' #+end_src #+name: to-dot : other -> eric : other -> seb : dan -> eric : eric -> seb : seb -> dan #+begin_src dot :var data=to-dot :file files.png digraph G{ $data } #+end_src #+name: [[file:files.png]] ** inline code block :PROPERTIES: :DATE: 2011-02-18 :END: here is an inline block src_R{1+1} ** recutils :PROPERTIES: :DATE: 2011-02-15 :END: #+begin_src sh :file book.rec cat < book.rec # -*- mode: rec -*- %rec: Book %mandatory: Title %type: Location enum loaned home unknown %doc: + A book in my personal collection. Title: GNU Emacs Manual Author: Richard M. Stallman Publisher: FSF Location: home Title: The Colour of Magic Author: Terry Pratchett Location: loaned Title: Mio Cid Author: Anonymous Location: home Title: chapters.gnu.org administration guide Author: Nacho Gonzalez Author: Jose E. Marchesi Location: unknown Title: Yeelong User Manual Location: home # End of books.rec EOF #+end_src #+name: [[file:book.rec]] #+begin_src rec :data book.rec :fields Title,Author Location = 'loaned' #+end_src #+name: | Title | Author | | The Colour of Magic | Terry Pratchett | #+begin_src rec :data book.rec :fields Title,Author #+end_src #+name: | Title | Author | Author_2 | | GNU Emacs Manual | Richard M. Stallman | | | The Colour of Magic | Terry Pratchett | | | Mio Cid | Anonymous | | | chapters.gnu.org administration guide | Nacho Gonzalez | Jose E. Marchesi | | Yeelong User Manual | | | ** SQL --- example reading org-mode table into sql :PROPERTIES: :DATE: 2011-02-15 :END: #+tblname: example-table-for-sql | a | b | |---+----| | 1 | 10 | | 2 | 11 | | 3 | 12 | | 4 | 13 | | 5 | 14 | | 6 | 15 | #+headers: :var table=example-table-for-sql #+begin_src sql :engine mysql load data infile "$table" into mytable; #+end_src ** passing keywords inside header arguments :PROPERTIES: :DATE: 2011-02-15 :END: #+begin_src emacs-lisp :var lst='(:no-expand :other) lst #+end_src #+name: | :no-expand | other | ** two vars in a properties block -- not possible :PROPERTIES: :var: test1=7 :var: test2=8 :DATE: 2011-02-10 :END: #+begin_src emacs-lisp (message "test1=%S test2=%S" test1 test2) #+end_src results in Error : let: Symbol's value as variable is void: test2 *** an alternative :PROPERTIES: :var: tests=all-tests :DATE: 2011-02-10 :END: #+tblname: all-tests - 7 - 8 #+begin_src emacs-lisp :var eric=89 (message "test1=%S test2=%S" (first tests) (second tests)) #+end_src #+name: : test1=7 test2=8 *** another alternative :PROPERTIES: :var: vars=variables :DATE: 2011-06-21 :END: #+tblname: variables | var1 | 1 | | var2 | 2 | #+begin_src python print vars[0][1] print vars[1][1] #+end_src ** how to set no-expand in properties :PROPERTIES: :no-expand: yes :DATE: 2011-02-10 :END: #+begin_src emacs-lisp :var something="other thing" :tangle no-expand.el :test #+end_src tangles to ** non-inlined inline code block :PROPERTIES: :DATE: 2011-01-27 :END: The Date is src_sh[:results replace]{date} at the time of =this= export. src_sh[:results replace]{ls} ** results replace not always working :PROPERTIES: :DATE: 2011-01-25 :END: #+begin_src sh :results output org replace :exports code for i in `seq 4`;do echo "- place $i in the list" done #+end_src #+name: #+BEGIN_ORG - place 1 in the list - place 2 in the list - place 3 in the list - place 4 in the list #+END_ORG inline block src_emacs-lisp[:exports code :results replace]{(+ 1 1 1)} here is was ** simple calc example :PROPERTIES: :DATE: 2011-01-25 :END: #+begin_src calc 2*3 #+end_src #+name: : 6 ** inserting wrappers eats following characters :PROPERTIES: :DATE: 2011-01-20 :END: *** Test :PROPERTIES: :DATE: 2011-01-20 :END: #+begin_src emacs-lisp :results latex "\\begin{equation}\\frac{1}{2}\n\\end{equation}" #+end_src #+name: #+BEGIN_LaTeX \begin{equation}\frac{1}{2} \end{equation} #+END_LaTeX *** Watch me die :-( :PROPERTIES: :DATE: 2011-01-20 :END: ** creating a directory when needed for tangling :PROPERTIES: :DATE: 2011-01-19 :END: #+begin_src clojure :tangle (prog1 "src/foo.clj" (make-directory "src" ".")) (ns something) #+end_src a helper function for the above #+begin_src emacs-lisp (defun mkdir-p (file &optional dir) "Create any parent directories of FILE if missing and return FILE." (make-directory (file-name-directory file) (or dir ".")) file) #+end_src allows the following #+begin_src clojure :tangle (mkdir-p "src/foo.clj") (ns something) #+end_src There is now a new header argument controlling this behavior #+begin_src emacs-lisp :mkdirp yes :tangle novel/nested/directories/finally.clj (message "contents") #+end_src ** passing arguments to the shell :PROPERTIES: :DATE: 2011-01-18 :END: #+name: something : eric : schulte : yes : more #+name: something-list | 1 | | 2 | | 3 | #+begin_src sh :var data=something-list echo "$data"|wc -l #+end_src #+name: : 3 #+begin_src emacs-lisp :results silent (setq org-babel-sh-var-quote-fmt "`cat <<'BABEL_TABLE'\n%s\nBABEL_TABLE\n`") #+end_src ** wrap noweb references in comments :PROPERTIES: :DATE: 2011-01-16 :END: #+name: wrappable #+begin_src emacs-lisp (setq x (+ 4 x)) #+end_src #+begin_src emacs-lisp :comments noweb :noweb yes :tangle yes (let ((x 1)) (message "x=%s" x) <> (message "x=%s" x)) #+end_src ** replace inline code block :PROPERTIES: :DATE: 2011-01-13 :END: This is src_emacs-lisp{(+ 1 2 3)} an inline block. #+begin_src emacs-lisp (defun replace-inline-block () (interactive) (if (save-excursion (re-search-backward "[ \f\t\n\r\v]" nil t) (looking-at org-babel-inline-src-block-regexp)) (replace-match ((lambda (el) (if (stringp el) el (format "%S" el))) (org-babel-execute-src-block)) nil nil nil 1) (error "not inside of an inline source block."))) #+end_src ** noweb then variables :PROPERTIES: :DATE: 2011-01-13 :END: #+name: replaced-first #+begin_src latex \begin{itemize} \item first \item data \item third \end{itemize} #+end_src #+begin_src latex :var data="second" :noweb yes \section{ordinals} \label{sec:ordinals} <> #+end_src ** empty strings as arguments :PROPERTIES: :DATE: 2011-01-11 :END: #+begin_src emacs-lisp :results output :var foo="" (concat foo "bar") #+end_src #+name: : bar ** call lines :PROPERTIES: :DATE: 2011-01-11 :END: #+name: doubler #+begin_src emacs-lisp :var n=2 (* n 2) #+end_src #+call: doubler(n=3) #+name: doubler(n=3) : 6 #+call: doubler[:var n=3]() #+name: doubler[:var n=3]() : 6 ** language name abbreviations :PROPERTIES: :DATE: 2011-01-07 :END: #+begin_src emacs-lisp (add-to-list 'org-src-lang-modes '("clj" . clojure)) #+end_src #+begin_src clj (map (partial + 1) (range 20)) #+end_src ** eval query :PROPERTIES: :DATE: 2010-12-21 :END: #+begin_src emacs-lisp (setq org-confirm-babel-evaluate (lambda (lang body) (not (equal "ditaa" lang)))) #+end_src #+name: | lambda | (lang body) | (not (equal ditaa lang)) | #+begin_src emacs-lisp :eval query (message "eval'd") #+end_src #+name: : eval'd #+begin_src ditaa --- #+end_src ** new file handling :PROPERTIES: :DATE: 2010-12-20 :END: #+begin_src sh :sep , :file dirlisting ls -l #+end_src #+name: [[file:dirlisting]] #+begin_src ruby :file ruby-out [[1, 2, 3, 4], [2, 4, 6, 8]] #+end_src #+name: [[file:ruby-out]] #+begin_src emacs-lisp :results file :results append (let ((today (replace-regexp-in-string "[ \t]" "-" (current-time-string)))) (with-temp-file today (insert (message "I'm feeling %s" (nth (random 3) (list "good" "bad" "just fine"))))) today) #+end_src #+name: [[file:Mon-Dec-20-17:27:52-2010]] from http://www.graphviz.org/Gallery/directed/fsm.gv.txt #+begin_src dot :file fsa.png digraph finite_state_machine { rankdir=LR; size="8,5" node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8; node [shape = circle]; LR_0 -> LR_2 [ label = "SS(B)" ]; LR_0 -> LR_1 [ label = "SS(S)" ]; LR_1 -> LR_3 [ label = "S($end)" ]; LR_2 -> LR_6 [ label = "SS(b)" ]; LR_2 -> LR_5 [ label = "SS(a)" ]; LR_2 -> LR_4 [ label = "S(A)" ]; LR_5 -> LR_7 [ label = "S(b)" ]; LR_5 -> LR_5 [ label = "S(a)" ]; LR_6 -> LR_6 [ label = "S(b)" ]; LR_6 -> LR_5 [ label = "S(a)" ]; LR_7 -> LR_8 [ label = "S(b)" ]; LR_7 -> LR_5 [ label = "S(a)" ]; LR_8 -> LR_6 [ label = "S(b)" ]; LR_8 -> LR_5 [ label = "S(a)" ]; } #+end_src #+name: [[file:fsa.png]] ** tangle templates :PROPERTIES: :DATE: 2010-12-13 :END: #+name: template-heading #+begin_src emacs-lisp some stuff here #+end_src #+name: template-footing #+begin_src emacs-lisp some other stuff here #+end_src #+name: template #+begin_src sh :results output :noweb yes :var body="body stuff" heading=$(cat<> EOF ) footing=$(cat<> EOF ) echo $heading echo "$body" echo $footing #+end_src #+call: template[:noweb yes](body="something new") #+name: template[:noweb yes](body="something new") : some stuff here : something new : some other stuff here ** missing lines on tangle :PROPERTIES: :ID: 83eb62fd-4147-405b-bdc2-567b2d5cbd70 :DATE: 2010-12-13 :END: #+begin_src org :results latex :tangle latex-err.tex ,one ,two ,three #+end_src #+begin_src org :results latex :results replace ,- eric ,- schulte #+end_src #+name: #+BEGIN_LaTeX \begin{itemize} \item eric \item schulte \end{itemize} #+END_LaTeX ** utf8 and latin-1 encodings :PROPERTIES: :DATE: 2010-12-13 :END: #+tblname: toto | é | #+begin_src python :var t=toto :preamble # -*- coding: latin1 -*- :return [len(babel), len(local)] babel = unicode (t[0][0],"latin1") local = unicode ("é","latin1") #+end_src #+name: | 2 | 2 | ** Python requires a utf-8 coding prefix :PROPERTIES: :DATE: 2010-12-02 :END: #+begin_src python :prefix # -*- coding: utf-8 -*- :return s s = "é" #+end_src #+name: : é #+begin_src python :prefix # -*- coding: utf-8 -*- :results output s = "é" print(s) #+end_src #+name: : é ** empty lines in R session output :PROPERTIES: :DATE: 2010-12-01 :END: #+begin_src R :results output :session x <- 1; x x + 1 x + 4 #+end_src R #+name: : [1] 1 : [1] 2 : [1] 5 ** =:eval query= shows the name :PROPERTIES: :DATE: 2010-11-30 :END: #+name: i-have-a-name #+begin_src sh :eval query date #+end_src #+name: i-have-a-name : Tue Nov 30 22:03:25 MST 2010 ** sql variables :PROPERTIES: :DATE: 2010-11-30 :END: #+name: sql-param | table | valueTable0 | | column | valueColumn0 | | type | valueType0 | | nullability | valueNullability0 | I want to apply the values onto the following chunk of code: #+name: add-column-in-table-0 #+begin_src sql :var table=sql-param[0,1] :var column=sql-param[1,1] :var type=sql-param[2,1] :var nullability=sql-param[3,1] -- add column `@column' (if column does not exist yet) IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '@table' AND COLUMN_NAME = '@column') BEGIN ALTER TABLE $table ADD $column $type @nullability END #+end_src ** python with return header argument :PROPERTIES: :DATE: 2010-11-27 :END: #+begin_src python :return y x = 8 y = 98 2 #+end_src #+name: : 98 ** safe lists for Haskell :PROPERTIES: :DATE: 2010-11-23 :END: #+tblname: mixed-table | 1 | first | | 2 | second | | 3 | third | | 4 | fourth | #+name: rec-string-wrap #+begin_src emacs-lisp :var data=mixed-table (defun rec-string-wrap (in) (if (listp in) (mapcar #'rec-string-wrap in) (format "%S" in))) (rec-string-wrap data) #+end_src #+begin_src haskell :var tbl=rec-string-wrap(data=mixed-table) map head tbl #+end_src #+name: | 1 | 2 | 3 | 4 | ** add column to table with awk :PROPERTIES: :question_author: Sébastien Vauban :DATE: 2010-11-23 :END: I want to *add a column* to the following table. #+name: table-message | This is line 1 of the message. | | This is line 2 of the message. | | This is the last line of the message. | Its value should be dependant on a *regexp matching* the *current row* (for example, if 1 is detected in the original column, then write "A" in the new one, "B" if 2 is read, "C" if 3 is read, etc.). Hence, I'm thinking using AWK as an easy solution. #+begin_src note I'm open to other ideas on how I could do this as easily. Just throw me ideas, if you have some. #+end_src the easiest (for me) would be with the elisp =mapcar= function #+begin_src emacs-lisp :var tbl=table-message (mapcar (lambda (row) (cons "New col" row)) tbl) #+end_src #+name: | New col | This is line 1 of the message. | | New col | This is line 2 of the message. | | New col | This is the last line of the message. | *First* trial: add a column whose cell contents will be *fixed* (here, equal to =New col=). #+name: add-col #+begin_src sh :var data=table-message :results output raw :exports both echo "$data" | awk '// {print "| New col | " $0 " |";}' #+end_src #+name: add-col | New col | This is line 1 of the message. | | New col | This is line 2 of the message. | | New col | This is the last line of the message. | ** reading from single-quote-delim languages :PROPERTIES: :DATE: 2010-11-23 :END: #+BEGIN_SRC python return [['607', 'Show license short, name on the deed'], ['255', "'(message (concat 'hello ' 'world))"]] #+END_SRC #+name: | 607 | Show license short, name on the deed | | 255 | '(message (concat 'hello ' 'world)) | #+begin_src ruby [['607', 'Show license, short name on the deed'], ['255', "))'(message (concat 'hello ' 'world"]] #+end_src #+name: | 607 | Show license, short name on the deed | | 255 | ))'(message (concat 'hello ' 'world | #+begin_src haskell [["'single quotes'", "b"], ["\"double quotes\"", "d"]] #+end_src #+name: | 'single quotes' | b | | "double quotes" | d | ** un-named R code blocks :PROPERTIES: :DATE: 2010-11-23 :END: #+begin_src R 8 #+end_src #+name: : 8 #+begin_src emacs-lisp :eric 8 #+end_src #+name: : 8 #+BEGIN_SRC R :session :results output xyz #+END_SRC #+BEGIN_SRC R :session *R-2* :results output | xyz 9 #+END_SRC #+name: : [1] 9 ** introducing =wrap= header argument :PROPERTIES: :DATE: 2010-11-19 :END: #+begin_src emacs-lisp :results wrap :exports both (mapcar (lambda (el) (list el (+ 1 (* el el)))) (number-sequence 0 10)) #+end_src #+name: #+BEGIN_RESULT | 0 | 1 | | 1 | 2 | | 2 | 5 | | 3 | 10 | | 4 | 17 | | 5 | 26 | | 6 | 37 | | 7 | 50 | | 8 | 65 | | 9 | 82 | | 10 | 101 | #+END_RESULT now indented - first - second #+begin_src emacs-lisp :results wrap :exports both "something else" #+end_src #+name: #+BEGIN_RESULT : something else #+END_RESULT ** lists as data types :PROPERTIES: :DATE: 2010-11-19 :END: #+name: a-list - org-mode - and - babel #+name: a-list #+begin_src emacs-lisp :var lst=a-list :results list (reverse lst) #+end_src also for a block inside of a list 1. First element 2. Second element -- has a block #+begin_src emacs-lisp (+ 1 1 1 1) #+end_src #+name: : 4 3. third element ** sqlite :PROPERTIES: :DATE: 2010-11-10 :END: #+begin_src sqlite :db paper/climate.sqlite select count(*) from temps; #+end_src #+name: : 422689 ** lob calls with header argument pass through :PROPERTIES: :DATE: 2010-11-08 :END: #+name: lob-header #+begin_src emacs-lisp :var n=20 n #+end_src #+call: lob-header[:results vector](n=15) #+name: lob-header[:results vector](n=15) | 15 | #+call: lob-header(n=10) :results vector #+name: lob-header(n=10) | 10 | need ob-ref.el to pass through the header arguments in "[]"s #+begin_src emacs-lisp :var n=lob-header[:results vector](n=8) n #+end_src #+name: | 8 | #+begin_src emacs-lisp :var n=lob-header[:results vector](n=8)[0,0] n #+end_src #+name: : 8 ** clojure code blocks and the lazies :PROPERTIES: :DATE: 2010-11-06 :END: #+begin_src emacs-lisp :results silent (defun org-babel-execute:clojure (body params) (with-temp-buffer (insert body) (read (slime-eval `(swank:interactive-eval-region ,(buffer-substring-no-properties (point-min) (point-max))))))) #+end_src #+begin_src clojure (map (fn [el] (list el (* el el)))(range 10)) #+end_src #+name: | 0 | 0 | | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | | 6 | 36 | | 7 | 49 | | 8 | 64 | | 9 | 81 | ** playing with calc support :PROPERTIES: :DATE: 2010-11-03 :END: #+begin_src emacs-lisp (require 'ob-calc) #+end_src #+begin_src calc :var some=8 some some '* 8+8 '+ #+end_src #+name: : 80 #+begin_src calc 2*(8+8) #+end_src #+name: : 32 #+begin_src calc 2*e #+end_src #+name: : 5.43656365692 #+begin_src calc :var something=9 2*something #+end_src #+name: : 18 ** shell blocks returning a file name :PROPERTIES: :DATE: 2010-11-03 :END: #+begin_src sh :file quick.txt :results output date #+end_src #+name: [[file:quick.txt]] ** passing arguments through call lines :PROPERTIES: :DATE: 2010-10-29 :END: #+name: test #+begin_src R :session :file test.pdf :var myarg="bla" plot(1:10, main=myarg) #+end_src #+name: test [[file:test.pdf]] #+call: test(myarg="hiho") #+name: test(myarg="hiho") : test.pdf ** simple gnuplot tests :PROPERTIES: :DATE: 2010-10-26 :END: #+name: some-more-gnuplot | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | | 6 | 36 | | 7 | 49 | | 8 | 64 | #+TBLFM: $2=$1*$1 #+begin_src gnuplot :var data=some-more-gnuplot plot "$data" #+end_src #+name: Plotting data points from a table could look like this: #+tblname: basic-plot | x | y1 | y2 | |-----+------------+------------| | 0.1 | 0.425 | 0.375 | | 0.2 | 0.3125 | 0.3375 | | 0.3 | 0.24999993 | 0.28333338 | | 0.4 | 0.275 | 0.28125 | | 0.5 | 0.26 | 0.27 | | 0.6 | 0.25833338 | 0.24999993 | | 0.7 | 0.24642845 | 0.23928553 | | 0.8 | 0.23125 | 0.2375 | | 0.9 | 0.23333323 | 0.2333332 | | 1 | 0.2225 | 0.22 | #+begin_src gnuplot :var data=basic-plot :exports code :file basic-plot.png set title "Putting it All Together" set xlabel "X" set xrange [0:1] set xtics 0,0.1,1 set ylabel "Y" set yrange [0.2:0.5] set ytics 0.2,0.05,0.5 plot data u 1:2 w p lw 2 title 'x vs. y1', \ data u 1:3 w lp lw 1 title 'x vx. y2' #+end_src #+name: [[file:basic-plot.png]] ** latex headers in latex code blocks :PROPERTIES: :DATE: 2010-10-26 :END: #+begin_src latex :headers \usepackage{lmodern} :file name1.pdf Eric Schulte #+end_src #+name: [[file:name1.pdf]] #+begin_src latex :headers '("\\usepackage{mathpazo}" "\\usepackage{fullpage}") :file name2.pdf Eric Schulte #+end_src #+name: [[file:name2.pdf]] ** export-specific header arguments :PROPERTIES: :DATE: 2010-10-26 :END: #+headers: :var out=(if (and (boundp 'latexp) latexp) "latex" "not latex") #+begin_src emacs-lisp out #+end_src #+name: : not latex ** security problem with elisp in header arguments :PROPERTIES: :DATE: 2010-10-14 :END: #+begin_src emacs-lisp :var data=(setq org-confirm-babel-evaluate nil) :results silent (+ 1 1) #+end_src ** preceding blank lines on tangle :PROPERTIES: :DATE: 2010-10-13 :END: #+begin_src emacs-lisp :results silent (setq org-babel-tangle-pad-newline nil) #+end_src #+begin_src sh :tangle something.reg # something echo "else" #+end_src ** very very large numbers :PROPERTIES: :DATE: 2010-10-13 :END: #+tblname: numbers | 1 | | 2 | | 12 | | 45 | | 166 | | 12567890 | | 231231282371983279389999999 | #+begin_src emacs-lisp :var numbers=numbers (mapcar (lambda (line) (let ((number (car line))) (list number (type-of number)))) numbers) #+end_src #+name: | 1 | integer | | 2 | integer | | 12 | integer | | 45 | integer | | 166 | integer | | 12567890 | integer | | 2.3123128237198328e+26 | float | ** weaving with noweb links :PROPERTIES: :tangle: yes :DATE: 2010-10-13 :END: #+name: name #+begin_src emacs-lisp (message "eric") #+end_src #+begin_src emacs-lisp :noweb tangle ;; name <> #+end_src ** index into a scalar :PROPERTIES: :DATE: 2010-10-13 :END: #+tblname: short-list | a | | b | #+begin_src emacs-lisp :var scalar=short-list[0,0] scalar #+end_src #+name: : a ** cycle -- the input is the output :PROPERTIES: :DATE: 2010-09-29 :END: and the rhythm is the base and the base is the treble #+name: cycle | one | | two | | three | #+name: cycle #+begin_src emacs-lisp :var table=cycle (append (last table) (butlast table)) #+end_src #+begin_src emacs-lisp :exports results (+ 1 1 1) #+end_src ** Letter :PROPERTIES: :DATE: 2010-09-21 :END: #+name: body #+begin_src org :results latex ,My body includes a list: ,- one ,- two ,and a small table: ,| first | second | ,| other | last | ,Not more. #+end_src #+begin_src latex :noweb yes :tangle yes \documentclass[11pt]{isodoc} \usepackage[utf8x]{inputenc} \usepackage[T1]{fontenc} \setupdocument{ to = {Eric}, subject = {Tough to understand what to do...}, opening = {Hi}, closing = {Best} } \begin{document} \letter{% <> } \end{document} #+end_src ** splitting code blocks :PROPERTIES: :DATE: 2010-09-19 :END: - with indentation #+begin_src emacs-lisp ;;;###autoload (defun org-babel-previous-src-block (&optional arg) "Jump to the previous source block. With optional prefix argument ARG, jump backward ARG many source blocks." (interactive "P") (condition-case nil (re-search-backward org-babel-src-block-regexp nil nil (or arg 1)) (error (error "No previous code blocks"))) (goto-char (match-beginning 0)) (org-show-context)) #+end_src #+begin_src emacs-lisp ;;;###autoload (defun org-babel-split-block-maybe (&optional arg) "Split the current source code block on the cursor." (interactive "p") ((lambda (info) (if info (let ((lang (nth 0 info)) (indent (nth 6 info)) (stars (make-string (org-current-level) ?*))) (insert (concat (if (looking-at "^") "" "\n") (make-string indent ? ) "#+end_src\n" (if arg stars (make-string indent ? )) "\n" (make-string indent ? ) "#+begin_src " lang (if (looking-at "[\n\r]") "" "\n ")))) (message "Not in src block."))) (org-babel-get-src-block-info))) ;; other stuff #+end_src ** header arguments on call line :PROPERTIES: :DATE: 2010-09-09 :END: #+name: eight #+begin_src R 8 #+end_src #+call: eight() :results vector #+name: eight() | 8 | maybe the following with the new proposed header arguments #+call: eight[:session *R*]() :results vector ** empty-string results :PROPERTIES: :DATE: 2010-09-08 :END: test me one two 3 #+begin_src emacs-lisp #+end_src More test #+begin_src emacs-lisp (mapcar (lambda (pair) (list (car pair) (cdr pair))) params) #+end_src #+name: | :cache | no | | :colnames | no | | :comments | | | :exports | code | | :hlines | yes | | :noweb | no | | :results | replace | | :session | none | | :shebang | | | :tangle | no | ** tangle org-mode block :PROPERTIES: :DATE: 2010-09-07 :END: #+name: org-list #+begin_src org :results latex - one - two - three #+end_src #+begin_src emacs-lisp :tangle example.tangled :noweb yes " <> " #+end_src ** remove results when nil is returned :PROPERTIES: :DATE: 2010-09-07 :END: #+begin_src emacs-lisp (progn (+ 1 1) nil) #+end_src #+name: ** comparative speed of python evaluation :PROPERTIES: :DATE: 2010-09-07 :END: #+begin_src python :session test 2+2 #+end_src #+name: : 4 #+begin_src python return 2+2 #+end_src #+name: : 4 #+begin_src python :session test def add(a,b): return a+b def sub(a,b): return a-b add(sub(10,1),sub(10,2)) #+end_src #+name: : org_babel_python_eoe ** customizable comment formats :PROPERTIES: :tangle: yes :comments: yes :DATE: 2010-09-05 :END: #+begin_src emacs-lisp :results silent (setq org-babel-tangle-comment-format-beg "{-# LINE %start-line \"%file\" #-}" org-babel-tangle-comment-format-end "" org-babel-tangle-pad-newline) #+end_src #+begin_src haskell :tangle Main.hs test = length main = print $ test [1,2,3] #+end_src I would like the following output in the tangled file Main.hs: : {-# LINE 4 "Haskell.org" #-} : test = length : main = print $ test [1,2,3] ** tangling with full comments :PROPERTIES: :comments: org :tangle: full-comments.el :DATE: 2010-09-04 :END: The top block #+begin_src emacs-lisp (message "first block") #+end_src here's some text which won't be tangled *** subheading :PROPERTIES: :DATE: 2010-09-04 :END: another block | 1 | first | | 2 | second | #+begin_src emacs-lisp (message "second") #+end_src and finally a block with a =:noweb= header argument #+begin_src emacs-lisp :noweb yes (progn <>) #+end_src ** quoting header args (e.g. :cmdline) :PROPERTIES: :DATE: 2010-09-03 :END: #+begin_src C :cmdline 1 2 3 4 5 :includes int main(int argc, char **argv){ printf("argv[1] %s\n", argv[1]); return 0; } #+end_src #+name: : argv[1] 1 ** :var (buffer-file-name) :PROPERTIES: :DATE: 2010-09-03 :END: during export (buffer-file-name) will return nil because the temporary export buffer is not visiting any file. /file=(vc-working-revision (buffer-file-name))/ #+begin_src sh :var file=(vc-working-revision (or (buffer-file-name) "")) :exports results echo $file Revision #+end_src /file=(vc-working-revision (or (buffer-file-name) org-current-export-file))/ #+begin_src sh :var file=(vc-working-revision (or (buffer-file-name) org-current-export-file)) :exports results echo $file Revision #+end_src ** :session evaluation on export :PROPERTIES: :DATE: 2010-09-01 :END: This first block is evaluated but /doesn't/ appear in export. /:session *R* :exports none/ #+begin_src R :session *R* :exports none x <- 8 #+end_src This second block /does/ appear in export. #+begin_src R :session *R* :exports results x #+end_src ** ditaa with tilda in path :PROPERTIES: :DATE: 2010-09-01 :END: #+begin_src ditaa :file example.png +--------------+ | | | | | | | | | | +--------------+ #+end_src ** conditional tangling :PROPERTIES: :DATE: 2010-08-31 :END: #+begin_src emacs-lisp :results silent (setq tangle-tag "right") #+end_src *** first subheading :left: :PROPERTIES: :DATE: 2010-08-31 :END: #+begin_src R :tangle (and (equal (car (org-get-tags-at (point))) tangle-tag) "yes") "first" #+end_src *** second subheading :right: :PROPERTIES: :DATE: 2010-08-31 :END: #+begin_src R :tangle (and (equal (car (org-get-tags-at (point))) tangle-tag) "yes") "second" #+end_src ** scheme sessions :PROPERTIES: :DATE: 2010-08-31 :END: #+begin_src scheme :var number=9 :session *scheme* :scheme guile (+ number 0) #+end_src #+name: : 9 #+begin_src scheme :var number=9 :session *scheme* :scheme racket (+ number 1) #+end_src #+name: : 10 ** pulling information from tags :blue: :PROPERTIES: :DATE: 2010-08-30 :END: #+begin_src R :var color=(car (org-get-tags-at (point))) :tangle example.R color #+end_src #+name: : blue ** initial scheme support :PROPERTIES: :DATE: 2010-08-27 :END: #+name: numbers #+begin_src scheme (map (lambda (el) (+ el 1)) '(1 2 3)) #+end_src #+name: | 2 | 3 | 4 | #+begin_src scheme :var numbers=numbers (map (lambda (el) (- el 1)) numbers) #+end_src #+name: | 1 | 2 | 3 | ** initial javascript support :PROPERTIES: :DATE: 2010-08-27 :END: using node.js #+begin_src js var n = 0; n = n+1; return n #+end_src #+name: : 1 #+name: cars #+begin_src js var cars = ["Saab","Volvo","BMW"]; return cars; #+end_src #+name: cars | Saab | Volvo | BMW | #+begin_src js :var cars=cars return cars[0][0]; #+end_src #+name: : Saab #+begin_src js :var cars=cars return cars[0].length; #+end_src #+name: : 3 ** duplicate results on execute subtree :PROPERTIES: :DATE: 2010-08-26 :END: #+begin_src emacs-lisp :results org :exports results "- first - second - third " #+end_src #+name: #+BEGIN_SRC org - first - second - third #+END_SRC ** eval for side effect on export :PROPERTIES: :DATE: 2010-08-26 :END: - one plus one #+name: one-plus-one #+begin_src emacs-lisp :exports none :results silent (+ 1 1) #+end_src - plus one is #+begin_src emacs-lisp :var two=one-plus-one :exports both (+ 1 two) #+end_src ** trying out plantuml :PROPERTIES: :DATE: 2010-08-26 :END: setup #+begin_src emacs-lisp :results silent (require 'ob-plantuml) (setq org-plantuml-jar-path "~/src/org/contrib/scripts/plantuml.jar") #+end_src usage -- sequence diagram #+begin_src plantuml :file tryout.png Alice -> Bob: synchronous call Alice ->> Bob: asynchronous call #+end_src #+name: [[file:tryout.png]] ** wrapping up raw/org results :PROPERTIES: :DATE: 2010-08-26 :END: #+begin_src emacs-lisp :results org :exports results "- first - second - third " #+end_src #+name: #+BEGIN_SRC org - first - second - third #+END_SRC ** not caching :PROPERTIES: :session: *R* :results: output :exports: both :cache: yes :DATE: 2010-08-25 :END: #+begin_src R :noeval cat("random result:", runif(1), "\n") Sys.sleep(2) alarm() #+end_src #+begin_src R :noeval cat("random result:", runif(1), "\n") Sys.sleep(2) alarm() #+end_src *** cache on export :PROPERTIES: :DATE: 2010-08-25 :END: do we export cached blocks #+begin_src emacs-lisp :cache yes :exports results (random) #+end_src #+name[46632b4fe2e3a23e847953c95adcba58c270b381]: : 490528137 *** looks like this is a problem with info collection :PROPERTIES: :DATE: 2010-08-25 :END: #+begin_src emacs-lisp (format "%S" info) #+end_src #+begin_src emacs-lisp :results scalar :exports results :tangle yes :comments yes (mapcar (lambda (el) (list (car el) (cdr el))) (nth 2 info)) #+end_src #+name[4184710f118ac768ea0d90632508792d695efd7a]: | :cache | yes | | :colnames | no | | :comments | yes | | :exports | results | | :hlines | yes | | :noweb | no | | :results | output replace scalar | | :session | *R* | | :shebang | | | :tangle | yes | #+begin_src emacs-lisp :exports results (message "calculating info") (org-babel-sha1-hash info) #+end_src #+name[0427db66afdc95462d1c8514b662829987d71ff5]: : 0427db66afdc95462d1c8514b662829987d71ff5 ** eval and noeval :PROPERTIES: :DATE: 2010-08-26 :END: date, should export both, but won't output results because of presence of the =:noeval= header argument. #+begin_src sh :noeval :exports both date #+end_src should export code, so no need to do anything #+begin_src sh date #+end_src should export nothing, and should not query #+name: this-is-ls #+begin_src sh :eval query :exports code date #+end_src should export results, and should trigger query above #+begin_src emacs-lisp :var ls=this-is-ls :exports results ls #+end_src ** issues with shell evaluation :PROPERTIES: :DATE: 2010-08-25 :END: #+begin_src sh :results silent cd ~/src/org/ make #+end_src ** org results and replace :PROPERTIES: :DATE: 2010-08-18 :END: #+begin_src emacs-lisp :results org "| 1 | 2 | | 2 | 3 |" #+end_src #+name: | 1 | 2 | | 2 | 3 | #+begin_src R rnorm(1) #+end_src #+begin_src R numbers <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE) numbers #+end_src #+name: | 51 | 43 | 22 | | 92 | 28 | 21 | | 68 | 22 | 9 | #+begin_src R :colnames yes numbers <- matrix(c(51,43,22,92,28,21,68,22,9),ncol=3,byrow=TRUE) numbers #+end_src #+name: | V1 | V2 | V3 | |----+----+----| | 51 | 43 | 22 | | 92 | 28 | 21 | | 68 | 22 | 9 | ** ledger example output text :PROPERTIES: :DATE: 2010-08-13 :END: #+name: ledger-stuff #+begin_example 09-Aug-21 CHEQUE : 9953055 Expenses:Unknown 166.70 EUR 166.70 EUR 09-Sep-17 CHEQUE : 7691785 Expenses:Unknown 100.00 EUR 266.70 EUR 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown -525.00 EUR -258.30 EUR #+end_example #+begin_src sh :var stuff=ledger-stuff echo "$stuff" #+end_src ** importing the output of ledger :PROPERTIES: :DATE: 2010-08-12 :END: #+name: ledger-output #+begin_example 09-Aug-21 CHEQUE : 9953055 Expenses:Unknown 166.70 EUR 166.70 EUR 09-Sep-17 CHEQUE : 7691785 Expenses:Unknown 100.00 EUR 266.70 EUR 09-Oct-16 REMISE CHEQUE N 8686318 001 105 Expenses:Unknown -525.00 EUR -258.30 EUR #+end_example #+begin_src emacs-lisp :var ledger=ledger-output (with-temp-buffer (insert ledger) (message ledger) (org-table-convert-region (point-min) (point-max) 2) (org-table-to-lisp)) #+end_src #+name: | 09-Aug-21 CHEQUE : 9953055 | Expenses:Unknown | 166.70 EUR | 166.70 EUR | | 09-Sep-17 CHEQUE : 7691785 | Expenses:Unknown | 100.00 EUR | 266.70 EUR | | 09-Oct-16 REMISE CHEQUE N 8686318 001 105 | Expenses:Unknown | -525.00 EUR | -258.30 EUR | ** lob -- writing results out to files :PROPERTIES: :DATE: 2010-08-12 :END: #+name: table #+begin_src emacs-lisp (mapcar (lambda (el) (number-sequence el (+ el 3))) (number-sequence 0 4)) #+end_src writes the results out as csv file #+call: write(data=table, file="~/Desktop/example.csv") :results silent writes the results out as tab separated file #+call: write(data=table, file="~/Desktop/example.tsv") :results silent write the results out as a normal org-mode file #+call: write(data=table, file="~/Desktop/example.org") :results silent ** lisp :PROPERTIES: :DATE: 2010-08-12 :END: #+begin_src lisp :var n=5 (mapcar (lambda (el) (* el el)) (append '(1 7 3 4) (list n))) #+end_src #+name: | 1 | 49 | 9 | 16 | 25 | #+name: short-list | 1 | | 2 | | 3 | #+begin_src lisp :var lst=short-list :session t (+ 1 (length lst)) #+end_src #+name: : 4 ** comments in R blocks :PROPERTIES: :DATE: 2010-08-12 :END: #+begin_src R :session *R* :results output # this is a comment x <- rnorm(1) # this is another comment x #+end_src #+name: : : [1] 1.320853 ** tangle R and load :PROPERTIES: :tangle: to-load.r :DATE: 2010-08-12 :END: evaluate this #+begin_src emacs-lisp :results silent :tangle no (setq org-babel-post-tangle-hook nil) (add-hook 'org-babel-post-tangle-hook (lambda () (ess-load-file (buffer-file-name)))) #+end_src then tangle #+begin_src R :comments yes x <- 10 #+end_src #+begin_src R y <- 9 #+end_src #+begin_src R :tangle file2.R y <- 9 #+end_src ** colnames to specific variables :PROPERTIES: :DATE: 2010-07-22 :END: #+tblname: spec-colnames | one | two | thee | |-----+-----+------| | 1 | 2 | 3 | #+tblname: nospec-colnames | three | two | one | |-------+-----+-----| | 3 | 2 | 1 | #+begin_src python :var nospec=nospec-colnames :var spec=spec-colnames :colnames '(spec) return nospec #+end_src #+name: | one | two | thee | |-------+-----+------| | three | two | one | | 3 | 2 | 1 | ** caption on code block :PROPERTIES: :DATE: 2010-07-22 :END: #+caption: Examples of variable declaration. #+label: sql-block #+begin_src sql SELECT 6*9; #+end_src ** palendromic primes :PROPERTIES: :DATE: 2010-07-20 :END: Note that because Haskell is funny about what can be typed into the interpreter, the following should be loaded with =org-babel-load-in-session=. #+begin_src haskell palendromic_primes = [x | x <- [1..], prime x, palendrome x] where factors n = [x | x <- [1..floor(sqrt(fromIntegral(n)))], n `mod` x == 0] prime n = factors n == [1] primes = [x | x <- [2..], prime x] palendrome n = show(n) == reverse(show(n)) palendromic_prime_distances = map (\(x,y)-> y-x) neighbors where neighbors = (zip palendromic_primes (tail palendromic_primes)) #+end_src #+name: palendromic_prime_distances #+begin_src haskell take 180 (zip [1..] palendromic_prime_distances) #+end_src For high-quality png output from gnuplot, the following sequence of graphing to a =.eps= file, and then converting to a =.png= can be useful. #+name: dist-graph #+begin_src gnuplot :var data=palendromic_prime_distances :file pps.eps set term postscript landscape color enhanced set log y set title "distance between consecutive palendromic primes" plot "$data" with fs notitle #+end_src The =convert= command is part of the [[http://www.imagemagick.org/script/index.php][imagemagick]] suite. #+begin_src sh :var input=dist-graph :results file convert -depth 300 -rotate 90 $input pps.png echo "pps.png" #+end_src ** input from an example block :PROPERTIES: :DATE: 2010-07-13 :END: #+name: lorem #+begin_example Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. #+end_example #+begin_src emacs-lisp :var lorem=lorem (message "%d words in Lorem" (length (split-string lorem))) #+end_src #+name: : 68 words in Lorem #+name: 1D | 1 | | 2 | | 3 | | 4 | #+begin_src emacs-lisp :var lst=1D[:,0] lst #+end_src #+name: : 1 ** fixing result insertion :PROPERTIES: :DATE: 2010-07-12 :END: needs to replace the results when there is a new hash *** normal results :PROPERTIES: :DATE: 2010-07-12 :END: #+begin_src sh date #+end_src #+name: : Mon Jul 12 22:18:16 PDT 2010 *** unnamed source block results :PROPERTIES: :DATE: 2010-07-12 :END: #+begin_src emacs-lisp :cache yes (+ 1 2 3 4) #+end_src #+name[16a776d6d139e1d39e99d736536a546df115c2dc]: : 10 #+begin_src emacs-lisp :cache yes (list '(1 2 3) '(4 5 6)) #+end_src #+name[53f489ed6977857b9945d79d06e575b2cbbebf11]: | 1 | 2 | 3 | | 4 | 5 | 6 | *** named source block results :PROPERTIES: :DATE: 2010-07-12 :END: #+name: something-w-table #+begin_src emacs-lisp (sleep-for 2) (list '(1 2 3) '(4 5 8)) #+end_src #+name: something #+begin_src emacs-lisp :cache yes (+ 1 2 3 4 8) #+end_src Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enimad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. # something else #+name[d053f6643d9dc52a0e804c15f2a762da73a00a07]: something : 18 #+attr_latex: width=0.4\textwidth #+name[5fac69648ab749ef9ee88ea65b3d49d93f3f6cc8]: something-w-table | 1 | 2 | 3 | | 4 | 5 | 8 | ** example w/o source name :PROPERTIES: :DATE: 2010-07-12 :END: delete emacs-lisp below for errors #+begin_src emacs-lisp (* (+ 1 1 1) (+ 1 1 1) (+ 1 1 1) (+ 1 1 1) (+ 1 1 1) (+ 1 1 1) (+ 1 1 1)) #+end_src ** limited precision :PROPERTIES: :DATE: 2010-07-12 :END: #+name: anova-example | Effect | DFn | DFd | SSn | SSd | F | p | p<.05 | pes | |--------+-----+-----+-----------------+------------------+------------------+----------------------+-------+------------------| | Days | 9 | 153 | 166235.12250176 | 151101.038615303 | 18.7026979326383 | 8.99534541600196e-21 | * | 0.52384550792003 | #+begin_src emacs-lisp :var tab=anova-example :colnames yes :cache yes (mapcar (lambda (row) (mapcar (lambda (cell) (if (numberp cell) (format "%.4f" cell) cell)) row)) tab) #+end_src #+name[16ac354f1e7a65594bb59e252ab221e6a4b10f80]: | Effect | DFn | DFd | SSn | SSd | F | p | p<.05 | pes | |--------+--------+----------+-------------+-------------+---------+----------------------+-------+--------| | Days | 9.0000 | 153.0000 | 166235.1225 | 151101.0386 | 18.7027 | 8.99534541600196e-21 | * | 0.5238 | ** export blocks w/o languages :PROPERTIES: :DATE: 2010-07-09 :END: should raise an error source #+begin_src emacs-lisp ;; this is a comment (+ 1 1 1) #+end_src broken source #+begin_src (+ 2 2 2) #+end_src example #+begin_example this is exampled #+end_example #+begin_src ruby # this is the first [1, 2, 3, 4, 5].map{|r| r+1} #+end_src ** scratch :PROPERTIES: :DATE: 2010-07-08 :END: #+begin_src emacs-lisp :exports results (+ 1 1 1 1) (setq org-export-babel-evaluate t) #+end_src and now for src_emacs-lisp{87} an inline block looking at paths #+begin_src emacs-lisp (buffer-file-name) #+end_src ** dot :PROPERTIES: :DATE: 2010-07-06 :END: #+begin_src dot :file models.png :cmdline -Tpng digraph data_relationships { "data_requirement" [shape=Mrecord, label="{DataRequirement|description\lformat\l}"] "data_product" [shape=Mrecord, label="{DataProduct|name\lversion\lpoc\lformat\l}"] "data_requirement" -> "data_product" } #+end_src #+name: [[file:models.png]] ** Tom found a bug :PROPERTIES: :DATE: 2010-07-06 :END: #+begin_src emacs-lisp :tangle something.el (list 1 (+ 2 3)) #+end_src #+name: | 1 | 5 | ** python errors :PROPERTIES: :DATE: 2010-07-04 :END: #+begin_src python :session :results value [1, [2], 3, 4] #+end_src #+name: | 1 | (2) | 3 | 4 | #+begin_src ruby :results output :session [1, 2, 3, 4, 6].map{|n| puts n} #+end_src #+name: : 1 : 2 : 3 : 4 : 6 #+begin_src python :session :results output print 9 #+end_src #+name: R-with-colnames | one | |-----| | 1 | #+begin_src R :results output "something" #+end_src #+name: : [1] "something" #+begin_src R :session *R* :results output 1 2 3 4 #+end_src #+name: : [1] 1 : [1] 2 : [1] 3 : [1] 4 #+begin_src perl :results output print "8\n"; print "9\n"; #+end_src #+name: : 8 : 9 #+begin_src clojure (+ 8 7) #+end_src #+name: : 15 #+begin_src clojure :session *clj* (println "eric") #+end_src #+name: : nil #+begin_src perl :results value 8 #+end_src #+name: : 8 #+begin_src c++ :includes '( ) printf("eric schulte\n"); #+end_src #+name: : eric schulte #+begin_src sh echo 78 #+end_src #+name: : 78 ** tangle R and load :PROPERTIES: :tangle: with-comments.r :comments: yes :DATE: 2010-07-09 :END: #+begin_src R :tangle no z <- 0 #+end_src #+begin_src R x <- 8 #+end_src #+begin_src R y <- 9 #+end_src #+name: i-have-a-name #+begin_src R x+y+z #+end_src ** table comment issue :PROPERTIES: :DATE: 2010-06-30 :END: #+BEGIN_changemargin {-4.2cm}{0cm} #+TBLNAME: AutresFPNVE #+ATTR_LaTeX: align=lrrrrr | | | Montant total (\EUR) | Taux amort (\%) | Part pro. (\%) | Déduc (\%) | NVE (\EUR) | |---+------------------------------------------+----------------------+-----------------+----------------+------------+------------| | | Documentation et formation | 51.05 | | | | 0.00 | | | Communications GSM | 831.16 | 100 | 25 | 100 | 207.79 | | | Internet (Dommel) | 167.88 | 100 | 33 | 100 | 55.40 | | | Fournitures à amortir (ordinateur + GSM) | 762.51 | 33 | 80 | 100 | 201.30 | | | Restaurant | 304.70 | 100 | 100 | 69 | 210.24 | |---+------------------------------------------+----------------------+-----------------+----------------+------------+------------| | | Total | | | | | 1062.02 | | ^ | | | | | | Total | #+tblfm: $7=$3*$4*$5*$6/1000000;%.2f::@2$3=51.05::@3$3=9.00+184.88+51.22+201.82+45.67+69.03+62.93+54.16+38.87+39.77+36.35+37.46::@4$3=12*13.99::@6$3=146.50+158.20;%.2f::@7$7=vsum(@-I..@-II);%.2f #+END_changemargin save me! #+begin_src org , #+TBLNAME: AutresFPNVE , #+ATTR_LaTeX: align=lrrrrr , | | | Montant total (\EUR) | Taux amort (\%) | Part pro. (\%) | Déduc (\%) | NVE (\EUR) | , |---+------------------------------------------+----------------------+-----------------+----------------+------------+------------| , | | Documentation et formation | 51.05 | | | | 0.00 | , | | Communications GSM | 831.16 | 100 | 25 | 100 | 207.79 | , | | Internet (Dommel) | 167.88 | 100 | 33 | 100 | 55.40 | , | | Fournitures à amortir (ordinateur + GSM) | 762.51 | 33 | 80 | 100 | 201.30 | , | | Restaurant | 304.70 | 100 | 100 | 69 | 210.24 | , |---+------------------------------------------+----------------------+-----------------+----------------+------------+------------| , | | Total | | | | | 1062.02 | , | ^ | | | | | | Total | , #+TBLFM: $7=$3*$4*$5*$6/1000000;%.2f::@2$3=51.05::@3$3=9.00+184.88+51.22+201.82+45.67+69.03+62.93+54.16+38.87+39.77+36.35+37.46::@4$3=12*13.99::@6$3=146.50+158.20;%.2f::@7$7=vsum(@-I..@-II);%.2f #+end_src #+begin_example #+tblname: example | 1 | 2 | #+end_example ** latex literals in export :PROPERTIES: :DATE: 2010-06-30 :END: #+ATTR_LaTeX: width=\textwidth [[./composite-pattern.png]] ** captions :PROPERTIES: :DATE: 2010-06-29 :END: #+caption: I'm not removed from export #+label: also-not-removed | A | B | | 1 | 2 | ** booktabs :PROPERTIES: :DATE: 2010-06-29 :END: #+tblname: months | num | Abbrev. | |-----+---------| | 1 | Jan. | | 2 | Feb. | | 3 | Mar. | #+call: booktabs(table=months, align="r|l") :results latex :exports results ** complex :PROPERTIES: :DATE: 2010-06-28 :END: #+name: raw-data #+begin_src sh :results scalar wget --quiet -qO- "http://ogdi.cloudapp.net/v1/dc/RecreationParks?format=json" #+end_src #+name: dc-parks #+begin_src emacs-lisp :var keys='(ward area) :var data=raw-data (mapcar (lambda (lis) (mapcar (lambda (key) (cdr (assoc key lis))) keys)) (cdr (car (with-temp-buffer (insert data) (goto-char (point-min)) (json-read))))) #+end_src #+name: dc-parks-metric #+begin_src ruby :var data=dc-parks data.map{|f| [f[0], 2.59 * f[1]]} #+end_src #+begin_src R :var parkData=dc-parks-metric :file parks.png :session *R* plot(parkData) title(main="Park size by Ward") #+end_src #+name: [[file:parks.png]] ** table-label :PROPERTIES: :DATE: 2010-06-28 :END: #+label: bam | 1 | | 2 | | 3 | ** haskell issues :PROPERTIES: :DATE: 2010-06-28 :END: #+begin_src haskell length [1, 2] #+end_src #+name: : 2 #+tblname: example-4-haskell | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | #+begin_src haskell :var this=example-4-haskell length this #+end_src #+name: : 7 ** possible prefixes :PROPERTIES: :DATE: 2010-06-26 :END: | prefix | remaining characters | |----------+----------------------| | ob- | 5 | | org-b- | 2 | | orgb- | 3 | | org-bbl- | 0 | | bbl- | 4 | | babel- | 2 | #+TBLFM: $2='(sbe leftover (prefix $$1)) #+name: leftover #+begin_src emacs-lisp :var prefix="" (- ;; length w/o .el (- 13 (length ".el")) ;; length of prefix (length prefix)) #+end_src ** hlines in python :PROPERTIES: :DATE: 2010-06-26 :END: #+tblname: many-cols | a | b | c | |---+---+---| | d | e | f | |---+---+---| | g | h | i | #+name: echo-table #+begin_src python :var tab=many-cols :hlines yes :exports both :session return tab #+end_src #+begin_src emacs-lisp :var table=echo-table :exports none (butlast (apply #'append (mapcar (lambda (el) (list el 'hline)) table))) #+end_src #+call: echo-table(tab=many-cols) #+begin_src python :exports results return [['foo', 'bar', 'baz'], ["a", "b", "None of the above"], ['1', 2, 3]] #+end_src #+begin_src emacs-lisp :exports results (message "Exist") #+end_src ** protecting block bodies :PROPERTIES: :DATE: 2010-06-25 :END: neither of these work as expected #+begin_src org ,#+TITLE: stuff ,#+begin_src emacs-lisp , (message "something") ,#+end_src ,more stuffs ,#+resname: something ,: value ,# and a comment #+end_src #+begin_src org ,* example org ,# this is a comment ,this is not a comment #+end_src #+begin_src org ,* escaped org-mode markup ,this should be exported as is ,#+results: escaping-example ,: 24 #+end_src #+begin_html
#comment
#+end_src
#+end_html final ** multiple evals for refs :PROPERTIES: :DATE: 2010-06-25 :END: #+begin_src emacs-lisp (setq counter 0) #+end_src #+name: : 0 #+name: counter #+begin_src emacs-lisp (setq counter (+ 1 counter)) counter #+end_src #+begin_src emacs-lisp :var counter_val=counter counter_val #+end_src #+name: : 3 ** tangling :PROPERTIES: :DATE: 2010-06-17 :END: #+begin_src sh :shebang #!/bin/sh :tangle yes date #+end_src #+begin_src sh :shebang #!/bin/bash :tangle whoisme :exports both echo $USER #+end_src #+begin_src emacs-lisp :tangle yes :comments yes (message "BAM") #+end_src #+begin_src fortran :exports both 1+8 #+end_src ** cache on export :PROPERTIES: :DATE: 2010-06-17 :END: do we export cached blocks #+begin_src sh :cache yes :exports results date #+end_src #+name[06ed73c6d8d022cf9c323d92af885952865add17]: : Thu Jun 17 07:35:19 PDT 2010 ** foo org :PROPERTIES: :session: *R* :DATE: 2010-06-16 :END: Figure \ref{fig:one} (p. \pageref{fig:one}) is produced by the following code #+BEGIN_SRC R plot(x, y) abline(out1) #+END_SRC Note that =x=, =y=, and =out1= are remembered from the preceding code chunk. We don't have to regenerate them. All code chunks are part of one R "session". and more stuff here and then the results #+attr_latex: width=0.8\textwidth,placement=[p] #+label: fig:one #+caption: Scatter Plot with Regression Line [[file:fig1.pdf]] ** comments not commented :PROPERTIES: :DATE: 2010-06-16 :END: # $some stuff # some more stuff$ -- I should be a comment line 1) a source block inside of an =enumerate= #+name: plotxy #+begin_src emacs-lisp :exports results (message "I think so") #+end_src #+begin_src emacs-lisp (message "don't eat me") #+end_src can cause problems 2) how about this one... ** don't eat me! :PROPERTIES: :DATE: 2010-06-15 :END: 1) a source block inside of an =enumerate= #+begin_src emacs-lisp :exports results (list (list "I'm hungry" "I'm hungry") (list "I'm hungry" "I'm hungry") (list "I'm hungry" "I'm hungry")) #+end_src #+name: | I'm hungry | I'm hungry | | I'm hungry | I'm hungry | | I'm hungry | I'm hungry | #+begin_src emacs-lisp (message "don't eat me") #+end_src can cause problems 2) source blocks should be able to be on adjacent lines ** simple reference :PROPERTIES: :DATE: 2010-06-13 :END: #+tblname: table-the-first | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 9 | #+begin_src emacs-lisp :var data=table-the-first[1,1] data #+end_src #+name: : 5 ** exporting with call lines :PROPERTIES: :DATE: 2010-06-11 :END: #+name: rpn-to-alg(alg) #+begin_src clojure :results output :var alg="00+" (def binary-operators '(\+ \- \* \/)) (def unary-operators '(\s)) (defn rpn-to-alg [chars stack] (if (> (.size chars) 0) (let [el (first chars)] (if (some #{el} binary-operators) (rpn-to-alg (rest chars) (cons (apply str "(" (or (second stack) 1) " " el " " (or (first stack) 1) ")") (rest (rest stack)))) (if (some #{el} unary-operators) (rpn-to-alg (rest chars) (cons (apply str "(" el " " (or (first stack) 1) ")") (rest (rest stack)))) (rpn-to-alg (rest chars) (cons el stack))))) (first stack))) (println (apply str (rpn-to-alg (seq alg) '()))) #+end_src #+name: distributed-best : 73*x11/+4/++51xxx13*y/++6y5*6/6-+xx+* #+call: rpn-to-alg(alg=distributed-best) ** can't open indented results :PROPERTIES: :DATE: 2010-06-11 :END: #+begin_src latex :packages '(("" "tikz") ("active,tightpage" "preview")) :file recursion.pdf \begin{preview} \ovalbox{ \begin{tikzpicture} \node{$n$} child { node{$\left(\frac{n}{2}\right)^2$} child{ node{$\left(\frac{n}{4}\right)^2$} node{$\left(\frac{n}{4}\right)^2$} } } child{ node{$\left(\frac{n}{2}\right)^2$} child{ node{$\left(\frac{n}{4}\right)^2$} node{$\left(\frac{n}{4}\right)^2$} } }; \end{tikzpicture} } \end{preview} #+end_src #+name: [[file:recursion.pdf]] ** indented source-code blocks and indented results :PROPERTIES: :DATE: 2010-06-10 :END: #+name: time #+begin_src emacs-lisp :results append ;; (list (list (current-time-string))) (current-time-string) #+end_src #+name: time | 1 | 2 | 3 | #+call: time() :results prepend #+name: time() | 1 | 2 | 3 | : Thu Jun 10 14:13:21 2010 : Thu Jun 10 14:13:21 2010 : : Thu Jun 10 14:13:21 2010 : : Thu Jun 10 14:13:21 2010 : : Thu Jun 10 14:13:21 2010 : nil : nil : Thu Jun 10 14:11:22 2010 : Thu Jun 10 14:11:20 2010 : nil : nil : Thu Jun 10 14:06:04 2010 : Thu Jun 10 14:06:03 2010 : Thu Jun 10 14:05:51 2010 : Thu Jun 10 14:05:57 2010 : Thu Jun 10 14:06:00 2010 ** not expand inlines in examples :PROPERTIES: :DATE: 2010-06-08 :END: : src_emacs-lisp{(+ 1 2 3)} #+begin_example src_emacs-lisp{(+ 1 2 3)} #+end_example src_emacs-lisp{(+ 1 2 3)} #+begin_example src_emacs-lisp{(+ 1 2 3)} #+end_example ** indented source names :PROPERTIES: :DATE: 2010-06-07 :END: #+name: i-am-indented #+begin_src emacs-lisp (message "i am indented") #+end_src #+name: i-am-indented : i am indented #+begin_src emacs-lisp :var output=i-am-indented (length output) #+end_src #+name: : 13 #+name: : eric ** updating results "in-situ" :PROPERTIES: :DATE: 2010-06-07 :END: #+name: in-situ : update me in place please -- Mon Jun 7 16:44:44 2010 : update me in place please -- Mon Jun 7 16:44:43 2010 : update me in place please -- Mon Jun 7 16:44:42 2010 : update me in place please -- Mon Jun 7 16:44:37 2010 : update me in place please -- Mon Jun 7 16:42:14 2010 : update me in place please (at the bottom) -- Mon Jun 7 16:44:59 2010 : update me in place please (at the bottom) -- Mon Jun 7 16:45:00 2010 : update me in place please (at the bottom) -- Mon Jun 7 16:45:02 2010 the results should be *above* the block #+name: in-situ #+begin_src emacs-lisp :results prepend (format "update me in place please -- %s" (current-time-string)) #+end_src #+name: in-situ #+begin_src emacs-lisp :results append (format "update me in place please (at the bottom) -- %s" (current-time-string)) #+end_src ** inhibiting evaluation on export :PROPERTIES: :noeval: don't do it :DATE: 2010-06-07 :END: #+begin_src clojure :session eric :exports none (+ 1 1 1 1) (error) #+end_src ** executing emacs-lisp on export :PROPERTIES: :DATE: 2010-06-07 :END: #+begin_src emacs-lisp (error "eric") #+end_src ** stripping existing results :PROPERTIES: :DATE: 2010-06-07 :END: #+name: trickily-located-somehwere-else : I shouldn't be exported Neither of the result strings for the following two code blocks should be included in the export. And only one of the bodies should be included... #+begin_src emacs-lisp :exports code (+ 1 1 1 1) #+end_src #+name: : don't include me in the export!!!!!!! #+name: trickily-located-somehwere-else #+begin_src emacs-lisp :exports none (message "I shouldn't be exported") #+end_src ** export with existing results :PROPERTIES: :DATE: 2010-06-07 :END: #+begin_src emacs-lisp :exports none :results silent '((1 2) (3 4)) #+end_src #+name: | 1 | 2 | | 3 | 4 | #+begin_src ditaa :file /tmp/eric.png :exports none :results silent +---------------+ | | | | | | +-----------------+ | Eric | | | | | | Schulte | | | | | | | +-----------------+ +---------------+ #+end_src #+name: [[file:/tmp/eric.png]] ** non-empty comint prompt :PROPERTIES: :DATE: 2010-06-07 :END: #+begin_src ruby :session eric 8 + 9 #+end_src ** unwind-protect with narrowing :PROPERTIES: :DATE: 2010-06-07 :END: I'm not in the subtree *** I'm in the subtree :PROPERTIES: :DATE: 2010-06-07 :END: #+begin_src emacs-lisp (+ 6 "I'm not a number!!") #+end_src ** commas on tangling test :PROPERTIES: :DATE: 2010-06-07 :END: test comma protection on tangling #+begin_src emacs-lisp :results silent (org-babel-add-interpreter "org") (add-to-list 'org-babel-tangle-langs '("org" "org")) #+end_src #+begin_src org :tangle commas.org ,* org-mode , :PROPERTIES: , :CUSTOM_ID: comma-protect , :END: ,#+begin_src emacs-lisp , protected? ,#+end_src #+end_src #+begin_example ,* this should be # commented out and maybe not this... #+end_example ** simple table :PROPERTIES: :DATE: 2010-06-06 :END: #+begin_src emacs-lisp '((1 2 3) (4 5 6) (7 8 900)) #+end_src #+name: | 1 | 2 | 3 | | 4 | 5 | 6 | | 7 | 8 | 900 | ** inline expressions :PROPERTIES: :session: 'default :DATE: 2010-06-06 :END: #+begin_src R :exports code :results silent x<-4 #+end_src the sum of 1 and x is equal to src_R{x+1}, now I'll sneakily reset this value in a hidden inline block src_R[:exports none]{x<-2}, so it's value is now src_R{x}. ** adding file names to literal values on export :PROPERTIES: :DATE: 2010-06-01 :END: #+name: three : 9 #+begin_src R :var num=three :exports results runif(n=num, min=0, max=1) #+end_src #+begin_src R :var num=3 :exports results runif(n=num, min=0, max=1) #+end_src ** appending tangle :PROPERTIES: :tangle: appended.el :DATE: 2010-05-28 :END: append all these block #+begin_src emacs-lisp (message "block %d" 1) #+end_src #+begin_src emacs-lisp (message "block %d" 2) #+end_src #+begin_src emacs-lisp (message "block %d" 3) #+end_src ** visibility affecting execution :PROPERTIES: :DATE: 2010-05-27 :END: *** folding :PROPERTIES: :DATE: 2010-05-27 :END: lets test folding **** folded :PROPERTIES: :DATE: 2010-05-27 :END: #+begin_src emacs-lisp (message "folded1") #+end_src #+name: : folded1 #+begin_src emacs-lisp (message "folded2") #+end_src #+name: : folded2 **** unfolded :PROPERTIES: :DATE: 2010-05-27 :END: #+begin_src emacs-lisp (message "unfolded1") #+end_src #+name: : unfolded1 #+begin_src emacs-lisp (message "unfolded2") #+end_src #+name: : unfolded2 ** empty code blocks -- and latex vs. LaTeX :PROPERTIES: :DATE: 2010-05-26 :END: eric #+begin_src latex #+end_src michael #+begin_src LaTeX #+end_src schulte #+begin_src emacs-lisp (message "error") #+end_src ** colnames :PROPERTIES: :DATE: 2010-05-04 :END: #+tblname: A | a | b | c | |---+---+---| | d | e | f | | g | h | i | #+begin_src python :var tab=A :colnames yes return [[val + '*' for val in row] for row in tab] #+end_src #+name: | a | b | c | |----+----+----| | d* | e* | f* | | g* | h* | i* | #+tblname: A | a | b | c | | d | e | f | | g | h | i | #+begin_src ruby :var tab=A :colnames yes tab.map{|r| r.map{|e| e+"*"} } #+end_src #+name: | a | b | c | |----+----+----| | d* | e* | f* | | g* | h* | i* | ** lisps not fully eval'd :PROPERTIES: :DATE: 2010-04-30 :END: #+begin_src emacs-lisp (message "one") (message "two") #+end_src #+name: : two #+begin_src clojure :session :default (println "one") (println "two") (+ 1 2) #+end_src #+name: : 3 ** tangling org :PROPERTIES: :DATE: 2010-04-27 :END: #+begin_src org :tangle ~/Desktop/test.org ,* first ,| eric | me | ,| patton | my dog | ,* second ,some more stuff... ,#+HTML: I bet this is quoted #+end_src #+begin_src ruby :tangle ~/Desktop/test.rb # this is a comment eric.map{|l| puts l} #+end_src ** colnames mismatched sizes :PROPERTIES: :DATE: 2010-04-23 :END: #+tblname: mismatch-colnames | a | b | |---+----| | 1 | 8 | | 2 | 9 | | 3 | 10 | | 4 | 11 | #+begin_src python :var tab=mismatch-colnames return [[1, 2, 3]] #+end_src #+name: | 1 | 2 | 3 | #+begin_src python :var tab=mismatch-colnames return [[1, 2]] #+end_src #+name: | a | b | |---+---| | 1 | 2 | #+begin_src python :var tab=mismatch-colnames :colnames yes return [1,2] #+end_src #+name: | 1 | 2 | ** variable indexing :PROPERTIES: :DATE: 2010-04-23 :END: #+TBLNAME: MyTable | X | Y | |-----+----| | 0 | 0 | | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | |-----+----| | Sum | 55 | #+TBLFM: $2=$1*$1::@8$2=vsum(@2..@-1) #+begin_src python :var sum=MyTable[2:7,1] :exports none return sum #+end_src #+name: | 0 | 1 | 4 | 9 | 16 | 25 | #+begin_src python :var sum=MyTable[9,1] :exports none return sum #+end_src #+name: : 55 #+begin_src gnuplot :var data=MyTable[1:-2] :var sum=MyTable[7,1] :results silent :exports none reset set label "Sum: %.0f",sum at graph 0.03, graph 0.93 plot data with linespoints #+end_src ** hline processing :PROPERTIES: :DATE: 2010-04-12 :END: #+tblname: many-cols | a | b | c | |---+---+---| | d | e | f | |---+---+---| | g | h | i | #+tblname: less-cols | 1 | |---| | 2 | | 3 | #+tblname: less-cols2 | 1 | 2 | 3 | #+begin_src emacs-lisp :var tab=many-cols (message "%S" tab) ;; (remove 'hline tab) ;; (flet ((rem-hline (el) ;; (if (listp el) ;; (remove nil (mapcar #'rem-hline el)) ;; (if (equal 'hline el) nil el)))) ;; (rem-hline tab)) #+end_src #+begin_src ruby :var tab=less-cols tab #+end_src #+name: | 1 | |---| | 2 | | 3 | #+begin_src ruby :var one=2 1 + 2 #+end_src #+name: : 3 #+begin_src python :var tab=less-cols return tab #+end_src #+name: | 1 | |---| | 2 | | 3 | #+begin_src ruby :var tab=less-cols :colnames no tab #+end_src #+name: | 1 | | 2 | | 3 | #+begin_src emacs-lisp :var tab=row-and-col-names (message "%S" tab) #+end_src #+name: : (("" "c1" "c2" "c3") hline ("r1" 1 4 7) ("r2" 2 5 8) ("r3" 3 6 9)) #+tblname: row-and-col-names | | c1 | c2 | c3 | |----+----+----+----| | r1 | 1 | 4 | 7 | | r2 | 2 | 5 | 8 | | r3 | 3 | 6 | 9 | functions #+begin_src emacs-lisp (defun org-babel-del-hlines (table) "Remove all 'hlines from TABLE." (remove 'hline table)) (defun org-babel-get-colnames (table) "Return a cons cell, the `car' of which contains the TABLE less colnames, and the `cdr' of which contains a list of the column names" (if (equal 'hline (second table)) (cons (cddr table) (car table)) table)) (defun org-babel-get-rownames (table) "Return a cons cell, the `car' of which contains the TABLE less colnames, and the `cdr' of which contains a list of the column names. Note: this function removes any hlines in TABLE" (flet ((trans (table) (apply #'mapcar* #'list table))) (let ((table (trans (remove 'hline table)))) (cons (cdr table) (car table))))) (defun org-babel-put-colnames (table colnames) "Add COLNAMES to TABLE if they exist." (if colnames (apply 'list colnames 'hline table) table)) (defun org-babel-put-rownames (table rownames) "Add ROWNAMES to TABLE if they exist." (if rownames (mapcar (lambda (row) (if (listp row) (cons (or (pop rownames) "") row) row)) table) table)) #+end_src ** test gnuplot :PROPERTIES: :DATE: 2010-04-17 :END: #+begin_src gnuplot plot sin(x), x+5 #+end_src ** evaluate references :PROPERTIES: :DATE: 2010-04-09 :END: #+begin_src emacs-lisp :var var=`(+ 9 ,(- 19 7)) :tangle yes (message "var is %S" var) #+end_src #+begin_src emacs-lisp (+ 1 2) #+end_src #+name: : 3 #+begin_src ruby + 1 2 #+end_src #+name: : nil ** tangling and variable resolution :PROPERTIES: :ID: 18b4f1be-bb1d-49bc-a651-c97406a35bdd :tangle: yes :DATE: 2010-03-31 :END: #+name: A #+begin_src emacs-lisp :eval no :expand yes :var id=(org-entry-get nil "ID" t) :var two=2 (concat "This is the entry ID: " id) #+end_src #+name: A : This is the entry ID: 18b4f1be-bb1d-49bc-a651-c97406a35bdd ** latex attributes :PROPERTIES: :DATE: 2010-03-23 :END: #+ATTR_LaTeX: width=0.38\textwidth wrap placement={r}{0.4\textwidth} #+begin_src ditaa :file=scrap.png +---------------------------+ | | | latex | | | | +------------+ | | | | | | | | | | | cBLU | | | +------------+ | | cPNK | +---------------------------+ #+end_src ** access to variables set in property drawers :PROPERTIES: :special: 89 :text: schulte :DATE: 2010-03-22 :END: : "(org-entry-get nil "special" t)" #+begin_src emacs-lisp :var special=(string-to-number (org-entry-get nil "special" t)) (+ special 1) #+end_src #+name: : 90 #+begin_src emacs-lisp :var special=(org-entry-get nil "text" t) special #+end_src #+name: : schulte ** variables into shell scripts :PROPERTIES: :DATE: 2010-02-23 :END: #+name: into-shell-scripts | username | guest | | password | nothing | #+begin_src sh :var username=into-shell-scripts[0,0] :var password=into-shell-scripts[1,1] :results output echo "$username -p $password" #+end_src #+name: : username -p nothing #+name: number-into-shell : 9 #+begin_src sh :var num=number-into-shell for i in `seq $num`; do echo $i done #+end_src #+name: | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | ** results lines for function calls :PROPERTIES: :DATE: 2010-02-15 :END: #+call: fibonacci(input=5) :resname eric #+name: : 8 #+begin_src emacs-lisp :var fib=fibonacci(input=5) (message "fib(5)=%d" fib) #+end_src #+name: : fib(5)=8 ** haskell variables :PROPERTIES: :DATE: 2010-02-15 :END: playing with Haskell #+name: haskell-stuff : 9 #+begin_src haskell :var num=haskell-stuff num + 1 #+end_src #+begin_src ruby :var num=haskell-stuff num + 1 #+end_src #+name: : 10 ** list index w/function style name :PROPERTIES: :DATE: 2010-02-14 :END: #+name: function-style-index | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | #+name: function-style-indexing(data=function-style-index[1:4,0]) #+begin_src emacs-lisp (message "%S" data) #+end_src #+name: function-style-indexing : ((1) (2) (3) (4)) ** looking at source name exports :PROPERTIES: :DATE: 2010-02-09 :END: #+name: fibonacci #+begin_src emacs-lisp :var input=0 (defun fib (n) (if (> n 1) (+ (fib (- n 1)) (fib (- n 2))) 1)) (fib input) #+end_src #+name: fibonacci : 1 now applying our Fibonacci function #+call: fibonacci(input=5) ** short shell test :PROPERTIES: :DATE: 2010-02-07 :END: #+begin_src sh date #+end_src #+name: : Sun Feb 7 10:17:44 MST 2010 #+tblname: fibs | 1 | 1 | | 2 | 1 | | 3 | 2 | | 4 | 3 | | 5 | 5 | | 6 | 8 | #+begin_src sh :var table=fibs echo "$table" |wc #+end_src #+name: : 6 12 24 #+begin_src sh :var table=fibs echo "$table" #+end_src #+name: | 1 | 1 | | 2 | 1 | | 3 | 2 | | 4 | 3 | | 5 | 5 | | 6 | 8 | #+begin_src sh :var table=fibs :separator -- echo "$table" | head -1 #+end_src #+name: : 1--1 ** tables to shell scripts ideas :PROPERTIES: :DATE: 2010-02-06 :END: #+tblname: sec | Hello | World | 1) allowing the user to specify a separator with a header argument as follows #+begin_src sh :var table=sec :separator , cat <> if not then we would probably need to wrap source-code blocks in figures to make them referable. how about a link back to [[keystone]] The above appears to work in LaTeX, but not in HTML. ** fancier export :PROPERTIES: :DATE: 2010-01-05 :END: #+name: square #+begin_src emacs-lisp :var input=1 (* input input) #+end_src ** exporting org-source :PROPERTIES: :DATE: 2009-12-23 :END: #+begin_src org ,lets see how this org-mode code exports to html ,is this [[link]] blue? ,#+begin_src emacs-lisp , (+ 1 2) ,#+end_src #+end_src ** exporting and caching :PROPERTIES: :DATE: 2009-12-23 :END: #+begin_src ditaa :file data/example.png :exports none +------------------+ | ditaa example | | | | | +------------------+ #+end_src #+name: [[file:data/example.png]] ** no noweb by default :PROPERTIES: :DATE: 2009-12-18 :END: #+name: sample #+begin_src emacs-lisp (message "sample") #+end_src #+begin_src emacs-lisp :noweb no <> #+end_src #+name: : sample ** looking at double quotes :PROPERTIES: :DATE: 2009-12-18 :END: #+tblname: double-quote-test-input | test | this | 8 | 9 | #+name: double-quote-test-output #+begin_src python :var data=double-quote-test-input return data #+end_src #+name: double-quote-test-output | test | this | 8 | 9 | ** quoted session name :PROPERTIES: :DATE: 2009-12-04 :END: #+begin_src sh :session "eric" echo 'name-me' #+end_src #+name: : name-me ** eval-buffer :PROPERTIES: :DATE: 2009-12-04 :END: #+begin_src emacs-lisp (+ 1 2) #+end_src #+name: : 3 #+begin_src emacs-lisp (+ 3 4) #+end_src #+name: : 7 ** gnuplot variable expansion :PROPERTIES: :DATE: 2009-11-30 :END: #+name: simple-function #+begin_src emacs-lisp "sin(x)" #+end_src #+begin_src gnuplot :var fun=simple-function plot $fun #+end_src ** debug hints :PROPERTIES: :DATE: 2009-11-30 :END: from mailing list - edebug-defun: (in emacs-lisp mode, C-u C-M-x) will mark the function so that when it is called, the interpreter stops and you can then single-step through it with . At each point, you can press "e" and evaluate variables (actually arbitrary expressions). - Insert a strategically placed (debug) call and then call the function. If/when the debug call is executed, you are dropped into the debugger and you can then evaluate arbitrary expressions. ** sql exports to latex :PROPERTIES: :DATE: 2009-11-30 :END: example from email list *** ECM :PROPERTIES: :DATE: 2009-11-30 :END: - faire un script Bash (et =isql=) envoyant un /listing/ de stagiaires; #+name: envoi-stg #+begin_src sql DECLARE @dateFmtStyleIn int; SET @dateFmtStyleIn = 120 -- ODBC canonical DECLARE @dateFmtStyleOut int; SET @dateFmtStyleOut = 103 -- French dd/mm/yyyy DECLARE @firstDayOfThisMonth smalldatetime SET @firstDayOfThisMonth = CONVERT(smalldatetime, CAST(YEAR(GETDATE()) AS char(4)) + '-' + CAST(MONTH(GETDATE()) AS char(2)) + '-' + '01' + ' 00:00:00', @dateFmtStyleIn) DECLARE @now smalldatetime SET @now = CONVERT(smalldatetime, CAST(YEAR(GETDATE()) AS char(4)) + '-' + CAST(MONTH(GETDATE()) AS char(2)) + '-' + CAST(DAY(GETDATE()) AS char(2)) + ' ' + CAST(DATEPART(hh, GETDATE()) AS char(2)) + ':' + CAST(DATEPART(mi, GETDATE()) AS char(2)) + ':' + '00', @dateFmtStyleIn) SELECT pfiID FROM dossier #+end_src ** whitespace/newline results issues :PROPERTIES: :DATE: 2009-11-27 :END: #+begin_src sh echo output #+end_src This #+begin_src sh echo output #+end_src text here results in t#+results: : output ext here #+begin_src emacs-lisp (+ 1 1) #+end_src #+name: : 2 ** sh with sessions :PROPERTIES: :DATE: 2009-11-27 :END: #+begin_src sh :session eric cd ~/Desktop #+end_src #+begin_src sh :session eric cd ~/Desktop/clj/ ls *.clj #+end_src #+name: | "ants.clj" | "" | "concurrent.clj" | "" | "hello.clj" | "" | "spell-checker.clj" | ** testing srcname aliases :PROPERTIES: :DATE: 2009-11-20 :END: #+name: two #+begin_src emacs-lisp 2 #+end_src #+begin_src emacs-lisp :var input=two (+ input 1) #+end_src #+name[1ec6c8d3de6aaeac7b2720f1d801402e762875ea]: : 3 ** hiding results :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp (mapcar (lambda (el) (list el)) (number-sequence 0 20)) #+end_src #+name: | 0 | | 1 | | 2 | | 3 | | 4 | | 5 | | 6 | | 7 | | 8 | | 9 | | 10 | | 11 | | 12 | | 13 | | 14 | | 15 | | 16 | | 17 | | 18 | | 19 | | 20 | ** elisp references :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results silent (setq first 10) #+end_src #+name: resolve(name=nil) #+begin_src emacs-lisp :results silent (eval (intern name)) #+end_src #+begin_src python :var a=resolve(name="first") return a + 10 #+end_src ** elisp variables :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src ditaa :file (format "%d.png" 45) +-----------+ | | | | | | | | +-----------+ #+end_src #+name: [[file:45.png]] ** haskell and tables :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src haskell sumListCond :: Int -> Int -> [Int] -> Int sumListCond l n xs | foldl (+) 0 (take l xs) <= n = sumListCond (l + 1) n xs | otherwise = foldl (+) 0 (take (l - 1) xs) #+end_src #+begin_src oz #+end_src ** latex pngs :PROPERTIES: :DATE: 2009-11-20 :END: $x \mapsto y$ *** Theorem :PROPERTIES: :DATE: 2009-11-20 :END: $|consts(t)| \leq sizes(t)$ - by induction on the structure of t - base cases are $t \in [true, false, 0]$: - $|consts(t)| = |[t]| = 1 = size(t)$ - inductive size - $t \in [succ(t_1), pred(t_1), iszero(t_1)]$: - $|consts(t)| = |consts(t_1)| = |[t]| \leq size(t_1) < size(t)$ - $t = if\, t_1 \, then \, t_2 \, else t_3$ - $|consts(t)| = |consts(t_1) \cup consts(t_1) \cup consts(t_1)|$ - $\leq |consts(t_1)| + |consts(t_1)| + |consts(t_1)|$ - $\leq size(t_1) + size(t_1) + size(t_1)$ - $< size(t)$ ** indexing into gnuplot :PROPERTIES: :DATE: 2009-11-20 :END: #+tblname: squares | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | | 6 | 36 | #+begin_src gnuplot :var data=squares :results silent plot data using 1:2 with lines #+end_src #+tblname: squares-with-sum | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | | 6 | 36 | |----+----| | 21 | 91 | #+begin_src gnuplot :var data=squares-with-sum[0:-3] :results silent plot data using 1:2 with lines #+end_src ** multiple arguments :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :var first=9 :var second=10 (+ first second) #+end_src #+resname: : 19 ** indexing into results :PROPERTIES: :DATE: 2009-11-20 :END: #+name: indexable-table | eric | | michael | | schulte | | is | | my | | name | #+begin_src emacs-lisp :var data=indexable-table[2:4] data #+end_src #+name: | schulte | | is | | my | #+tblname: multidimensional-indexing | 1 | 2 | | 3 | 4 | | 5 | 6 | | 7 | 8 | | 9 | 10 | #+begin_src emacs-lisp :var data=multidimensional-indexing[0:-2] data #+end_src #+resname: | 1 | 2 | | 3 | 4 | | 5 | 6 | | 7 | 8 | ** cached results :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :cache yes (setq org-babel-default-header-args '((:session . "none") (:results . "replace") (:exports . "code")(:cache))) #+end_src #+name[937269632ae5b5eee5c93f9eb50e0bc55e34520d]: | (:session . none) | (:results . replace) | (:exports . code) | (:cache) | #+name: eric-schulte #+begin_src emacs-lisp :cache yes (+ 5 7 1) #+end_src #+name[005b04829608b3d22b61686e90309af3a9a6fe7c]: eric-schulte : 13 #+begin_src ditaa :file caching-example.png +--------------------+ | | +-----------+ | | | | | | | | | +----+ | | | | | | | +-----------+ | +----+ | | | +--------------------+ #+end_src #+name[fd11ddbfd00f6038e6e37db71ddaf43d65b0e200]: [[file:caching-example.png]] ** switches and references :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src ruby -n -r -l "(ref:%s)" :results output class Schulte def self.eric puts :imp # (ref:imp) end end Schulte.eric #+end_src #+resname[bb4cebabe38a5d3d43835acebdbe17aa3314cef6]: : imp Line no. [[(imp)]] is important! #+begin_src ruby -n -r -l "(ref:%s)" :results output class Schulte def self.eric puts :imp # (ref:imp) end end Schulte.eric # (ref:output) #+end_src #+resname: eric : imp ** unresolved noweb references :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results silent (setq org-babel-noweb-error-langs '("ruby")) #+end_src #+name: i-have-a-name #+begin_src ruby 1 + 2 #+end_src #+begin_src ruby :noweb <> + 3 #+end_src #+resname: : 6 ** clojure :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src clojure :results silent (list 8 9) #+end_src ** reference parts of tables :PROPERTIES: :DATE: 2009-11-20 :END: #+TBLNAME: squares | 1 | 1 | | 2 | 4 | | 3 | 9 | | 4 | 16 | | 5 | 25 | | 6 | 36 | | 7 | 49 | | 8 | 64 | | 9 | 81 | | 10 | 100 | | 11 | 121 | | 12 | 144 | | 13 | 169 | | 14 | 196 | | 15 | 225 | | 16 | 256 | | 17 | 289 | | 18 | 324 | #+TBLFM: $2=$1*$1 #+begin_src gnuplot :var data=squares set title "Implementing Gnuplot" plot data using 1:2 with lines #+end_src ** results switches :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src ruby :results output :results_switches -n 10.times do |n| puts "-"*n end #+end_src #+resname: #+begin_example -n - -- --- ---- ----- ------ ------- -------- --------- #+end_example #+begin_src ruby :results output 10.times do |n| puts "-"*n end #+end_src #+resname: #+begin_example - -- --- ---- ----- ------ ------- -------- --------- #+end_example ** xml and n3 :PROPERTIES: :DATE: 2009-11-20 :END: introduce org-babel to =xml= and =n3= #+begin_src emacs-lisp :results silent (add-to-list 'org-babel-interpreters "xml") (add-to-list 'org-babel-interpreters "n3") #+end_src inform org-babel-tangle of their existence and file extensions #+begin_src emacs-lisp :results silent (add-to-list 'org-babel-tangle-langs '("xml" "xml")) (add-to-list 'org-babel-tangle-langs '("n3" "n3")) #+end_src #+begin_src xml :tangle example #+end_src #+begin_src n3 :tangle example n3 stuff #+end_src ** noweb referernces :PROPERTIES: :DATE: 2009-11-20 :END: #+name: noweb-example #+begin_src ruby a = 28 #+end_src #+begin_src ruby :noweb # <> a + 4 #+end_src #+resname: : 32 ** =pp= results :PROPERTIES: :DATE: 2009-11-20 :END: *** python :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src python :results pp :session ['one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three'] #+end_src #+resname: : ['one', 'two', 'three', 'one', 'two', 'three', 'one', 'two', 'three'] *** ruby :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src ruby :results pp class Schulte attr_accessor :name, :age end eric = Schulte.new eric.name = "eric" eric.age = 27 eric #+end_src #+resname: #+begin_src ruby :results pp a = [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] a #+end_src #+resname: #+begin_example [1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3] #+end_example ** empty =output= results for emacs-lisp :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results output 8 #+end_src #+resname: ** =:table= results param :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results table 8 #+end_src #+resname: | 8 | ** code results :PROPERTIES: :DATE: 2009-11-20 :END: *** emacs lisp :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results code (mapcar (lambda (el) (lambda (item) (+ item el))) '(1 2 3 4 5)) #+end_src #+resname: #+BEGIN_SRC emacs-lisp ((lambda (item) (+ item el)) (lambda (item) (+ item el)) (lambda (item) (+ item el)) (lambda (item) (+ item el)) (lambda (item) (+ item el))) #+END_SRC #+begin_src emacs-lisp :results code (mapcar (lambda (el) (* el el)) '(1 2 3 89)) #+end_src #+resname: #+BEGIN_SRC emacs-lisp (1 4 9 7921) #+END_SRC *** ruby :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src ruby :results code [1, 2, 33, 4].map{|n| "the number #{n}"} #+end_src #+resname: #+BEGIN_SRC ruby ["the number 1", "the number 2", "the number 33", "the number 4"] #+END_SRC #+begin_src ruby :session :results code [1, 2, 33, 4].map{|n| n + 10 } #+end_src #+resname: #+BEGIN_SRC ruby [11, 12, 43, 14] #+END_SRC *** python :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src python :results code ['one', 'two', 'three'] #+end_src #+resname: #+BEGIN_SRC python ['one', 'two', 'three'] #+END_SRC #+begin_src python :results code [1, 2, 33, 4] #+end_src #+resname: #+BEGIN_SRC python [1, 2, 33, 4] #+END_SRC #+begin_src python :session :results code [1, 2, 33, 4] #+end_src #+resname: #+BEGIN_SRC python [1, 2, 33, 4] #+END_SRC ** indentation :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src python 9 #+end_src ** persistent python :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src python :session :results silent import types #+end_src #+begin_src python :session types.FunctionType #+end_src #+resname: : function *** more persistent python :PROPERTIES: :session: default :DATE: 2009-11-20 :END: #+begin_src python :results silent import types #+end_src #+begin_src python types.FunctionType #+end_src #+resname: : function ** quoted latex :PROPERTIES: :DATE: 2009-11-20 :END: The following latex isn't exported correctly #+begin_latex \begin{code} data BTree = Leaf a | Node Tree Tree \end{code} #+end_latex #+begin_src haskell data BTree = Leaf a | Node Tree Tree #+end_src ** pretty print :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp :results scalar '(1 2 3 4) #+end_src ** simple scalar :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp (+ 1 3) #+end_src #+resname: : 4 ** lua export :PROPERTIES: :DATE: 2009-11-20 :END: #+name: determine the neighbors of the segments that the bisector hits #+begin_src lua :tangle no :exports code local s1, s2 = intersecting_segs[1], intersecting_segs[2] local n1 = table_find_segment(cell.neighbors, s1) local n2 = table_find_segment(cell.neighbors, s2) #+end_src I got: #+begin_example \lstset{language=lua} \begin{lstlisting} local s1, s2 = intersecting_segs[1], intersecting_segs[2] local n1 = table_find_segment(cell.neighbors, s1) local n2 = table_find_segment(cell.neighbors, s2) \end{lstlisting} #+end_example Emacs -Q got: #+begin_example \begin{verbatim} local s1, s2 = intersecting_segs[1], intersecting_segs[2] local n1 = table_find_segment(cell.neighbors, s1) local n2 = table_find_segment(cell.neighbors, s2) \end{verbatim} #+end_example Emacs -Q + Org-babel got: #+begin_example \begin{verbatim} local s1, s2 = intersecting_segs[1], intersecting_segs[2] local n1 = table_find_segment(cell.neighbors, s1) local n2 = table_find_segment(cell.neighbors, s2) \end{verbatim} #+end_example ** simple R :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src R :session R 8 #+end_src #+resname: : 8 ** changing source name :PROPERTIES: :DATE: 2009-11-20 :END: #+name: emacs-nine #+begin_src emacs-lisp 8 #+end_src #+resname: emacs-nine : 8 #+resname: emacs-eight : 8 ** advanced table :PROPERTIES: :DATE: 2009-11-20 :END: | DATA | WHAT | WHERE | HOW MUCH | |------------------+------------+-------------+----------| | [2009-09-25 Fri] | | | 28.95 | |------------------+------------+-------------+----------| | | food | supermarket | 7.85 | | | ticket bus | | 2.3 | | | tea + ice | ice uno | 4.4 | | | ticket | | 14.4 | |------------------+------------+-------------+----------| | [2009-09-26 Sat] | | | 41 | #+begin_src emacs-lisp (let ((total 0) (responding t) purchases) (while responding (setq purchases (cons (list "" (read-from-minibuffer "What: ") (read-from-minibuffer "Where: ") (read-minibuffer "How Much: ")) purchases)) (setq responding (y-or-n-p "more? "))) (append purchases (list (list (format-time-string "%Y-%m-%d" (current-time)) "" "" (progn (mapc (lambda (purchase) (setq total (+ total (fourth purchase)))) purchases) total))))) #+end_src #+resname: | "" | "fish and chips" | "diner" | 9.78 | | "" | "food" | "subway" | 5.45 | | "2009-09-29" | "" | "" | 15.23 | ** haskell :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src haskell powerSet :: [a] -> [[a]] powerSet = foldr (\ x ps -> map (\ y -> x : y) ps ++ ps ) [[]] #+end_src #+begin_src haskell powerSet [1, 2, 3] #+end_src ** indented :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src emacs-lisp (message "I ran!!") #+end_src #+resname: : I ran!! ** dynamic table :PROPERTIES: :DATE: 2009-11-20 :END: #+TBLNAME: todays-clock #+BEGIN: clocktable :maxlevel 2 :block today :scope tree1 :link t Clock summary at [2009-09-15 Tue 08:51], for Tuesday, September 15, 2009. | L | Headline | Time | | |---+--------------+--------+------| | | *Total time* | *1:10* | | |---+--------------+--------+------| | 1 | [[file:/Users/eschulte/Desktop/test.org::top][top]] | 1:10 | 1 | | 2 | [[file:/Users/eschulte/Desktop/test.org::show%20all][show all]] | | 1:00 | | 2 | [[file:/Users/eschulte/Desktop/test.org::later][later]] | | 0:10 | #+END: clocktable #+begin_src emacs-lisp :var data=todays-clock(1,1) (message "table is %S" data) #+end_src #+resname: : table is (("L" "Headline" "Time" "") hline ("" "*Total time*" "*1:10*" "") hline (1 "[[file:/Users/eschulte/Desktop/test.org::top][top]]" "1:10" 1) (2 "[[file:/Users/eschulte/Desktop/test.org::show%20all][show all]]" "" "1:00") (2 "[[file:/Users/eschulte/Desktop/test.org::later][later]]" "" "0:10")) #+begin_src R :session R-pie-example :var times=todays-clock :results silent pie(times[2:length(times),4], labels = times[2:length(times),2]) #+end_src ** show all CLOCK: [2009-09-15 Tue 07:51]--[2009-09-15 Tue 08:51] => 1:00 :PROPERTIES: :exports: both :DATE: 2009-11-20 :END: #+begin_src ditaa :file blue.png +----------------------+ | | | | | +-----------+ | | | | | | | | | | +-----------+ | | +----------------------+ #+end_src ** later CLOCK: [2009-09-15 Tue 09:41]--[2009-09-15 Tue 09:51] => 0:10 :PROPERTIES: :DATE: 2009-11-20 :END: stuff here ** and then more :PROPERTIES: :DATE: 2009-11-20 :END: and more stuffs here ** asymptote :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src asymptote :file asymptote-test.png :exports code import graph; size(0,4cm); real f(real t) {return 1+cos(t);} path g=polargraph(f,0,2pi,operator ..)--cycle; filldraw(g,pink); xaxis("$x$",above=true); yaxis("$y$",above=true); dot("$(a,0)$",(1,0),N); dot("$(2a,0)$",(2,0),N+E); #+end_src #+resname: [[file:asymptote-test.png]] ** asymptote cosine :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src asymptote :exports code import graph; size(0,4cm); real f(real t) {return cos(t);} path g=polargraph(f,0,2pi,operator ..)--cycle; filldraw(g,pink); for(int i=0; i < 8; ++i) { real j = 0.125 + 0.125*i; real h(real t) {return j;}; path k=polargraph(h, -(acos(j)), acos(j), operator ..); draw(k,blue); } xaxis("$x$",above=true); yaxis("$y$",above=true); dot("$(pi,0)$",(1,0),N); #+end_src ** gnuplot :PROPERTIES: :DATE: 2009-11-20 :END: #+begin_src gnuplot plot cosx #+end_src #+end_src * tools Map over all scraps and export each to a separate file. Note that this relies on the fontification in the original Org-mode buffer, so before exporting expand the entire buffer, and scroll through from top to bottom so that everything will be fontified. #+begin_src emacs-lisp :results silent (defun dump-subtree-to-file () (let* ((replacements '((" " . "-") ("w/o" . "without") ("w/" . "with-") ("/" . "-") ("\"" . "") ("=" . "") ("'" . ""))) (full-title (nth 4 (org-heading-components))) (title ((lambda (title) (dolist (rep replacements) (setq title (replace-regexp-in-string (car rep) (cdr rep) title))) (downcase title)) full-title)) (date (org-entry-get (point) "DATE")) (path (expand-file-name (concat date "-" title ".html") "scraps")) buf) (unless (file-exists-p path) (call-interactively #'org-copy-subtree) (with-temp-buffer (call-interactively #'yank) (setq buf (htmlize-buffer))) (set-buffer buf) (goto-char (point-min)) (write-file path) (kill-buffer)))) (org-id-goto "96eaa17f-f1b6-4958-acb1-e271045fdfa2") (org-map-entries #'dump-subtree-to-file "+LEVEL=2") #+end_src add date properties to all subheadings using the git log #+begin_src emacs-lisp (defun set-date-from-git-log () (org-entry-put (point) "DATE" (org-babel-trim (shell-command-to-string (format "git log --date=short --summary -1 %s|grep Date|awk '{print $2}'" (git-blame-current-commit)))))) (defun do-date-tree () (org-map-entries #'set-date-from-git-log nil 'tree)) #+end_src