This page contains orgmode.leo, a Leo file that represents all of orgmode's elisp (.el) files.

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet ekr_test?>
<leo_file>
<leo_header file_format="2" tnodes="0" max_tnode_index="0" clone_windows="0"/>
<globals body_outline_ratio="0.5" body_secondary_ratio="0.5">
    <global_window_position top="50" left="50" height="500" width="700"/>
    <global_log_window_position top="0" left="0" height="0" width="0"/>
</globals>
<preferences/>
<find_panel_settings/>
<vnodes>
<v t="ekr.20100929212226.11691" a="E"><vh>orgmode in Leo</vh>
<v t="ekr.20100929212226.14079" a="E"><vh>@path C:\prog\org-7.01h\lisp</vh>
<v t="ekr.20100929212226.14080"><vh>ob</vh>
<v t="ekr.20100929212226.14081"><vh>ob-asymptote.el</vh>
<v t="ekr.20100929212226.14082"><vh>ob-asymptote declarations</vh></v>
<v t="ekr.20100929212226.14083"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14084"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14085"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14086"><vh>org-babel-asymptote-var-to-asymptote</vh></v>
<v t="ekr.20100929212226.14087"><vh>org-babel-asymptote-table-to-array</vh></v>
<v t="ekr.20100929212226.14088"><vh>org-babel-asymptote-define-type</vh></v>
</v>
<v t="ekr.20100929212226.14089"><vh>ob-C.el</vh>
<v t="ekr.20100929212226.14090"><vh>ob-C declarations</vh></v>
<v t="ekr.20100929212226.14091"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14092"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14093"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14094"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14095"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14096"><vh>org-babel-C-execute</vh></v>
<v t="ekr.20100929212226.14097"><vh>org-babel-C-expand</vh></v>
<v t="ekr.20100929212226.14098"><vh>org-babel-C-ensure-main-wrap</vh></v>
<v t="ekr.20100929212226.14099"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14100"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14101"><vh>org-babel-C-var-to-C</vh></v>
</v>
<v t="ekr.20100929212226.14102"><vh>ob-clojure.el</vh>
<v t="ekr.20100929212226.14103"><vh>ob-clojure declarations</vh></v>
<v t="ekr.20100929212226.14104"><vh>org-babel-clojure-clojure-slime-eval</vh></v>
<v t="ekr.20100929212226.14105"><vh>org-babel-clojure-slime-eval-sync</vh></v>
<v t="ekr.20100929212226.14106"><vh>org-babel-clojure-babel-clojure-cmd</vh></v>
<v t="ekr.20100929212226.14107"><vh>org-babel-clojure-table-or-string</vh></v>
<v t="ekr.20100929212226.14108"><vh>org-babel-clojure-var-to-clojure</vh></v>
<v t="ekr.20100929212226.14109"><vh>org-babel-clojure-build-full-form</vh></v>
<v t="ekr.20100929212226.14110"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14111"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14112"><vh>org-babel-clojure-session-buffer</vh></v>
<v t="ekr.20100929212226.14113"><vh>org-babel-clojure-initiate-session-by-key</vh></v>
<v t="ekr.20100929212226.14114"><vh>org-babel-clojure-initiate-session</vh></v>
<v t="ekr.20100929212226.14115"><vh>org-babel-clojure-session-connected-hook</vh></v>
<v t="ekr.20100929212226.14116"><vh>org-babel-clojure-bind-session-to-repl-buffer</vh></v>
<v t="ekr.20100929212226.14117"><vh>org-babel-clojure-repl-buffer-pred</vh></v>
<v t="ekr.20100929212226.14118"><vh>org-babel-clojure-bind-session-to-repl</vh></v>
<v t="ekr.20100929212226.14119"><vh>org-babel-clojure-evaluate-external-process</vh></v>
<v t="ekr.20100929212226.14120"><vh>org-babel-clojure-evaluate-session</vh></v>
<v t="ekr.20100929212226.14121"><vh>org-babel-clojure-evaluate</vh></v>
<v t="ekr.20100929212226.14122"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14123"><vh>org-babel-execute</vh></v>
</v>
<v t="ekr.20100929212226.14124"><vh>ob-comint.el</vh>
<v t="ekr.20100929212226.14125"><vh>ob-comint declarations</vh></v>
<v t="ekr.20100929212226.14126"><vh>org-babel-comint-buffer-livep</vh></v>
<v t="ekr.20100929212226.14127"><vh>org-babel-comint-input-command</vh></v>
<v t="ekr.20100929212226.14128"><vh>org-babel-comint-wait-for-output</vh></v>
</v>
<v t="ekr.20100929212226.14129"><vh>ob-css.el</vh>
<v t="ekr.20100929212226.14130"><vh>ob-css declarations</vh></v>
<v t="ekr.20100929212226.14131"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14132"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14133"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14134"><vh>ob-ditaa.el</vh>
<v t="ekr.20100929212226.14135"><vh>ob-ditaa declarations</vh></v>
<v t="ekr.20100929212226.14136"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14137"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14138"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14139"><vh>ob-dot.el</vh>
<v t="ekr.20100929212226.14140"><vh>ob-dot declarations</vh></v>
<v t="ekr.20100929212226.14141"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14142"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14143"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14144"><vh>ob-emacs-lisp.el</vh>
<v t="ekr.20100929212226.14145"><vh>ob-emacs-lisp declarations</vh></v>
<v t="ekr.20100929212226.14146"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14147"><vh>org-babel-execute</vh></v>
</v>
<v t="ekr.20100929212226.14148"><vh>ob-eval.el</vh>
<v t="ekr.20100929212226.14149"><vh>ob-eval declarations</vh></v>
<v t="ekr.20100929212226.14150"><vh>org-babel-eval-error-notify</vh></v>
<v t="ekr.20100929212226.14151"><vh>org-babel-eval</vh></v>
<v t="ekr.20100929212226.14152"><vh>org-babel-eval-read-file</vh></v>
<v t="ekr.20100929212226.14153"><vh>org-babel-shell-command-on-region</vh></v>
</v>
<v t="ekr.20100929212226.14154"><vh>ob-exp.el</vh>
<v t="ekr.20100929212226.14155"><vh>ob-exp declarations</vh></v>
<v t="ekr.20100929212226.14156"><vh>org-babel-exp-src-blocks</vh></v>
<v t="ekr.20100929212226.14157"><vh>org-babel-exp-inline-src-blocks</vh></v>
<v t="ekr.20100929212226.14158"><vh>org-exp-res</vh></v>
<v t="ekr.20100929212226.14159"><vh>org-babel-in-example-or-verbatim</vh></v>
<v t="ekr.20100929212226.14160"><vh>org-babel-exp-lob-one-liners</vh></v>
<v t="ekr.20100929212226.14161"><vh>org-babel-exp-do-export</vh></v>
<v t="ekr.20100929212226.14162"><vh>org-babel-exp-code</vh></v>
<v t="ekr.20100929212226.14163"><vh>org-babel-exp-results</vh></v>
</v>
<v t="ekr.20100929212226.14164"><vh>ob-gnuplot.el</vh>
<v t="ekr.20100929212226.14165"><vh>ob-gnuplot declarations</vh></v>
<v t="ekr.20100929212226.14166"><vh>org-babel-gnuplot-process-vars</vh></v>
<v t="ekr.20100929212226.14167"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14168"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14169"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14170"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14171"><vh>org-babel-gnuplot-initiate-session</vh></v>
<v t="ekr.20100929212226.14172"><vh>org-babel-gnuplot-quote-timestamp-field</vh></v>
<v t="ekr.20100929212226.14173"><vh>org-babel-gnuplot-quote-tsv-field</vh></v>
<v t="ekr.20100929212226.14174"><vh>org-babel-gnuplot-table-to-data</vh></v>
</v>
<v t="ekr.20100929212226.14175"><vh>ob-haskell.el</vh>
<v t="ekr.20100929212226.14176"><vh>ob-haskell declarations</vh></v>
<v t="ekr.20100929212226.14177"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14178"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14179"><vh>org-babel-haskell-read-string</vh></v>
<v t="ekr.20100929212226.14180"><vh>org-babel-haskell-initiate-session</vh></v>
<v t="ekr.20100929212226.14181"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14182"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14183"><vh>org-babel-haskell-table-or-string</vh></v>
<v t="ekr.20100929212226.14184"><vh>org-babel-haskell-var-to-haskell</vh></v>
<v t="ekr.20100929212226.14185"><vh>org-babel-haskell-export-to-lhs</vh></v>
</v>
<v t="ekr.20100929212226.14186"><vh>ob-keys.el</vh>
<v t="ekr.20100929212226.14187"><vh>ob-keys declarations</vh></v>
<v t="ekr.20100929212226.14188"><vh>org-babel-describe-bindings</vh></v>
</v>
<v t="ekr.20100929212226.14189"><vh>ob-latex.el</vh>
<v t="ekr.20100929212226.14190"><vh>ob-latex declarations</vh></v>
<v t="ekr.20100929212226.14191"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14192"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14193"><vh>org-babel-latex-body-to-tex-file</vh></v>
<v t="ekr.20100929212226.14194"><vh>org-babel-latex-tex-to-pdf</vh></v>
<v t="ekr.20100929212226.14195"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14196"><vh>ob-lob.el</vh>
<v t="ekr.20100929212226.14197"><vh>ob-lob declarations</vh></v>
<v t="ekr.20100929212226.14198"><vh>org-babel-lob-ingest</vh></v>
<v t="ekr.20100929212226.14199"><vh>org-babel-lob-execute-maybe</vh></v>
<v t="ekr.20100929212226.14200"><vh>org-babel-lob-get-info</vh></v>
<v t="ekr.20100929212226.14201"><vh>org-babel-lob-execute</vh></v>
</v>
<v t="ekr.20100929212226.14202"><vh>ob-matlab.el</vh>
<v t="ekr.20100929212226.14203"><vh>ob-matlab declarations</vh></v>
</v>
<v t="ekr.20100929212226.14204"><vh>ob-mscgen.el</vh>
<v t="ekr.20100929212226.14205"><vh>ob-mscgen declarations</vh></v>
<v t="ekr.20100929212226.14206"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14207"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14208"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14209"><vh>ob-ocaml.el</vh>
<v t="ekr.20100929212226.14210"><vh>ob-ocaml declarations</vh></v>
<v t="ekr.20100929212226.14211"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14212"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14213"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14214"><vh>org-babel-ocaml-elisp-to-ocaml</vh></v>
<v t="ekr.20100929212226.14215"><vh>org-babel-ocaml-parse-output</vh></v>
<v t="ekr.20100929212226.14216"><vh>org-babel-ocaml-read-list</vh></v>
<v t="ekr.20100929212226.14217"><vh>org-babel-ocaml-read-array</vh></v>
</v>
<v t="ekr.20100929212226.14218"><vh>ob-octave.el</vh>
<v t="ekr.20100929212226.14219"><vh>ob-octave declarations</vh></v>
<v t="ekr.20100929212226.14220"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14221"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14222"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14223"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14224"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14225"><vh>org-babel-octave-var-to-octave</vh></v>
<v t="ekr.20100929212226.14226"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14227"><vh>org-babel-matlab-initiate-session</vh></v>
<v t="ekr.20100929212226.14228"><vh>org-babel-octave-initiate-session</vh></v>
<v t="ekr.20100929212226.14229"><vh>org-babel-octave-evaluate</vh></v>
<v t="ekr.20100929212226.14230"><vh>org-babel-octave-evaluate-external-process</vh></v>
<v t="ekr.20100929212226.14231"><vh>org-babel-octave-evaluate-session</vh></v>
<v t="ekr.20100929212226.14232"><vh>org-babel-octave-import-elisp-from-file</vh></v>
<v t="ekr.20100929212226.14233"><vh>org-babel-octave-read-string</vh></v>
</v>
<v t="ekr.20100929212226.14234"><vh>ob-perl.el</vh>
<v t="ekr.20100929212226.14235"><vh>ob-perl declarations</vh></v>
<v t="ekr.20100929212226.14236"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14237"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14238"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14239"><vh>org-babel-perl-var-to-perl</vh></v>
<v t="ekr.20100929212226.14240"><vh>org-babel-perl-initiate-session</vh></v>
<v t="ekr.20100929212226.14241"><vh>org-babel-perl-evaluate</vh></v>
</v>
<v t="ekr.20100929212226.14242"><vh>ob-python.el</vh>
<v t="ekr.20100929212226.14243"><vh>ob-python declarations</vh></v>
<v t="ekr.20100929212226.14244"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14245"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14246"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14247"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14248"><vh>org-babel-python-var-to-python</vh></v>
<v t="ekr.20100929212226.14249"><vh>org-babel-python-table-or-string</vh></v>
<v t="ekr.20100929212226.14250"><vh>org-babel-python-session-buffer</vh></v>
<v t="ekr.20100929212226.14251"><vh>org-babel-python-initiate-session-by-key</vh></v>
<v t="ekr.20100929212226.14252"><vh>org-babel-python-initiate-session</vh></v>
<v t="ekr.20100929212226.14253"><vh>org-babel-python-evaluate</vh></v>
<v t="ekr.20100929212226.14254"><vh>org-babel-python-read-string</vh></v>
</v>
<v t="ekr.20100929212226.14255"><vh>ob-R.el</vh>
<v t="ekr.20100929212226.14256"><vh>ob-R declarations</vh></v>
<v t="ekr.20100929212226.14257"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14258"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14259"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14260"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14261"><vh>org-babel-R-quote-tsv-field</vh></v>
<v t="ekr.20100929212226.14262"><vh>org-babel-R-assign-elisp</vh></v>
<v t="ekr.20100929212226.14263"><vh>org-babel-R-initiate-session</vh></v>
<v t="ekr.20100929212226.14264"><vh>org-babel-R-construct-graphics-device-call</vh></v>
<v t="ekr.20100929212226.14265"><vh>org-babel-R-evaluate</vh></v>
<v t="ekr.20100929212226.14266"><vh>org-babel-R-process-value-result</vh></v>
</v>
<v t="ekr.20100929212226.14267"><vh>ob-ref.el</vh>
<v t="ekr.20100929212226.14268"><vh>ob-ref declarations</vh></v>
<v t="ekr.20100929212226.14269"><vh>org-babel-ref-variables</vh></v>
<v t="ekr.20100929212226.14270"><vh>org-babel-ref-parse</vh></v>
<v t="ekr.20100929212226.14271"><vh>org-babel-ref-literal</vh></v>
<v t="ekr.20100929212226.14272"><vh>org-babel-ref-resolve-reference</vh></v>
<v t="ekr.20100929212226.14273"><vh>org-babel-ref-index-list</vh></v>
<v t="ekr.20100929212226.14274"><vh>org-babel-ref-split-args</vh></v>
<v t="ekr.20100929212226.14275"><vh>org-babel-ref-at-ref-p</vh></v>
</v>
<v t="ekr.20100929212226.14276"><vh>ob-ruby.el</vh>
<v t="ekr.20100929212226.14277"><vh>ob-ruby declarations</vh></v>
<v t="ekr.20100929212226.14278"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14279"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14280"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14281"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14282"><vh>org-babel-ruby-var-to-ruby</vh></v>
<v t="ekr.20100929212226.14283"><vh>org-babel-ruby-table-or-string</vh></v>
<v t="ekr.20100929212226.14284"><vh>org-babel-ruby-initiate-session</vh></v>
<v t="ekr.20100929212226.14285"><vh>org-babel-ruby-evaluate</vh></v>
<v t="ekr.20100929212226.14286"><vh>org-babel-ruby-read-string</vh></v>
</v>
<v t="ekr.20100929212226.14287"><vh>ob-sass.el</vh>
<v t="ekr.20100929212226.14288"><vh>ob-sass declarations</vh></v>
<v t="ekr.20100929212226.14289"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14290"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14291"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14292"><vh>ob-screen.el</vh>
<v t="ekr.20100929212226.14293"><vh>ob-screen declarations</vh></v>
<v t="ekr.20100929212226.14294"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14295"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14296"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14297"><vh>org-babel-screen-session-execute-string</vh></v>
<v t="ekr.20100929212226.14298"><vh>org-babel-screen-session-socketname</vh></v>
<v t="ekr.20100929212226.14299"><vh>org-babel-screen-session-write-temp-file</vh></v>
<v t="ekr.20100929212226.14300"><vh>org-babel-screen-test</vh></v>
</v>
<v t="ekr.20100929212226.14301"><vh>ob-sh.el</vh>
<v t="ekr.20100929212226.14302"><vh>ob-sh declarations</vh></v>
<v t="ekr.20100929212226.14303"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14304"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14305"><vh>org-babel-prep-session</vh></v>
<v t="ekr.20100929212226.14306"><vh>org-babel-load-session</vh></v>
<v t="ekr.20100929212226.14307"><vh>org-babel-sh-var-to-sh</vh></v>
<v t="ekr.20100929212226.14308"><vh>org-babel-sh-table-or-results</vh></v>
<v t="ekr.20100929212226.14309"><vh>org-babel-sh-initiate-session</vh></v>
<v t="ekr.20100929212226.14310"><vh>org-babel-sh-evaluate</vh></v>
<v t="ekr.20100929212226.14311"><vh>org-babel-sh-strip-weird-long-prompt</vh></v>
</v>
<v t="ekr.20100929212226.14312"><vh>ob-sql.el</vh>
<v t="ekr.20100929212226.14313"><vh>ob-sql declarations</vh></v>
<v t="ekr.20100929212226.14314"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14315"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14316"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14317"><vh>ob-sqlite.el</vh>
<v t="ekr.20100929212226.14318"><vh>ob-sqlite declarations</vh></v>
<v t="ekr.20100929212226.14319"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14320"><vh>org-babel-execute</vh></v>
<v t="ekr.20100929212226.14321"><vh>org-babel-sqlite-expand-vars</vh></v>
<v t="ekr.20100929212226.14322"><vh>org-babel-sqlite-table-or-scalar</vh></v>
<v t="ekr.20100929212226.14323"><vh>org-babel-sqlite-offset-colnames</vh></v>
<v t="ekr.20100929212226.14324"><vh>org-babel-prep-session</vh></v>
</v>
<v t="ekr.20100929212226.14325"><vh>ob-table.el</vh>
<v t="ekr.20100929212226.14326"><vh>ob-table declarations</vh></v>
<v t="ekr.20100929212226.14327"><vh>org-babel-table-truncate-at-newline</vh></v>
</v>
<v t="ekr.20100929212226.14328"><vh>ob-tangle.el</vh>
<v t="ekr.20100929212226.14329"><vh>ob-tangle declarations</vh></v>
<v t="ekr.20100929212226.14330"><vh>org-babel-load-file</vh></v>
<v t="ekr.20100929212226.14331"><vh>org-babel-tangle-file</vh></v>
<v t="ekr.20100929212226.14332"><vh>org-babel-tangle-publish</vh></v>
<v t="ekr.20100929212226.14333"><vh>org-babel-tangle</vh></v>
<v t="ekr.20100929212226.14334"><vh>org-babel-tangle-clean</vh></v>
<v t="ekr.20100929212226.14335"><vh>org-babel-tangle-collect-blocks</vh></v>
<v t="ekr.20100929212226.14336"><vh>org-babel-spec-to-string</vh></v>
</v>
<v t="ekr.20100929212226.14337"><vh>ob.el</vh>
<v t="ekr.20100929212226.14338"><vh>ob declarations</vh></v>
<v t="ekr.20100929212226.14339"><vh>org-babel-get-src-block-info</vh></v>
<v t="ekr.20100929212226.14340"><vh>org-babel-confirm-evaluate</vh></v>
<v t="ekr.20100929212226.14341"><vh>org-babel-execute-src-block-maybe</vh></v>
<v t="ekr.20100929212226.14342"><vh>org-babel-expand-src-block-maybe</vh></v>
<v t="ekr.20100929212226.14343"><vh>org-babel-load-in-session-maybe</vh></v>
<v t="ekr.20100929212226.14344"><vh>org-babel-pop-to-session-maybe</vh></v>
<v t="ekr.20100929212226.14345"><vh>org-babel-named-src-block-regexp-for-name</vh></v>
<v t="ekr.20100929212226.14346"><vh>org-babel-execute-src-block</vh></v>
<v t="ekr.20100929212226.14347"><vh>org-babel-expand-body</vh></v>
<v t="ekr.20100929212226.14348"><vh>org-babel-expand-src-block</vh></v>
<v t="ekr.20100929212226.14349"><vh>org-babel-load-in-session</vh></v>
<v t="ekr.20100929212226.14350"><vh>org-babel-switch-to-session</vh></v>
<v t="ekr.20100929212226.14351"><vh>org-babel-open-src-block-result</vh></v>
<v t="ekr.20100929212226.14352"><vh>org-babel-execute-buffer</vh></v>
<v t="ekr.20100929212226.14353"><vh>org-babel-execute-subtree</vh></v>
<v t="ekr.20100929212226.14354"><vh>org-babel-sha1-hash</vh></v>
<v t="ekr.20100929212226.14355"><vh>org-babel-result-hash</vh></v>
<v t="ekr.20100929212226.14356"><vh>org-babel-hide-hash</vh></v>
<v t="ekr.20100929212226.14357"><vh>org-babel-hide-all-hashes</vh></v>
<v t="ekr.20100929212226.14358"><vh>org-babel-hash-at-point</vh></v>
<v t="ekr.20100929212226.14359"><vh>org-babel-result-hide-spec</vh></v>
<v t="ekr.20100929212226.14360"><vh>org-babel-result-hide-all</vh></v>
<v t="ekr.20100929212226.14361"><vh>org-babel-show-result-all</vh></v>
<v t="ekr.20100929212226.14362"><vh>org-babel-hide-result-toggle</vh></v>
<v t="ekr.20100929212226.14363"><vh>org-babel-params-from-properties</vh></v>
<v t="ekr.20100929212226.14364"><vh>org-babel-params-from-buffer</vh></v>
<v t="ekr.20100929212226.14365"><vh>org-babel-parse-src-block-match</vh></v>
<v t="ekr.20100929212226.14366"><vh>org-babel-parse-inline-src-block-match</vh></v>
<v t="ekr.20100929212226.14367"><vh>org-babel-parse-header-arguments</vh></v>
<v t="ekr.20100929212226.14368"><vh>org-babel-process-params</vh></v>
<v t="ekr.20100929212226.14369"><vh>org-babel-del-hlines</vh></v>
<v t="ekr.20100929212226.14370"><vh>org-babel-get-colnames</vh></v>
<v t="ekr.20100929212226.14371"><vh>org-babel-get-rownames</vh></v>
<v t="ekr.20100929212226.14372"><vh>org-babel-put-colnames</vh></v>
<v t="ekr.20100929212226.14373"><vh>org-babel-put-rownames</vh></v>
<v t="ekr.20100929212226.14374"><vh>org-babel-pick-name</vh></v>
<v t="ekr.20100929212226.14375"><vh>org-babel-disassemble-tables</vh></v>
<v t="ekr.20100929212226.14376"><vh>org-babel-reassemble-table</vh></v>
<v t="ekr.20100929212226.14377"><vh>org-babel-where-is-src-block-head</vh></v>
<v t="ekr.20100929212226.14378"><vh>org-babel-goto-named-src-block</vh></v>
<v t="ekr.20100929212226.14379"><vh>org-babel-find-named-block</vh></v>
<v t="ekr.20100929212226.14380"><vh>org-babel-src-block-names</vh></v>
<v t="ekr.20100929212226.14381"><vh>org-babel-goto-named-result</vh></v>
<v t="ekr.20100929212226.14382"><vh>org-babel-find-named-result</vh></v>
<v t="ekr.20100929212226.14383"><vh>org-babel-result-names</vh></v>
<v t="ekr.20100929212226.14384"><vh>org-babel-next-src-block</vh></v>
<v t="ekr.20100929212226.14385"><vh>org-babel-previous-src-block</vh></v>
<v t="ekr.20100929212226.14386"><vh>org-babel-where-is-src-block-result</vh></v>
<v t="ekr.20100929212226.14387"><vh>org-babel-read-result</vh></v>
<v t="ekr.20100929212226.14388"><vh>org-babel-read-table</vh></v>
<v t="ekr.20100929212226.14389"><vh>org-babel-read-link</vh></v>
<v t="ekr.20100929212226.14390"><vh>org-babel-insert-result</vh></v>
<v t="ekr.20100929212226.14391"><vh>org-babel-remove-result</vh></v>
<v t="ekr.20100929212226.14392"><vh>org-babel-result-end</vh></v>
<v t="ekr.20100929212226.14393"><vh>org-babel-result-to-file</vh></v>
<v t="ekr.20100929212226.14394"><vh>org-babel-examplize-region</vh></v>
<v t="ekr.20100929212226.14395"><vh>org-babel-merge-params</vh></v>
<v t="ekr.20100929212226.14396"><vh>org-babel-expand-noweb-references</vh></v>
<v t="ekr.20100929212226.14397"><vh>org-babel-clean-text-properties</vh></v>
<v t="ekr.20100929212226.14398"><vh>org-babel-strip-protective-commas</vh></v>
<v t="ekr.20100929212226.14399"><vh>org-babel-read</vh></v>
<v t="ekr.20100929212226.14400"><vh>org-babel-number-p</vh></v>
<v t="ekr.20100929212226.14401"><vh>org-babel-import-elisp-from-file</vh></v>
<v t="ekr.20100929212226.14402"><vh>org-babel-string-read</vh></v>
<v t="ekr.20100929212226.14403"><vh>org-babel-reverse-string</vh></v>
<v t="ekr.20100929212226.14404"><vh>org-babel-chomp</vh></v>
<v t="ekr.20100929212226.14405"><vh>org-babel-trim</vh></v>
<v t="ekr.20100929212226.14406"><vh>org-babel-tramp-handle-call-process-region</vh></v>
<v t="ekr.20100929212226.14407"><vh>org-babel-maybe-remote-file</vh></v>
</v>
</v>
<v t="ekr.20100929212226.14408"><vh>org</vh>
<v t="ekr.20100929212226.14409"><vh>packages</vh>
<v t="ekr.20100929212226.14410"><vh>org-bbdb.el</vh>
<v t="ekr.20100929212226.14411"><vh>org-bbdb declarations</vh></v>
<v t="ekr.20100929212226.14412"><vh>org-bbdb-store-link</vh></v>
<v t="ekr.20100929212226.14413"><vh>org-bbdb-export</vh></v>
<v t="ekr.20100929212226.14414"><vh>org-bbdb-open</vh></v>
<v t="ekr.20100929212226.14415"><vh>org-bbdb-anniv-extract-date</vh></v>
<v t="ekr.20100929212226.14416"><vh>org-bbdb-anniv-split</vh></v>
<v t="ekr.20100929212226.14417"><vh>org-bbdb-make-anniv-hash</vh></v>
<v t="ekr.20100929212226.14418"><vh>org-bbdb-updated</vh></v>
<v t="ekr.20100929212226.14419"><vh>org-bbdb-anniversaries</vh></v>
<v t="ekr.20100929212226.14420"><vh>org-bbdb-complete-link</vh></v>
<v t="ekr.20100929212226.14421"><vh>org-bbdb-anniv-export-ical</vh></v>
<v t="ekr.20100929212226.14422"><vh>org-bbdb-format-vevent</vh></v>
</v>
<v t="ekr.20100929212226.14423"><vh>org-bibtex.el</vh>
<v t="ekr.20100929212226.14424"><vh>org-bibtex declarations</vh></v>
<v t="ekr.20100929212226.14425"><vh>org-bibtex-open</vh></v>
<v t="ekr.20100929212226.14426"><vh>org-bibtex-store-link</vh></v>
<v t="ekr.20100929212226.14427"><vh>org-create-file-search-in-bibtex</vh></v>
<v t="ekr.20100929212226.14428"><vh>org-execute-file-search-in-bibtex</vh></v>
</v>
<v t="ekr.20100929212226.14429"><vh>org-capture.el</vh>
<v t="ekr.20100929212226.14430"><vh>org-capture declarations</vh></v>
<v t="ekr.20100929212226.14431"><vh>org-capture-put</vh></v>
<v t="ekr.20100929212226.14432"><vh>org-capture-get</vh></v>
<v t="ekr.20100929212226.14433"><vh>org-capture-member</vh></v>
<v t="ekr.20100929212226.14434"><vh>org-capture</vh></v>
<v t="ekr.20100929212226.14435"><vh>org-capture-get-template</vh></v>
<v t="ekr.20100929212226.14436"><vh>org-capture-finalize</vh></v>
<v t="ekr.20100929212226.14437"><vh>org-capture-refile</vh></v>
<v t="ekr.20100929212226.14438"><vh>org-capture-kill</vh></v>
<v t="ekr.20100929212226.14439"><vh>org-capture-goto-last-stored</vh></v>
<v t="ekr.20100929212226.14440"><vh>org-capture-set-target-location</vh></v>
<v t="ekr.20100929212226.14441"><vh>org-capture-target-buffer</vh></v>
<v t="ekr.20100929212226.14442"><vh>org-capture-steal-local-variables</vh></v>
<v t="ekr.20100929212226.14443"><vh>org-capture-place-template</vh></v>
<v t="ekr.20100929212226.14444"><vh>org-capture-place-entry</vh></v>
<v t="ekr.20100929212226.14445"><vh>org-capture-place-item</vh></v>
<v t="ekr.20100929212226.14446"><vh>org-capture-place-table-line</vh></v>
<v t="ekr.20100929212226.14447"><vh>org-capture-place-plain-text</vh></v>
<v t="ekr.20100929212226.14448"><vh>org-capture-mark-kill-region</vh></v>
<v t="ekr.20100929212226.14449"><vh>org-capture-position-for-last-stored</vh></v>
<v t="ekr.20100929212226.14450"><vh>org-capture-bookmark-last-stored-position</vh></v>
<v t="ekr.20100929212226.14451"><vh>org-capture-narrow</vh></v>
<v t="ekr.20100929212226.14452"><vh>org-capture-empty-lines-before</vh></v>
<v t="ekr.20100929212226.14453"><vh>org-capture-empty-lines-after</vh></v>
<v t="ekr.20100929212226.14454"><vh>org-capture-insert-template-here</vh></v>
<v t="ekr.20100929212226.14455"><vh>org-capture-set-plist</vh></v>
<v t="ekr.20100929212226.14456"><vh>org-capture-goto-target</vh></v>
<v t="ekr.20100929212226.14457"><vh>org-capture-get-indirect-buffer</vh></v>
<v t="ekr.20100929212226.14458"><vh>org-capture-select-template</vh></v>
<v t="ekr.20100929212226.14459"><vh>org-capture-fill-template</vh></v>
<v t="ekr.20100929212226.14460"><vh>org-capture-escaped-</vh></v>
<v t="ekr.20100929212226.14461"><vh>org-capture-import-remember-templates</vh></v>
</v>
<v t="ekr.20100929212226.14462"><vh>org-crypt.el</vh>
<v t="ekr.20100929212226.14463"><vh>org-crypt declarations</vh></v>
<v t="ekr.20100929212226.14464"><vh>org-crypt-key-for-heading</vh></v>
<v t="ekr.20100929212226.14465"><vh>org-encrypt-entry</vh></v>
<v t="ekr.20100929212226.14466"><vh>org-decrypt-entry</vh></v>
<v t="ekr.20100929212226.14467"><vh>org-encrypt-entries</vh></v>
<v t="ekr.20100929212226.14468"><vh>org-decrypt-entries</vh></v>
<v t="ekr.20100929212226.14469"><vh>org-crypt-use-before-save-magic</vh></v>
</v>
<v t="ekr.20100929212226.14470"><vh>org-ctags.el</vh>
<v t="ekr.20100929212226.14471"><vh>org-ctags declarations</vh></v>
<v t="ekr.20100929212226.14472"><vh>org-ctags-enable</vh></v>
<v t="ekr.20100929212226.14473"><vh>org-ctags-get-filename-for-tag</vh></v>
<v t="ekr.20100929212226.14474"><vh>org-ctags-all-tags-in-current-tags-table</vh></v>
<v t="ekr.20100929212226.14475"><vh>org-ctags-string-search-and-replace</vh></v>
<v t="ekr.20100929212226.14476"><vh>y-or-n-minibuffer</vh></v>
<v t="ekr.20100929212226.14477"><vh>org-ctags-open-file</vh></v>
<v t="ekr.20100929212226.14478"><vh>org-ctags-find-tag-at-point</vh></v>
<v t="ekr.20100929212226.14479"><vh>org-ctags-find-tag</vh></v>
<v t="ekr.20100929212226.14480"><vh>org-ctags-visit-buffer-or-file</vh></v>
<v t="ekr.20100929212226.14481"><vh>org-ctags-ask-visit-buffer-or-file</vh></v>
<v t="ekr.20100929212226.14482"><vh>org-ctags-append-topic</vh></v>
<v t="ekr.20100929212226.14483"><vh>org-ctags-ask-append-topic</vh></v>
<v t="ekr.20100929212226.14484"><vh>org-ctags-rebuild-tags-file-then-find-tag</vh></v>
<v t="ekr.20100929212226.14485"><vh>org-ctags-ask-rebuild-tags-file-then-find-tag</vh></v>
<v t="ekr.20100929212226.14486"><vh>org-ctags-fail-silently</vh></v>
<v t="ekr.20100929212226.14487"><vh>org-ctags-create-tags</vh></v>
<v t="ekr.20100929212226.14488"><vh>org-ctags-find-tag-interactive</vh></v>
</v>
</v>
<v t="ekr.20100929212226.14489"><vh>exporters</vh>
<v t="ekr.20100929212226.14490"><vh>org-docbook.el</vh>
<v t="ekr.20100929212226.14491"><vh>org-docbook declarations</vh></v>
<v t="ekr.20100929212226.14492"><vh>org-export-as-docbook-batch</vh></v>
<v t="ekr.20100929212226.14493"><vh>org-export-as-docbook-to-buffer</vh></v>
<v t="ekr.20100929212226.14494"><vh>org-replace-region-by-docbook</vh></v>
<v t="ekr.20100929212226.14495"><vh>org-export-region-as-docbook</vh></v>
<v t="ekr.20100929212226.14496"><vh>org-export-as-docbook-pdf</vh></v>
<v t="ekr.20100929212226.14497"><vh>org-export-as-docbook-pdf-and-open</vh></v>
<v t="ekr.20100929212226.14498"><vh>org-export-as-docbook</vh></v>
<v t="ekr.20100929212226.14499"><vh>org-export-docbook-open-para</vh></v>
<v t="ekr.20100929212226.14500"><vh>org-export-docbook-close-para-maybe</vh></v>
<v t="ekr.20100929212226.14501"><vh>org-export-docbook-close-li</vh></v>
<v t="ekr.20100929212226.14502"><vh>org-export-docbook-close-lists-maybe</vh></v>
<v t="ekr.20100929212226.14503"><vh>org-export-docbook-level-start</vh></v>
<v t="ekr.20100929212226.14504"><vh>org-docbook-expand</vh></v>
<v t="ekr.20100929212226.14505"><vh>org-docbook-do-expand</vh></v>
<v t="ekr.20100929212226.14506"><vh>org-export-docbook-format-desc</vh></v>
<v t="ekr.20100929212226.14507"><vh>org-export-docbook-convert-emphasize</vh></v>
<v t="ekr.20100929212226.14508"><vh>org-docbook-protect</vh></v>
<v t="ekr.20100929212226.14509"><vh>org-export-docbook-convert-special-strings</vh></v>
<v t="ekr.20100929212226.14510"><vh>org-export-docbook-get-footnotes</vh></v>
<v t="ekr.20100929212226.14511"><vh>org-export-docbook-format-image</vh></v>
<v t="ekr.20100929212226.14512"><vh>org-export-docbook-preprocess</vh></v>
<v t="ekr.20100929212226.14513"><vh>org-export-docbook-finalize-table</vh></v>
<v t="ekr.20100929212226.14514"><vh>org-export-docbook-convert-sub-super</vh></v>
<v t="ekr.20100929212226.14515"><vh>org-export-docbook-protect-tags</vh></v>
<v t="ekr.20100929212226.14516"><vh>org-export-docbook-handle-time-stamps</vh></v>
</v>
<v t="ekr.20100929212226.14517"><vh>org-icalendar.el</vh>
<v t="ekr.20100929212226.14518"><vh>org-icalendar declarations</vh></v>
<v t="ekr.20100929212226.14519"><vh>org-export-icalendar-this-file</vh></v>
<v t="ekr.20100929212226.14520"><vh>org-export-icalendar-all-agenda-files</vh></v>
<v t="ekr.20100929212226.14521"><vh>org-export-icalendar-combine-agenda-files</vh></v>
<v t="ekr.20100929212226.14522"><vh>org-export-icalendar</vh></v>
<v t="ekr.20100929212226.14523"><vh>org-print-icalendar-entries</vh></v>
<v t="ekr.20100929212226.14524"><vh>org-export-get-categories</vh></v>
<v t="ekr.20100929212226.14525"><vh>org-icalendar-cleanup-string</vh></v>
<v t="ekr.20100929212226.14526"><vh>org-icalendar-cleanup-string-rfc2455</vh></v>
<v t="ekr.20100929212226.14527"><vh>org-start-icalendar-file</vh></v>
<v t="ekr.20100929212226.14528"><vh>org-finish-icalendar-file</vh></v>
<v t="ekr.20100929212226.14529"><vh>org-ical-ts-to-string</vh></v>
</v>
<v t="ekr.20100929212226.14530"><vh>org-exp-blocks.el</vh>
<v t="ekr.20100929212226.14531"><vh>org-exp-blocks declarations</vh></v>
<v t="ekr.20100929212226.14532"><vh>org-export-blocks-set</vh></v>
<v t="ekr.20100929212226.14533"><vh>org-export-blocks-add-block</vh></v>
<v t="ekr.20100929212226.14534"><vh>org-export-blocks-html-quote</vh></v>
<v t="ekr.20100929212226.14535"><vh>org-export-blocks-latex-quote</vh></v>
<v t="ekr.20100929212226.14536"><vh>org-export-blocks-preprocess</vh></v>
<v t="ekr.20100929212226.14537"><vh>org-export-blocks-format-ditaa</vh></v>
<v t="ekr.20100929212226.14538"><vh>org-export-blocks-format-dot</vh></v>
<v t="ekr.20100929212226.14539"><vh>org-export-blocks-format-comment</vh></v>
</v>
<v t="ekr.20100929212226.14540"><vh>org-freemind.el</vh>
<v t="ekr.20100929212226.14541"><vh>org-freemind declarations</vh></v>
<v t="ekr.20100929212226.14542"><vh>org-export-as-freemind</vh></v>
<v t="ekr.20100929212226.14543"><vh>org-freemind-show</vh></v>
<v t="ekr.20100929212226.14544"><vh>org-freemind-escape-str-from-org</vh></v>
<v t="ekr.20100929212226.14545"><vh>org-freemind-unescape-str-to-org</vh></v>
<v t="ekr.20100929212226.14546"><vh>org-freemind-test-escape</vh></v>
<v t="ekr.20100929212226.14547"><vh>org-freemind-convert-links-from-org</vh></v>
<v t="ekr.20100929212226.14548"><vh>org-freemind-convert-links-to-org</vh></v>
<v t="ekr.20100929212226.14549"><vh>org-freemind-convert-text-p</vh></v>
<v t="ekr.20100929212226.14550"><vh>org-freemind-org-text-to-freemind-subnode</vh></v>
<v t="ekr.20100929212226.14551"><vh>org-freemind-write-node</vh></v>
<v t="ekr.20100929212226.14552"><vh>org-freemind-check-overwrite</vh></v>
<v t="ekr.20100929212226.14553"><vh>org-freemind-look-for-visible-child</vh></v>
<v t="ekr.20100929212226.14554"><vh>org-freemind-goto-line</vh></v>
<v t="ekr.20100929212226.14555"><vh>org-freemind-write-mm-buffer</vh></v>
<v t="ekr.20100929212226.14556"><vh>org-freemind-get-node-style</vh></v>
<v t="ekr.20100929212226.14557"><vh>org-freemind-do-apply-node-style</vh></v>
<v t="ekr.20100929212226.14558"><vh>org-freemind-from-org-mode-node</vh></v>
<v t="ekr.20100929212226.14559"><vh>org-freemind-from-org-mode</vh></v>
<v t="ekr.20100929212226.14560"><vh>org-freemind-from-org-sparse-tree</vh></v>
<v t="ekr.20100929212226.14561"><vh>org-freemind-lt-symbols</vh></v>
<v t="ekr.20100929212226.14562"><vh>org-freemind-lt-xml-attrs</vh></v>
<v t="ekr.20100929212226.14563"><vh>org-freemind-get-children</vh></v>
<v t="ekr.20100929212226.14564"><vh>org-freemind-get-richcontent-node</vh></v>
<v t="ekr.20100929212226.14565"><vh>org-freemind-get-richcontent-note</vh></v>
<v t="ekr.20100929212226.14566"><vh>org-freemind-test-get-tree-text</vh></v>
<v t="ekr.20100929212226.14567"><vh>org-freemind-get-tree-text</vh></v>
<v t="ekr.20100929212226.14568"><vh>org-freemind-get-richcontent-node-text</vh></v>
<v t="ekr.20100929212226.14569"><vh>org-freemind-get-richcontent-note-text</vh></v>
<v t="ekr.20100929212226.14570"><vh>org-freemind-get-icon-names</vh></v>
<v t="ekr.20100929212226.14571"><vh>org-freemind-node-to-org</vh></v>
<v t="ekr.20100929212226.14572"><vh>org-freemind-to-org-mode</vh></v>
</v>
<v t="ekr.20100929212226.14573"><vh>org-latex.el</vh>
<v t="ekr.20100929212226.14574"><vh>org-latex declarations</vh></v>
<v t="ekr.20100929212226.14575"><vh>org-export-as-latex-batch</vh></v>
<v t="ekr.20100929212226.14576"><vh>org-export-as-latex-to-buffer</vh></v>
<v t="ekr.20100929212226.14577"><vh>org-replace-region-by-latex</vh></v>
<v t="ekr.20100929212226.14578"><vh>org-export-region-as-latex</vh></v>
<v t="ekr.20100929212226.14579"><vh>org-export-as-latex</vh></v>
<v t="ekr.20100929212226.14580"><vh>org-export-as-pdf</vh></v>
<v t="ekr.20100929212226.14581"><vh>org-export-as-pdf-and-open</vh></v>
<v t="ekr.20100929212226.14582"><vh>org-export-latex-parse-global</vh></v>
<v t="ekr.20100929212226.14583"><vh>org-export-latex-parse-content</vh></v>
<v t="ekr.20100929212226.14584"><vh>org-export-latex-parse-subcontent</vh></v>
<v t="ekr.20100929212226.14585"><vh>org-export-latex-global</vh></v>
<v t="ekr.20100929212226.14586"><vh>org-export-latex-sub</vh></v>
<v t="ekr.20100929212226.14587"><vh>org-export-latex-subcontent</vh></v>
<v t="ekr.20100929212226.14588"><vh>org-export-latex-set-initial-vars</vh></v>
<v t="ekr.20100929212226.14589"><vh>org-export-latex-make-header</vh></v>
<v t="ekr.20100929212226.14590"><vh>org-export-latex-format-toc-default</vh></v>
<v t="ekr.20100929212226.14591"><vh>org-export-latex-first-lines</vh></v>
<v t="ekr.20100929212226.14592"><vh>org-export-latex-content</vh></v>
<v t="ekr.20100929212226.14593"><vh>org-export-latex-protect-string</vh></v>
<v t="ekr.20100929212226.14594"><vh>org-export-latex-protect-char-in-string</vh></v>
<v t="ekr.20100929212226.14595"><vh>org-export-latex-keywords-maybe</vh></v>
<v t="ekr.20100929212226.14596"><vh>org-export-latex-fontify-headline</vh></v>
<v t="ekr.20100929212226.14597"><vh>org-export-latex-time-stamps</vh></v>
<v t="ekr.20100929212226.14598"><vh>org-export-latex-quotation-marks</vh></v>
<v t="ekr.20100929212226.14599"><vh>org-export-latex-special-chars</vh></v>
<v t="ekr.20100929212226.14600"><vh>org-inside-latex-math-p</vh></v>
<v t="ekr.20100929212226.14601"><vh>org-export-latex-treat-sub-super-char</vh></v>
<v t="ekr.20100929212226.14602"><vh>org-export-latex-treat-backslash-char</vh></v>
<v t="ekr.20100929212226.14603"><vh>org-export-latex-keywords</vh></v>
<v t="ekr.20100929212226.14604"><vh>org-export-latex-fixed-width</vh></v>
<v t="ekr.20100929212226.14605"><vh>org-export-latex-tables</vh></v>
<v t="ekr.20100929212226.14606"><vh>org-export-latex-convert-table</vh></v>
<v t="ekr.20100929212226.14607"><vh>org-export-latex-fontify</vh></v>
<v t="ekr.20100929212226.14608"><vh>org-export-latex-emph-format</vh></v>
<v t="ekr.20100929212226.14609"><vh>org-export-latex-links</vh></v>
<v t="ekr.20100929212226.14610"><vh>org-export-latex-format-image</vh></v>
<v t="ekr.20100929212226.14611"><vh>org-export-latex-protect-amp</vh></v>
<v t="ekr.20100929212226.14612"><vh>org-remove-initial-hash</vh></v>
<v t="ekr.20100929212226.14613"><vh>org-export-latex-preprocess</vh></v>
<v t="ekr.20100929212226.14614"><vh>org-export-latex-fix-inputenc</vh></v>
<v t="ekr.20100929212226.14615"><vh>org-export-latex-lists</vh></v>
</v>
</v>
<v t="ekr.20100929212226.14616"><vh>org-agenda.el</vh>
<v t="ekr.20100929212226.14617"><vh>org-agenda declarations</vh></v>
<v t="ekr.20100929212226.14618"><vh>org-agenda-format-date-aligned</vh></v>
<v t="ekr.20100929212226.14619"><vh>org-add-agenda-custom-command</vh></v>
<v t="ekr.20100929212226.14620"><vh>org-agenda-mode</vh></v>
<v t="ekr.20100929212226.14621"><vh>org-agenda-undo</vh></v>
<v t="ekr.20100929212226.14622"><vh>org-verify-change-for-undo</vh></v>
<v t="ekr.20100929212226.14623"><vh>org-agenda</vh></v>
<v t="ekr.20100929212226.14624"><vh>org-agenda-normalize-custom-commands</vh></v>
<v t="ekr.20100929212226.14625"><vh>org-agenda-get-restriction-and-command</vh></v>
<v t="ekr.20100929212226.14626"><vh>org-run-agenda-series</vh></v>
<v t="ekr.20100929212226.14627"><vh>org-encode-for-stdout</vh></v>
<v t="ekr.20100929212226.14628"><vh>org-fix-agenda-info</vh></v>
<v t="ekr.20100929212226.14629"><vh>org-agenda-export-csv-mapper</vh></v>
<v t="ekr.20100929212226.14630"><vh>org-store-agenda-views</vh></v>
<v t="ekr.20100929212226.14631"><vh>org-agenda-mark-header-line</vh></v>
<v t="ekr.20100929212226.14632"><vh>org-write-agenda</vh></v>
<v t="ekr.20100929212226.14633"><vh>org-agenda-mark-filtered-text</vh></v>
<v t="ekr.20100929212226.14634"><vh>org-agenda-unmark-filtered-text</vh></v>
<v t="ekr.20100929212226.14635"><vh>org-agenda-remove-marked-text</vh></v>
<v t="ekr.20100929212226.14636"><vh>org-agenda-add-entry-text</vh></v>
<v t="ekr.20100929212226.14637"><vh>org-agenda-get-some-entry-text</vh></v>
<v t="ekr.20100929212226.14638"><vh>org-agenda-collect-markers</vh></v>
<v t="ekr.20100929212226.14639"><vh>org-create-marker-find-array</vh></v>
<v t="ekr.20100929212226.14640"><vh>org-check-agenda-marker-table</vh></v>
<v t="ekr.20100929212226.14641"><vh>org-check-for-org-mode</vh></v>
<v t="ekr.20100929212226.14642"><vh>org-fit-agenda-window</vh></v>
<v t="ekr.20100929212226.14643"><vh>org-prepare-agenda</vh></v>
<v t="ekr.20100929212226.14644"><vh>org-finalize-agenda</vh></v>
<v t="ekr.20100929212226.14645"><vh>org-agenda-mark-clocking-task</vh></v>
<v t="ekr.20100929212226.14646"><vh>org-agenda-fontify-priorities</vh></v>
<v t="ekr.20100929212226.14647"><vh>org-agenda-dim-blocked-tasks</vh></v>
<v t="ekr.20100929212226.14648"><vh>org-agenda-skip</vh></v>
<v t="ekr.20100929212226.14649"><vh>org-agenda-new-marker</vh></v>
<v t="ekr.20100929212226.14650"><vh>org-agenda-reset-markers</vh></v>
<v t="ekr.20100929212226.14651"><vh>org-agenda-save-markers-for-cut-and-paste</vh></v>
<v t="ekr.20100929212226.14652"><vh>org-agenda-entry-text-show-here</vh></v>
<v t="ekr.20100929212226.14653"><vh>org-agenda-entry-text-show</vh></v>
<v t="ekr.20100929212226.14654"><vh>org-agenda-entry-text-hide</vh></v>
<v t="ekr.20100929212226.14655"><vh>org-timeline</vh></v>
<v t="ekr.20100929212226.14656"><vh>org-get-all-dates</vh></v>
<v t="ekr.20100929212226.14657"><vh>org-agenda-list</vh></v>
<v t="ekr.20100929212226.14658"><vh>org-agenda-ndays-to-span</vh></v>
<v t="ekr.20100929212226.14659"><vh>org-search-syntax-table</vh></v>
<v t="ekr.20100929212226.14660"><vh>org-search-view</vh></v>
<v t="ekr.20100929212226.14661"><vh>org-todo-list</vh></v>
<v t="ekr.20100929212226.14662"><vh>org-tags-view</vh></v>
<v t="ekr.20100929212226.14663"><vh>org-agenda-skip-entry-when-regexp-matches</vh></v>
<v t="ekr.20100929212226.14664"><vh>org-agenda-skip-subtree-when-regexp-matches</vh></v>
<v t="ekr.20100929212226.14665"><vh>org-agenda-skip-entry-when-regexp-matches-in-subtree</vh></v>
<v t="ekr.20100929212226.14666"><vh>org-agenda-skip-entry-if</vh></v>
<v t="ekr.20100929212226.14667"><vh>org-agenda-skip-subtree-if</vh></v>
<v t="ekr.20100929212226.14668"><vh>org-agenda-skip-if</vh></v>
<v t="ekr.20100929212226.14669"><vh>org-agenda-skip-if-todo</vh></v>
<v t="ekr.20100929212226.14670"><vh>org-agenda-list-stuck-projects</vh></v>
<v t="ekr.20100929212226.14671"><vh>org-get-entries-from-diary</vh></v>
<v t="ekr.20100929212226.14672"><vh>org-agenda-cleanup-fancy-diary</vh></v>
<v t="ekr.20100929212226.14673"><vh>org-modify-diary-entry-string</vh></v>
<v t="ekr.20100929212226.14674"><vh>org-diary-default-entry</vh></v>
<v t="ekr.20100929212226.14675"><vh>org-add-to-diary-list</vh></v>
<v t="ekr.20100929212226.14676"><vh>org-diary</vh></v>
<v t="ekr.20100929212226.14677"><vh>org-agenda-get-day-entries</vh></v>
<v t="ekr.20100929212226.14678"><vh>org-agenda-get-todos</vh></v>
<v t="ekr.20100929212226.14679"><vh>org-agenda-check-for-timestamp-as-reason-to-ignore-todo-item</vh></v>
<v t="ekr.20100929212226.14680"><vh>org-agenda-get-timestamps</vh></v>
<v t="ekr.20100929212226.14681"><vh>org-agenda-get-sexps</vh></v>
<v t="ekr.20100929212226.14682"><vh>org-diary-class</vh></v>
<v t="ekr.20100929212226.14683"><vh>org-agenda-get-progress</vh></v>
<v t="ekr.20100929212226.14684"><vh>org-agenda-get-deadlines</vh></v>
<v t="ekr.20100929212226.14685"><vh>org-agenda-deadline-face</vh></v>
<v t="ekr.20100929212226.14686"><vh>org-agenda-get-scheduled</vh></v>
<v t="ekr.20100929212226.14687"><vh>org-agenda-get-blocks</vh></v>
<v t="ekr.20100929212226.14688"><vh>org-format-agenda-item</vh></v>
<v t="ekr.20100929212226.14689"><vh>org-agenda-fix-displayed-tags</vh></v>
<v t="ekr.20100929212226.14690"><vh>org-downcase-keep-props</vh></v>
<v t="ekr.20100929212226.14691"><vh>org-agenda-add-time-grid-maybe</vh></v>
<v t="ekr.20100929212226.14692"><vh>org-compile-prefix-format</vh></v>
<v t="ekr.20100929212226.14693"><vh>org-set-sorting-strategy</vh></v>
<v t="ekr.20100929212226.14694"><vh>org-get-time-of-day</vh></v>
<v t="ekr.20100929212226.14695"><vh>org-finalize-agenda-entries</vh></v>
<v t="ekr.20100929212226.14696"><vh>org-agenda-highlight-todo</vh></v>
<v t="ekr.20100929212226.14697"><vh>org-entries-lessp</vh></v>
<v t="ekr.20100929212226.14698"><vh>org-agenda-set-restriction-lock</vh></v>
<v t="ekr.20100929212226.14699"><vh>org-agenda-remove-restriction-lock</vh></v>
<v t="ekr.20100929212226.14700"><vh>org-agenda-maybe-redo</vh></v>
<v t="ekr.20100929212226.14701"><vh>org-agenda-check-type</vh></v>
<v t="ekr.20100929212226.14702"><vh>org-agenda-quit</vh></v>
<v t="ekr.20100929212226.14703"><vh>org-agenda-exit</vh></v>
<v t="ekr.20100929212226.14704"><vh>org-agenda-execute</vh></v>
<v t="ekr.20100929212226.14705"><vh>org-agenda-redo</vh></v>
<v t="ekr.20100929212226.14706"><vh>org-agenda-filter-by-tag</vh></v>
<v t="ekr.20100929212226.14707"><vh>org-agenda-get-represented-tags</vh></v>
<v t="ekr.20100929212226.14708"><vh>org-agenda-filter-by-tag-refine</vh></v>
<v t="ekr.20100929212226.14709"><vh>org-agenda-filter-make-matcher</vh></v>
<v t="ekr.20100929212226.14710"><vh>org-agenda-filter-effort-form</vh></v>
<v t="ekr.20100929212226.14711"><vh>org-agenda-compare-effort</vh></v>
<v t="ekr.20100929212226.14712"><vh>org-agenda-filter-apply</vh></v>
<v t="ekr.20100929212226.14713"><vh>org-agenda-filter-by-tag-hide-line</vh></v>
<v t="ekr.20100929212226.14714"><vh>org-agenda-fix-tags-filter-overlays-at</vh></v>
<v t="ekr.20100929212226.14715"><vh>org-agenda-filter-by-tag-show-all</vh></v>
<v t="ekr.20100929212226.14716"><vh>org-agenda-manipulate-query-add</vh></v>
<v t="ekr.20100929212226.14717"><vh>org-agenda-manipulate-query-subtract</vh></v>
<v t="ekr.20100929212226.14718"><vh>org-agenda-manipulate-query-add-re</vh></v>
<v t="ekr.20100929212226.14719"><vh>org-agenda-manipulate-query-subtract-re</vh></v>
<v t="ekr.20100929212226.14720"><vh>org-agenda-manipulate-query</vh></v>
<v t="ekr.20100929212226.14721"><vh>org-add-to-string</vh></v>
<v t="ekr.20100929212226.14722"><vh>org-agenda-goto-date</vh></v>
<v t="ekr.20100929212226.14723"><vh>org-agenda-goto-today</vh></v>
<v t="ekr.20100929212226.14724"><vh>org-agenda-find-same-or-today-or-agenda</vh></v>
<v t="ekr.20100929212226.14725"><vh>org-agenda-later</vh></v>
<v t="ekr.20100929212226.14726"><vh>org-agenda-earlier</vh></v>
<v t="ekr.20100929212226.14727"><vh>org-agenda-view-mode-dispatch</vh></v>
<v t="ekr.20100929212226.14728"><vh>org-agenda-day-view</vh></v>
<v t="ekr.20100929212226.14729"><vh>org-agenda-week-view</vh></v>
<v t="ekr.20100929212226.14730"><vh>org-agenda-month-view</vh></v>
<v t="ekr.20100929212226.14731"><vh>org-agenda-year-view</vh></v>
<v t="ekr.20100929212226.14732"><vh>org-agenda-change-time-span</vh></v>
<v t="ekr.20100929212226.14733"><vh>org-agenda-compute-time-span</vh></v>
<v t="ekr.20100929212226.14734"><vh>org-agenda-next-date-line</vh></v>
<v t="ekr.20100929212226.14735"><vh>org-agenda-previous-date-line</vh></v>
<v t="ekr.20100929212226.14736"><vh>org-highlight</vh></v>
<v t="ekr.20100929212226.14737"><vh>org-unhighlight</vh></v>
<v t="ekr.20100929212226.14738"><vh>org-highlight-until-next-command</vh></v>
<v t="ekr.20100929212226.14739"><vh>org-unhighlight-once</vh></v>
<v t="ekr.20100929212226.14740"><vh>org-agenda-follow-mode</vh></v>
<v t="ekr.20100929212226.14741"><vh>org-agenda-entry-text-mode</vh></v>
<v t="ekr.20100929212226.14742"><vh>org-agenda-clockreport-mode</vh></v>
<v t="ekr.20100929212226.14743"><vh>org-agenda-log-mode</vh></v>
<v t="ekr.20100929212226.14744"><vh>org-agenda-archives-mode</vh></v>
<v t="ekr.20100929212226.14745"><vh>org-agenda-toggle-diary</vh></v>
<v t="ekr.20100929212226.14746"><vh>org-agenda-toggle-deadlines</vh></v>
<v t="ekr.20100929212226.14747"><vh>org-agenda-toggle-time-grid</vh></v>
<v t="ekr.20100929212226.14748"><vh>org-agenda-set-mode-name</vh></v>
<v t="ekr.20100929212226.14749"><vh>org-agenda-post-command-hook</vh></v>
<v t="ekr.20100929212226.14750"><vh>org-agenda-next-line</vh></v>
<v t="ekr.20100929212226.14751"><vh>org-agenda-previous-line</vh></v>
<v t="ekr.20100929212226.14752"><vh>org-agenda-do-context-action</vh></v>
<v t="ekr.20100929212226.14753"><vh>org-agenda-show-priority</vh></v>
<v t="ekr.20100929212226.14754"><vh>org-agenda-show-tags</vh></v>
<v t="ekr.20100929212226.14755"><vh>org-agenda-goto</vh></v>
<v t="ekr.20100929212226.14756"><vh>org-agenda-kill</vh></v>
<v t="ekr.20100929212226.14757"><vh>org-agenda-archive-default</vh></v>
<v t="ekr.20100929212226.14758"><vh>org-agenda-archive-default-with-confirmation</vh></v>
<v t="ekr.20100929212226.14759"><vh>org-agenda-archive</vh></v>
<v t="ekr.20100929212226.14760"><vh>org-agenda-archive-to-archive-sibling</vh></v>
<v t="ekr.20100929212226.14761"><vh>org-agenda-archive-with</vh></v>
<v t="ekr.20100929212226.14762"><vh>org-remove-subtree-entries-from-agenda</vh></v>
<v t="ekr.20100929212226.14763"><vh>org-agenda-refile</vh></v>
<v t="ekr.20100929212226.14764"><vh>org-agenda-open-link</vh></v>
<v t="ekr.20100929212226.14765"><vh>org-agenda-copy-local-variable</vh></v>
<v t="ekr.20100929212226.14766"><vh>org-agenda-goto-mouse</vh></v>
<v t="ekr.20100929212226.14767"><vh>org-agenda-show</vh></v>
<v t="ekr.20100929212226.14768"><vh>org-agenda-show-and-scroll-up</vh></v>
<v t="ekr.20100929212226.14769"><vh>org-agenda-show-scroll-down</vh></v>
<v t="ekr.20100929212226.14770"><vh>org-agenda-show-1</vh></v>
<v t="ekr.20100929212226.14771"><vh>org-recenter-heading</vh></v>
<v t="ekr.20100929212226.14772"><vh>org-agenda-cycle-show</vh></v>
<v t="ekr.20100929212226.14773"><vh>org-agenda-recenter</vh></v>
<v t="ekr.20100929212226.14774"><vh>org-agenda-show-mouse</vh></v>
<v t="ekr.20100929212226.14775"><vh>org-agenda-check-no-diary</vh></v>
<v t="ekr.20100929212226.14776"><vh>org-agenda-error</vh></v>
<v t="ekr.20100929212226.14777"><vh>org-agenda-tree-to-indirect-buffer</vh></v>
<v t="ekr.20100929212226.14778"><vh>org-agenda-todo-nextset</vh></v>
<v t="ekr.20100929212226.14779"><vh>org-agenda-todo-previousset</vh></v>
<v t="ekr.20100929212226.14780"><vh>org-agenda-todo</vh></v>
<v t="ekr.20100929212226.14781"><vh>org-agenda-add-note</vh></v>
<v t="ekr.20100929212226.14782"><vh>org-agenda-change-all-lines</vh></v>
<v t="ekr.20100929212226.14783"><vh>org-agenda-align-tags</vh></v>
<v t="ekr.20100929212226.14784"><vh>org-agenda-priority-up</vh></v>
<v t="ekr.20100929212226.14785"><vh>org-agenda-priority-down</vh></v>
<v t="ekr.20100929212226.14786"><vh>org-agenda-priority</vh></v>
<v t="ekr.20100929212226.14787"><vh>org-agenda-set-tags</vh></v>
<v t="ekr.20100929212226.14788"><vh>org-agenda-set-property</vh></v>
<v t="ekr.20100929212226.14789"><vh>org-agenda-set-effort</vh></v>
<v t="ekr.20100929212226.14790"><vh>org-agenda-toggle-archive-tag</vh></v>
<v t="ekr.20100929212226.14791"><vh>org-agenda-do-date-later</vh></v>
<v t="ekr.20100929212226.14792"><vh>org-agenda-do-date-earlier</vh></v>
<v t="ekr.20100929212226.14793"><vh>org-agenda-date-later</vh></v>
<v t="ekr.20100929212226.14794"><vh>org-agenda-date-earlier</vh></v>
<v t="ekr.20100929212226.14795"><vh>org-agenda-date-later-minutes</vh></v>
<v t="ekr.20100929212226.14796"><vh>org-agenda-date-earlier-minutes</vh></v>
<v t="ekr.20100929212226.14797"><vh>org-agenda-date-later-hours</vh></v>
<v t="ekr.20100929212226.14798"><vh>org-agenda-date-earlier-hours</vh></v>
<v t="ekr.20100929212226.14799"><vh>org-agenda-show-new-time</vh></v>
<v t="ekr.20100929212226.14800"><vh>org-agenda-date-prompt</vh></v>
<v t="ekr.20100929212226.14801"><vh>org-agenda-schedule</vh></v>
<v t="ekr.20100929212226.14802"><vh>org-agenda-deadline</vh></v>
<v t="ekr.20100929212226.14803"><vh>org-agenda-action</vh></v>
<v t="ekr.20100929212226.14804"><vh>org-agenda-do-action</vh></v>
<v t="ekr.20100929212226.14805"><vh>org-agenda-clock-in</vh></v>
<v t="ekr.20100929212226.14806"><vh>org-agenda-clock-out</vh></v>
<v t="ekr.20100929212226.14807"><vh>org-agenda-clock-cancel</vh></v>
<v t="ekr.20100929212226.14808"><vh>org-agenda-diary-entry-in-org-file</vh></v>
<v t="ekr.20100929212226.14809"><vh>org-agenda-add-entry-to-org-agenda-diary-file</vh></v>
<v t="ekr.20100929212226.14810"><vh>org-agenda-insert-diary-as-top-level</vh></v>
<v t="ekr.20100929212226.14811"><vh>org-agenda-insert-diary-make-new-entry</vh></v>
<v t="ekr.20100929212226.14812"><vh>org-agenda-diary-entry</vh></v>
<v t="ekr.20100929212226.14813"><vh>org-agenda-execute-calendar-command</vh></v>
<v t="ekr.20100929212226.14814"><vh>org-agenda-phases-of-moon</vh></v>
<v t="ekr.20100929212226.14815"><vh>org-agenda-holidays</vh></v>
<v t="ekr.20100929212226.14816"><vh>org-agenda-sunrise-sunset</vh></v>
<v t="ekr.20100929212226.14817"><vh>org-agenda-goto-calendar</vh></v>
<v t="ekr.20100929212226.14818"><vh>org-calendar-goto-agenda</vh></v>
<v t="ekr.20100929212226.14819"><vh>org-agenda-convert-date</vh></v>
<v t="ekr.20100929212226.14820"><vh>org-agenda-bulk-marked-p</vh></v>
<v t="ekr.20100929212226.14821"><vh>org-agenda-bulk-mark</vh></v>
<v t="ekr.20100929212226.14822"><vh>org-agenda-bulk-unmark</vh></v>
<v t="ekr.20100929212226.14823"><vh>org-agenda-bulk-toggle</vh></v>
<v t="ekr.20100929212226.14824"><vh>org-agenda-bulk-remove-overlays</vh></v>
<v t="ekr.20100929212226.14825"><vh>org-agenda-bulk-remove-all-marks</vh></v>
<v t="ekr.20100929212226.14826"><vh>org-agenda-bulk-action</vh></v>
<v t="ekr.20100929212226.14827"><vh>org-agenda-show-the-flagging-note</vh></v>
<v t="ekr.20100929212226.14828"><vh>org-agenda-remove-flag</vh></v>
<v t="ekr.20100929212226.14829"><vh>org-agenda-get-any-marker</vh></v>
<v t="ekr.20100929212226.14830"><vh>org-agenda-to-appt</vh></v>
<v t="ekr.20100929212226.14831"><vh>org-agenda-todayp</vh></v>
</v>
<v t="ekr.20100929212226.14832"><vh>org-archive.el</vh>
<v t="ekr.20100929212226.14833"><vh>org-archive declarations</vh></v>
<v t="ekr.20100929212226.14834"><vh>org-get-local-archive-location</vh></v>
<v t="ekr.20100929212226.14835"><vh>org-add-archive-files</vh></v>
<v t="ekr.20100929212226.14836"><vh>org-all-archive-files</vh></v>
<v t="ekr.20100929212226.14837"><vh>org-extract-archive-file</vh></v>
<v t="ekr.20100929212226.14838"><vh>org-extract-archive-heading</vh></v>
<v t="ekr.20100929212226.14839"><vh>org-archive-subtree</vh></v>
<v t="ekr.20100929212226.14840"><vh>org-archive-to-archive-sibling</vh></v>
<v t="ekr.20100929212226.14841"><vh>org-archive-all-done</vh></v>
<v t="ekr.20100929212226.14842"><vh>org-toggle-archive-tag</vh></v>
<v t="ekr.20100929212226.14843"><vh>org-archive-set-tag</vh></v>
<v t="ekr.20100929212226.14844"><vh>org-archive-subtree-default</vh></v>
<v t="ekr.20100929212226.14845"><vh>org-archive-subtree-default-with-confirmation</vh></v>
</v>
<v t="ekr.20100929212226.14846"><vh>org-ascii.el</vh>
<v t="ekr.20100929212226.14847"><vh>org-ascii declarations</vh></v>
<v t="ekr.20100929212226.14848"><vh>org-export-as-latin1</vh></v>
<v t="ekr.20100929212226.14849"><vh>org-export-as-latin1-to-buffer</vh></v>
<v t="ekr.20100929212226.14850"><vh>org-export-as-utf8</vh></v>
<v t="ekr.20100929212226.14851"><vh>org-export-as-utf8-to-buffer</vh></v>
<v t="ekr.20100929212226.14852"><vh>org-export-as-encoding</vh></v>
<v t="ekr.20100929212226.14853"><vh>org-export-as-ascii-to-buffer</vh></v>
<v t="ekr.20100929212226.14854"><vh>org-replace-region-by-ascii</vh></v>
<v t="ekr.20100929212226.14855"><vh>org-export-region-as-ascii</vh></v>
<v t="ekr.20100929212226.14856"><vh>org-export-as-ascii</vh></v>
<v t="ekr.20100929212226.14857"><vh>org-export-ascii-preprocess</vh></v>
<v t="ekr.20100929212226.14858"><vh>org-html-expand-for-ascii</vh></v>
<v t="ekr.20100929212226.14859"><vh>org-ascii-replace-entities</vh></v>
<v t="ekr.20100929212226.14860"><vh>org-export-ascii-wrap</vh></v>
<v t="ekr.20100929212226.14861"><vh>org-export-ascii-push-links</vh></v>
<v t="ekr.20100929212226.14862"><vh>org-ascii-level-start</vh></v>
<v t="ekr.20100929212226.14863"><vh>org-insert-centered</vh></v>
<v t="ekr.20100929212226.14864"><vh>org-format-table-ascii</vh></v>
<v t="ekr.20100929212226.14865"><vh>org-colgroup-info-to-vline-list</vh></v>
</v>
<v t="ekr.20100929212226.14866"><vh>org-attach.el</vh>
<v t="ekr.20100929212226.14867"><vh>org-attach declarations</vh></v>
<v t="ekr.20100929212226.14868"><vh>org-attach</vh></v>
<v t="ekr.20100929212226.14869"><vh>org-attach-dir</vh></v>
<v t="ekr.20100929212226.14870"><vh>org-attach-check-absolute-path</vh></v>
<v t="ekr.20100929212226.14871"><vh>org-attach-set-directory</vh></v>
<v t="ekr.20100929212226.14872"><vh>org-attach-set-inherit</vh></v>
<v t="ekr.20100929212226.14873"><vh>org-attach-commit</vh></v>
<v t="ekr.20100929212226.14874"><vh>org-attach-tag</vh></v>
<v t="ekr.20100929212226.14875"><vh>org-attach-untag</vh></v>
<v t="ekr.20100929212226.14876"><vh>org-attach-attach</vh></v>
<v t="ekr.20100929212226.14877"><vh>org-attach-attach-cp</vh></v>
<v t="ekr.20100929212226.14878"><vh>org-attach-attach-mv</vh></v>
<v t="ekr.20100929212226.14879"><vh>org-attach-attach-ln</vh></v>
<v t="ekr.20100929212226.14880"><vh>org-attach-new</vh></v>
<v t="ekr.20100929212226.14881"><vh>org-attach-delete-one</vh></v>
<v t="ekr.20100929212226.14882"><vh>org-attach-delete-all</vh></v>
<v t="ekr.20100929212226.14883"><vh>org-attach-sync</vh></v>
<v t="ekr.20100929212226.14884"><vh>org-attach-file-list</vh></v>
<v t="ekr.20100929212226.14885"><vh>org-attach-reveal</vh></v>
<v t="ekr.20100929212226.14886"><vh>org-attach-reveal-in-emacs</vh></v>
<v t="ekr.20100929212226.14887"><vh>org-attach-open</vh></v>
<v t="ekr.20100929212226.14888"><vh>org-attach-open-in-emacs</vh></v>
<v t="ekr.20100929212226.14889"><vh>org-attach-expand</vh></v>
<v t="ekr.20100929212226.14890"><vh>org-attach-expand-link</vh></v>
</v>
<v t="ekr.20100929212226.14891"><vh>org-beamer.el</vh>
<v t="ekr.20100929212226.14892"><vh>org-beamer declarations</vh></v>
<v t="ekr.20100929212226.14893"><vh>org-beamer-cleanup-column-width</vh></v>
<v t="ekr.20100929212226.14894"><vh>org-beamer-open-column</vh></v>
<v t="ekr.20100929212226.14895"><vh>org-beamer-close-column-maybe</vh></v>
<v t="ekr.20100929212226.14896"><vh>org-beamer-open-columns-maybe</vh></v>
<v t="ekr.20100929212226.14897"><vh>org-beamer-close-columns-maybe</vh></v>
<v t="ekr.20100929212226.14898"><vh>org-beamer-select-environment</vh></v>
<v t="ekr.20100929212226.14899"><vh>org-beamer-sectioning</vh></v>
<v t="ekr.20100929212226.14900"><vh>org-beamer-get-special</vh></v>
<v t="ekr.20100929212226.14901"><vh>org-beamer-assoc-not-empty</vh></v>
<v t="ekr.20100929212226.14902"><vh>org-beamer-place-default-actions-for-lists</vh></v>
<v t="ekr.20100929212226.14903"><vh>org-beamer-amend-header</vh></v>
<v t="ekr.20100929212226.14904"><vh>org-beamer-initialize-open-trackers</vh></v>
<v t="ekr.20100929212226.14905"><vh>org-beamer-after-initial-vars</vh></v>
<v t="ekr.20100929212226.14906"><vh>org-beamer-auto-fragile-frames</vh></v>
<v t="ekr.20100929212226.14907"><vh>org-beamer-fix-toc</vh></v>
<v t="ekr.20100929212226.14908"><vh>org-beamer-property-changed</vh></v>
<v t="ekr.20100929212226.14909"><vh>org-beamer-select-beamer-code</vh></v>
<v t="ekr.20100929212226.14910"><vh>org-insert-beamer-options-template</vh></v>
<v t="ekr.20100929212226.14911"><vh>org-beamer-allowed-property-values</vh></v>
</v>
<v t="ekr.20100929212226.14912"><vh>org-clock.el</vh>
<v t="ekr.20100929212226.14913"><vh>org-clock declarations</vh></v>
<v t="ekr.20100929212226.14914"><vh>org-clock-menu</vh></v>
<v t="ekr.20100929212226.14915"><vh>org-clock-history-push</vh></v>
<v t="ekr.20100929212226.14916"><vh>org-clock-save-markers-for-cut-and-paste</vh></v>
<v t="ekr.20100929212226.14917"><vh>org-clocking-buffer</vh></v>
<v t="ekr.20100929212226.14918"><vh>org-clocking-p</vh></v>
<v t="ekr.20100929212226.14919"><vh>org-clock-select-task</vh></v>
<v t="ekr.20100929212226.14920"><vh>org-clock-insert-selection-line</vh></v>
<v t="ekr.20100929212226.14921"><vh>org-clock-get-clock-string</vh></v>
<v t="ekr.20100929212226.14922"><vh>org-clock-update-mode-line</vh></v>
<v t="ekr.20100929212226.14923"><vh>org-clock-get-clocked-time</vh></v>
<v t="ekr.20100929212226.14924"><vh>org-clock-modify-effort-estimate</vh></v>
<v t="ekr.20100929212226.14925"><vh>org-clock-notify-once-if-expired</vh></v>
<v t="ekr.20100929212226.14926"><vh>org-notify</vh></v>
<v t="ekr.20100929212226.14927"><vh>org-show-notification</vh></v>
<v t="ekr.20100929212226.14928"><vh>org-clock-play-sound</vh></v>
<v t="ekr.20100929212226.14929"><vh>org-program-exists</vh></v>
<v t="ekr.20100929212226.14930"><vh>org-find-open-clocks</vh></v>
<v t="ekr.20100929212226.14931"><vh>org-clock-resolve-clock</vh></v>
<v t="ekr.20100929212226.14932"><vh>org-clock-jump-to-current-clock</vh></v>
<v t="ekr.20100929212226.14933"><vh>org-clock-resolve</vh></v>
<v t="ekr.20100929212226.14934"><vh>org-resolve-clocks</vh></v>
<v t="ekr.20100929212226.14935"><vh>org-emacs-idle-seconds</vh></v>
<v t="ekr.20100929212226.14936"><vh>org-mac-idle-seconds</vh></v>
<v t="ekr.20100929212226.14937"><vh>org-x11-idle-seconds</vh></v>
<v t="ekr.20100929212226.14938"><vh>org-user-idle-seconds</vh></v>
<v t="ekr.20100929212226.14939"><vh>org-resolve-clocks-if-idle</vh></v>
<v t="ekr.20100929212226.14940"><vh>org-clock-in</vh></v>
<v t="ekr.20100929212226.14941"><vh>org-clock-set-current</vh></v>
<v t="ekr.20100929212226.14942"><vh>org-clock-delete-current</vh></v>
<v t="ekr.20100929212226.14943"><vh>org-clock-mark-default-task</vh></v>
<v t="ekr.20100929212226.14944"><vh>org-clock-get-sum-start</vh></v>
<v t="ekr.20100929212226.14945"><vh>org-clock-find-position</vh></v>
<v t="ekr.20100929212226.14946"><vh>org-clock-out</vh></v>
<v t="ekr.20100929212226.14947"><vh>org-clock-cancel</vh></v>
<v t="ekr.20100929212226.14948"><vh>org-clock-goto</vh></v>
<v t="ekr.20100929212226.14949"><vh>org-clock-sum</vh></v>
<v t="ekr.20100929212226.14950"><vh>org-clock-sum-current-item</vh></v>
<v t="ekr.20100929212226.14951"><vh>org-clock-display</vh></v>
<v t="ekr.20100929212226.14952"><vh>org-clock-put-overlay</vh></v>
<v t="ekr.20100929212226.14953"><vh>org-clock-remove-overlays</vh></v>
<v t="ekr.20100929212226.14954"><vh>org-clock-out-if-current</vh></v>
<v t="ekr.20100929212226.14955"><vh>org-get-clocktable</vh></v>
<v t="ekr.20100929212226.14956"><vh>org-clock-report</vh></v>
<v t="ekr.20100929212226.14957"><vh>org-in-clocktable-p</vh></v>
<v t="ekr.20100929212226.14958"><vh>org-clock-special-range</vh></v>
<v t="ekr.20100929212226.14959"><vh>org-clocktable-shift</vh></v>
<v t="ekr.20100929212226.14960"><vh>org-dblock-write</vh></v>
<v t="ekr.20100929212226.14961"><vh>org-clocktable-steps</vh></v>
<v t="ekr.20100929212226.14962"><vh>org-clocktable-add-file</vh></v>
<v t="ekr.20100929212226.14963"><vh>org-clock-time</vh></v>
<v t="ekr.20100929212226.14964"><vh>org-clock-save</vh></v>
<v t="ekr.20100929212226.14965"><vh>org-clock-load</vh></v>
<v t="ekr.20100929212226.14966"><vh>org-clock-persistence-insinuate</vh></v>
</v>
<v t="ekr.20100929212226.14967"><vh>org-colview-xemacs.el</vh>
<v t="ekr.20100929212226.14968"><vh>org-colview-xemacs declarations</vh></v>
<v t="ekr.20100929212226.14969"><vh>org-get-columns-level-face</vh></v>
<v t="ekr.20100929212226.14970"><vh>org-columns-content</vh></v>
<v t="ekr.20100929212226.14971"><vh>org-columns-current-column</vh></v>
<v t="ekr.20100929212226.14972"><vh>org-columns-forward-char</vh></v>
<v t="ekr.20100929212226.14973"><vh>org-columns-backward-char</vh></v>
<v t="ekr.20100929212226.14974"><vh>org-columns-new-overlay</vh></v>
<v t="ekr.20100929212226.14975"><vh>org-columns-display-here</vh></v>
<v t="ekr.20100929212226.14976"><vh>org-columns-add-ellipses</vh></v>
<v t="ekr.20100929212226.14977"><vh>org-columns-display-here-title</vh></v>
<v t="ekr.20100929212226.14978"><vh>org-columns-hscoll-title</vh></v>
<v t="ekr.20100929212226.14979"><vh>org-columns-remove-overlays</vh></v>
<v t="ekr.20100929212226.14980"><vh>org-columns-cleanup-item</vh></v>
<v t="ekr.20100929212226.14981"><vh>org-columns-compact-links</vh></v>
<v t="ekr.20100929212226.14982"><vh>org-agenda-columns-cleanup-item</vh></v>
<v t="ekr.20100929212226.14983"><vh>org-columns-show-value</vh></v>
<v t="ekr.20100929212226.14984"><vh>org-columns-quit</vh></v>
<v t="ekr.20100929212226.14985"><vh>org-columns-check-computed</vh></v>
<v t="ekr.20100929212226.14986"><vh>org-columns-todo</vh></v>
<v t="ekr.20100929212226.14987"><vh>org-columns-set-tags-or-toggle</vh></v>
<v t="ekr.20100929212226.14988"><vh>org-columns-edit-value</vh></v>
<v t="ekr.20100929212226.14989"><vh>org-edit-headline</vh></v>
<v t="ekr.20100929212226.14990"><vh>org-columns-edit-allowed</vh></v>
<v t="ekr.20100929212226.14991"><vh>org-columns-eval</vh></v>
<v t="ekr.20100929212226.14992"><vh>org-columns-previous-allowed-value</vh></v>
<v t="ekr.20100929212226.14993"><vh>org-columns-next-allowed-value</vh></v>
<v t="ekr.20100929212226.14994"><vh>org-colview-construct-allowed-dates</vh></v>
<v t="ekr.20100929212226.14995"><vh>org-verify-version</vh></v>
<v t="ekr.20100929212226.14996"><vh>org-columns-open-link</vh></v>
<v t="ekr.20100929212226.14997"><vh>org-columns-get-format-and-top-level</vh></v>
<v t="ekr.20100929212226.14998"><vh>org-columns</vh></v>
<v t="ekr.20100929212226.14999"><vh>org-columns-new</vh></v>
<v t="ekr.20100929212226.15000"><vh>org-columns-delete</vh></v>
<v t="ekr.20100929212226.15001"><vh>org-columns-edit-attributes</vh></v>
<v t="ekr.20100929212226.15002"><vh>org-columns-widen</vh></v>
<v t="ekr.20100929212226.15003"><vh>org-columns-narrow</vh></v>
<v t="ekr.20100929212226.15004"><vh>org-columns-move-right</vh></v>
<v t="ekr.20100929212226.15005"><vh>org-columns-move-left</vh></v>
<v t="ekr.20100929212226.15006"><vh>org-columns-store-format</vh></v>
<v t="ekr.20100929212226.15007"><vh>org-columns-get-autowidth-alist</vh></v>
<v t="ekr.20100929212226.15008"><vh>org-columns-compute-all</vh></v>
<v t="ekr.20100929212226.15009"><vh>org-columns-update</vh></v>
<v t="ekr.20100929212226.15010"><vh>org-columns-compute</vh></v>
<v t="ekr.20100929212226.15011"><vh>org-columns-redo</vh></v>
<v t="ekr.20100929212226.15012"><vh>org-columns-not-in-agenda</vh></v>
<v t="ekr.20100929212226.15013"><vh>org-string-to-number</vh></v>
<v t="ekr.20100929212226.15014"><vh>org-columns-number-to-string</vh></v>
<v t="ekr.20100929212226.15015"><vh>org-nofm-to-completion</vh></v>
<v t="ekr.20100929212226.15016"><vh>org-columns-string-to-number</vh></v>
<v t="ekr.20100929212226.15017"><vh>org-columns-uncompile-format</vh></v>
<v t="ekr.20100929212226.15018"><vh>org-columns-compile-format</vh></v>
<v t="ekr.20100929212226.15019"><vh>org-columns-capture-view</vh></v>
<v t="ekr.20100929212226.15020"><vh>org-dblock-write</vh></v>
<v t="ekr.20100929212226.15021"><vh>org-listtable-to-string</vh></v>
<v t="ekr.20100929212226.15022"><vh>org-insert-columns-dblock</vh></v>
<v t="ekr.20100929212226.15023"><vh>org-agenda-columns</vh></v>
<v t="ekr.20100929212226.15024"><vh>org-agenda-colview-summarize</vh></v>
<v t="ekr.20100929212226.15025"><vh>org-agenda-colview-compute</vh></v>
<v t="ekr.20100929212226.15026"><vh>org-format-time-period</vh></v>
<v t="ekr.20100929212226.15027"><vh>org-estimate-mean-and-var</vh></v>
<v t="ekr.20100929212226.15028"><vh>org-estimate-combine</vh></v>
<v t="ekr.20100929212226.15029"><vh>org-estimate-print</vh></v>
<v t="ekr.20100929212226.15030"><vh>org-string-to-estimate</vh></v>
</v>
<v t="ekr.20100929212226.15031"><vh>org-colview.el</vh>
<v t="ekr.20100929212226.15032"><vh>org-colview declarations</vh></v>
<v t="ekr.20100929212226.15033"><vh>org-columns-content</vh></v>
<v t="ekr.20100929212226.15034"><vh>org-columns-new-overlay</vh></v>
<v t="ekr.20100929212226.15035"><vh>org-columns-display-here</vh></v>
<v t="ekr.20100929212226.15036"><vh>org-columns-add-ellipses</vh></v>
<v t="ekr.20100929212226.15037"><vh>org-columns-display-here-title</vh></v>
<v t="ekr.20100929212226.15038"><vh>org-columns-hscoll-title</vh></v>
<v t="ekr.20100929212226.15039"><vh>org-columns-remove-overlays</vh></v>
<v t="ekr.20100929212226.15040"><vh>org-columns-cleanup-item</vh></v>
<v t="ekr.20100929212226.15041"><vh>org-columns-compact-links</vh></v>
<v t="ekr.20100929212226.15042"><vh>org-agenda-columns-cleanup-item</vh></v>
<v t="ekr.20100929212226.15043"><vh>org-columns-show-value</vh></v>
<v t="ekr.20100929212226.15044"><vh>org-columns-quit</vh></v>
<v t="ekr.20100929212226.15045"><vh>org-columns-check-computed</vh></v>
<v t="ekr.20100929212226.15046"><vh>org-columns-todo</vh></v>
<v t="ekr.20100929212226.15047"><vh>org-columns-set-tags-or-toggle</vh></v>
<v t="ekr.20100929212226.15048"><vh>org-columns-edit-value</vh></v>
<v t="ekr.20100929212226.15049"><vh>org-edit-headline</vh></v>
<v t="ekr.20100929212226.15050"><vh>org-columns-edit-allowed</vh></v>
<v t="ekr.20100929212226.15051"><vh>org-columns-eval</vh></v>
<v t="ekr.20100929212226.15052"><vh>org-columns-previous-allowed-value</vh></v>
<v t="ekr.20100929212226.15053"><vh>org-columns-next-allowed-value</vh></v>
<v t="ekr.20100929212226.15054"><vh>org-colview-construct-allowed-dates</vh></v>
<v t="ekr.20100929212226.15055"><vh>org-verify-version</vh></v>
<v t="ekr.20100929212226.15056"><vh>org-columns-open-link</vh></v>
<v t="ekr.20100929212226.15057"><vh>org-columns-get-format-and-top-level</vh></v>
<v t="ekr.20100929212226.15058"><vh>org-columns</vh></v>
<v t="ekr.20100929212226.15059"><vh>org-columns-new</vh></v>
<v t="ekr.20100929212226.15060"><vh>org-columns-delete</vh></v>
<v t="ekr.20100929212226.15061"><vh>org-columns-edit-attributes</vh></v>
<v t="ekr.20100929212226.15062"><vh>org-columns-widen</vh></v>
<v t="ekr.20100929212226.15063"><vh>org-columns-narrow</vh></v>
<v t="ekr.20100929212226.15064"><vh>org-columns-move-right</vh></v>
<v t="ekr.20100929212226.15065"><vh>org-columns-move-left</vh></v>
<v t="ekr.20100929212226.15066"><vh>org-columns-store-format</vh></v>
<v t="ekr.20100929212226.15067"><vh>org-columns-get-autowidth-alist</vh></v>
<v t="ekr.20100929212226.15068"><vh>org-columns-compute-all</vh></v>
<v t="ekr.20100929212226.15069"><vh>org-columns-update</vh></v>
<v t="ekr.20100929212226.15070"><vh>org-columns-compute</vh></v>
<v t="ekr.20100929212226.15071"><vh>org-columns-redo</vh></v>
<v t="ekr.20100929212226.15072"><vh>org-columns-not-in-agenda</vh></v>
<v t="ekr.20100929212226.15073"><vh>org-string-to-number</vh></v>
<v t="ekr.20100929212226.15074"><vh>org-columns-number-to-string</vh></v>
<v t="ekr.20100929212226.15075"><vh>org-nofm-to-completion</vh></v>
<v t="ekr.20100929212226.15076"><vh>org-columns-string-to-number</vh></v>
<v t="ekr.20100929212226.15077"><vh>org-columns-uncompile-format</vh></v>
<v t="ekr.20100929212226.15078"><vh>org-columns-compile-format</vh></v>
<v t="ekr.20100929212226.15079"><vh>org-columns-capture-view</vh></v>
<v t="ekr.20100929212226.15080"><vh>org-dblock-write</vh></v>
<v t="ekr.20100929212226.15081"><vh>org-listtable-to-string</vh></v>
<v t="ekr.20100929212226.15082"><vh>org-insert-columns-dblock</vh></v>
<v t="ekr.20100929212226.15083"><vh>org-agenda-columns</vh></v>
<v t="ekr.20100929212226.15084"><vh>org-agenda-colview-summarize</vh></v>
<v t="ekr.20100929212226.15085"><vh>org-agenda-colview-compute</vh></v>
<v t="ekr.20100929212226.15086"><vh>org-format-time-period</vh></v>
<v t="ekr.20100929212226.15087"><vh>org-estimate-mean-and-var</vh></v>
<v t="ekr.20100929212226.15088"><vh>org-estimate-combine</vh></v>
<v t="ekr.20100929212226.15089"><vh>org-estimate-print</vh></v>
<v t="ekr.20100929212226.15090"><vh>org-string-to-estimate</vh></v>
</v>
<v t="ekr.20100929212226.15091"><vh>org-compat.el</vh>
<v t="ekr.20100929212226.15092"><vh>org-compat declarations</vh></v>
<v t="ekr.20100929212226.15093"><vh>org-compatible-face</vh></v>
<v t="ekr.20100929212226.15094"><vh>org-version-check</vh></v>
<v t="ekr.20100929212226.15095"><vh>org-detach-overlay</vh></v>
<v t="ekr.20100929212226.15096"><vh>org-overlay-display</vh></v>
<v t="ekr.20100929212226.15097"><vh>org-overlay-before-string</vh></v>
<v t="ekr.20100929212226.15098"><vh>org-find-overlays</vh></v>
<v t="ekr.20100929212226.15099"><vh>org-get-x-clipboard</vh></v>
<v t="ekr.20100929212226.15100"><vh>org-add-hook</vh></v>
<v t="ekr.20100929212226.15101"><vh>org-add-props</vh></v>
<v t="ekr.20100929212226.15102"><vh>org-fit-window-to-buffer</vh></v>
<v t="ekr.20100929212226.15103"><vh>org-cursor-to-region-beginning</vh></v>
<v t="ekr.20100929212226.15104"><vh>org-remove-from-invisibility-spec</vh></v>
<v t="ekr.20100929212226.15105"><vh>org-in-invisibility-spec-p</vh></v>
<v t="ekr.20100929212226.15106"><vh>org-indent-to-column</vh></v>
<v t="ekr.20100929212226.15107"><vh>org-indent-line-to</vh></v>
<v t="ekr.20100929212226.15108"><vh>org-move-to-column</vh></v>
<v t="ekr.20100929212226.15109"><vh>org-get-x-clipboard-compat</vh></v>
<v t="ekr.20100929212226.15110"><vh>org-propertize</vh></v>
<v t="ekr.20100929212226.15111"><vh>org-substring-no-properties</vh></v>
<v t="ekr.20100929212226.15112"><vh>org-find-library-name</vh></v>
<v t="ekr.20100929212226.15113"><vh>org-count-lines</vh></v>
<v t="ekr.20100929212226.15114"><vh>org-kill-new</vh></v>
<v t="ekr.20100929212226.15115"><vh>org-select-frame-set-input-focus</vh></v>
<v t="ekr.20100929212226.15116"><vh>org-float-time</vh></v>
<v t="ekr.20100929212226.15117"><vh>org-string-match-p</vh></v>
<v t="ekr.20100929212226.15118"><vh>org-looking-at-p</vh></v>
<v t="ekr.20100929212226.15119"><vh>org-looking-back</vh></v>
</v>
<v t="ekr.20100929212226.15120"><vh>org-datetree.el</vh>
<v t="ekr.20100929212226.15121"><vh>org-datetree declarations</vh></v>
<v t="ekr.20100929212226.15122"><vh>org-datetree-find-date-create</vh></v>
<v t="ekr.20100929212226.15123"><vh>org-datetree-find-year-create</vh></v>
<v t="ekr.20100929212226.15124"><vh>org-datetree-find-month-create</vh></v>
<v t="ekr.20100929212226.15125"><vh>org-datetree-find-day-create</vh></v>
<v t="ekr.20100929212226.15126"><vh>org-datetree-insert-line</vh></v>
<v t="ekr.20100929212226.15127"><vh>org-datetree-file-entry-under</vh></v>
<v t="ekr.20100929212226.15128"><vh>org-datetree-cleanup</vh></v>
</v>
<v t="ekr.20100929212226.15129"><vh>org-docview.el</vh>
<v t="ekr.20100929212226.15130"><vh>org-docview declarations</vh></v>
<v t="ekr.20100929212226.15131"><vh>org-docview-open</vh></v>
<v t="ekr.20100929212226.15132"><vh>org-docview-store-link</vh></v>
<v t="ekr.20100929212226.15133"><vh>org-docview-complete-link</vh></v>
</v>
<v t="ekr.20100929212226.15134"><vh>org-entities.el</vh>
<v t="ekr.20100929212226.15135"><vh>org-entities declarations</vh></v>
<v t="ekr.20100929212226.15136"><vh>org-entity-get-representation</vh></v>
<v t="ekr.20100929212226.15137"><vh>org-entities-create-table</vh></v>
<v t="ekr.20100929212226.15138"><vh>org-entities-help</vh></v>
<v t="ekr.20100929212226.15139"><vh>replace-amp</vh></v>
</v>
<v t="ekr.20100929212226.15140"><vh>org-exp.el</vh>
<v t="ekr.20100929212226.15141"><vh>org-exp declarations</vh></v>
<v t="ekr.20100929212226.15142"><vh>org-default-export-plist</vh></v>
<v t="ekr.20100929212226.15143"><vh>org-infile-export-plist</vh></v>
<v t="ekr.20100929212226.15144"><vh>org-export-interpolate-newlines</vh></v>
<v t="ekr.20100929212226.15145"><vh>org-export-confirm-letbind</vh></v>
<v t="ekr.20100929212226.15146"><vh>org-install-letbind</vh></v>
<v t="ekr.20100929212226.15147"><vh>org-export-add-options-to-plist</vh></v>
<v t="ekr.20100929212226.15148"><vh>org-export-add-subtree-options</vh></v>
<v t="ekr.20100929212226.15149"><vh>org-export-directory</vh></v>
<v t="ekr.20100929212226.15150"><vh>org-export-process-option-filters</vh></v>
<v t="ekr.20100929212226.15151"><vh>org-export</vh></v>
<v t="ekr.20100929212226.15152"><vh>org-export-process-sentinel</vh></v>
<v t="ekr.20100929212226.15153"><vh>org-export-preprocess-string</vh></v>
<v t="ekr.20100929212226.15154"><vh>org-export-kill-licensed-text</vh></v>
<v t="ekr.20100929212226.15155"><vh>org-export-define-heading-targets</vh></v>
<v t="ekr.20100929212226.15156"><vh>org-export-handle-invisible-targets</vh></v>
<v t="ekr.20100929212226.15157"><vh>org-export-target-internal-links</vh></v>
<v t="ekr.20100929212226.15158"><vh>org-export-remember-html-container-classes</vh></v>
<v t="ekr.20100929212226.15159"><vh>org-export-remove-or-extract-drawers</vh></v>
<v t="ekr.20100929212226.15160"><vh>org-export-format-drawer</vh></v>
<v t="ekr.20100929212226.15161"><vh>org-export-handle-export-tags</vh></v>
<v t="ekr.20100929212226.15162"><vh>org-export-remove-archived-trees</vh></v>
<v t="ekr.20100929212226.15163"><vh>org-export-remove-headline-metadata</vh></v>
<v t="ekr.20100929212226.15164"><vh>org-export-remove-timestamps</vh></v>
<v t="ekr.20100929212226.15165"><vh>org-export-remove-clock-lines</vh></v>
<v t="ekr.20100929212226.15166"><vh>org-export-protect-quoted-subtrees</vh></v>
<v t="ekr.20100929212226.15167"><vh>org-export-protect-verbatim</vh></v>
<v t="ekr.20100929212226.15168"><vh>org-export-protect-colon-examples</vh></v>
<v t="ekr.20100929212226.15169"><vh>org-export-select-backend-specific-text</vh></v>
<v t="ekr.20100929212226.15170"><vh>org-export-mark-blockquote-verse-center</vh></v>
<v t="ekr.20100929212226.15171"><vh>org-export-attach-captions-and-attributes</vh></v>
<v t="ekr.20100929212226.15172"><vh>org-export-remove-comment-blocks-and-subtrees</vh></v>
<v t="ekr.20100929212226.15173"><vh>org-export-handle-comments</vh></v>
<v t="ekr.20100929212226.15174"><vh>org-export-handle-table-metalines</vh></v>
<v t="ekr.20100929212226.15175"><vh>org-export-mark-radio-links</vh></v>
<v t="ekr.20100929212226.15176"><vh>org-export-remove-special-table-lines</vh></v>
<v t="ekr.20100929212226.15177"><vh>org-export-protect-sub-super</vh></v>
<v t="ekr.20100929212226.15178"><vh>org-export-normalize-links</vh></v>
<v t="ekr.20100929212226.15179"><vh>org-export-concatenate-multiline-links</vh></v>
<v t="ekr.20100929212226.15180"><vh>org-export-concatenate-multiline-emphasis</vh></v>
<v t="ekr.20100929212226.15181"><vh>org-export-grab-title-from-buffer</vh></v>
<v t="ekr.20100929212226.15182"><vh>org-export-get-title-from-subtree</vh></v>
<v t="ekr.20100929212226.15183"><vh>org-solidify-link-text</vh></v>
<v t="ekr.20100929212226.15184"><vh>org-get-min-level</vh></v>
<v t="ekr.20100929212226.15185"><vh>org-init-section-numbers</vh></v>
<v t="ekr.20100929212226.15186"><vh>org-section-number</vh></v>
<v t="ekr.20100929212226.15187"><vh>org-number-to-counter</vh></v>
<v t="ekr.20100929212226.15188"><vh>org-number-to-roman</vh></v>
<v t="ekr.20100929212226.15189"><vh>org-export-preprocess-apply-macros</vh></v>
<v t="ekr.20100929212226.15190"><vh>org-export-apply-macros-in-string</vh></v>
<v t="ekr.20100929212226.15191"><vh>org-export-handle-include-files</vh></v>
<v t="ekr.20100929212226.15192"><vh>org-export-handle-include-files-recurse</vh></v>
<v t="ekr.20100929212226.15193"><vh>org-get-file-contents</vh></v>
<v t="ekr.20100929212226.15194"><vh>org-get-and-remove-property</vh></v>
<v t="ekr.20100929212226.15195"><vh>org-symname-or-string</vh></v>
<v t="ekr.20100929212226.15196"><vh>org-export-replace-src-segments-and-examples</vh></v>
<v t="ekr.20100929212226.15197"><vh>org-export-format-source-code-or-example</vh></v>
<v t="ekr.20100929212226.15198"><vh>org-export-number-lines</vh></v>
<v t="ekr.20100929212226.15199"><vh>org-search-todo-below</vh></v>
<v t="ekr.20100929212226.15200"><vh>org-export-visible</vh></v>
<v t="ekr.20100929212226.15201"><vh>org-find-visible</vh></v>
<v t="ekr.20100929212226.15202"><vh>org-find-invisible</vh></v>
<v t="ekr.20100929212226.15203"><vh>org-export-as-org</vh></v>
<v t="ekr.20100929212226.15204"><vh>org-get-current-options</vh></v>
<v t="ekr.20100929212226.15205"><vh>org-insert-export-options-template</vh></v>
<v t="ekr.20100929212226.15206"><vh>org-table-clean-before-export</vh></v>
<v t="ekr.20100929212226.15207"><vh>org-export-cleanup-toc-line</vh></v>
<v t="ekr.20100929212226.15208"><vh>org-get-text-property-any</vh></v>
<v t="ekr.20100929212226.15209"><vh>org-export-get-coderef-format</vh></v>
<v t="ekr.20100929212226.15210"><vh>org-export-push-to-kill-ring</vh></v>
</v>
<v t="ekr.20100929212226.15211"><vh>org-faces.el</vh>
<v t="ekr.20100929212226.15212"><vh>org-faces declarations</vh></v>
<v t="ekr.20100929212226.15213"><vh>org-copy-face</vh></v>
<v t="ekr.20100929212226.15214"><vh>org-set-tag-faces</vh></v>
</v>
<v t="ekr.20100929212226.15215"><vh>org-feed.el</vh>
<v t="ekr.20100929212226.15216"><vh>org-feed declarations</vh></v>
<v t="ekr.20100929212226.15217"><vh>org-feed-unescape</vh></v>
<v t="ekr.20100929212226.15218"><vh>org-feed-update-all</vh></v>
<v t="ekr.20100929212226.15219"><vh>org-feed-update</vh></v>
<v t="ekr.20100929212226.15220"><vh>org-feed-goto-inbox</vh></v>
<v t="ekr.20100929212226.15221"><vh>org-feed-show-raw-feed</vh></v>
<v t="ekr.20100929212226.15222"><vh>org-feed-goto-inbox-internal</vh></v>
<v t="ekr.20100929212226.15223"><vh>org-feed-read-previous-status</vh></v>
<v t="ekr.20100929212226.15224"><vh>org-feed-write-status</vh></v>
<v t="ekr.20100929212226.15225"><vh>org-feed-add-items</vh></v>
<v t="ekr.20100929212226.15226"><vh>org-feed-format-entry</vh></v>
<v t="ekr.20100929212226.15227"><vh>org-feed-make-indented-block</vh></v>
<v t="ekr.20100929212226.15228"><vh>org-feed-skip-http-headers</vh></v>
<v t="ekr.20100929212226.15229"><vh>org-feed-get-feed</vh></v>
<v t="ekr.20100929212226.15230"><vh>org-feed-parse-rss-feed</vh></v>
<v t="ekr.20100929212226.15231"><vh>org-feed-parse-rss-entry</vh></v>
<v t="ekr.20100929212226.15232"><vh>org-feed-parse-atom-feed</vh></v>
<v t="ekr.20100929212226.15233"><vh>org-feed-parse-atom-entry</vh></v>
</v>
<v t="ekr.20100929212226.15234"><vh>org-footnote.el</vh>
<v t="ekr.20100929212226.15235"><vh>org-footnote declarations</vh></v>
<v t="ekr.20100929212226.15236"><vh>org-footnote-at-reference-p</vh></v>
<v t="ekr.20100929212226.15237"><vh>org-footnote-at-definition-p</vh></v>
<v t="ekr.20100929212226.15238"><vh>org-footnote-goto-definition</vh></v>
<v t="ekr.20100929212226.15239"><vh>org-footnote-goto-previous-reference</vh></v>
<v t="ekr.20100929212226.15240"><vh>org-footnote-normalize-label</vh></v>
<v t="ekr.20100929212226.15241"><vh>org-footnote-all-labels</vh></v>
<v t="ekr.20100929212226.15242"><vh>org-footnote-unique-label</vh></v>
<v t="ekr.20100929212226.15243"><vh>org-footnote-new</vh></v>
<v t="ekr.20100929212226.15244"><vh>org-footnote-create-definition</vh></v>
<v t="ekr.20100929212226.15245"><vh>org-footnote-action</vh></v>
<v t="ekr.20100929212226.15246"><vh>org-footnote-normalize</vh></v>
<v t="ekr.20100929212226.15247"><vh>org-insert-footnote-reference-near-definition</vh></v>
<v t="ekr.20100929212226.15248"><vh>org-footnote-goto-local-insertion-point</vh></v>
<v t="ekr.20100929212226.15249"><vh>org-footnote-delete</vh></v>
<v t="ekr.20100929212226.15250"><vh>org-footnote-renumber-fn</vh></v>
<v t="ekr.20100929212226.15251"><vh>org-footnote-auto-adjust-maybe</vh></v>
</v>
<v t="ekr.20100929212226.15252"><vh>org-gnus.el</vh>
<v t="ekr.20100929212226.15253"><vh>org-gnus declarations</vh></v>
<v t="ekr.20100929212226.15254"><vh>org-gnus-group-link</vh></v>
<v t="ekr.20100929212226.15255"><vh>org-gnus-article-link</vh></v>
<v t="ekr.20100929212226.15256"><vh>org-gnus-store-link</vh></v>
<v t="ekr.20100929212226.15257"><vh>org-gnus-open</vh></v>
<v t="ekr.20100929212226.15258"><vh>org-gnus-follow-link</vh></v>
<v t="ekr.20100929212226.15259"><vh>org-gnus-no-new-news</vh></v>
</v>
<v t="ekr.20100929212226.15260"><vh>org-habit.el</vh>
<v t="ekr.20100929212226.15261"><vh>org-habit declarations</vh></v>
<v t="ekr.20100929212226.15262"><vh>org-habit-duration-to-days</vh></v>
<v t="ekr.20100929212226.15263"><vh>org-is-habit-p</vh></v>
<v t="ekr.20100929212226.15264"><vh>org-habit-parse-todo</vh></v>
<v t="ekr.20100929212226.15265"><vh>org-habit-get-faces</vh></v>
<v t="ekr.20100929212226.15266"><vh>org-habit-build-graph</vh></v>
<v t="ekr.20100929212226.15267"><vh>org-habit-insert-consistency-graphs</vh></v>
<v t="ekr.20100929212226.15268"><vh>org-habit-toggle-habits</vh></v>
</v>
<v t="ekr.20100929212226.15269"><vh>org-html.el</vh>
<v t="ekr.20100929212226.15270"><vh>org-html declarations</vh></v>
<v t="ekr.20100929212226.15271"><vh>org-export-html-preprocess</vh></v>
<v t="ekr.20100929212226.15272"><vh>org-export-as-html-and-open</vh></v>
<v t="ekr.20100929212226.15273"><vh>org-export-as-html-batch</vh></v>
<v t="ekr.20100929212226.15274"><vh>org-export-as-html-to-buffer</vh></v>
<v t="ekr.20100929212226.15275"><vh>org-replace-region-by-html</vh></v>
<v t="ekr.20100929212226.15276"><vh>org-export-region-as-html</vh></v>
<v t="ekr.20100929212226.15277"><vh>org-html-cvt-org-as-html</vh></v>
<v t="ekr.20100929212226.15278"><vh>org-html-should-inline-p</vh></v>
<v t="ekr.20100929212226.15279"><vh>org-html-make-link</vh></v>
<v t="ekr.20100929212226.15280"><vh>org-export-as-html</vh></v>
<v t="ekr.20100929212226.15281"><vh>org-export-html-insert-plist-item</vh></v>
<v t="ekr.20100929212226.15282"><vh>org-export-html-format-href</vh></v>
<v t="ekr.20100929212226.15283"><vh>org-export-html-format-desc</vh></v>
<v t="ekr.20100929212226.15284"><vh>org-export-html-format-image</vh></v>
<v t="ekr.20100929212226.15285"><vh>org-export-html-get-bibliography</vh></v>
<v t="ekr.20100929212226.15286"><vh>org-format-table-html</vh></v>
<v t="ekr.20100929212226.15287"><vh>org-format-org-table-html</vh></v>
<v t="ekr.20100929212226.15288"><vh>org-export-splice-attributes</vh></v>
<v t="ekr.20100929212226.15289"><vh>org-format-table-table-html</vh></v>
<v t="ekr.20100929212226.15290"><vh>org-format-table-table-html-using-table-generate-source</vh></v>
<v t="ekr.20100929212226.15291"><vh>org-export-splice-style</vh></v>
<v t="ekr.20100929212226.15292"><vh>org-html-handle-time-stamps</vh></v>
<v t="ekr.20100929212226.15293"><vh>org-export-htmlize-region-for-paste</vh></v>
<v t="ekr.20100929212226.15294"><vh>org-export-htmlize-generate-css</vh></v>
<v t="ekr.20100929212226.15295"><vh>org-html-protect</vh></v>
<v t="ekr.20100929212226.15296"><vh>org-html-expand</vh></v>
<v t="ekr.20100929212226.15297"><vh>org-html-do-expand</vh></v>
<v t="ekr.20100929212226.15298"><vh>org-export-html-convert-special-strings</vh></v>
<v t="ekr.20100929212226.15299"><vh>org-export-html-convert-sub-super</vh></v>
<v t="ekr.20100929212226.15300"><vh>org-export-html-convert-emphasize</vh></v>
<v t="ekr.20100929212226.15301"><vh>org-open-par</vh></v>
<v t="ekr.20100929212226.15302"><vh>org-close-par-maybe</vh></v>
<v t="ekr.20100929212226.15303"><vh>org-close-li</vh></v>
<v t="ekr.20100929212226.15304"><vh>org-export-html-close-lists-maybe</vh></v>
<v t="ekr.20100929212226.15305"><vh>org-html-level-start</vh></v>
<v t="ekr.20100929212226.15306"><vh>org-export-html-get-tag-class-name</vh></v>
<v t="ekr.20100929212226.15307"><vh>org-export-html-get-todo-kwd-class-name</vh></v>
<v t="ekr.20100929212226.15308"><vh>org-html-level-close</vh></v>
</v>
<v t="ekr.20100929212226.15309"><vh>org-id.el</vh>
<v t="ekr.20100929212226.15310"><vh>org-id declarations</vh></v>
<v t="ekr.20100929212226.15311"><vh>org-id-get-create</vh></v>
<v t="ekr.20100929212226.15312"><vh>org-id-copy</vh></v>
<v t="ekr.20100929212226.15313"><vh>org-id-get</vh></v>
<v t="ekr.20100929212226.15314"><vh>org-id-get-with-outline-path-completion</vh></v>
<v t="ekr.20100929212226.15315"><vh>org-id-get-with-outline-drilling</vh></v>
<v t="ekr.20100929212226.15316"><vh>org-id-goto</vh></v>
<v t="ekr.20100929212226.15317"><vh>org-id-find</vh></v>
<v t="ekr.20100929212226.15318"><vh>org-id-new</vh></v>
<v t="ekr.20100929212226.15319"><vh>org-id-uuid</vh></v>
<v t="ekr.20100929212226.15320"><vh>org-id-reverse-string</vh></v>
<v t="ekr.20100929212226.15321"><vh>org-id-int-to-b36-one-digit</vh></v>
<v t="ekr.20100929212226.15322"><vh>org-id-b36-to-int-one-digit</vh></v>
<v t="ekr.20100929212226.15323"><vh>org-id-int-to-b36</vh></v>
<v t="ekr.20100929212226.15324"><vh>org-id-b36-to-int</vh></v>
<v t="ekr.20100929212226.15325"><vh>org-id-time-to-b36</vh></v>
<v t="ekr.20100929212226.15326"><vh>org-id-decode</vh></v>
<v t="ekr.20100929212226.15327"><vh>org-id-update-id-locations</vh></v>
<v t="ekr.20100929212226.15328"><vh>org-id-locations-save</vh></v>
<v t="ekr.20100929212226.15329"><vh>org-id-locations-load</vh></v>
<v t="ekr.20100929212226.15330"><vh>org-id-add-location</vh></v>
<v t="ekr.20100929212226.15331"><vh>org-id-hash-to-alist</vh></v>
<v t="ekr.20100929212226.15332"><vh>org-id-alist-to-hash</vh></v>
<v t="ekr.20100929212226.15333"><vh>org-id-paste-tracker</vh></v>
<v t="ekr.20100929212226.15334"><vh>org-id-find-id-file</vh></v>
<v t="ekr.20100929212226.15335"><vh>org-id-find-id-in-file</vh></v>
<v t="ekr.20100929212226.15336"><vh>org-id-store-link</vh></v>
<v t="ekr.20100929212226.15337"><vh>org-id-open</vh></v>
</v>
<v t="ekr.20100929212226.15338"><vh>org-indent.el</vh>
<v t="ekr.20100929212226.15339"><vh>org-indent declarations</vh></v>
<v t="ekr.20100929212226.15340"><vh>org-indent-initialize</vh></v>
<v t="ekr.20100929212226.15341"><vh>org-indent-indent-buffer</vh></v>
<v t="ekr.20100929212226.15342"><vh>org-indent-remove-properties</vh></v>
<v t="ekr.20100929212226.15343"><vh>org-indent-remove-properties-from-string</vh></v>
<v t="ekr.20100929212226.15344"><vh>org-indent-add-properties</vh></v>
<v t="ekr.20100929212226.15345"><vh>org-indent-refresh-section</vh></v>
<v t="ekr.20100929212226.15346"><vh>org-indent-refresh-to</vh></v>
<v t="ekr.20100929212226.15347"><vh>org-indent-refresh-subtree</vh></v>
<v t="ekr.20100929212226.15348"><vh>org-indent-refresh-buffer</vh></v>
</v>
<v t="ekr.20100929212226.15349"><vh>org-info.el</vh>
<v t="ekr.20100929212226.15350"><vh>org-info declarations</vh></v>
<v t="ekr.20100929212226.15351"><vh>org-info-store-link</vh></v>
<v t="ekr.20100929212226.15352"><vh>org-info-open</vh></v>
<v t="ekr.20100929212226.15353"><vh>org-info-follow-link</vh></v>
</v>
<v t="ekr.20100929212226.15354"><vh>org-inlinetask.el</vh>
<v t="ekr.20100929212226.15355"><vh>org-inlinetask declarations</vh></v>
<v t="ekr.20100929212226.15356"><vh>org-inlinetask-insert-task</vh></v>
<v t="ekr.20100929212226.15357"><vh>org-inlinetask-export-handler</vh></v>
<v t="ekr.20100929212226.15358"><vh>org-inlinetask-get-current-indentation</vh></v>
<v t="ekr.20100929212226.15359"><vh>org-inlinetask-fontify</vh></v>
<v t="ekr.20100929212226.15360"><vh>org-inlinetask-remove-END-maybe</vh></v>
<v t="ekr.20100929212226.15361"><vh>org-inlinetask-remove-terminator</vh></v>
</v>
<v t="ekr.20100929212226.15362"><vh>org-install.el</vh>
<v t="ekr.20100929212226.15363"><vh>org-install declarations</vh></v>
</v>
<v t="ekr.20100929212226.15364"><vh>org-irc.el</vh>
<v t="ekr.20100929212226.15365"><vh>org-irc declarations</vh></v>
<v t="ekr.20100929212226.15366"><vh>org-irc-visit</vh></v>
<v t="ekr.20100929212226.15367"><vh>org-irc-parse-link</vh></v>
<v t="ekr.20100929212226.15368"><vh>org-irc-store-link</vh></v>
<v t="ekr.20100929212226.15369"><vh>org-irc-elipsify-description</vh></v>
<v t="ekr.20100929212226.15370"><vh>org-irc-erc-get-line-from-log</vh></v>
<v t="ekr.20100929212226.15371"><vh>org-irc-erc-store-link</vh></v>
<v t="ekr.20100929212226.15372"><vh>org-irc-get-erc-link</vh></v>
<v t="ekr.20100929212226.15373"><vh>org-irc-get-current-erc-port</vh></v>
<v t="ekr.20100929212226.15374"><vh>org-irc-visit-erc</vh></v>
</v>
<v t="ekr.20100929212226.15375"><vh>org-jsinfo.el</vh>
<v t="ekr.20100929212226.15376"><vh>org-jsinfo declarations</vh></v>
<v t="ekr.20100929212226.15377"><vh>org-infojs-handle-options</vh></v>
<v t="ekr.20100929212226.15378"><vh>org-infojs-options-inbuffer-template</vh></v>
</v>
<v t="ekr.20100929212226.15379"><vh>org-list.el</vh>
<v t="ekr.20100929212226.15380"><vh>org-list declarations</vh></v>
<v t="ekr.20100929212226.15381"><vh>org-item-re</vh></v>
<v t="ekr.20100929212226.15382"><vh>org-at-item-p</vh></v>
<v t="ekr.20100929212226.15383"><vh>org-at-item-bullet-p</vh></v>
<v t="ekr.20100929212226.15384"><vh>org-in-item-p</vh></v>
<v t="ekr.20100929212226.15385"><vh>org-insert-item</vh></v>
<v t="ekr.20100929212226.15386"><vh>org-at-item-checkbox-p</vh></v>
<v t="ekr.20100929212226.15387"><vh>org-toggle-checkbox</vh></v>
<v t="ekr.20100929212226.15388"><vh>org-reset-checkbox-state-subtree</vh></v>
<v t="ekr.20100929212226.15389"><vh>org-checkbox-blocked-p</vh></v>
<v t="ekr.20100929212226.15390"><vh>org-update-checkbox-count-maybe</vh></v>
<v t="ekr.20100929212226.15391"><vh>org-update-checkbox-count</vh></v>
<v t="ekr.20100929212226.15392"><vh>org-get-checkbox-statistics-face</vh></v>
<v t="ekr.20100929212226.15393"><vh>org-beginning-of-item</vh></v>
<v t="ekr.20100929212226.15394"><vh>org-end-of-item</vh></v>
<v t="ekr.20100929212226.15395"><vh>org-end-of-item-text-before-children</vh></v>
<v t="ekr.20100929212226.15396"><vh>org-next-item</vh></v>
<v t="ekr.20100929212226.15397"><vh>org-previous-item</vh></v>
<v t="ekr.20100929212226.15398"><vh>org-first-list-item-p</vh></v>
<v t="ekr.20100929212226.15399"><vh>org-move-item-down</vh></v>
<v t="ekr.20100929212226.15400"><vh>org-move-item-up</vh></v>
<v t="ekr.20100929212226.15401"><vh>org-maybe-renumber-ordered-list</vh></v>
<v t="ekr.20100929212226.15402"><vh>org-maybe-renumber-ordered-list-safe</vh></v>
<v t="ekr.20100929212226.15403"><vh>org-cycle-list-bullet</vh></v>
<v t="ekr.20100929212226.15404"><vh>org-get-string-indentation</vh></v>
<v t="ekr.20100929212226.15405"><vh>org-renumber-ordered-list</vh></v>
<v t="ekr.20100929212226.15406"><vh>org-fix-bullet-type</vh></v>
<v t="ekr.20100929212226.15407"><vh>org-shift-item-indentation</vh></v>
<v t="ekr.20100929212226.15408"><vh>org-beginning-of-item-list</vh></v>
<v t="ekr.20100929212226.15409"><vh>org-end-of-item-list</vh></v>
<v t="ekr.20100929212226.15410"><vh>org-outdent-item</vh></v>
<v t="ekr.20100929212226.15411"><vh>org-indent-item</vh></v>
<v t="ekr.20100929212226.15412"><vh>org-outdent-item-tree</vh></v>
<v t="ekr.20100929212226.15413"><vh>org-indent-item-tree</vh></v>
<v t="ekr.20100929212226.15414"><vh>org-item-indent-positions</vh></v>
<v t="ekr.20100929212226.15415"><vh>org-cycle-item-indentation</vh></v>
<v t="ekr.20100929212226.15416"><vh>org-get-bullet</vh></v>
<v t="ekr.20100929212226.15417"><vh>org-list-parse-list</vh></v>
<v t="ekr.20100929212226.15418"><vh>org-list-item-beginning</vh></v>
<v t="ekr.20100929212226.15419"><vh>org-list-goto-true-beginning</vh></v>
<v t="ekr.20100929212226.15420"><vh>org-list-make-subtree</vh></v>
<v t="ekr.20100929212226.15421"><vh>org-list-make-subtrees</vh></v>
<v t="ekr.20100929212226.15422"><vh>org-list-end</vh></v>
<v t="ekr.20100929212226.15423"><vh>org-list-insert-radio-list</vh></v>
<v t="ekr.20100929212226.15424"><vh>org-list-send-list</vh></v>
<v t="ekr.20100929212226.15425"><vh>org-list-to-generic</vh></v>
<v t="ekr.20100929212226.15426"><vh>org-list-to-latex</vh></v>
<v t="ekr.20100929212226.15427"><vh>org-list-to-html</vh></v>
<v t="ekr.20100929212226.15428"><vh>org-list-to-texinfo</vh></v>
</v>
<v t="ekr.20100929212226.15429"><vh>org-mac-message.el</vh>
<v t="ekr.20100929212226.15430"><vh>org-mac-message declarations</vh></v>
<v t="ekr.20100929212226.15431"><vh>do-applescript</vh></v>
<v t="ekr.20100929212226.15432"><vh>org-mac-message-open</vh></v>
<v t="ekr.20100929212226.15433"><vh>as-get-selected-mail</vh></v>
<v t="ekr.20100929212226.15434"><vh>as-get-flagged-mail</vh></v>
<v t="ekr.20100929212226.15435"><vh>org-mac-message-get-links</vh></v>
<v t="ekr.20100929212226.15436"><vh>org-mac-message-insert-selected</vh></v>
<v t="ekr.20100929212226.15437"><vh>org-mac-message-insert-flagged</vh></v>
</v>
<v t="ekr.20100929212226.15438"><vh>org-macs.el</vh>
<v t="ekr.20100929212226.15439"><vh>org-macs declarations</vh></v>
<v t="ekr.20100929212226.15440"><vh>org-string-nw-p</vh></v>
<v t="ekr.20100929212226.15441"><vh>org-not-nil</vh></v>
<v t="ekr.20100929212226.15442"><vh>org-re-search-forward-unprotected</vh></v>
<v t="ekr.20100929212226.15443"><vh>org-let</vh></v>
<v t="ekr.20100929212226.15444"><vh>org-let2</vh></v>
<v t="ekr.20100929212226.15445"><vh>org-autoload</vh></v>
<v t="ekr.20100929212226.15446"><vh>org-match-line</vh></v>
<v t="ekr.20100929212226.15447"><vh>org-plist-delete</vh></v>
<v t="ekr.20100929212226.15448"><vh>org-replace-match-keep-properties</vh></v>
<v t="ekr.20100929212226.15449"><vh>org-get-limited-outline-regexp</vh></v>
</v>
<v t="ekr.20100929212226.15450"><vh>org-mew.el</vh>
<v t="ekr.20100929212226.15451"><vh>org-mew declarations</vh></v>
<v t="ekr.20100929212226.15452"><vh>org-mew-store-link</vh></v>
<v t="ekr.20100929212226.15453"><vh>org-mew-open</vh></v>
</v>
<v t="ekr.20100929212226.15454"><vh>org-mhe.el</vh>
<v t="ekr.20100929212226.15455"><vh>org-mhe declarations</vh></v>
<v t="ekr.20100929212226.15456"><vh>org-mhe-store-link</vh></v>
<v t="ekr.20100929212226.15457"><vh>org-mhe-open</vh></v>
<v t="ekr.20100929212226.15458"><vh>org-mhe-get-message-real-folder</vh></v>
<v t="ekr.20100929212226.15459"><vh>org-mhe-get-message-folder-from-index</vh></v>
<v t="ekr.20100929212226.15460"><vh>org-mhe-get-message-folder</vh></v>
<v t="ekr.20100929212226.15461"><vh>org-mhe-get-message-num</vh></v>
<v t="ekr.20100929212226.15462"><vh>org-mhe-get-header</vh></v>
<v t="ekr.20100929212226.15463"><vh>org-mhe-follow-link</vh></v>
</v>
<v t="ekr.20100929212226.15464"><vh>org-mks.el</vh>
<v t="ekr.20100929212226.15465"><vh>org-mks declarations</vh></v>
<v t="ekr.20100929212226.15466"><vh>org-mks</vh></v>
</v>
<v t="ekr.20100929212226.15467"><vh>org-mobile.el</vh>
<v t="ekr.20100929212226.15468"><vh>org-mobile declarations</vh></v>
<v t="ekr.20100929212226.15469"><vh>org-mobile-prepare-file-lists</vh></v>
<v t="ekr.20100929212226.15470"><vh>org-mobile-files-alist</vh></v>
<v t="ekr.20100929212226.15471"><vh>org-mobile-push</vh></v>
<v t="ekr.20100929212226.15472"><vh>org-mobile-pull</vh></v>
<v t="ekr.20100929212226.15473"><vh>org-mobile-check-setup</vh></v>
<v t="ekr.20100929212226.15474"><vh>org-mobile-create-index-file</vh></v>
<v t="ekr.20100929212226.15475"><vh>org-mobile-copy-agenda-files</vh></v>
<v t="ekr.20100929212226.15476"><vh>org-mobile-write-checksums</vh></v>
<v t="ekr.20100929212226.15477"><vh>org-mobile-sumo-agenda-command</vh></v>
<v t="ekr.20100929212226.15478"><vh>org-mobile-write-agenda-for-mobile</vh></v>
<v t="ekr.20100929212226.15479"><vh>org-mobile-create-sumo-agenda</vh></v>
<v t="ekr.20100929212226.15480"><vh>org-mobile-encrypt-and-move</vh></v>
<v t="ekr.20100929212226.15481"><vh>org-mobile-encrypt-file</vh></v>
<v t="ekr.20100929212226.15482"><vh>org-mobile-decrypt-file</vh></v>
<v t="ekr.20100929212226.15483"><vh>org-mobile-move-capture</vh></v>
<v t="ekr.20100929212226.15484"><vh>org-mobile-update-checksum-for-capture-file</vh></v>
<v t="ekr.20100929212226.15485"><vh>org-mobile-apply</vh></v>
<v t="ekr.20100929212226.15486"><vh>org-mobile-timestamp-buffer</vh></v>
<v t="ekr.20100929212226.15487"><vh>org-mobile-smart-read</vh></v>
<v t="ekr.20100929212226.15488"><vh>org-mobile-locate-entry</vh></v>
<v t="ekr.20100929212226.15489"><vh>org-mobile-edit</vh></v>
<v t="ekr.20100929212226.15490"><vh>org-mobile-tags-same-p</vh></v>
<v t="ekr.20100929212226.15491"><vh>org-mobile-bodies-same-p</vh></v>
</v>
<v t="ekr.20100929212226.15492"><vh>org-mouse.el</vh>
<v t="ekr.20100929212226.15493"><vh>org-mouse declarations</vh></v>
<v t="ekr.20100929212226.15494"><vh>org-mouse-re-search-line</vh></v>
<v t="ekr.20100929212226.15495"><vh>org-mouse-end-headline</vh></v>
<v t="ekr.20100929212226.15496"><vh>org-mouse-show-context-menu</vh></v>
<v t="ekr.20100929212226.15497"><vh>org-mouse-line-position</vh></v>
<v t="ekr.20100929212226.15498"><vh>org-mouse-empty-line</vh></v>
<v t="ekr.20100929212226.15499"><vh>org-mouse-next-heading</vh></v>
<v t="ekr.20100929212226.15500"><vh>org-mouse-insert-heading</vh></v>
<v t="ekr.20100929212226.15501"><vh>org-mouse-timestamp-today</vh></v>
<v t="ekr.20100929212226.15502"><vh>org-mouse-keyword-menu</vh></v>
<v t="ekr.20100929212226.15503"><vh>org-mouse-remove-match-and-spaces</vh></v>
<v t="ekr.20100929212226.15504"><vh>org-mouse-replace-match-and-surround</vh></v>
<v t="ekr.20100929212226.15505"><vh>org-mouse-keyword-replace-menu</vh></v>
<v t="ekr.20100929212226.15506"><vh>org-mouse-show-headlines</vh></v>
<v t="ekr.20100929212226.15507"><vh>org-mouse-show-overview</vh></v>
<v t="ekr.20100929212226.15508"><vh>org-mouse-set-priority</vh></v>
<v t="ekr.20100929212226.15509"><vh>org-mouse-get-priority</vh></v>
<v t="ekr.20100929212226.15510"><vh>org-mouse-delete-timestamp</vh></v>
<v t="ekr.20100929212226.15511"><vh>org-mouse-looking-at</vh></v>
<v t="ekr.20100929212226.15512"><vh>org-mouse-priority-list</vh></v>
<v t="ekr.20100929212226.15513"><vh>org-mouse-todo-menu</vh></v>
<v t="ekr.20100929212226.15514"><vh>org-mouse-tag-menu</vh></v>
<v t="ekr.20100929212226.15515"><vh>org-mouse-set-tags</vh></v>
<v t="ekr.20100929212226.15516"><vh>org-mouse-insert-checkbox</vh></v>
<v t="ekr.20100929212226.15517"><vh>org-mouse-agenda-type</vh></v>
<v t="ekr.20100929212226.15518"><vh>org-mouse-list-options-menu</vh></v>
<v t="ekr.20100929212226.15519"><vh>org-mouse-clip-text</vh></v>
<v t="ekr.20100929212226.15520"><vh>org-mouse-popup-global-menu</vh></v>
<v t="ekr.20100929212226.15521"><vh>org-mouse-get-context</vh></v>
<v t="ekr.20100929212226.15522"><vh>org-mouse-for-each-item</vh></v>
<v t="ekr.20100929212226.15523"><vh>org-mouse-bolp</vh></v>
<v t="ekr.20100929212226.15524"><vh>org-mouse-insert-item</vh></v>
<v t="ekr.20100929212226.15525"><vh>org-mouse-match-closure</vh></v>
<v t="ekr.20100929212226.15526"><vh>org-mouse-match-todo-keyword</vh></v>
<v t="ekr.20100929212226.15527"><vh>org-mouse-yank-link</vh></v>
<v t="ekr.20100929212226.15528"><vh>org-mouse-context-menu</vh></v>
<v t="ekr.20100929212226.15529"><vh>org-mouse-mark-active</vh></v>
<v t="ekr.20100929212226.15530"><vh>org-mouse-in-region-p</vh></v>
<v t="ekr.20100929212226.15531"><vh>org-mouse-down-mouse</vh></v>
<v t="ekr.20100929212226.15532"><vh>org-mouse-move-tree-start</vh></v>
<v t="ekr.20100929212226.15533"><vh>org-mouse-make-marker</vh></v>
<v t="ekr.20100929212226.15534"><vh>org-mouse-move-tree</vh></v>
<v t="ekr.20100929212226.15535"><vh>org-mouse-transform-to-outline</vh></v>
<v t="ekr.20100929212226.15536"><vh>org-mouse-do-remotely</vh></v>
<v t="ekr.20100929212226.15537"><vh>org-mouse-agenda-context-menu</vh></v>
<v t="ekr.20100929212226.15538"><vh>org-mouse-get-gesture</vh></v>
</v>
<v t="ekr.20100929212226.15539"><vh>org-plot.el</vh>
<v t="ekr.20100929212226.15540"><vh>org-plot declarations</vh></v>
<v t="ekr.20100929212226.15541"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15542"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15543"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15544"><vh>org-plot-quote-timestamp-field</vh></v>
<v t="ekr.20100929212226.15545"><vh>org-plot-quote-tsv-field</vh></v>
<v t="ekr.20100929212226.15546"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15547"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15548"><vh>org-plot</vh></v>
<v t="ekr.20100929212226.15549"><vh>org-plot</vh></v>
</v>
<v t="ekr.20100929212226.15550"><vh>org-protocol.el</vh>
<v t="ekr.20100929212226.15551"><vh>org-protocol declarations</vh></v>
<v t="ekr.20100929212226.15552"><vh>org-protocol-sanitize-uri</vh></v>
<v t="ekr.20100929212226.15553"><vh>org-protocol-split-data</vh></v>
<v t="ekr.20100929212226.15554"><vh>org-protocol-unhex-string</vh></v>
<v t="ekr.20100929212226.15555"><vh>org-protocol-unhex-compound</vh></v>
<v t="ekr.20100929212226.15556"><vh>org-protocol-flatten-greedy</vh></v>
<v t="ekr.20100929212226.15557"><vh>org-protocol-flatten</vh></v>
<v t="ekr.20100929212226.15558"><vh>org-protocol-store-link</vh></v>
<v t="ekr.20100929212226.15559"><vh>org-protocol-remember</vh></v>
<v t="ekr.20100929212226.15560"><vh>org-protocol-capture</vh></v>
<v t="ekr.20100929212226.15561"><vh>org-protocol-do-capture</vh></v>
<v t="ekr.20100929212226.15562"><vh>org-protocol-open-source</vh></v>
<v t="ekr.20100929212226.15563"><vh>org-protocol-check-filename-for-protocol</vh></v>
<v t="ekr.20100929212226.15564"><vh>org-protocol-create-for-org</vh></v>
<v t="ekr.20100929212226.15565"><vh>org-protocol-create</vh></v>
</v>
<v t="ekr.20100929212226.15566"><vh>org-publish.el</vh>
<v t="ekr.20100929212226.15567"><vh>org-publish-sanitize-plist</vh></v>
<v t="ekr.20100929212226.15568"><vh>org-publish-timestamp-filename</vh></v>
<v t="ekr.20100929212226.15569"><vh>org-publish-needed-p</vh></v>
<v t="ekr.20100929212226.15570"><vh>org-publish-update-timestamp</vh></v>
<v t="ekr.20100929212226.15571"><vh>org-publish-remove-all-timestamps</vh></v>
<v t="ekr.20100929212226.15572"><vh>org-publish-delete-dups</vh></v>
<v t="ekr.20100929212226.15573"><vh>org-publish-expand-projects</vh></v>
<v t="ekr.20100929212226.15574"><vh>org-publish-compare-directory-files</vh></v>
<v t="ekr.20100929212226.15575"><vh>org-publish-get-base-files-1</vh></v>
<v t="ekr.20100929212226.15576"><vh>org-publish-get-base-files</vh></v>
<v t="ekr.20100929212226.15577"><vh>org-publish-get-project-from-filename</vh></v>
<v t="ekr.20100929212226.15578"><vh>org-publish-org-to</vh></v>
<v t="ekr.20100929212226.15579"><vh>org-publish-org-to-latex</vh></v>
<v t="ekr.20100929212226.15580"><vh>org-publish-org-to-pdf</vh></v>
<v t="ekr.20100929212226.15581"><vh>org-publish-org-to-html</vh></v>
<v t="ekr.20100929212226.15582"><vh>org-publish-org-to-org</vh></v>
<v t="ekr.20100929212226.15583"><vh>org-publish-attachment</vh></v>
<v t="ekr.20100929212226.15584"><vh>org-publish-file</vh></v>
<v t="ekr.20100929212226.15585"><vh>org-publish-projects</vh></v>
<v t="ekr.20100929212226.15586"><vh>org-publish-org-sitemap</vh></v>
<v t="ekr.20100929212226.15587"><vh>org-publish-find-title</vh></v>
<v t="ekr.20100929212226.15588"><vh>org-publish</vh></v>
<v t="ekr.20100929212226.15589"><vh>org-publish-all</vh></v>
<v t="ekr.20100929212226.15590"><vh>org-publish-current-file</vh></v>
<v t="ekr.20100929212226.15591"><vh>org-publish-current-project</vh></v>
<v t="ekr.20100929212226.15592"><vh>org-publish-aux-preprocess</vh></v>
<v t="ekr.20100929212226.15593"><vh>org-publish-index-generate-theindex</vh></v>
<v t="ekr.20100929212226.15594"><vh>org-publish-write-cache-file</vh></v>
<v t="ekr.20100929212226.15595"><vh>org-publish-initialize-cache</vh></v>
<v t="ekr.20100929212226.15596"><vh>org-publish-reset-cache</vh></v>
<v t="ekr.20100929212226.15597"><vh>org-publish-cache-file-needs-publishing</vh></v>
<v t="ekr.20100929212226.15598"><vh>org-publish-cache-set-file-property</vh></v>
<v t="ekr.20100929212226.15599"><vh>org-publish-cache-get-file-property</vh></v>
<v t="ekr.20100929212226.15600"><vh>org-publish-cache-get</vh></v>
<v t="ekr.20100929212226.15601"><vh>org-publish-cache-set</vh></v>
<v t="ekr.20100929212226.15602"><vh>org-publish-cache-ctime-of-src</vh></v>
</v>
<v t="ekr.20100929212226.15603"><vh>org-remember.el</vh>
<v t="ekr.20100929212226.15604"><vh>org-remember declarations</vh></v>
<v t="ekr.20100929212226.15605"><vh>org-remember-insinuate</vh></v>
<v t="ekr.20100929212226.15606"><vh>org-remember-annotation</vh></v>
<v t="ekr.20100929212226.15607"><vh>org-select-remember-template</vh></v>
<v t="ekr.20100929212226.15608"><vh>org-remember-apply-template</vh></v>
<v t="ekr.20100929212226.15609"><vh>org-remember-escaped-</vh></v>
<v t="ekr.20100929212226.15610"><vh>org-remember-finish-immediately</vh></v>
<v t="ekr.20100929212226.15611"><vh>org-remember-visit-immediately</vh></v>
<v t="ekr.20100929212226.15612"><vh>org-remember-finalize</vh></v>
<v t="ekr.20100929212226.15613"><vh>org-remember-kill</vh></v>
<v t="ekr.20100929212226.15614"><vh>org-remember</vh></v>
<v t="ekr.20100929212226.15615"><vh>org-remember-goto-last-stored</vh></v>
<v t="ekr.20100929212226.15616"><vh>org-go-to-remember-target</vh></v>
<v t="ekr.20100929212226.15617"><vh>org-do-remember</vh></v>
<v t="ekr.20100929212226.15618"><vh>org-require-remember</vh></v>
</v>
<v t="ekr.20100929212226.15619"><vh>org-rmail.el</vh>
<v t="ekr.20100929212226.15620"><vh>org-rmail declarations</vh></v>
<v t="ekr.20100929212226.15621"><vh>org-rmail-store-link</vh></v>
<v t="ekr.20100929212226.15622"><vh>org-rmail-open</vh></v>
<v t="ekr.20100929212226.15623"><vh>org-rmail-follow-link</vh></v>
</v>
<v t="ekr.20100929212226.15624"><vh>org-src.el</vh>
<v t="ekr.20100929212226.15625"><vh>org-src declarations</vh></v>
<v t="ekr.20100929212226.15626"><vh>org-edit-src-code</vh></v>
<v t="ekr.20100929212226.15627"><vh>org-edit-src-continue</vh></v>
<v t="ekr.20100929212226.15628"><vh>org-src-switch-to-buffer</vh></v>
<v t="ekr.20100929212226.15629"><vh>org-src-construct-edit-buffer-name</vh></v>
<v t="ekr.20100929212226.15630"><vh>org-edit-src-find-buffer</vh></v>
<v t="ekr.20100929212226.15631"><vh>org-edit-fixed-width-region</vh></v>
<v t="ekr.20100929212226.15632"><vh>org-edit-src-find-region-and-lang</vh></v>
<v t="ekr.20100929212226.15633"><vh>org-edit-src-get-lang</vh></v>
<v t="ekr.20100929212226.15634"><vh>org-edit-src-get-label-format</vh></v>
<v t="ekr.20100929212226.15635"><vh>org-edit-src-get-indentation</vh></v>
<v t="ekr.20100929212226.15636"><vh>org-edit-src-exit</vh></v>
<v t="ekr.20100929212226.15637"><vh>org-edit-src-save</vh></v>
<v t="ekr.20100929212226.15638"><vh>org-src-mode-configure-edit-buffer</vh></v>
</v>
<v t="ekr.20100929212226.15639"><vh>org-table.el</vh>
<v t="ekr.20100929212226.15640"><vh>org-table declarations</vh></v>
<v t="ekr.20100929212226.15641"><vh>org-table-colgroup-line-p</vh></v>
<v t="ekr.20100929212226.15642"><vh>org-table-cookie-line-p</vh></v>
<v t="ekr.20100929212226.15643"><vh>org-table-create-with-table</vh></v>
<v t="ekr.20100929212226.15644"><vh>org-table-create-or-convert-from-region</vh></v>
<v t="ekr.20100929212226.15645"><vh>org-table-create</vh></v>
<v t="ekr.20100929212226.15646"><vh>org-table-convert-region</vh></v>
<v t="ekr.20100929212226.15647"><vh>org-table-import</vh></v>
<v t="ekr.20100929212226.15648"><vh>org-table-export</vh></v>
<v t="ekr.20100929212226.15649"><vh>org-table-align</vh></v>
<v t="ekr.20100929212226.15650"><vh>org-table-begin</vh></v>
<v t="ekr.20100929212226.15651"><vh>org-table-end</vh></v>
<v t="ekr.20100929212226.15652"><vh>org-table-justify-field-maybe</vh></v>
<v t="ekr.20100929212226.15653"><vh>org-table-next-field</vh></v>
<v t="ekr.20100929212226.15654"><vh>org-table-previous-field</vh></v>
<v t="ekr.20100929212226.15655"><vh>org-table-beginning-of-field</vh></v>
<v t="ekr.20100929212226.15656"><vh>org-table-end-of-field</vh></v>
<v t="ekr.20100929212226.15657"><vh>org-table-next-row</vh></v>
<v t="ekr.20100929212226.15658"><vh>org-table-copy-down</vh></v>
<v t="ekr.20100929212226.15659"><vh>org-table-check-inside-data-field</vh></v>
<v t="ekr.20100929212226.15660"><vh>org-table-get</vh></v>
<v t="ekr.20100929212226.15661"><vh>org-table-put</vh></v>
<v t="ekr.20100929212226.15662"><vh>org-table-current-line</vh></v>
<v t="ekr.20100929212226.15663"><vh>org-table-goto-line</vh></v>
<v t="ekr.20100929212226.15664"><vh>org-table-blank-field</vh></v>
<v t="ekr.20100929212226.15665"><vh>org-table-get-field</vh></v>
<v t="ekr.20100929212226.15666"><vh>org-table-field-info</vh></v>
<v t="ekr.20100929212226.15667"><vh>org-table-current-column</vh></v>
<v t="ekr.20100929212226.15668"><vh>org-table-current-dline</vh></v>
<v t="ekr.20100929212226.15669"><vh>org-table-goto-column</vh></v>
<v t="ekr.20100929212226.15670"><vh>org-table-insert-column</vh></v>
<v t="ekr.20100929212226.15671"><vh>org-table-find-dataline</vh></v>
<v t="ekr.20100929212226.15672"><vh>org-table-delete-column</vh></v>
<v t="ekr.20100929212226.15673"><vh>org-table-move-column-right</vh></v>
<v t="ekr.20100929212226.15674"><vh>org-table-move-column-left</vh></v>
<v t="ekr.20100929212226.15675"><vh>org-table-move-column</vh></v>
<v t="ekr.20100929212226.15676"><vh>org-table-move-row-down</vh></v>
<v t="ekr.20100929212226.15677"><vh>org-table-move-row-up</vh></v>
<v t="ekr.20100929212226.15678"><vh>org-table-move-row</vh></v>
<v t="ekr.20100929212226.15679"><vh>org-table-insert-row</vh></v>
<v t="ekr.20100929212226.15680"><vh>org-table-insert-hline</vh></v>
<v t="ekr.20100929212226.15681"><vh>org-table-hline-and-move</vh></v>
<v t="ekr.20100929212226.15682"><vh>org-table-clean-line</vh></v>
<v t="ekr.20100929212226.15683"><vh>org-table-kill-row</vh></v>
<v t="ekr.20100929212226.15684"><vh>org-table-sort-lines</vh></v>
<v t="ekr.20100929212226.15685"><vh>org-table-cut-region</vh></v>
<v t="ekr.20100929212226.15686"><vh>org-table-copy-region</vh></v>
<v t="ekr.20100929212226.15687"><vh>org-table-paste-rectangle</vh></v>
<v t="ekr.20100929212226.15688"><vh>org-table-convert</vh></v>
<v t="ekr.20100929212226.15689"><vh>org-table-wrap-region</vh></v>
<v t="ekr.20100929212226.15690"><vh>org-table-edit-field</vh></v>
<v t="ekr.20100929212226.15691"><vh>org-table-finish-edit-field</vh></v>
<v t="ekr.20100929212226.15692"><vh>org-table-sum</vh></v>
<v t="ekr.20100929212226.15693"><vh>org-table-get-number-for-summing</vh></v>
<v t="ekr.20100929212226.15694"><vh>org-table-current-field-formula</vh></v>
<v t="ekr.20100929212226.15695"><vh>org-table-get-formula</vh></v>
<v t="ekr.20100929212226.15696"><vh>org-table-store-formulas</vh></v>
<v t="ekr.20100929212226.15697"><vh>org-table-formula-less-p</vh></v>
<v t="ekr.20100929212226.15698"><vh>org-table-get-stored-formulas</vh></v>
<v t="ekr.20100929212226.15699"><vh>org-table-fix-formulas</vh></v>
<v t="ekr.20100929212226.15700"><vh>org-table-get-specials</vh></v>
<v t="ekr.20100929212226.15701"><vh>org-table-maybe-eval-formula</vh></v>
<v t="ekr.20100929212226.15702"><vh>org-table-rotate-recalc-marks</vh></v>
<v t="ekr.20100929212226.15703"><vh>org-table-maybe-recalculate-line</vh></v>
<v t="ekr.20100929212226.15704"><vh>org-table-eval-formula</vh></v>
<v t="ekr.20100929212226.15705"><vh>org-table-put-field-property</vh></v>
<v t="ekr.20100929212226.15706"><vh>org-table-get-range</vh></v>
<v t="ekr.20100929212226.15707"><vh>org-table-get-descriptor-line</vh></v>
<v t="ekr.20100929212226.15708"><vh>org-table-find-row-type</vh></v>
<v t="ekr.20100929212226.15709"><vh>org-table-rewrite-old-row-references</vh></v>
<v t="ekr.20100929212226.15710"><vh>org-table-make-reference</vh></v>
<v t="ekr.20100929212226.15711"><vh>org-table-recalculate</vh></v>
<v t="ekr.20100929212226.15712"><vh>org-table-iterate</vh></v>
<v t="ekr.20100929212226.15713"><vh>org-table-recalculate-buffer-tables</vh></v>
<v t="ekr.20100929212226.15714"><vh>org-table-iterate-buffer-tables</vh></v>
<v t="ekr.20100929212226.15715"><vh>org-table-formula-substitute-names</vh></v>
<v t="ekr.20100929212226.15716"><vh>org-table-get-constant</vh></v>
<v t="ekr.20100929212226.15717"><vh>org-table-edit-formulas</vh></v>
<v t="ekr.20100929212226.15718"><vh>org-table-fedit-post-command</vh></v>
<v t="ekr.20100929212226.15719"><vh>org-table-formula-to-user</vh></v>
<v t="ekr.20100929212226.15720"><vh>org-table-formula-from-user</vh></v>
<v t="ekr.20100929212226.15721"><vh>org-table-convert-refs-to-rc</vh></v>
<v t="ekr.20100929212226.15722"><vh>org-table-convert-refs-to-an</vh></v>
<v t="ekr.20100929212226.15723"><vh>org-letters-to-number</vh></v>
<v t="ekr.20100929212226.15724"><vh>org-number-to-letters</vh></v>
<v t="ekr.20100929212226.15725"><vh>org-table-fedit-convert-buffer</vh></v>
<v t="ekr.20100929212226.15726"><vh>org-table-fedit-toggle-ref-type</vh></v>
<v t="ekr.20100929212226.15727"><vh>org-table-fedit-ref-up</vh></v>
<v t="ekr.20100929212226.15728"><vh>org-table-fedit-ref-down</vh></v>
<v t="ekr.20100929212226.15729"><vh>org-table-fedit-ref-left</vh></v>
<v t="ekr.20100929212226.15730"><vh>org-table-fedit-ref-right</vh></v>
<v t="ekr.20100929212226.15731"><vh>org-table-fedit-shift-reference</vh></v>
<v t="ekr.20100929212226.15732"><vh>org-rematch-and-replace</vh></v>
<v t="ekr.20100929212226.15733"><vh>org-table-shift-refpart</vh></v>
<v t="ekr.20100929212226.15734"><vh>org-table-fedit-toggle-coordinates</vh></v>
<v t="ekr.20100929212226.15735"><vh>org-table-fedit-finish</vh></v>
<v t="ekr.20100929212226.15736"><vh>org-table-fedit-abort</vh></v>
<v t="ekr.20100929212226.15737"><vh>org-table-fedit-lisp-indent</vh></v>
<v t="ekr.20100929212226.15738"><vh>org-table-show-reference</vh></v>
<v t="ekr.20100929212226.15739"><vh>org-table-force-dataline</vh></v>
<v t="ekr.20100929212226.15740"><vh>org-table-fedit-line-up</vh></v>
<v t="ekr.20100929212226.15741"><vh>org-table-fedit-line-down</vh></v>
<v t="ekr.20100929212226.15742"><vh>org-table-fedit-move</vh></v>
<v t="ekr.20100929212226.15743"><vh>org-table-fedit-scroll</vh></v>
<v t="ekr.20100929212226.15744"><vh>org-table-fedit-scroll-down</vh></v>
<v t="ekr.20100929212226.15745"><vh>org-table-add-rectangle-overlay</vh></v>
<v t="ekr.20100929212226.15746"><vh>org-table-highlight-rectangle</vh></v>
<v t="ekr.20100929212226.15747"><vh>org-table-remove-rectangle-highlight</vh></v>
<v t="ekr.20100929212226.15748"><vh>org-table-overlay-coordinates</vh></v>
<v t="ekr.20100929212226.15749"><vh>org-table-toggle-coordinate-overlays</vh></v>
<v t="ekr.20100929212226.15750"><vh>org-table-toggle-formula-debugger</vh></v>
<v t="ekr.20100929212226.15751"><vh>turn-on-orgtbl</vh></v>
<v t="ekr.20100929212226.15752"><vh>orgtbl-setup</vh></v>
<v t="ekr.20100929212226.15753"><vh>org-table-cleanup-narrow-column-properties</vh></v>
<v t="ekr.20100929212226.15754"><vh>orgtbl-make-binding</vh></v>
<v t="ekr.20100929212226.15755"><vh>orgtbl-error</vh></v>
<v t="ekr.20100929212226.15756"><vh>orgtbl-setup</vh></v>
<v t="ekr.20100929212226.15757"><vh>orgtbl-ctrl-c-ctrl-c</vh></v>
<v t="ekr.20100929212226.15758"><vh>orgtbl-create-or-convert-from-region</vh></v>
<v t="ekr.20100929212226.15759"><vh>orgtbl-tab</vh></v>
<v t="ekr.20100929212226.15760"><vh>orgtbl-ret</vh></v>
<v t="ekr.20100929212226.15761"><vh>orgtbl-self-insert-command</vh></v>
<v t="ekr.20100929212226.15762"><vh>orgtbl-export</vh></v>
<v t="ekr.20100929212226.15763"><vh>orgtbl-gather-send-defs</vh></v>
<v t="ekr.20100929212226.15764"><vh>orgtbl-send-replace-tbl</vh></v>
<v t="ekr.20100929212226.15765"><vh>org-table-to-lisp</vh></v>
<v t="ekr.20100929212226.15766"><vh>orgtbl-send-table</vh></v>
<v t="ekr.20100929212226.15767"><vh>org-remove-by-index</vh></v>
<v t="ekr.20100929212226.15768"><vh>orgtbl-toggle-comment</vh></v>
<v t="ekr.20100929212226.15769"><vh>orgtbl-insert-radio-table</vh></v>
<v t="ekr.20100929212226.15770"><vh>orgtbl-format-line</vh></v>
<v t="ekr.20100929212226.15771"><vh>orgtbl-format-section</vh></v>
<v t="ekr.20100929212226.15772"><vh>orgtbl-to-generic</vh></v>
<v t="ekr.20100929212226.15773"><vh>orgtbl-to-tsv</vh></v>
<v t="ekr.20100929212226.15774"><vh>orgtbl-to-csv</vh></v>
<v t="ekr.20100929212226.15775"><vh>orgtbl-to-latex</vh></v>
<v t="ekr.20100929212226.15776"><vh>orgtbl-to-html</vh></v>
<v t="ekr.20100929212226.15777"><vh>orgtbl-to-texinfo</vh></v>
<v t="ekr.20100929212226.15778"><vh>orgtbl-to-orgtbl</vh></v>
<v t="ekr.20100929212226.15779"><vh>org-table-get-remote-range</vh></v>
</v>
<v t="ekr.20100929212226.15780"><vh>org-taskjuggler.el</vh>
<v t="ekr.20100929212226.15781"><vh>org-taskjuggler declarations</vh></v>
<v t="ekr.20100929212226.15782"><vh>org-export-as-taskjuggler</vh></v>
<v t="ekr.20100929212226.15783"><vh>org-export-as-taskjuggler-and-open</vh></v>
<v t="ekr.20100929212226.15784"><vh>org-taskjuggler-parent-is-ordered-p</vh></v>
<v t="ekr.20100929212226.15785"><vh>org-taskjuggler-components</vh></v>
<v t="ekr.20100929212226.15786"><vh>org-taskjuggler-assign-task-ids</vh></v>
<v t="ekr.20100929212226.15787"><vh>org-taskjuggler-assign-resource-ids</vh></v>
<v t="ekr.20100929212226.15788"><vh>org-taskjuggler-resolve-dependencies</vh></v>
<v t="ekr.20100929212226.15789"><vh>org-taskjuggler-tokenize-dependencies</vh></v>
<v t="ekr.20100929212226.15790"><vh>org-taskjuggler-resolve-explicit-dependencies</vh></v>
<v t="ekr.20100929212226.15791"><vh>org-taskjuggler-find-task-with-id</vh></v>
<v t="ekr.20100929212226.15792"><vh>org-taskjuggler-get-unique-id</vh></v>
<v t="ekr.20100929212226.15793"><vh>org-taskjuggler-clean-id</vh></v>
<v t="ekr.20100929212226.15794"><vh>org-taskjuggler-open-project</vh></v>
<v t="ekr.20100929212226.15795"><vh>org-taskjuggler-filter-and-join</vh></v>
<v t="ekr.20100929212226.15796"><vh>org-taskjuggler-get-attributes</vh></v>
<v t="ekr.20100929212226.15797"><vh>org-taskjuggler-get-attribute</vh></v>
<v t="ekr.20100929212226.15798"><vh>org-taskjuggler-open-resource</vh></v>
<v t="ekr.20100929212226.15799"><vh>org-taskjuggler-clean-effort</vh></v>
<v t="ekr.20100929212226.15800"><vh>org-taskjuggler-get-priority</vh></v>
<v t="ekr.20100929212226.15801"><vh>org-taskjuggler-open-task</vh></v>
<v t="ekr.20100929212226.15802"><vh>org-taskjuggler-close-maybe</vh></v>
<v t="ekr.20100929212226.15803"><vh>org-taskjuggler-insert-reports</vh></v>
</v>
<v t="ekr.20100929212226.15804"><vh>org-timer.el</vh>
<v t="ekr.20100929212226.15805"><vh>org-timer declarations</vh></v>
<v t="ekr.20100929212226.15806"><vh>org-timer-start</vh></v>
<v t="ekr.20100929212226.15807"><vh>org-timer-pause-or-continue</vh></v>
<v t="ekr.20100929212226.15808"><vh>org-timer-stop</vh></v>
<v t="ekr.20100929212226.15809"><vh>org-timer</vh></v>
<v t="ekr.20100929212226.15810"><vh>org-timer-value-string</vh></v>
<v t="ekr.20100929212226.15811"><vh>org-timer-seconds</vh></v>
<v t="ekr.20100929212226.15812"><vh>org-timer-change-times-in-region</vh></v>
<v t="ekr.20100929212226.15813"><vh>org-timer-item</vh></v>
<v t="ekr.20100929212226.15814"><vh>org-timer-fix-incomplete</vh></v>
<v t="ekr.20100929212226.15815"><vh>org-timer-hms-to-secs</vh></v>
<v t="ekr.20100929212226.15816"><vh>org-timer-secs-to-hms</vh></v>
<v t="ekr.20100929212226.15817"><vh>org-timer-set-mode-line</vh></v>
<v t="ekr.20100929212226.15818"><vh>org-timer-update-mode-line</vh></v>
<v t="ekr.20100929212226.15819"><vh>org-timer-cancel-timer</vh></v>
<v t="ekr.20100929212226.15820"><vh>org-timer-show-remaining-time</vh></v>
<v t="ekr.20100929212226.15821"><vh>bzg-test</vh></v>
<v t="ekr.20100929212226.15822"><vh>org-timer-set-timer</vh></v>
</v>
<v t="ekr.20100929212226.15823"><vh>org-vm.el</vh>
<v t="ekr.20100929212226.15824"><vh>org-vm declarations</vh></v>
<v t="ekr.20100929212226.15825"><vh>org-vm-store-link</vh></v>
<v t="ekr.20100929212226.15826"><vh>org-vm-open</vh></v>
<v t="ekr.20100929212226.15827"><vh>org-vm-follow-link</vh></v>
</v>
<v t="ekr.20100929212226.15828"><vh>org-w3m.el</vh>
<v t="ekr.20100929212226.15829"><vh>org-w3m declarations</vh></v>
<v t="ekr.20100929212226.15830"><vh>org-w3m-copy-for-org-mode</vh></v>
<v t="ekr.20100929212226.15831"><vh>org-w3m-get-anchor-start</vh></v>
<v t="ekr.20100929212226.15832"><vh>org-w3m-get-anchor-end</vh></v>
<v t="ekr.20100929212226.15833"><vh>org-w3m-get-next-link-start</vh></v>
<v t="ekr.20100929212226.15834"><vh>org-w3m-get-prev-link-start</vh></v>
<v t="ekr.20100929212226.15835"><vh>org-w3m-no-next-link-p</vh></v>
<v t="ekr.20100929212226.15836"><vh>org-w3m-no-prev-link-p</vh></v>
</v>
<v t="ekr.20100929212226.15837"><vh>org-wl.el</vh>
<v t="ekr.20100929212226.15838"><vh>org-wl declarations</vh></v>
<v t="ekr.20100929212226.15839"><vh>org-wl-folder-type</vh></v>
<v t="ekr.20100929212226.15840"><vh>org-wl-message-field</vh></v>
<v t="ekr.20100929212226.15841"><vh>org-wl-store-link</vh></v>
<v t="ekr.20100929212226.15842"><vh>org-wl-store-link-folder</vh></v>
<v t="ekr.20100929212226.15843"><vh>org-wl-store-link-message</vh></v>
<v t="ekr.20100929212226.15844"><vh>org-wl-open</vh></v>
</v>
<v t="ekr.20100929212226.15845"><vh>org-xoxo.el</vh>
<v t="ekr.20100929212226.15846"><vh>org-xoxo declarations</vh></v>
<v t="ekr.20100929212226.15847"><vh>org-export-as-xoxo-insert-into</vh></v>
<v t="ekr.20100929212226.15848"><vh>org-export-as-xoxo</vh></v>
</v>
</v>
<v t="ekr.20100930104733.11882" a="E"><vh>org.el</vh>
<v t="ekr.20100930104733.11883"><vh>&lt;&lt; org copyright &gt;&gt;</vh></v>
<v t="ekr.20100930104733.11884"><vh>&lt;&lt; org commentary &gt;&gt;</vh></v>
<v t="ekr.20100930104733.11885"><vh>&lt;&lt; org declarations &gt;&gt;</vh></v>
<v t="ekr.20100930104733.11886"><vh>org-babel-do-load-languages</vh></v>
<v t="ekr.20100930104733.11887"><vh>org-babel-load-languages</vh></v>
<v t="ekr.20100930104733.11888"><vh>Customization variables</vh>
<v t="ekr.20100930104733.11889"><vh>org-version</vh></v>
<v t="ekr.20100930104733.11890"><vh>org-load-modules-maybe</vh></v>
<v t="ekr.20100930104733.11891"><vh>org-set-modules</vh></v>
<v t="ekr.20100930104733.11892"><vh>org-key</vh></v>
<v t="ekr.20100930104733.11893"><vh>org-find-if</vh></v>
<v t="ekr.20100930104733.11894"><vh>org-defkey</vh></v>
<v t="ekr.20100930104733.11895"><vh>org-log-into-drawer</vh></v>
<v t="ekr.20100930104733.11896"><vh>org-time-stamp-format</vh></v>
<v t="ekr.20100930104733.11897"><vh>org-tag-inherit-p</vh></v>
<v t="ekr.20100930104733.11898"><vh>org-property-inherit-p</vh></v>
<v t="ekr.20100930104733.11899"><vh>org-set-packages-alist</vh></v>
<v t="ekr.20100930104733.11900"><vh>org-get-packages-alist</vh></v>
<v t="ekr.20100930104733.11901"><vh>org-set-emph-re</vh></v>
<v t="ekr.20100930104733.11902"><vh>org-at-table-p</vh></v>
<v t="ekr.20100930104733.11903"><vh>org-at-table</vh></v>
<v t="ekr.20100930104733.11904"><vh>org-table-recognize-table</vh></v>
<v t="ekr.20100930104733.11905"><vh>org-at-table-hline-p</vh></v>
<v t="ekr.20100930104733.11906"><vh>org-table-map-tables</vh></v>
<v t="ekr.20100930104733.11907"><vh>org-clock-is-active</vh></v>
<v t="ekr.20100930104733.11908"><vh>org-clock-update-time-maybe</vh></v>
<v t="ekr.20100930104733.11909"><vh>org-check-running-clock</vh></v>
<v t="ekr.20100930104733.11910"><vh>org-clocktable-try-shift</vh></v>
<v t="ekr.20100930104733.11911"><vh>org-cycle-hide-archived-subtrees</vh></v>
<v t="ekr.20100930104733.11912"><vh>org-force-cycle-archived</vh></v>
<v t="ekr.20100930104733.11913"><vh>org-hide-archived-subtrees</vh></v>
<v t="ekr.20100930104733.11914"><vh>org-flag-subtree</vh></v>
<v t="ekr.20100930104733.11915"><vh>org-set-regexps-and-options</vh></v>
<v t="ekr.20100930104733.11916"><vh>org-file-contents</vh></v>
<v t="ekr.20100930104733.11917"><vh>org-extract-log-state-settings</vh></v>
<v t="ekr.20100930104733.11918"><vh>org-remove-keyword-keys</vh></v>
<v t="ekr.20100930104733.11919"><vh>org-assign-fast-keys</vh></v>
</v>
<v t="ekr.20100930104733.11920"><vh>Define org mode</vh>
<v t="ekr.20100930104733.11921"><vh>variables</vh></v>
<v t="ekr.20100930104733.11922"><vh>org-mode</vh></v>
<v t="ekr.20100930104733.11923"><vh>org-current-time</vh></v>
</v>
<v t="ekr.20100930104733.11924"><vh>Font-lock stuff</vh>
<v t="ekr.20100930104733.11925"><vh>org-create-multibrace-regexp</vh></v>
<v t="ekr.20100930104733.11926"><vh>org-make-link-regexps</vh></v>
<v t="ekr.20100930104733.11927"><vh>org-do-emphasis-faces</vh></v>
<v t="ekr.20100930104733.11928"><vh>org-emphasize</vh></v>
<v t="ekr.20100930104733.11929"><vh>org-activate-plain-links</vh></v>
<v t="ekr.20100930104733.11930"><vh>org-activate-code</vh></v>
<v t="ekr.20100930104733.11931"><vh>org-fontify-meta-lines-and-blocks</vh></v>
<v t="ekr.20100930104733.11932"><vh>org-activate-angle-links</vh></v>
<v t="ekr.20100930104733.11933"><vh>org-activate-footnote-links</vh></v>
<v t="ekr.20100930104733.11934"><vh>org-activate-bracket-links</vh></v>
<v t="ekr.20100930104733.11935"><vh>org-activate-dates</vh></v>
<v t="ekr.20100930104733.11936"><vh>org-activate-target-links</vh></v>
<v t="ekr.20100930104733.11937"><vh>org-update-radio-target-regexp</vh></v>
<v t="ekr.20100930104733.11938"><vh>org-hide-wide-columns</vh></v>
<v t="ekr.20100930104733.11939"><vh>org-compute-latex-and-specials-regexp</vh></v>
<v t="ekr.20100930104733.11940"><vh>org-do-latex-and-special-faces</vh></v>
<v t="ekr.20100930104733.11941"><vh>org-restart-font-lock</vh></v>
<v t="ekr.20100930104733.11942"><vh>org-all-targets</vh></v>
<v t="ekr.20100930104733.11943"><vh>org-make-target-link-regexp</vh></v>
<v t="ekr.20100930104733.11944"><vh>org-activate-tags</vh></v>
<v t="ekr.20100930104733.11945"><vh>org-outline-level</vh></v>
<v t="ekr.20100930104733.11946"><vh>org-font-lock-hook</vh></v>
<v t="ekr.20100930104733.11947"><vh>org-set-font-lock-defaults</vh></v>
<v t="ekr.20100930104733.11948"><vh>org-toggle-pretty-entities</vh></v>
<v t="ekr.20100930104733.11949"><vh>org-fontify-entities</vh></v>
<v t="ekr.20100930104733.11950"><vh>org-fontify-like-in-org-mode</vh></v>
<v t="ekr.20100930104733.11951"><vh>org-get-level-face</vh></v>
<v t="ekr.20100930104733.11952"><vh>org-get-todo-face</vh></v>
<v t="ekr.20100930104733.11953"><vh>org-face-from-face-or-color</vh></v>
<v t="ekr.20100930104733.11954"><vh>org-font-lock-add-tag-faces</vh></v>
<v t="ekr.20100930104733.11955"><vh>org-font-lock-add-priority-faces</vh></v>
<v t="ekr.20100930104733.11956"><vh>org-get-tag-face</vh></v>
<v t="ekr.20100930104733.11957"><vh>org-unfontify-region</vh></v>
<v t="ekr.20100930104733.11958"><vh>org-remove-font-lock-display-properties</vh></v>
<v t="ekr.20100930104733.11959"><vh>org-raise-scripts</vh></v>
</v>
<v t="ekr.20100930104733.11960"><vh>Visibility cycling</vh>
<v t="ekr.20100930104733.11961"><vh>org-cycle</vh></v>
<v t="ekr.20100930104733.11962"><vh>org-cycle-internal-global</vh></v>
<v t="ekr.20100930104733.11963"><vh>org-cycle-internal-local</vh></v>
<v t="ekr.20100930104733.11964"><vh>org-global-cycle</vh></v>
<v t="ekr.20100930104733.11965"><vh>org-set-startup-visibility</vh></v>
<v t="ekr.20100930104733.11966"><vh>org-set-visibility-according-to-property</vh></v>
<v t="ekr.20100930104733.11967"><vh>org-overview</vh></v>
<v t="ekr.20100930104733.11968"><vh>org-content</vh></v>
<v t="ekr.20100930104733.11969"><vh>org-optimize-window-after-visibility-change</vh></v>
<v t="ekr.20100930104733.11970"><vh>org-remove-empty-overlays-at</vh></v>
<v t="ekr.20100930104733.11971"><vh>org-clean-visibility-after-subtree-move</vh></v>
<v t="ekr.20100930104733.11972"><vh>org-cycle-show-empty-lines</vh></v>
<v t="ekr.20100930104733.11973"><vh>org-show-empty-lines-in-parent</vh></v>
<v t="ekr.20100930104733.11974"><vh>org-files-list</vh></v>
<v t="ekr.20100930104733.11975"><vh>org-cycle-hide-drawers</vh></v>
<v t="ekr.20100930104733.11976"><vh>org-flag-drawer</vh></v>
<v t="ekr.20100930104733.11977"><vh>org-subtree-end-visible-p</vh></v>
<v t="ekr.20100930104733.11978"><vh>org-first-headline-recenter</vh></v>
<v t="ekr.20100930104733.11979"><vh>org-outline-overlay-data</vh></v>
<v t="ekr.20100930104733.11980"><vh>org-set-outline-overlay-data</vh></v>
<v t="ekr.20100930104733.11981"><vh>org-block-map</vh></v>
<v t="ekr.20100930104733.11982"><vh>org-hide-block-toggle-all</vh></v>
<v t="ekr.20100930104733.11983"><vh>org-hide-block-all</vh></v>
<v t="ekr.20100930104733.11984"><vh>org-show-block-all</vh></v>
<v t="ekr.20100930104733.11985"><vh>org-hide-block-toggle</vh></v>
<v t="ekr.20100930104733.11986"><vh>org-goto</vh></v>
<v t="ekr.20100930104733.11987"><vh>org-get-location</vh></v>
<v t="ekr.20100930104733.11988"><vh>org-goto-local-search-headings</vh></v>
<v t="ekr.20100930104733.11989"><vh>org-goto-local-auto-isearch</vh></v>
<v t="ekr.20100930104733.11990"><vh>org-goto-ret</vh></v>
<v t="ekr.20100930104733.11991"><vh>org-goto-left</vh></v>
<v t="ekr.20100930104733.11992"><vh>org-goto-right</vh></v>
<v t="ekr.20100930104733.11993"><vh>org-goto-quit</vh></v>
<v t="ekr.20100930104733.11994"><vh>org-tree-to-indirect-buffer</vh></v>
<v t="ekr.20100930104733.11995"><vh>org-get-indirect-buffer</vh></v>
<v t="ekr.20100930104733.11996"><vh>org-set-frame-title</vh></v>
</v>
<v t="ekr.20100930104733.11997"><vh>Structure editing</vh>
<v t="ekr.20100930104733.11998"><vh>org-previous-line-empty-p</vh></v>
<v t="ekr.20100930104733.11999"><vh>org-insert-heading</vh></v>
<v t="ekr.20100930104733.12000"><vh>org-get-heading</vh></v>
<v t="ekr.20100930104733.12001"><vh>org-heading-components</vh></v>
<v t="ekr.20100930104733.12002"><vh>org-get-entry</vh></v>
<v t="ekr.20100930104733.12003"><vh>org-insert-heading-after-current</vh></v>
<v t="ekr.20100930104733.12004"><vh>org-insert-heading-respect-content</vh></v>
<v t="ekr.20100930104733.12005"><vh>org-insert-todo-heading-respect-content</vh></v>
<v t="ekr.20100930104733.12006"><vh>org-insert-todo-heading</vh></v>
<v t="ekr.20100930104733.12007"><vh>org-insert-subheading</vh></v>
<v t="ekr.20100930104733.12008"><vh>org-insert-todo-subheading</vh></v>
<v t="ekr.20100930104733.12009"><vh>org-promote-subtree</vh></v>
<v t="ekr.20100930104733.12010"><vh>org-demote-subtree</vh></v>
<v t="ekr.20100930104733.12011"><vh>org-do-promote</vh></v>
<v t="ekr.20100930104733.12012"><vh>org-do-demote</vh></v>
<v t="ekr.20100930104733.12013"><vh>org-fix-position-after-promote</vh></v>
<v t="ekr.20100930104733.12014"><vh>org-current-level</vh></v>
<v t="ekr.20100930104733.12015"><vh>org-get-previous-line-level</vh></v>
<v t="ekr.20100930104733.12016"><vh>org-reduced-level</vh></v>
<v t="ekr.20100930104733.12017"><vh>org-level-increment</vh></v>
<v t="ekr.20100930104733.12018"><vh>org-get-valid-level</vh></v>
<v t="ekr.20100930104733.12019"><vh>org-promote</vh></v>
<v t="ekr.20100930104733.12020"><vh>org-demote</vh></v>
<v t="ekr.20100930104733.12021"><vh>org-cycle-level</vh></v>
<v t="ekr.20100930104733.12022"><vh>org-map-tree</vh></v>
<v t="ekr.20100930104733.12023"><vh>org-map-region</vh></v>
<v t="ekr.20100930104733.12024"><vh>org-fixup-indentation</vh></v>
<v t="ekr.20100930104733.12025"><vh>org-convert-to-odd-levels</vh></v>
<v t="ekr.20100930104733.12026"><vh>org-convert-to-oddeven-levels</vh></v>
<v t="ekr.20100930104733.12027"><vh>org-tr-level</vh></v>
<v t="ekr.20100930104733.12028"><vh>org-move-subtree-up</vh></v>
<v t="ekr.20100930104733.12029"><vh>org-move-subtree-down</vh></v>
<v t="ekr.20100930104733.12030"><vh>org-cut-subtree</vh></v>
<v t="ekr.20100930104733.12031"><vh>org-copy-subtree</vh></v>
<v t="ekr.20100930104733.12032"><vh>org-paste-subtree</vh></v>
<v t="ekr.20100930104733.12033"><vh>org-kill-is-subtree-p</vh></v>
<v t="ekr.20100930104733.12034"><vh>org-save-markers-in-region</vh></v>
<v t="ekr.20100930104733.12035"><vh>org-check-and-save-marker</vh></v>
<v t="ekr.20100930104733.12036"><vh>org-reinstall-markers-in-region</vh></v>
<v t="ekr.20100930104733.12037"><vh>org-narrow-to-subtree</vh></v>
<v t="ekr.20100930104733.12038"><vh>org-clone-subtree-with-time-shift</vh></v>
<v t="ekr.20100930104733.12039"><vh>org-sort</vh></v>
<v t="ekr.20100930104733.12040"><vh>org-sort-remove-invisible</vh></v>
<v t="ekr.20100930104733.12041"><vh>org-sort-entries-or-items</vh></v>
<v t="ekr.20100930104733.12042"><vh>org-do-sort</vh></v>
<v t="ekr.20100930104733.12043"><vh>orgstruct-setup</vh></v>
<v t="ekr.20100930104733.12044"><vh>turn-on-orgstruct</vh></v>
<v t="ekr.20100930104733.12045"><vh>orgstruct</vh></v>
<v t="ekr.20100930104733.12046"><vh>turn-on-orgstruct</vh></v>
<v t="ekr.20100930104733.12047"><vh>orgstruct-error</vh></v>
<v t="ekr.20100930104733.12048"><vh>orgstruct-setup</vh></v>
<v t="ekr.20100930104733.12049"><vh>orgstruct-make-binding</vh></v>
<v t="ekr.20100930104733.12050"><vh>org-context-p</vh></v>
<v t="ekr.20100930104733.12051"><vh>org-get-local-variables</vh></v>
<v t="ekr.20100930104733.12052"><vh>org-run-like-in-org-mode</vh></v>
</v>
<v t="ekr.20100930104733.12053"><vh>Archiving</vh>
<v t="ekr.20100930104733.12054"><vh>org-get-category</vh></v>
<v t="ekr.20100930104733.12055"><vh>org-refresh-category-properties</vh></v>
</v>
<v t="ekr.20100930104733.12056"><vh>Link stuff</vh>
<v t="ekr.20100930104733.12057"><vh>org-link-expand-abbrev</vh></v>
<v t="ekr.20100930104733.12058"><vh>org-add-link-type</vh></v>
<v t="ekr.20100930104733.12059"><vh>org-store-link</vh></v>
<v t="ekr.20100930104733.12060"><vh>org-store-link-props</vh></v>
<v t="ekr.20100930104733.12061"><vh>org-add-link-props</vh></v>
<v t="ekr.20100930104733.12062"><vh>org-email-link-description</vh></v>
<v t="ekr.20100930104733.12063"><vh>org-make-org-heading-search-string</vh></v>
<v t="ekr.20100930104733.12064"><vh>org-make-link</vh></v>
<v t="ekr.20100930104733.12065"><vh>org-make-link-string</vh></v>
<v t="ekr.20100930104733.12066"><vh>org-link-escape</vh></v>
<v t="ekr.20100930104733.12067"><vh>org-link-unescape</vh></v>
<v t="ekr.20100930104733.12068"><vh>org-xor</vh></v>
<v t="ekr.20100930104733.12069"><vh>org-fixup-message-id-for-http</vh></v>
<v t="ekr.20100930104733.12070"><vh>org-insert-link-global</vh></v>
<v t="ekr.20100930104733.12071"><vh>org-insert-link</vh></v>
<v t="ekr.20100930104733.12072"><vh>org-link-try-special-completion</vh></v>
<v t="ekr.20100930104733.12073"><vh>org-file-complete-link</vh></v>
<v t="ekr.20100930104733.12074"><vh>org-completing-read</vh></v>
<v t="ekr.20100930104733.12075"><vh>org-completing-read-no-i</vh></v>
<v t="ekr.20100930104733.12076"><vh>org-iswitchb-completing-read</vh></v>
<v t="ekr.20100930104733.12077"><vh>org-icompleting-read</vh></v>
<v t="ekr.20100930104733.12078"><vh>org-extract-attributes</vh></v>
<v t="ekr.20100930104733.12079"><vh>org-extract-attributes-from-string</vh></v>
<v t="ekr.20100930104733.12080"><vh>org-attributes-to-string</vh></v>
<v t="ekr.20100930104733.12081"><vh>org-next-link</vh></v>
<v t="ekr.20100930104733.12082"><vh>org-previous-link</vh></v>
<v t="ekr.20100930104733.12083"><vh>org-translate-link</vh></v>
<v t="ekr.20100930104733.12084"><vh>org-translate-link-from-planner</vh></v>
<v t="ekr.20100930104733.12085"><vh>org-find-file-at-mouse</vh></v>
<v t="ekr.20100930104733.12086"><vh>org-open-at-mouse</vh></v>
<v t="ekr.20100930104733.12087"><vh>org-open-at-point-global</vh></v>
<v t="ekr.20100930104733.12088"><vh>org-open-link-from-string</vh></v>
<v t="ekr.20100930104733.12089"><vh>org-open-at-point</vh></v>
<v t="ekr.20100930104733.12090"><vh>org-offer-links-in-entry</vh></v>
<v t="ekr.20100930104733.12091"><vh>org-open-file-with-system</vh></v>
<v t="ekr.20100930104733.12092"><vh>org-open-file-with-emacs</vh></v>
<v t="ekr.20100930104733.12093"><vh>org-remove-file-link-modifiers</vh></v>
<v t="ekr.20100930104733.12094"><vh>org-get-effort</vh></v>
</v>
<v t="ekr.20100930104733.12095"><vh>Time estimates</vh>
<v t="ekr.20100930104733.12096"><vh>org-link-search</vh></v>
<v t="ekr.20100930104733.12097"><vh>org-search-not-self</vh></v>
<v t="ekr.20100930104733.12098"><vh>org-get-buffer-for-internal-link</vh></v>
<v t="ekr.20100930104733.12099"><vh>org-do-occur</vh></v>
<v t="ekr.20100930104733.12100"><vh>org-mark-ring-push</vh></v>
<v t="ekr.20100930104733.12101"><vh>org-mark-ring-goto</vh></v>
<v t="ekr.20100930104733.12102"><vh>org-remove-angle-brackets</vh></v>
<v t="ekr.20100930104733.12103"><vh>org-add-angle-brackets</vh></v>
<v t="ekr.20100930104733.12104"><vh>org-remove-double-quotes</vh></v>
<v t="ekr.20100930104733.12105"><vh>org-follow-timestamp-link</vh></v>
<v t="ekr.20100930104733.12106"><vh>org-open-file</vh></v>
<v t="ekr.20100930104733.12107"><vh>org-file-apps-entry-match-against-dlink-p</vh></v>
<v t="ekr.20100930104733.12108"><vh>org-default-apps</vh></v>
<v t="ekr.20100930104733.12109"><vh>org-apps-regexp-alist</vh></v>
<v t="ekr.20100930104733.12110"><vh>org-file-remote-p</vh></v>
</v>
<v t="ekr.20100930104733.12111"><vh>Refiling</vh>
<v t="ekr.20100930104733.12112"><vh>org-get-org-file</vh></v>
<v t="ekr.20100930104733.12113"><vh>org-notes-order-reversed-p</vh></v>
<v t="ekr.20100930104733.12114"><vh>org-refile-marker</vh></v>
<v t="ekr.20100930104733.12115"><vh>org-refile-cache-clear</vh></v>
<v t="ekr.20100930104733.12116"><vh>org-refile-cache-check-set</vh></v>
<v t="ekr.20100930104733.12117"><vh>org-refile-cache-put</vh></v>
<v t="ekr.20100930104733.12118"><vh>org-refile-cache-get</vh></v>
<v t="ekr.20100930104733.12119"><vh>org-get-refile-targets</vh></v>
<v t="ekr.20100930104733.12120"><vh>org-protect-slash</vh></v>
<v t="ekr.20100930104733.12121"><vh>org-get-outline-path</vh></v>
<v t="ekr.20100930104733.12122"><vh>org-format-outline-path</vh></v>
<v t="ekr.20100930104733.12123"><vh>org-display-outline-path</vh></v>
<v t="ekr.20100930104733.12124"><vh>org-refile</vh></v>
<v t="ekr.20100930104733.12125"><vh>org-refile-goto-last-stored</vh></v>
<v t="ekr.20100930104733.12126"><vh>org-refile-get-location</vh></v>
<v t="ekr.20100930104733.12127"><vh>org-refile-new-child</vh></v>
<v t="ekr.20100930104733.12128"><vh>org-olpath-completing-read</vh></v>
</v>
<v t="ekr.20100930104733.12129"><vh>Dynamic blocks</vh>
<v t="ekr.20100930104733.12130"><vh>org-find-dblock</vh></v>
<v t="ekr.20100930104733.12131"><vh>org-create-dblock</vh></v>
<v t="ekr.20100930104733.12132"><vh>org-prepare-dblock</vh></v>
<v t="ekr.20100930104733.12133"><vh>org-map-dblocks</vh></v>
<v t="ekr.20100930104733.12134"><vh>org-dblock-update</vh></v>
<v t="ekr.20100930104733.12135"><vh>org-update-dblock</vh></v>
<v t="ekr.20100930104733.12136"><vh>org-beginning-of-dblock</vh></v>
<v t="ekr.20100930104733.12137"><vh>org-update-all-dblocks</vh></v>
</v>
<v t="ekr.20100930104733.12138"><vh>Completion</vh>
<v t="ekr.20100930104733.12139"><vh>org-try-structure-completion</vh></v>
<v t="ekr.20100930104733.12140"><vh>org-complete-expand-structure-template</vh></v>
<v t="ekr.20100930104733.12141"><vh>org-complete</vh></v>
</v>
<v t="ekr.20100930104733.12142"><vh>Todo deadline comments</vh>
<v t="ekr.20100930104733.12143"><vh>org-toggle-comment</vh></v>
<v t="ekr.20100930104733.12144"><vh>org-parse-local-options</vh></v>
<v t="ekr.20100930104733.12145"><vh>org-todo</vh></v>
<v t="ekr.20100930104733.12146"><vh>org-toggle-ordered-property</vh></v>
<v t="ekr.20100930104733.12147"><vh>org-entry-blocked-p</vh></v>
<v t="ekr.20100930104733.12148"><vh>org-update-statistics-cookies</vh></v>
<v t="ekr.20100930104733.12149"><vh>org-update-parent-todo-statistics</vh></v>
<v t="ekr.20100930104733.12150"><vh>org-todo-trigger-tag-changes</vh></v>
<v t="ekr.20100930104733.12151"><vh>org-local-logging</vh></v>
<v t="ekr.20100930104733.12152"><vh>org-get-todo-sequence-head</vh></v>
<v t="ekr.20100930104733.12153"><vh>org-fast-todo-selection</vh></v>
<v t="ekr.20100930104733.12154"><vh>org-entry-is-todo-p</vh></v>
<v t="ekr.20100930104733.12155"><vh>org-entry-is-done-p</vh></v>
<v t="ekr.20100930104733.12156"><vh>org-get-todo-state</vh></v>
<v t="ekr.20100930104733.12157"><vh>org-at-date-range-p</vh></v>
<v t="ekr.20100930104733.12158"><vh>org-get-repeat</vh></v>
<v t="ekr.20100930104733.12159"><vh>org-auto-repeat-maybe</vh></v>
<v t="ekr.20100930104733.12160"><vh>org-show-todo-tree</vh></v>
<v t="ekr.20100930104733.12161"><vh>org-deadline</vh></v>
<v t="ekr.20100930104733.12162"><vh>org-schedule</vh></v>
<v t="ekr.20100930104733.12163"><vh>org-get-scheduled-time</vh></v>
<v t="ekr.20100930104733.12164"><vh>org-get-deadline-time</vh></v>
<v t="ekr.20100930104733.12165"><vh>org-remove-timestamp-with-keyword</vh></v>
<v t="ekr.20100930104733.12166"><vh>org-add-planning-info</vh></v>
<v t="ekr.20100930104733.12167"><vh>org-add-note</vh></v>
<v t="ekr.20100930104733.12168"><vh>org-add-log-setup</vh></v>
<v t="ekr.20100930104733.12169"><vh>org-skip-over-state-notes</vh></v>
<v t="ekr.20100930104733.12170"><vh>org-add-log-note</vh></v>
<v t="ekr.20100930104733.12171"><vh>org-store-log-note</vh></v>
<v t="ekr.20100930104733.12172"><vh>org-remove-empty-drawer-at</vh></v>
<v t="ekr.20100930104733.12173"><vh>org-sparse-tree</vh></v>
<v t="ekr.20100930104733.12174"><vh>org-occur</vh></v>
<v t="ekr.20100930104733.12175"><vh>org-show-context</vh></v>
<v t="ekr.20100930104733.12176"><vh>org-reveal</vh></v>
<v t="ekr.20100930104733.12177"><vh>org-highlight-new-match</vh></v>
<v t="ekr.20100930104733.12178"><vh>org-remove-occur-highlights</vh></v>
</v>
<v t="ekr.20100930104733.12179"><vh>Priorities</vh>
<v t="ekr.20100930104733.12180"><vh>org-priority-up</vh></v>
<v t="ekr.20100930104733.12181"><vh>org-priority-down</vh></v>
<v t="ekr.20100930104733.12182"><vh>org-priority</vh></v>
<v t="ekr.20100930104733.12183"><vh>org-get-priority</vh></v>
</v>
<v t="ekr.20100930104733.12184"><vh>Tags</vh>
<v t="ekr.20100930104733.12185"><vh>org-scan-tags</vh></v>
<v t="ekr.20100930104733.12186"><vh>org-remove-uniherited-tags</vh></v>
<v t="ekr.20100930104733.12187"><vh>org-match-sparse-tree</vh></v>
<v t="ekr.20100930104733.12188"><vh>org-cached-entry-get</vh></v>
<v t="ekr.20100930104733.12189"><vh>org-global-tags-completion-table</vh></v>
<v t="ekr.20100930104733.12190"><vh>org-make-tags-matcher</vh></v>
<v t="ekr.20100930104733.12191"><vh>org-op-to-function</vh></v>
<v t="ekr.20100930104733.12192"><vh>org</vh></v>
<v t="ekr.20100930104733.12193"><vh>org-string</vh></v>
<v t="ekr.20100930104733.12194"><vh>org-string</vh></v>
<v t="ekr.20100930104733.12195"><vh>org-string</vh></v>
<v t="ekr.20100930104733.12196"><vh>org-string</vh></v>
<v t="ekr.20100930104733.12197"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12198"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12199"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12200"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12201"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12202"><vh>org-time</vh></v>
<v t="ekr.20100930104733.12203"><vh>org-2ft</vh></v>
<v t="ekr.20100930104733.12204"><vh>org-time-today</vh></v>
<v t="ekr.20100930104733.12205"><vh>org-matcher-time</vh></v>
<v t="ekr.20100930104733.12206"><vh>org-match-any-p</vh></v>
<v t="ekr.20100930104733.12207"><vh>org-get-local-tags-at</vh></v>
<v t="ekr.20100930104733.12208"><vh>org-get-local-tags</vh></v>
<v t="ekr.20100930104733.12209"><vh>org-get-tags-at</vh></v>
<v t="ekr.20100930104733.12210"><vh>org-add-prop-inherited</vh></v>
<v t="ekr.20100930104733.12211"><vh>org-toggle-tag</vh></v>
<v t="ekr.20100930104733.12212"><vh>org-align-tags-here</vh></v>
<v t="ekr.20100930104733.12213"><vh>org-set-tags-command</vh></v>
<v t="ekr.20100930104733.12214"><vh>org-set-tags-to</vh></v>
<v t="ekr.20100930104733.12215"><vh>org-align-all-tags</vh></v>
<v t="ekr.20100930104733.12216"><vh>org-set-tags</vh></v>
<v t="ekr.20100930104733.12217"><vh>org-change-tag-in-region</vh></v>
<v t="ekr.20100930104733.12218"><vh>org-tags-completion-function</vh></v>
<v t="ekr.20100930104733.12219"><vh>org-fast-tag-insert</vh></v>
<v t="ekr.20100930104733.12220"><vh>org-fast-tag-show-exit</vh></v>
<v t="ekr.20100930104733.12221"><vh>org-set-current-tags-overlay</vh></v>
<v t="ekr.20100930104733.12222"><vh>org-fast-tag-selection</vh></v>
<v t="ekr.20100930104733.12223"><vh>org-get-tags-string</vh></v>
<v t="ekr.20100930104733.12224"><vh>org-get-tags</vh></v>
<v t="ekr.20100930104733.12225"><vh>org-get-buffer-tags</vh></v>
</v>
<v t="ekr.20100930104733.12226"><vh>The mapping api</vh>
<v t="ekr.20100930104733.12227"><vh>org-map-entries</vh></v>
</v>
<v t="ekr.20100930104733.12228"><vh>Properties</vh>
<v t="ekr.20100930104733.12229"><vh>org-property-action</vh></v>
<v t="ekr.20100930104733.12230"><vh>org-set-effort</vh></v>
<v t="ekr.20100930104733.12231"><vh>org-at-property-p</vh></v>
<v t="ekr.20100930104733.12232"><vh>org-get-property-block</vh></v>
<v t="ekr.20100930104733.12233"><vh>org-entry-properties</vh></v>
<v t="ekr.20100930104733.12234"><vh>org-entry-get</vh></v>
<v t="ekr.20100930104733.12235"><vh>org-property-or-variable-value</vh></v>
<v t="ekr.20100930104733.12236"><vh>org-entry-delete</vh></v>
<v t="ekr.20100930104733.12237"><vh>org-entry-add-to-multivalued-property</vh></v>
<v t="ekr.20100930104733.12238"><vh>org-entry-remove-from-multivalued-property</vh></v>
<v t="ekr.20100930104733.12239"><vh>org-entry-member-in-multivalued-property</vh></v>
<v t="ekr.20100930104733.12240"><vh>org-entry-get-multivalued-property</vh></v>
<v t="ekr.20100930104733.12241"><vh>org-entry-put-multivalued-property</vh></v>
<v t="ekr.20100930104733.12242"><vh>org-entry-protect-space</vh></v>
<v t="ekr.20100930104733.12243"><vh>org-entry-restore-space</vh></v>
<v t="ekr.20100930104733.12244"><vh>org-entry-get-with-inheritance</vh></v>
<v t="ekr.20100930104733.12245"><vh>org-entry-put</vh></v>
<v t="ekr.20100930104733.12246"><vh>org-buffer-property-keys</vh></v>
<v t="ekr.20100930104733.12247"><vh>org-property-values</vh></v>
<v t="ekr.20100930104733.12248"><vh>org-insert-property-drawer</vh></v>
<v t="ekr.20100930104733.12249"><vh>org-set-property</vh></v>
<v t="ekr.20100930104733.12250"><vh>org-delete-property</vh></v>
<v t="ekr.20100930104733.12251"><vh>org-delete-property-globally</vh></v>
<v t="ekr.20100930104733.12252"><vh>org-compute-property-at-point</vh></v>
<v t="ekr.20100930104733.12253"><vh>org-property-get-allowed-values</vh></v>
<v t="ekr.20100930104733.12254"><vh>org-property-previous-allowed-value</vh></v>
<v t="ekr.20100930104733.12255"><vh>org-property-next-allowed-value</vh></v>
<v t="ekr.20100930104733.12256"><vh>org-find-olp</vh></v>
<v t="ekr.20100930104733.12257"><vh>org-find-entry-with-id</vh></v>
</v>
<v t="ekr.20100930104733.12258"><vh>Timestamps</vh>
<v t="ekr.20100930104733.12259"><vh>org-time-stamp</vh></v>
<v t="ekr.20100930104733.12260"><vh>org-get-compact-tod</vh></v>
<v t="ekr.20100930104733.12261"><vh>org-time-stamp-inactive</vh></v>
<v t="ekr.20100930104733.12262"><vh>org-read-date</vh></v>
<v t="ekr.20100930104733.12263"><vh>org-read-date-display</vh></v>
<v t="ekr.20100930104733.12264"><vh>org-read-date-analyze</vh></v>
<v t="ekr.20100930104733.12265"><vh>org-read-date-get-relative</vh></v>
<v t="ekr.20100930104733.12266"><vh>org-order-calendar-date-args</vh></v>
<v t="ekr.20100930104733.12267"><vh>org-eval-in-calendar</vh></v>
<v t="ekr.20100930104733.12268"><vh>org-calendar-select</vh></v>
<v t="ekr.20100930104733.12269"><vh>org-insert-time-stamp</vh></v>
<v t="ekr.20100930104733.12270"><vh>org-toggle-time-stamp-overlays</vh></v>
<v t="ekr.20100930104733.12271"><vh>org-display-custom-time</vh></v>
<v t="ekr.20100930104733.12272"><vh>org-translate-time</vh></v>
<v t="ekr.20100930104733.12273"><vh>org-fix-decoded-time</vh></v>
<v t="ekr.20100930104733.12274"><vh>org-days-to-time</vh></v>
<v t="ekr.20100930104733.12275"><vh>org-deadline-close</vh></v>
<v t="ekr.20100930104733.12276"><vh>org-get-wdays</vh></v>
<v t="ekr.20100930104733.12277"><vh>org-calendar-select-mouse</vh></v>
<v t="ekr.20100930104733.12278"><vh>org-check-deadlines</vh></v>
<v t="ekr.20100930104733.12279"><vh>org-check-before-date</vh></v>
<v t="ekr.20100930104733.12280"><vh>org-check-after-date</vh></v>
<v t="ekr.20100930104733.12281"><vh>org-evaluate-time-range</vh></v>
<v t="ekr.20100930104733.12282"><vh>org-make-tdiff-string</vh></v>
<v t="ekr.20100930104733.12283"><vh>org-time-string-to-time</vh></v>
<v t="ekr.20100930104733.12284"><vh>org-time-string-to-seconds</vh></v>
<v t="ekr.20100930104733.12285"><vh>org-time-string-to-absolute</vh></v>
<v t="ekr.20100930104733.12286"><vh>org-days-to-iso-week</vh></v>
<v t="ekr.20100930104733.12287"><vh>org-small-year-to-year</vh></v>
<v t="ekr.20100930104733.12288"><vh>org-time-from-absolute</vh></v>
<v t="ekr.20100930104733.12289"><vh>org-calendar-holiday</vh></v>
<v t="ekr.20100930104733.12290"><vh>org-diary-sexp-entry</vh></v>
<v t="ekr.20100930104733.12291"><vh>org-diary-to-ical-string</vh></v>
<v t="ekr.20100930104733.12292"><vh>org-closest-date</vh></v>
<v t="ekr.20100930104733.12293"><vh>org-date-to-gregorian</vh></v>
<v t="ekr.20100930104733.12294"><vh>org-parse-time-string</vh></v>
<v t="ekr.20100930104733.12295"><vh>org-timestamp-up</vh></v>
<v t="ekr.20100930104733.12296"><vh>org-timestamp-down</vh></v>
<v t="ekr.20100930104733.12297"><vh>org-timestamp-up-day</vh></v>
<v t="ekr.20100930104733.12298"><vh>org-timestamp-down-day</vh></v>
<v t="ekr.20100930104733.12299"><vh>org-at-timestamp-p</vh></v>
<v t="ekr.20100930104733.12300"><vh>org-toggle-timestamp-type</vh></v>
<v t="ekr.20100930104733.12301"><vh>org-timestamp-change</vh></v>
<v t="ekr.20100930104733.12302"><vh>org-modify-ts-extra</vh></v>
<v t="ekr.20100930104733.12303"><vh>org-recenter-calendar</vh></v>
<v t="ekr.20100930104733.12304"><vh>org-goto-calendar</vh></v>
<v t="ekr.20100930104733.12305"><vh>org-get-date-from-calendar</vh></v>
<v t="ekr.20100930104733.12306"><vh>org-date-from-calendar</vh></v>
<v t="ekr.20100930104733.12307"><vh>org-minutes-to-hh</vh></v>
<v t="ekr.20100930104733.12308"><vh>org-hh</vh></v>
</v>
<v t="ekr.20100930104733.12309"><vh>Files</vh>
<v t="ekr.20100930104733.12310"><vh>org-save-all-org-buffers</vh></v>
<v t="ekr.20100930104733.12311"><vh>org-revert-all-org-buffers</vh></v>
</v>
<v t="ekr.20100930104733.12312"><vh>Agenda files</vh>
<v t="ekr.20100930104733.12313"><vh>org-switchb</vh></v>
<v t="ekr.20100930104733.12314"><vh>org-buffer-list</vh></v>
<v t="ekr.20100930104733.12315"><vh>org-agenda-files</vh></v>
<v t="ekr.20100930104733.12316"><vh>org-agenda-file-p</vh></v>
<v t="ekr.20100930104733.12317"><vh>org-edit-agenda-file-list</vh></v>
<v t="ekr.20100930104733.12318"><vh>org-store-new-agenda-file-list</vh></v>
<v t="ekr.20100930104733.12319"><vh>org-read-agenda-file-list</vh></v>
<v t="ekr.20100930104733.12320"><vh>org-cycle-agenda-files</vh></v>
<v t="ekr.20100930104733.12321"><vh>org-agenda-file-to-front</vh></v>
<v t="ekr.20100930104733.12322"><vh>org-remove-file</vh></v>
<v t="ekr.20100930104733.12323"><vh>org-file-menu-entry</vh></v>
<v t="ekr.20100930104733.12324"><vh>org-check-agenda-file</vh></v>
<v t="ekr.20100930104733.12325"><vh>org-get-agenda-file-buffer</vh></v>
<v t="ekr.20100930104733.12326"><vh>org-release-buffers</vh></v>
<v t="ekr.20100930104733.12327"><vh>org-prepare-agenda-buffers</vh></v>
</v>
<v t="ekr.20100930104733.12328"><vh>Embedded Latex</vh>
<v t="ekr.20100930104733.12329"><vh>turn-on-org-cdlatex</vh></v>
<v t="ekr.20100930104733.12330"><vh>org-inside-LaTeX-fragment-p</vh></v>
<v t="ekr.20100930104733.12331"><vh>org-inside-latex-macro-p</vh></v>
<v t="ekr.20100930104733.12332"><vh>org-try-cdlatex-tab</vh></v>
<v t="ekr.20100930104733.12333"><vh>org-cdlatex-underscore-caret</vh></v>
<v t="ekr.20100930104733.12334"><vh>org-cdlatex-math-modify</vh></v>
<v t="ekr.20100930104733.12335"><vh>org-remove-latex-fragment-image-overlays</vh></v>
<v t="ekr.20100930104733.12336"><vh>org-preview-latex-fragment</vh></v>
<v t="ekr.20100930104733.12337"><vh>org-format-latex</vh></v>
<v t="ekr.20100930104733.12338"><vh>org-create-formula-image</vh></v>
<v t="ekr.20100930104733.12339"><vh>org-splice-latex-header</vh></v>
<v t="ekr.20100930104733.12340"><vh>org-latex-packages-to-string</vh></v>
<v t="ekr.20100930104733.12341"><vh>org-dvipng-color</vh></v>
<v t="ekr.20100930104733.12342"><vh>org-normalize-color</vh></v>
<v t="ekr.20100930104733.12343"><vh>org-toggle-inline-images</vh></v>
<v t="ekr.20100930104733.12344"><vh>org-display-inline-images</vh></v>
<v t="ekr.20100930104733.12345"><vh>org-display-inline-modification-hook</vh></v>
<v t="ekr.20100930104733.12346"><vh>org-remove-inline-images</vh></v>
</v>
<v t="ekr.20100930104733.12347"><vh>Key bindings</vh>
<v t="ekr.20100930104733.12348"><vh>org-print-speed-command</vh></v>
<v t="ekr.20100930104733.12349"><vh>org-speed-command-help</vh></v>
<v t="ekr.20100930104733.12350"><vh>org-speed-move-safe</vh></v>
<v t="ekr.20100930104733.12351"><vh>org-self-insert-command</vh></v>
<v t="ekr.20100930104733.12352"><vh>org-fix-tags-on-the-fly</vh></v>
<v t="ekr.20100930104733.12353"><vh>org-delete-backward-char</vh></v>
<v t="ekr.20100930104733.12354"><vh>org-delete-char</vh></v>
<v t="ekr.20100930104733.12355"><vh>org-remap</vh></v>
<v t="ekr.20100930104733.12356"><vh>org-modifier-cursor-error</vh></v>
<v t="ekr.20100930104733.12357"><vh>org-shiftselect-error</vh></v>
<v t="ekr.20100930104733.12358"><vh>org-call-for-shift-select</vh></v>
<v t="ekr.20100930104733.12359"><vh>org-shifttab</vh></v>
<v t="ekr.20100930104733.12360"><vh>org-shiftmetaleft</vh></v>
<v t="ekr.20100930104733.12361"><vh>org-shiftmetaright</vh></v>
<v t="ekr.20100930104733.12362"><vh>org-shiftmetaup</vh></v>
<v t="ekr.20100930104733.12363"><vh>org-shiftmetadown</vh></v>
<v t="ekr.20100930104733.12364"><vh>org-metaleft</vh></v>
<v t="ekr.20100930104733.12365"><vh>org-metaright</vh></v>
<v t="ekr.20100930104733.12366"><vh>org-check-for-hidden</vh></v>
<v t="ekr.20100930104733.12367"><vh>org-metaup</vh></v>
<v t="ekr.20100930104733.12368"><vh>org-metadown</vh></v>
<v t="ekr.20100930104733.12369"><vh>org-shiftup</vh></v>
<v t="ekr.20100930104733.12370"><vh>org-shiftdown</vh></v>
<v t="ekr.20100930104733.12371"><vh>org-shiftright</vh></v>
<v t="ekr.20100930104733.12372"><vh>org-shiftleft</vh></v>
<v t="ekr.20100930104733.12373"><vh>org-shiftcontrolright</vh></v>
<v t="ekr.20100930104733.12374"><vh>org-shiftcontrolleft</vh></v>
<v t="ekr.20100930104733.12375"><vh>org-ctrl-c-ret</vh></v>
<v t="ekr.20100930104733.12376"><vh>org-copy-special</vh></v>
<v t="ekr.20100930104733.12377"><vh>org-cut-special</vh></v>
<v t="ekr.20100930104733.12378"><vh>org-paste-special</vh></v>
<v t="ekr.20100930104733.12379"><vh>org-edit-special</vh></v>
<v t="ekr.20100930104733.12380"><vh>org-ctrl-c-ctrl-c</vh></v>
<v t="ekr.20100930104733.12381"><vh>org-mode-restart</vh></v>
<v t="ekr.20100930104733.12382"><vh>org-kill-note-or-show-branches</vh></v>
<v t="ekr.20100930104733.12383"><vh>org-return</vh></v>
<v t="ekr.20100930104733.12384"><vh>org-return-indent</vh></v>
<v t="ekr.20100930104733.12385"><vh>org-ctrl-c-star</vh></v>
<v t="ekr.20100930104733.12386"><vh>org-ctrl-c-minus</vh></v>
<v t="ekr.20100930104733.12387"><vh>org-toggle-item</vh></v>
<v t="ekr.20100930104733.12388"><vh>org-toggle-heading</vh></v>
<v t="ekr.20100930104733.12389"><vh>org-meta-return</vh></v>
<v t="ekr.20100930104733.12390"><vh>org-info</vh></v>
<v t="ekr.20100930104733.12391"><vh>org-submit-bug-report</vh></v>
<v t="ekr.20100930104733.12392"><vh>org-install-agenda-files-menu</vh></v>
</v>
<v t="ekr.20100930104733.12393"><vh>Documentation</vh>
<v t="ekr.20100930104733.12394"><vh>org-require-autoloaded-modules</vh></v>
<v t="ekr.20100930104733.12395"><vh>org-reload</vh></v>
<v t="ekr.20100930104733.12396"><vh>org-customize</vh></v>
<v t="ekr.20100930104733.12397"><vh>org-create-customize-menu</vh></v>
</v>
<v t="ekr.20100930104733.12398"><vh>Miscellaneous</vh>
<v t="ekr.20100930104733.12399"><vh>org-get-at-bol</vh></v>
<v t="ekr.20100930104733.12400"><vh>org-find-text-property-in-string</vh></v>
<v t="ekr.20100930104733.12401"><vh>org-display-warning</vh></v>
<v t="ekr.20100930104733.12402"><vh>org-in-commented-line</vh></v>
<v t="ekr.20100930104733.12403"><vh>org-in-indented-comment-line</vh></v>
<v t="ekr.20100930104733.12404"><vh>org-in-verbatim-emphasis</vh></v>
<v t="ekr.20100930104733.12405"><vh>org-goto-marker-or-bmk</vh></v>
<v t="ekr.20100930104733.12406"><vh>org-quote-csv-field</vh></v>
<v t="ekr.20100930104733.12407"><vh>org-plist-delete</vh></v>
<v t="ekr.20100930104733.12408"><vh>org-force-self-insert</vh></v>
<v t="ekr.20100930104733.12409"><vh>org-string-width</vh></v>
<v t="ekr.20100930104733.12410"><vh>org-get-indentation</vh></v>
<v t="ekr.20100930104733.12411"><vh>org-remove-tabs</vh></v>
<v t="ekr.20100930104733.12412"><vh>org-fix-indentation</vh></v>
<v t="ekr.20100930104733.12413"><vh>org-remove-indentation</vh></v>
<v t="ekr.20100930104733.12414"><vh>org-do-remove-indentation</vh></v>
<v t="ekr.20100930104733.12415"><vh>org-fill-template</vh></v>
<v t="ekr.20100930104733.12416"><vh>org-base-buffer</vh></v>
<v t="ekr.20100930104733.12417"><vh>org-trim</vh></v>
<v t="ekr.20100930104733.12418"><vh>org-wrap</vh></v>
<v t="ekr.20100930104733.12419"><vh>org-do-wrap</vh></v>
<v t="ekr.20100930104733.12420"><vh>org-split-string</vh></v>
<v t="ekr.20100930104733.12421"><vh>org-quote-vert</vh></v>
<v t="ekr.20100930104733.12422"><vh>org-uuidgen-p</vh></v>
<v t="ekr.20100930104733.12423"><vh>org-context</vh></v>
<v t="ekr.20100930104733.12424"><vh>org-in-regexp</vh></v>
<v t="ekr.20100930104733.12425"><vh>org-at-regexp-p</vh></v>
<v t="ekr.20100930104733.12426"><vh>org-in-regexps-block-p</vh></v>
<v t="ekr.20100930104733.12427"><vh>org-occur-in-agenda-files</vh></v>
<v t="ekr.20100930104733.12428"><vh>org-occur-link-in-agenda-files</vh></v>
<v t="ekr.20100930104733.12429"><vh>org-uniquify</vh></v>
<v t="ekr.20100930104733.12430"><vh>org-delete-all</vh></v>
<v t="ekr.20100930104733.12431"><vh>org-count</vh></v>
<v t="ekr.20100930104733.12432"><vh>org-remove-if</vh></v>
<v t="ekr.20100930104733.12433"><vh>org-remove-if-not</vh></v>
<v t="ekr.20100930104733.12434"><vh>org-back-over-empty-lines</vh></v>
<v t="ekr.20100930104733.12435"><vh>org-skip-whitespace</vh></v>
<v t="ekr.20100930104733.12436"><vh>org-point-in-group</vh></v>
<v t="ekr.20100930104733.12437"><vh>org-switch-to-buffer-other-window</vh></v>
<v t="ekr.20100930104733.12438"><vh>org-combine-plists</vh></v>
<v t="ekr.20100930104733.12439"><vh>org-move-line-down</vh></v>
<v t="ekr.20100930104733.12440"><vh>org-move-line-up</vh></v>
<v t="ekr.20100930104733.12441"><vh>org-replace-escapes</vh></v>
<v t="ekr.20100930104733.12442"><vh>org-sublist</vh></v>
<v t="ekr.20100930104733.12443"><vh>org-find-base-buffer-visiting</vh></v>
<v t="ekr.20100930104733.12444"><vh>org-image-file-name-regexp</vh></v>
<v t="ekr.20100930104733.12445"><vh>org-file-image-p</vh></v>
<v t="ekr.20100930104733.12446"><vh>org-get-cursor-date</vh></v>
<v t="ekr.20100930104733.12447"><vh>org-mark-entry-for-agenda-action</vh></v>
<v t="ekr.20100930104733.12448"><vh>org-indent-line-function</vh></v>
<v t="ekr.20100930104733.12449"><vh>org-set-autofill-regexps</vh></v>
<v t="ekr.20100930104733.12450"><vh>org-adaptive-fill-function</vh></v>
<v t="ekr.20100930104733.12451"><vh>org-toggle-fixed-width-section</vh></v>
<v t="ekr.20100930104733.12452"><vh>org-reftex-citation</vh></v>
</v>
<v t="ekr.20100930104733.12453"><vh>Functions extending outline functionality</vh>
<v t="ekr.20100930104733.12454"><vh>org-beginning-of-line</vh></v>
<v t="ekr.20100930104733.12455"><vh>org-end-of-line</vh></v>
<v t="ekr.20100930104733.12456"><vh>org-backward-sentence</vh></v>
<v t="ekr.20100930104733.12457"><vh>org-forward-sentence</vh></v>
<v t="ekr.20100930104733.12458"><vh>org-kill-line</vh></v>
<v t="ekr.20100930104733.12459"><vh>org-yank</vh></v>
<v t="ekr.20100930104733.12460"><vh>org-yank-generic</vh></v>
<v t="ekr.20100930104733.12461"><vh>org-invisible-p</vh></v>
<v t="ekr.20100930104733.12462"><vh>org-truely-invisible-p</vh></v>
<v t="ekr.20100930104733.12463"><vh>org-invisible-p2</vh></v>
<v t="ekr.20100930104733.12464"><vh>org-back-to-heading</vh></v>
<v t="ekr.20100930104733.12465"><vh>org-beginning-of-defun</vh></v>
<v t="ekr.20100930104733.12466"><vh>org-end-of-defun</vh></v>
<v t="ekr.20100930104733.12467"><vh>org-before-first-heading-p</vh></v>
<v t="ekr.20100930104733.12468"><vh>org-on-heading-p</vh></v>
<v t="ekr.20100930104733.12469"><vh>org-at-heading-p</vh></v>
<v t="ekr.20100930104733.12470"><vh>org-point-at-end-of-empty-headline</vh></v>
<v t="ekr.20100930104733.12471"><vh>org-at-heading-or-item-p</vh></v>
<v t="ekr.20100930104733.12472"><vh>org-on-target-p</vh></v>
<v t="ekr.20100930104733.12473"><vh>org-up-heading-safe</vh></v>
<v t="ekr.20100930104733.12474"><vh>org-first-sibling-p</vh></v>
<v t="ekr.20100930104733.12475"><vh>org-goto-sibling</vh></v>
<v t="ekr.20100930104733.12476"><vh>org-show-siblings</vh></v>
<v t="ekr.20100930104733.12477"><vh>org-show-hidden-entry</vh></v>
<v t="ekr.20100930104733.12478"><vh>org-flag-heading</vh></v>
<v t="ekr.20100930104733.12479"><vh>org-get-next-sibling</vh></v>
<v t="ekr.20100930104733.12480"><vh>org-get-last-sibling</vh></v>
<v t="ekr.20100930104733.12481"><vh>org-end-of-subtree</vh></v>
<v t="ekr.20100930104733.12482"><vh>org-forward-same-level</vh></v>
<v t="ekr.20100930104733.12483"><vh>org-backward-same-level</vh></v>
<v t="ekr.20100930104733.12484"><vh>org-show-subtree</vh></v>
<v t="ekr.20100930104733.12485"><vh>org-show-entry</vh></v>
<v t="ekr.20100930104733.12486"><vh>org-make-options-regexp</vh></v>
<v t="ekr.20100930104733.12487"><vh>org-isearch-end</vh></v>
<v t="ekr.20100930104733.12488"><vh>org-isearch-post-command</vh></v>
</v>
<v t="ekr.20100930104733.12489"><vh>Integration with and fixes for other packages</vh>
<v t="ekr.20100930104733.12490"><vh>org-imenu-new-marker</vh></v>
<v t="ekr.20100930104733.12491"><vh>org-imenu-get-tree</vh></v>
<v t="ekr.20100930104733.12492"><vh>org-link-display-format</vh></v>
<v t="ekr.20100930104733.12493"><vh>org-speedbar-set-agenda-restriction</vh></v>
<v t="ekr.20100930104733.12494"><vh>org-mode-flyspell-verify</vh></v>
<v t="ekr.20100930104733.12495"><vh>org-remove-flyspell-overlays-in</vh></v>
<v t="ekr.20100930104733.12496"><vh>org-bookmark-jump-unhide</vh></v>
<v t="ekr.20100930104733.12497"><vh>Experimental code</vh>
<v t="ekr.20100930104733.12498"><vh>org-closed-in-range</vh></v>
</v>
</v>
</v>
</v>
</v>
</vnodes>
<tnodes>
<t tx="ekr.20100929212226.11691"></t>
<t tx="ekr.20100929212226.14079"></t>
<t tx="ekr.20100929212226.14080"></t>
<t tx="ekr.20100929212226.14081">@language lisp
@tabwidth -4
@others

(provide 'ob-asymptote)

;; arch-tag: f2f5bd0d-78e8-412b-8e6c-6dadc94cc06b

;;; ob-asymptote.el ends here
</t>
<t tx="ekr.20100929212226.14082">;;; ob-asymptote.el --- org-babel functions for asymptote evaluation

;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating asymptote source code.
;;
;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in asymptote
;;
;; 2) we are generally only going to return results of type "file"
;;
;; 3) we are adding the "file" and "cmdline" header arguments, if file
;;    is omitted then the -V option is passed to the asy command for
;;    interactive viewing

;;; Requirements:

;; - The asymptote program :: http://asymptote.sourceforge.net/
;;
;; - asy-mode :: Major mode for editing asymptote files

;;; Code:
(require 'ob)
(eval-when-compile (require 'cl))

(declare-function orgtbl-to-generic "org-table" (table params))
(declare-function org-combine-plists "org" (&amp;rest plists))

(add-to-list 'org-babel-tangle-lang-exts '("asymptote" . "asy"))

(defvar org-babel-default-header-args:asymptote
  '((:results . "file") (:exports . "results"))
  "Default arguments when evaluating an Asymptote source block.")

</t>
<t tx="ekr.20100929212226.14083">(defun org-babel-expand-body:asymptote (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params
                          (org-babel-process-params params)))))
    (concat (mapconcat 'org-babel-asymptote-var-to-asymptote vars "\n")
        "\n" body "\n")))
</t>
<t tx="ekr.20100929212226.14084">
(defun org-babel-execute:asymptote (body params)
  "Execute a block of Asymptote code.
This function is called by `org-babel-execute-src-block'."
  (let* ((processed-params (org-babel-process-params params))
         (result-params (split-string (or (cdr (assoc :results params)) "")))
         (out-file (cdr (assoc :file params)))
         (format (or (and out-file
                          (string-match ".+\\.\\(.+\\)" out-file)
                          (match-string 1 out-file))
                     "pdf"))
         (cmdline (cdr (assoc :cmdline params)))
         (in-file (make-temp-file "org-babel-asymptote"))
         (cmd (concat "asy "
                      (if out-file
                          (concat "-globalwrite -f " format " -o " out-file)
                        "-V")
                      " " cmdline " " in-file)))
    (with-temp-file in-file
      (insert (org-babel-expand-body:asymptote body params processed-params)))
    (message cmd) (shell-command cmd)
    out-file))
</t>
<t tx="ekr.20100929212226.14085">
(defun org-babel-prep-session:asymptote (session params)
  "Return an error if the :session header argument is set.
Asymptote does not support sessions"
  (error "Asymptote does not support sessions"))
</t>
<t tx="ekr.20100929212226.14086">
(defun org-babel-asymptote-var-to-asymptote (pair)
  "Convert an elisp value into an Asymptote variable.
The elisp value PAIR is converted into Asymptote code specifying
a variable of the same value."
  (let ((var (car pair))
        (val (if (symbolp (cdr pair))
                 (symbol-name (cdr pair))
               (cdr pair))))
    (cond
     ((integerp val)
      (format "int %S=%S;" var val))
     ((floatp val)
      (format "real %S=%S;" var val))
     ((stringp val)
      (format "string %S=\"%s\";" var val))
     ((listp val)
      (let* ((dimension-2-p (not (null (cdr val))))
             (dim (if dimension-2-p "[][]" "[]"))
             (type (org-babel-asymptote-define-type val))
             (array (org-babel-asymptote-table-to-array
                     val
                     (if dimension-2-p '(:lstart "{" :lend "}," :llend "}")))))
        (format "%S%s %S=%s;" type dim var array))))))
</t>
<t tx="ekr.20100929212226.14087">
(defun org-babel-asymptote-table-to-array (table params)
  "Convert values of an elisp table into a string of an asymptote array.
Empty cells are ignored."
  (labels ((atom-to-string (table)
                           (cond
                            ((null table) '())
                            ((not (listp (car table)))
                             (cons (if (and (stringp (car table))
                                            (not (string= (car table) "")))
                                       (format "\"%s\"" (car table))
                                     (format "%s" (car table)))
                                   (atom-to-string (cdr table))))
                            (t
                             (cons (atom-to-string (car table))
                                   (atom-to-string (cdr table))))))
           ;; Remove any empty row
           (fix-empty-lines (table)
                            (delq nil (mapcar (lambda (l) (delq "" l)) table))))
    (orgtbl-to-generic
     (fix-empty-lines (atom-to-string table))
     (org-combine-plists '(:hline nil :sep "," :tstart "{" :tend "}") params))))
</t>
<t tx="ekr.20100929212226.14088">
(defun org-babel-asymptote-define-type (data)
  "Determine type of DATA.
DATA is a list. Type symbol is returned as 'symbol. The type is
usually the type of the first atom encountered, except for arrays
of int, where every cell must be of int type."
  (labels ((anything-but-int (el)
                             (cond
                              ((null el) nil)
                              ((not (listp (car el)))
                               (cond
                                ((floatp (car el)) 'real)
                                ((stringp (car el)) 'string)
                                (t
                                 (anything-but-int (cdr el)))))
                              (t
                               (or (anything-but-int (car el))
                                   (anything-but-int (cdr el)))))))
    (or (anything-but-int data) 'int)))
</t>
<t tx="ekr.20100929212226.14089">@language lisp
@tabwidth -4
@others


(provide 'ob-C)

;; arch-tag: 8f49e462-54e3-417b-9a8d-423864893b37

;;; ob-C.el ends here
</t>
<t tx="ekr.20100929212226.14090">;;; ob-C.el --- org-babel functions for C and similar languages

;; Copyright (C) 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating C code.
;;
;; very limited implementation:
;; - currently only support :results output
;; - not much in the way of error feedback

;;; Code:
(require 'ob)
(require 'ob-eval)
(require 'org)
(require 'cc-mode)

(declare-function org-entry-get "org"
          (pom property &amp;optional inherit literal-nil))

(add-to-list 'org-babel-tangle-lang-exts '("c++" . "cpp"))

(defvar org-babel-default-header-args:C '())

(defvar org-babel-C-compiler "gcc"
  "Command used to compile a C source code file into an
  executable.")

(defvar org-babel-c++-compiler "g++"
  "Command used to compile a c++ source code file into an
  executable.")

(defvar org-babel-c-variant nil
  "Internal variable used to hold which type of C (e.g. C or C++)
is currently being evaluated.")

</t>
<t tx="ekr.20100929212226.14091">(defun org-babel-execute:cpp (body params)
  "Execute BODY according to PARAMS.  This function calls
`org-babel-execute:C'."
  (org-babel-execute:C body params))
</t>
<t tx="ekr.20100929212226.14092">
(defun org-babel-execute:c++ (body params)
    "Execute a block of C++ code with org-babel.  This function is
called by `org-babel-execute-src-block'."
  (let ((org-babel-c-variant 'cpp)) (org-babel-C-execute body params)))
</t>
<t tx="ekr.20100929212226.14093">
(defun org-babel-expand-body:c++ (body params &amp;optional processed-params)
  "Expand a block of C++ code with org-babel according to it's
header arguments (calls `org-babel-C-expand')."
  (let ((org-babel-c-variant 'cpp)) (org-babel-C-expand body params processed-params)))
</t>
<t tx="ekr.20100929212226.14094">
(defun org-babel-execute:C (body params)
  "Execute a block of C code with org-babel.  This function is
called by `org-babel-execute-src-block'."
  (let ((org-babel-c-variant 'c)) (org-babel-C-execute body params)))
</t>
<t tx="ekr.20100929212226.14095">
(defun org-babel-expand-body:c (body params &amp;optional processed-params)
  "Expand a block of C code with org-babel according to it's
header arguments (calls `org-babel-C-expand')."
  (let ((org-babel-c-variant 'c)) (org-babel-C-expand body params processed-params)))
</t>
<t tx="ekr.20100929212226.14096">
(defun org-babel-C-execute (body params)
  "This function should only be called by `org-babel-execute:C'
or `org-babel-execute:c++'."
  (let* ((processed-params (org-babel-process-params params))
         (tmp-src-file (make-temp-file "org-babel-C-src" nil
                                       (cond
                    ((equal org-babel-c-variant 'c) ".c")
                    ((equal org-babel-c-variant 'cpp) ".cpp"))))
         (tmp-bin-file (make-temp-file "org-babel-C-bin"))
         (tmp-out-file (make-temp-file "org-babel-C-out"))
         (cmdline (cdr (assoc :cmdline params)))
         (flags (cdr (assoc :flags params)))
         (full-body (org-babel-C-expand body params))
         (compile
      (progn
        (with-temp-file tmp-src-file (insert full-body))
        (org-babel-eval
         (format "%s -o %s %s %s"
             (cond
              ((equal org-babel-c-variant 'c) org-babel-C-compiler)
              ((equal org-babel-c-variant 'cpp) org-babel-c++-compiler))
             tmp-bin-file
             (mapconcat 'identity
                (if (listp flags) flags (list flags)) " ")
             tmp-src-file) ""))))
    ((lambda (results)
       (org-babel-reassemble-table
    (if (member "vector" (nth 2 processed-params))
        (let ((tmp-file (make-temp-file "ob-c")))
          (with-temp-file tmp-file (insert results))
          (org-babel-import-elisp-from-file tmp-file))
      (org-babel-read results))
    (org-babel-pick-name
     (nth 4 processed-params) (cdr (assoc :colnames params)))
    (org-babel-pick-name
     (nth 5 processed-params) (cdr (assoc :rownames params)))))
     (org-babel-trim
       (org-babel-eval
    (concat tmp-bin-file (if cmdline (concat " " cmdline) "")) "")))))
</t>
<t tx="ekr.20100929212226.14097">
(defun org-babel-C-expand (body params &amp;optional processed-params)
  "Expand a block of C or C++ code with org-babel according to
it's header arguments."
  (let ((vars (nth 1 (or processed-params
                          (org-babel-process-params params))))
        (main-p (not (string= (cdr (assoc :main params)) "no")))
        (includes (or (cdr (assoc :includes params))
                      (org-babel-read (org-entry-get nil "includes" t))))
        (defines (org-babel-read
                  (or (cdr (assoc :defines params))
                      (org-babel-read (org-entry-get nil "defines" t))))))
    (org-babel-trim
     (mapconcat 'identity
        (list
         ;; includes
         (mapconcat
          (lambda (inc) (format "#include %s" inc))
          (if (listp includes) includes (list includes)) "\n")
         ;; defines
         (mapconcat
          (lambda (inc) (format "#define %s" inc))
          (if (listp defines) defines (list defines)) "\n")
         ;; variables
         (mapconcat 'org-babel-C-var-to-C vars "\n")
         ;; body
         (if main-p
             (org-babel-C-ensure-main-wrap body)
           body) "\n") "\n"))))
</t>
<t tx="ekr.20100929212226.14098">
(defun org-babel-C-ensure-main-wrap (body)
  "Wrap body in a \"main\" function call if none exists."
  (if (string-match "^[ \t]*[intvod]+[ \t]*main[ \t]*(.*)" body)
      body
    (format "int main() {\n%s\n}\n" body)))
</t>
<t tx="ekr.20100929212226.14099">
(defun org-babel-prep-session:C (session params)
  "This function does nothing as C is a compiled language with no
support for sessions"
  (error "C is a compiled languages -- no support for sessions"))
</t>
<t tx="ekr.20100929212226.14100">
(defun org-babel-load-session:C (session body params)
  "This function does nothing as C is a compiled language with no
support for sessions"
  (error "C is a compiled languages -- no support for sessions"))
</t>
<t tx="ekr.20100929212226.14101">
;; helper functions

(defun org-babel-C-var-to-C (pair)
  "Convert an elisp val into a string of C code specifying a var
of the same value."
  ;; TODO list support
  (let ((var (car pair))
        (val (cdr pair)))
    (when (symbolp val)
      (setq val (symbol-name val))
      (when (= (length val) 1)
        (setq val (string-to-char val))))
    (cond
     ((integerp val)
      (format "int %S = %S;" var val))
     ((floatp val)
      (format "double %S = %S;" var val))
     ((or (characterp val))
      (format "char %S = '%S';" var val))
     ((stringp val)
      (format "char %S[%d] = \"%s\";"
              var (+ 1 (length val)) val))
     (t
      (format "u32 %S = %S;" var val)))))
</t>
<t tx="ekr.20100929212226.14102">@language lisp
@tabwidth -4
@others

(provide 'ob-clojure)

;; arch-tag: a43b33f2-653e-46b1-ac56-2805cf05b7d1

;;; ob-clojure.el ends here
</t>
<t tx="ekr.20100929212226.14103">;;; ob-clojure.el --- org-babel functions for clojure evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Joel Boehland
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;;; ob support for evaluating clojure code

;;; Requirements:

;;; A working clojure install. This also implies a working java executable
;;; clojure-mode
;;; slime
;;; swank-clojure

;;; By far, the best way to install these components is by following
;;; the directions as set out by Phil Hagelberg (Technomancy) on the
;;; web page: http://technomancy.us/126

;;; Code:
(require 'ob)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(declare-function slime-eval-async "ext:slime" (sexp &amp;optional cont package))
(declare-function slime-eval "ext:slime" (sexp &amp;optional package))
(declare-function swank-clojure-concat-paths "ext:slime" (paths))
(declare-function org-babel-ref-variables "ext:slime" (params))
(declare-function slime "ext:slime" (&amp;optional command coding-system))
(declare-function slime-output-buffer "ext:slime" (&amp;optional noprompt))
(declare-function slime-filter-buffers "ext:slime" (predicate))

(add-to-list 'org-babel-tangle-lang-exts '("clojure" . "clj"))

(defvar org-babel-default-header-args:clojure '())

(defvar org-babel-clojure-wrapper-method
  "
(defn spit
  [f content]
  (with-open [#^java.io.PrintWriter w
                 (java.io.PrintWriter.
                   (java.io.BufferedWriter.
                     (java.io.OutputStreamWriter.
                       (java.io.FileOutputStream.
                         (java.io.File. f)))))]
      (.print w content)))

(defn main
  []
  %s)

(spit \"%s\" (str (main)))")
</t>
<t tx="ekr.20100929212226.14104">;;";; &lt;-- syntax highlighting is messed without this double quote

;;taken mostly from clojure-test-mode.el
(defun org-babel-clojure-clojure-slime-eval (string &amp;optional handler)
  "Evaluate a STRING of clojure code using `slime-eval-async'."
  (slime-eval-async `(swank:eval-and-grab-output ,string)
                    (or handler #'identity)))
</t>
<t tx="ekr.20100929212226.14105">
(defun org-babel-clojure-slime-eval-sync (string)
  "Evaluate a STRING of clojure code using `slime-eval'."
  (slime-eval `(swank:eval-and-grab-output ,string)))
</t>
<t tx="ekr.20100929212226.14106">
;;taken from swank-clojure.el
(defvar swank-clojure-binary)
(defvar swank-clojure-classpath)
(defvar swank-clojure-java-path)
(defvar swank-clojure-extra-vm-args)
(defvar swank-clojure-library-paths)
(defvar swank-clojure-extra-classpaths)
(defun org-babel-clojure-babel-clojure-cmd ()
  "Create the command to start clojure according to current settings."
  (if (and (not swank-clojure-binary) (not swank-clojure-classpath))
      (error "%s" (concat "You must specifiy either a `swank-clojure-binary' "
              "or a `swank-clojure-jar-path'"))
    (if swank-clojure-binary
        (if (listp swank-clojure-binary)
            swank-clojure-binary
          (list swank-clojure-binary))
      (delq
       nil
       (append
        (list swank-clojure-java-path)
        swank-clojure-extra-vm-args
        (list
         (when swank-clojure-library-paths
           (concat "-Djava.library.path="
                   (swank-clojure-concat-paths swank-clojure-library-paths)))
         "-classpath"
         (swank-clojure-concat-paths
          (append
           swank-clojure-classpath
           swank-clojure-extra-classpaths))
         "clojure.main"))))))
</t>
<t tx="ekr.20100929212226.14107">
(defun org-babel-clojure-table-or-string (results)
  "Convert RESULTS to an elisp value.
If RESULTS looks like a table, then convert to an Emacs-lisp
table, otherwise return the results as a string."
  (org-babel-read
   (if (string-match "^\\[.+\\]$" results)
       (org-babel-read
        (concat "'"
                (replace-regexp-in-string
                 "\\[" "(" (replace-regexp-in-string
                            "\\]" ")" (replace-regexp-in-string
                                       ", " " " (replace-regexp-in-string
                                                 "'" "\"" results))))))
     results)))
</t>
<t tx="ekr.20100929212226.14108">
(defun org-babel-clojure-var-to-clojure (var)
  "Convert an elisp value into a clojure variable.
The elisp value VAR is converted into a string of clojure source
code specifying a variable of the same value."
  (if (listp var)
      (format "'%s" var)
    (format "%S" var)))
</t>
<t tx="ekr.20100929212226.14109">
(defun org-babel-clojure-build-full-form (body vars)
  "Construct a clojure let form with VARS as the let variables."
  (let ((vars-forms
     (mapconcat ;; define any variables
      (lambda (pair)
        (format "%s %s"
            (car pair) (org-babel-clojure-var-to-clojure (cdr pair))))
      vars "\n      "))
    (body (org-babel-trim body)))
    (if (&gt; (length vars-forms) 0)
    (format "(let [%s]\n  %s)" vars-forms body)
      body)))
</t>
<t tx="ekr.20100929212226.14110">
(defun org-babel-prep-session:clojure (session params)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  (require 'slime) (require 'swank-clojure)
  (let* ((session-buf (org-babel-clojure-initiate-session session))
         (vars (org-babel-ref-variables params))
         (var-lines (mapcar ;; define any top level session variables
                     (lambda (pair)
                       (format "(def %s %s)\n" (car pair)
                               (org-babel-clojure-var-to-clojure (cdr pair))))
                     vars)))
    session-buf))
</t>
<t tx="ekr.20100929212226.14111">
(defun org-babel-load-session:clojure (session body params)
  "Load BODY into SESSION."
  (require 'slime) (require 'swank-clojure)
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:clojure session params)))
      (with-current-buffer buffer
        (goto-char (point-max))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14112">
(defvar org-babel-clojure-buffers '())
(defvar org-babel-clojure-pending-sessions '())

(defun org-babel-clojure-session-buffer (session)
  "Return the buffer associated with SESSION."
  (cdr (assoc session org-babel-clojure-buffers)))
</t>
<t tx="ekr.20100929212226.14113">
(defun org-babel-clojure-initiate-session-by-key (&amp;optional session)
  "Initiate a clojure session in an inferior-process-buffer.
If there is not a current inferior-process-buffer in SESSION
then create one.  Return the initialized session."
  (save-window-excursion
    (let* ((session (if session
                        (if (stringp session) (intern session)
                          session)
              :default))
           (clojure-buffer (org-babel-clojure-session-buffer session)))
      (unless (and clojure-buffer (buffer-live-p clojure-buffer))
        (setq org-babel-clojure-buffers
          (assq-delete-all session org-babel-clojure-buffers))
        (push session org-babel-clojure-pending-sessions)
        (slime)
        ;; we are waiting to finish setting up which will be done in
        ;; org-babel-clojure-session-connected-hook below.
        (let ((timeout 9))
          (while (and (not (org-babel-clojure-session-buffer session))
                      (&lt; 0 timeout))
            (message "Waiting for clojure repl for session: %s ... %i"
             session timeout)
            (sit-for 1)
            (decf timeout)))
        (setq org-babel-clojure-pending-sessions
              (remove session org-babel-clojure-pending-sessions))
        (unless (org-babel-clojure-session-buffer session)
          (error "Couldn't create slime clojure process"))
        (setq clojure-buffer (org-babel-clojure-session-buffer session)))
      session)))
</t>
<t tx="ekr.20100929212226.14114">
(defun org-babel-clojure-initiate-session (&amp;optional session params)
  "Return the slime-clojure repl buffer bound to SESSION.
Returns nil if \"none\" is specified."
  (require 'slime) (require 'swank-clojure)
  (unless (and (stringp session) (string= session "none"))
    (org-babel-clojure-session-buffer
     (org-babel-clojure-initiate-session-by-key session))))
</t>
<t tx="ekr.20100929212226.14115">
(defun org-babel-clojure-session-connected-hook ()
  "Finish  binding an org-babel session to a slime-clojure repl."
  (let ((pending-session (pop org-babel-clojure-pending-sessions)))
    (when pending-session
      (save-excursion
        (switch-to-buffer (slime-output-buffer))
        (rename-buffer
     (if (stringp pending-session)
         pending-session (symbol-name pending-session)))
        (org-babel-clojure-bind-session-to-repl-buffer
     pending-session (slime-output-buffer))))))
</t>
<t tx="ekr.20100929212226.14116">
(add-hook 'slime-connected-hook 'org-babel-clojure-session-connected-hook)

(defun org-babel-clojure-bind-session-to-repl-buffer (session repl-buffer)
  "Associate SESSION with REPL-BUFFER."
  (when (stringp session) (setq session (intern session)))
  (setq org-babel-clojure-buffers
        (cons (cons session repl-buffer)
              (assq-delete-all session org-babel-clojure-buffers))))
</t>
<t tx="ekr.20100929212226.14117">
(defun org-babel-clojure-repl-buffer-pred ()
  "Test whether the current buffer is an active slime-clojure
repl buffer."
  (and (buffer-live-p (current-buffer)) (eq major-mode 'slime-repl-mode)))
</t>
<t tx="ekr.20100929212226.14118">
(defun org-babel-clojure-bind-session-to-repl (session)
  "Bind SESSION to a clojure repl."
  (interactive "sEnter session name: ")
  (let ((repl-bufs (slime-filter-buffers 'org-babel-clojure-repl-buffer-pred)))
    (unless repl-bufs (error "No existing slime-clojure repl buffers exist"))
    (let ((repl-buf (read-buffer "Choose slime-clojure repl: " repl-bufs t)))
      (org-babel-clojure-bind-session-to-repl-buffer session repl-buf))))
</t>
<t tx="ekr.20100929212226.14119">
(defun org-babel-clojure-evaluate-external-process
  (buffer body &amp;optional result-type)
  "Evaluate the body in an external process."
  (let ((cmd (format "%s -" (mapconcat #'identity
                       (org-babel-clojure-babel-clojure-cmd)
                       " "))))
    (case result-type
      (output (org-babel-eval cmd body))
      (value (let* ((tmp-file (make-temp-file "org-babel-clojure-results-")))
           (org-babel-eval cmd (format org-babel-clojure-wrapper-method
                       body tmp-file tmp-file))
           (org-babel-clojure-table-or-string
        (org-babel-eval-read-file tmp-file)))))))
</t>
<t tx="ekr.20100929212226.14120">
(defun org-babel-clojure-evaluate-session (buffer body &amp;optional result-type)
  "Evaluate the body in the context of a clojure session."
  (require 'slime) (require 'swank-clojure)
  (let ((raw nil)
        (results nil))
    (with-current-buffer buffer
      (setq raw (org-babel-clojure-slime-eval-sync body))
      (setq results (reverse (mapcar #'org-babel-trim raw)))
      (cond
       ((equal result-type 'output)
    (mapconcat #'identity (reverse (cdr results)) "\n"))
       ((equal result-type 'value)
    (org-babel-clojure-table-or-string (car results)))))))
</t>
<t tx="ekr.20100929212226.14121">
(defun org-babel-clojure-evaluate (buffer body &amp;optional result-type)
  "Pass BODY to the Clojure process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY as elisp."
  (if buffer
      (org-babel-clojure-evaluate-session buffer body result-type)
    (org-babel-clojure-evaluate-external-process buffer body result-type)))
</t>
<t tx="ekr.20100929212226.14122">
(defun org-babel-expand-body:clojure (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (org-babel-clojure-build-full-form
   body (nth 1 (or processed-params (org-babel-process-params params)))))
</t>
<t tx="ekr.20100929212226.14123">
(defun org-babel-execute:clojure (body params)
  "Execute a block of Clojure code."
  (require 'slime) (require 'swank-clojure)
  (let* ((processed-params (org-babel-process-params params))
         (body (org-babel-expand-body:clojure body params processed-params))
         (session (org-babel-clojure-initiate-session
           (first processed-params))))
    (org-babel-reassemble-table
     (org-babel-clojure-evaluate session body (nth 3 processed-params))
     (org-babel-pick-name
      (nth 4 processed-params) (cdr (assoc :colnames params)))
     (org-babel-pick-name
      (nth 5 processed-params) (cdr (assoc :rownames params))))))
</t>
<t tx="ekr.20100929212226.14124">@language lisp
@tabwidth -4
@others

(provide 'ob-comint)

;; arch-tag: 9adddce6-0864-4be3-b0b5-6c5157dc7889

;;; ob-comint.el ends here
</t>
<t tx="ekr.20100929212226.14125">;;; ob-comint.el --- org-babel functions for interaction with comint buffers

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, comint
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; These functions build on comint to ease the sending and receiving
;; of commands and results from comint buffers.

;; Note that the buffers in this file are analogous to sessions in
;; org-babel at large.

;;; Code:
(require 'ob)
(require 'comint)
(eval-when-compile (require 'cl))

</t>
<t tx="ekr.20100929212226.14126">(defun org-babel-comint-buffer-livep (buffer)
  "Check if BUFFER is a comint buffer with a live process."
  (let ((buffer (if buffer (get-buffer buffer))))
    (and buffer (buffer-live-p buffer) (get-buffer-process buffer) buffer)))
</t>
<t tx="ekr.20100929212226.14127">
(defmacro org-babel-comint-in-buffer (buffer &amp;rest body)
  "Check BUFFER and execute BODY.
BUFFER is checked with `org-babel-comint-buffer-livep'.  BODY is
executed inside the protection of `save-window-excursion' and
`save-match-data'."
  (declare (indent 1))
  `(save-excursion
     (save-match-data
       (unless (org-babel-comint-buffer-livep ,buffer)
         (error "buffer %s doesn't exist or has no process" ,buffer))
       (set-buffer ,buffer)
       ,@body)))

(defmacro org-babel-comint-with-output (meta &amp;rest body)
  "Evaluate BODY in BUFFER and return process output.
Will wait until EOE-INDICATOR appears in the output, then return
all process output.  If REMOVE-ECHO and FULL-BODY are present and
non-nil, then strip echo'd body from the returned output.  META
should be a list containing the following where the last two
elements are optional.

 (BUFFER EOE-INDICATOR REMOVE-ECHO FULL-BODY)

This macro ensures that the filter is removed in case of an error
or user `keyboard-quit' during execution of body."
  (declare (indent 1))
  (let ((buffer (car meta))
    (eoe-indicator (cadr meta))
    (remove-echo (cadr (cdr meta)))
    (full-body (cadr (cdr (cdr meta)))))
    `(org-babel-comint-in-buffer ,buffer
       (let ((string-buffer "") dangling-text raw)
     (flet ((my-filt (text)
             (setq string-buffer (concat string-buffer text))))
       ;; setup filter
       (add-hook 'comint-output-filter-functions 'my-filt)
       (unwind-protect
           (progn
         ;; got located, and save dangling text
         (goto-char (process-mark (get-buffer-process (current-buffer))))
         (let ((start (point))
               (end (point-max)))
           (setq dangling-text (buffer-substring start end))
           (delete-region start end))
         ;; pass FULL-BODY to process
         ,@body
         ;; wait for end-of-evaluation indicator
         (while (progn
              (goto-char comint-last-input-end)
              (not (save-excursion
                 (and (re-search-forward
                       comint-prompt-regexp nil t)
                      (re-search-forward
                       (regexp-quote ,eoe-indicator) nil t)))))
           (accept-process-output (get-buffer-process (current-buffer)))
           ;; thought the following this would allow async
           ;; background running, but I was wrong...
           ;; (run-with-timer .5 .5 'accept-process-output
           ;;                (get-buffer-process (current-buffer)))
           )
         ;; replace cut dangling text
         (goto-char (process-mark (get-buffer-process (current-buffer))))
         (insert dangling-text))
         ;; remove filter
         (remove-hook 'comint-output-filter-functions 'my-filt)))
     ;; remove echo'd FULL-BODY from input
     (if (and ,remove-echo ,full-body
          (string-match
           (replace-regexp-in-string
            "\n" "[\r\n]+" (regexp-quote (or ,full-body "")))
           string-buffer))
         (setq raw (substring string-buffer (match-end 0))))
     (split-string string-buffer comint-prompt-regexp)))))

(defun org-babel-comint-input-command (buffer cmd)
  "Pass CMD to BUFFER.
The input will not be echoed."
  (org-babel-comint-in-buffer buffer
    (goto-char (process-mark (get-buffer-process buffer)))
    (insert cmd)
    (comint-send-input)
    (org-babel-comint-wait-for-output buffer)))
</t>
<t tx="ekr.20100929212226.14128">
(defun org-babel-comint-wait-for-output (buffer)
  "Wait until output arrives from BUFFER.
Note: this is only safe when waiting for the result of a single
statement (not large blocks of code)."
  (org-babel-comint-in-buffer buffer
    (while (progn
             (goto-char comint-last-input-end)
             (not (and (re-search-forward comint-prompt-regexp nil t)
                       (goto-char (match-beginning 0))
                       (string= (face-name (face-at-point))
                                "comint-highlight-prompt"))))
      (accept-process-output (get-buffer-process buffer)))))
</t>
<t tx="ekr.20100929212226.14129">@language lisp
@tabwidth -4
@others

(provide 'ob-css)

;; arch-tag: f4447e8c-50ab-41f9-b322-b7b9574d9fbe

;;; ob-css.el ends here
</t>
<t tx="ekr.20100929212226.14130">;;; ob-css.el --- org-babel functions for css evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Since CSS can't be executed, this file exists solely for tangling
;; CSS from org-mode files.

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:css '())

</t>
<t tx="ekr.20100929212226.14131">(defun org-babel-expand-body:css (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14132">
(defun org-babel-execute:css (body params)
  "Execute a block of CSS code.
This function is called by `org-babel-execute-src-block'."
 body)
</t>
<t tx="ekr.20100929212226.14133">
(defun org-babel-prep-session:css (session params)
  "Return an error if the :session header argument is set.
CSS does not support sessions."
  (error "CSS sessions are nonsensical"))
</t>
<t tx="ekr.20100929212226.14134">@language lisp
@tabwidth -4
@others

(provide 'ob-ditaa)

;; arch-tag: 492cd006-07d9-4fac-bef6-5bb60b48842e

;;; ob-ditaa.el ends here
</t>
<t tx="ekr.20100929212226.14135">;;; ob-ditaa.el --- org-babel functions for ditaa evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating ditaa source code.
;;
;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in ditaa
;;
;; 2) we are generally only going to return results of type "file"
;;
;; 3) we are adding the "file" and "cmdline" header arguments
;;
;; 4) there are no variables (at least for now)

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:ditaa
  '((:results . "file") (:exports . "results"))
  "Default arguments for evaluating a ditaa source block.")

</t>
<t tx="ekr.20100929212226.14136">(defun org-babel-expand-body:ditaa (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14137">
(defvar org-ditaa-jar-path)
(defun org-babel-execute:ditaa (body params)
  "Execute a block of Ditaa code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
        (out-file (cdr (assoc :file params)))
        (cmdline (cdr (assoc :cmdline params)))
        (in-file (make-temp-file "org-babel-ditaa")))
    (unless (file-exists-p org-ditaa-jar-path)
      (error "Could not find ditaa.jar at %s" org-ditaa-jar-path))
    (with-temp-file in-file (insert body))
    (message (concat "java -jar " org-ditaa-jar-path " " cmdline " " in-file " " out-file))
    (shell-command (concat "java -jar " (shell-quote-argument org-ditaa-jar-path) " " cmdline " " in-file " " out-file))
    out-file))
</t>
<t tx="ekr.20100929212226.14138">
(defun org-babel-prep-session:ditaa (session params)
  "Return an error because ditaa does not support sessions."
  (error "Ditaa does not support sessions"))
</t>
<t tx="ekr.20100929212226.14139">@language lisp
@tabwidth -4
@others

(provide 'ob-dot)

;; arch-tag: 817d0516-7b47-4f77-a8b2-2aadd8e4d0e2

;;; ob-dot.el ends here
</t>
<t tx="ekr.20100929212226.14140">;;; ob-dot.el --- org-babel functions for dot evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating dot source code.
;;
;; For information on dot see http://www.graphviz.org/
;;
;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in dot
;;
;; 2) we are generally only going to return results of type "file"
;;
;; 3) we are adding the "file" and "cmdline" header arguments
;;
;; 4) there are no variables (at least for now)

;;; Code:
(require 'ob)
(require 'ob-eval)

(defvar org-babel-default-header-args:dot
  '((:results . "file") (:exports . "results"))
  "Default arguments to use when evaluating a dot source block.")

</t>
<t tx="ekr.20100929212226.14141">(defun org-babel-expand-body:dot (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params
             (org-babel-process-params params)))))
    (mapc
     (lambda (pair)
       (let ((name (symbol-name (car pair)))
         (value (cdr pair)))
     (setq body
           (replace-regexp-in-string
        (concat "\$" (regexp-quote name))
        (if (stringp value) value (format "%S" value))
        body))))
     vars)
    body))
</t>
<t tx="ekr.20100929212226.14142">
(defun org-babel-execute:dot (body params)
  "Execute a block of Dot code with org-babel.
This function is called by `org-babel-execute-src-block'."
  (let ((processed-params (org-babel-process-params params))
    (result-params (split-string (or (cdr (assoc :results params)) "")))
        (out-file (cdr (assoc :file params)))
        (cmdline (cdr (assoc :cmdline params)))
        (cmd (or (cdr (assoc :cmd params)) "dot"))
        (in-file (make-temp-file "org-babel-dot")))
    (with-temp-file in-file
      (insert (org-babel-expand-body:dot body params processed-params)))
    (org-babel-eval (concat cmd " " in-file " " cmdline " -o " out-file) "")
    out-file))
</t>
<t tx="ekr.20100929212226.14143">
(defun org-babel-prep-session:dot (session params)
  "Return an error because Dot does not support sessions."
  (error "Dot does not support sessions"))
</t>
<t tx="ekr.20100929212226.14144">@language lisp
@tabwidth -4
@others

(provide 'ob-emacs-lisp)

;; arch-tag: e9a3acca-dc84-472a-9f5a-23c35befbcd6

;;; ob-emacs-lisp.el ends here
</t>
<t tx="ekr.20100929212226.14145">;;; ob-emacs-lisp.el --- org-babel functions for emacs-lisp code evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating emacs-lisp code

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:emacs-lisp
  '((:hlines . "yes") (:colnames . "no"))
  "Default arguments for evaluating an emacs-lisp source block.")

(declare-function org-babel-comint-with-output "ob-comint" (&amp;rest body))
(declare-function org-babel-comint-buffer-livep "ob-comint" (buffer))
(declare-function org-babel-comint-wait-for-output "ob-comint" (buffer))
(declare-function org-babel-comint-in-buffer "ob-comint" (buffer &amp;rest body))
(declare-function orgtbl-to-generic "org-table" (table params))

</t>
<t tx="ekr.20100929212226.14146">(defun org-babel-expand-body:emacs-lisp (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let* ((processed-params (or processed-params (org-babel-process-params params)))
         (vars (nth 1 processed-params))
         (result-params (nth 2 processed-params))
         (print-level nil) (print-length nil)
         (body (if (&gt; (length vars) 0)
           (concat "(let ("
             (mapconcat
              (lambda (var) (format "%S" (print `(,(car var) ',(cdr var)))))
              vars "\n      ")
             ")\n" body ")")
         body)))
    (if (or (member "code" result-params)
        (member "pp" result-params))
    (concat "(pp " body ")") body)))
</t>
<t tx="ekr.20100929212226.14147">
(defun org-babel-execute:emacs-lisp (body params)
  "Execute a block of emacs-lisp code with Babel."
  (save-window-excursion
    (let ((processed-params (org-babel-process-params params)))
      (org-babel-reassemble-table
       (eval (read (format "(progn %s)"
               (org-babel-expand-body:emacs-lisp
                body params processed-params))))
       (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
       (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
</t>
<t tx="ekr.20100929212226.14148">@language lisp
@tabwidth -4
@others

(provide 'ob-eval)

;; arch-tag: 5328b17f-957d-42d9-94da-a2952682d04d

;;; ob-comint.el ends here
</t>
<t tx="ekr.20100929212226.14149">;;; ob-run.el --- org-babel functions for external code evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research, comint
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; These functions build existing Emacs support for executing external
;; shell commands.

;;; Code:
(require 'ob)
(eval-when-compile (require 'cl))

</t>
<t tx="ekr.20100929212226.14150">(defun org-babel-eval-error-notify (exit-code stderr)
  "Open a buffer to display STDERR and a message with the value of EXIT-CODE."
  (let ((buf (get-buffer-create "*Org-Babel Error Output*")))
    (with-current-buffer buf
      (goto-char (point-max))
      (save-excursion (insert stderr)))
    (display-buffer buf))
  (message "Babel evaluation exited with code %S" exit-code))
</t>
<t tx="ekr.20100929212226.14151">
(defun org-babel-eval (cmd body)
  "Run CMD on BODY.
If CMD succeeds then return it's results, otherwise display
STDERR with `org-babel-eval-error-notify'."
  (let ((err-buff (get-buffer-create "*Org-Babel Error*")) exit-code)
    (with-current-buffer err-buff (erase-buffer))
    (with-temp-buffer
      (insert body)
      (setq exit-code
        (org-babel-shell-command-on-region
         (point-min) (point-max) cmd t 'replace err-buff))
      (if (or (not (numberp exit-code)) (&gt; exit-code 0))
      (progn
        (with-current-buffer err-buff
          (org-babel-eval-error-notify exit-code (buffer-string)))
        nil)
    (buffer-string)))))
</t>
<t tx="ekr.20100929212226.14152">
(defun org-babel-eval-read-file (file)
  "Return the contents of FILE as a string."
  (with-temp-buffer (insert-file-contents
             (org-babel-maybe-remote-file file))
            (buffer-string)))
</t>
<t tx="ekr.20100929212226.14153">
(defun org-babel-shell-command-on-region (start end command
                      &amp;optional output-buffer replace
                      error-buffer display-error-buffer)
  "Execute COMMAND in an inferior shell with region as input.

Fixes bugs in the emacs 23.1.1 version of `shell-command-on-region'

Normally display output (if any) in temp buffer `*Shell Command Output*';
Prefix arg means replace the region with it.  Return the exit code of
COMMAND.

To specify a coding system for converting non-ASCII characters in
the input and output to the shell command, use
\\[universal-coding-system-argument] before this command.  By
default, the input (from the current buffer) is encoded in the
same coding system that will be used to save the file,
`buffer-file-coding-system'.  If the output is going to replace
the region, then it is decoded from that same coding system.

The noninteractive arguments are START, END, COMMAND,
OUTPUT-BUFFER, REPLACE, ERROR-BUFFER, and DISPLAY-ERROR-BUFFER.
Noninteractive callers can specify coding systems by binding
`coding-system-for-read' and `coding-system-for-write'.

If the command generates output, the output may be displayed
in the echo area or in a buffer.
If the output is short enough to display in the echo area
\(determined by the variable `max-mini-window-height' if
`resize-mini-windows' is non-nil), it is shown there.  Otherwise
it is displayed in the buffer `*Shell Command Output*'.  The output
is available in that buffer in both cases.

If there is output and an error, a message about the error
appears at the end of the output.

If there is no output, or if output is inserted in the current buffer,
then `*Shell Command Output*' is deleted.

If the optional fourth argument OUTPUT-BUFFER is non-nil,
that says to put the output in some other buffer.
If OUTPUT-BUFFER is a buffer or buffer name, put the output there.
If OUTPUT-BUFFER is not a buffer and not nil,
insert output in the current buffer.
In either case, the output is inserted after point (leaving mark after it).

If REPLACE, the optional fifth argument, is non-nil, that means insert
the output in place of text from START to END, putting point and mark
around it.

If optional sixth argument ERROR-BUFFER is non-nil, it is a buffer
or buffer name to which to direct the command's standard error output.
If it is nil, error output is mingled with regular output.
If DISPLAY-ERROR-BUFFER is non-nil, display the error buffer if there
were any errors.  (This is always t, interactively.)
In an interactive call, the variable `shell-command-default-error-buffer'
specifies the value of ERROR-BUFFER."
  (interactive (let (string)
         (unless (mark)
           (error "The mark is not set now, so there is no region"))
         ;; Do this before calling region-beginning
         ;; and region-end, in case subprocess output
         ;; relocates them while we are in the minibuffer.
         (setq string (read-shell-command "Shell command on region: "))
         ;; call-interactively recognizes region-beginning and
         ;; region-end specially, leaving them in the history.
         (list (region-beginning) (region-end)
               string
               current-prefix-arg
               current-prefix-arg
               shell-command-default-error-buffer
               t)))
  (let ((error-file
     (if error-buffer
         (make-temp-file
          (expand-file-name "scor"
                (or (unless (featurep 'xemacs)
                      small-temporary-file-directory)
                    temporary-file-directory)))
       nil))
    exit-status)
    (if (or replace
        (and output-buffer
         (not (or (bufferp output-buffer) (stringp output-buffer)))))
    ;; Replace specified region with output from command.
    (let ((swap (and replace (&lt; start end))))
      ;; Don't muck with mark unless REPLACE says we should.
      (goto-char start)
      (and replace (push-mark (point) 'nomsg))
      (setq exit-status
        (call-process-region start end shell-file-name t
                     (if error-file
                     (list output-buffer error-file)
                       t)
                     nil shell-command-switch command))
      ;; It is rude to delete a buffer which the command is not using.
      ;; (let ((shell-buffer (get-buffer "*Shell Command Output*")))
      ;;   (and shell-buffer (not (eq shell-buffer (current-buffer)))
      ;;     (kill-buffer shell-buffer)))
      ;; Don't muck with mark unless REPLACE says we should.
      (and replace swap (exchange-point-and-mark)))
      ;; No prefix argument: put the output in a temp buffer,
      ;; replacing its entire contents.
      (let ((buffer (get-buffer-create
             (or output-buffer "*Shell Command Output*"))))
    (unwind-protect
        (if (eq buffer (current-buffer))
        ;; If the input is the same buffer as the output,
        ;; delete everything but the specified region,
        ;; then replace that region with the output.
        (progn (setq buffer-read-only nil)
               (delete-region (max start end) (point-max))
               (delete-region (point-min) (min start end))
               (setq exit-status
                 (call-process-region (point-min) (point-max)
                          shell-file-name t
                          (if error-file
                              (list t error-file)
                            t)
                          nil shell-command-switch
                          command)))
          ;; Clear the output buffer, then run the command with
          ;; output there.
          (let ((directory default-directory))
        (with-current-buffer buffer
          (setq buffer-read-only nil)
          (if (not output-buffer)
              (setq default-directory directory))
          (erase-buffer)))
          (setq exit-status
            (call-process-region start end shell-file-name nil
                     (if error-file
                         (list buffer error-file)
                       buffer)
                     nil shell-command-switch command)))
      ;; Report the output.
      (with-current-buffer buffer
        (setq mode-line-process
          (cond ((null exit-status)
             " - Error")
            ((stringp exit-status)
             (format " - Signal [%s]" exit-status))
            ((not (equal 0 exit-status))
             (format " - Exit [%d]" exit-status)))))
      (if (with-current-buffer buffer (&gt; (point-max) (point-min)))
          ;; There's some output, display it
          (display-message-or-buffer buffer)
        ;; No output; error?
        (let ((output
           (if (and error-file
                (&lt; 0 (nth 7 (file-attributes error-file))))
               "some error output"
             "no output")))
          (cond ((null exit-status)
             (message "(Shell command failed with error)"))
            ((equal 0 exit-status)
             (message "(Shell command succeeded with %s)"
                  output))
            ((stringp exit-status)
             (message "(Shell command killed by signal %s)"
                  exit-status))
            (t
             (message "(Shell command failed with code %d and %s)"
                  exit-status output))))
        ;; Don't kill: there might be useful info in the undo-log.
        ;; (kill-buffer buffer)
        ))))

    (when (and error-file (file-exists-p error-file))
      (if (&lt; 0 (nth 7 (file-attributes error-file)))
      (with-current-buffer (get-buffer-create error-buffer)
        (let ((pos-from-end (- (point-max) (point))))
          (or (bobp)
          (insert "\f\n"))
          ;; Do no formatting while reading error file,
          ;; because that can run a shell command, and we
          ;; don't want that to cause an infinite recursion.
          (format-insert-file error-file nil)
          ;; Put point after the inserted errors.
          (goto-char (- (point-max) pos-from-end)))
        (and display-error-buffer
         (display-buffer (current-buffer)))))
      (delete-file error-file))
    exit-status))
</t>
<t tx="ekr.20100929212226.14154">@language lisp
@tabwidth -4
@others

(provide 'ob-exp)

;; arch-tag: 523abf4c-76d1-44ed-9f27-e3bddf34bf0f

;;; ob-exp.el ends here
</t>
<t tx="ekr.20100929212226.14155">;;; ob-exp.el --- Exportation of org-babel source blocks

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; See the online documentation for more information
;;
;;   http://orgmode.org/worg/org-contrib/babel/

;;; Code:
(require 'ob)
(require 'org-exp-blocks)
(eval-when-compile
  (require 'cl))

(defvar obe-marker nil)
(defvar org-current-export-file)
(defvar org-babel-lob-one-liner-regexp)
(defvar org-babel-ref-split-regexp)
(declare-function org-babel-lob-get-info "ob-lob" ())
(declare-function org-babel-ref-literal "ob-ref" (ref))

(add-to-list 'org-export-interblocks '(src org-babel-exp-inline-src-blocks))
(add-to-list 'org-export-interblocks '(lob org-babel-exp-lob-one-liners))
(add-hook 'org-export-blocks-postblock-hook 'org-exp-res/src-name-cleanup)

(org-export-blocks-add-block '(src org-babel-exp-src-blocks nil))

(defcustom org-export-babel-evaluate t
  "Switch controlling code evaluation during export.
When set to nil no code will be exported as part of the export
process."
  :group 'org-babel
  :type 'boolean)
(put 'org-export-babel-evaluate 'safe-local-variable (lambda (x) (eq x nil)))

(defvar org-babel-function-def-export-keyword "function"
  "The keyword to substitute for the source name line on export.
When exporting a source block function, this keyword will
appear in the exported version in the place of source name
line. A source block is considered to be a source block function
if the source name is present and is followed by a parenthesized
argument list. The parentheses may be empty or contain
whitespace. An example is the following which generates n random
\(uniform) numbers.

#+source: rand(n)
#+begin_src R
  runif(n)
#+end_src")

(defvar org-babel-function-def-export-indent 4
  "Number of characters to indent a source block on export.
When exporting a source block function, the block contents will
be indented by this many characters. See
`org-babel-function-def-export-name' for the definition of a
source block function.")

</t>
<t tx="ekr.20100929212226.14156">(defun org-babel-exp-src-blocks (body &amp;rest headers)
  "Process source block for export.
Depending on the 'export' headers argument in replace the source
code block with...

both ---- display the code and the results

code ---- the default, display the code inside the block but do
          not process

results - just like none only the block is run on export ensuring
          that it's results are present in the org-mode buffer

none ----- do not display either code or results upon export"
  (interactive)
  (message "org-babel-exp processing...")
  (save-excursion
    (goto-char (match-beginning 0))
    (let* ((info (org-babel-get-src-block-info))
       (params (nth 2 info)))
      ;; bail if we couldn't get any info from the block
      (when info
    ;; expand noweb references in the original file
    (setf (nth 1 info)
          (if (and (cdr (assoc :noweb params))
               (string= "yes" (cdr (assoc :noweb params))))
          (org-babel-expand-noweb-references
           info (get-file-buffer org-current-export-file))
        (nth 1 info))))
      (org-babel-exp-do-export info 'block))))
</t>
<t tx="ekr.20100929212226.14157">
(defun org-babel-exp-inline-src-blocks (start end)
  "Process inline source blocks between START and END for export.
See `org-babel-exp-src-blocks' for export options, currently the
options and are taken from `org-babel-default-inline-header-args'."
  (interactive)
  (save-excursion
    (goto-char start)
    (while (and (&lt; (point) end)
                (re-search-forward org-babel-inline-src-block-regexp end t))
      (let* ((info (save-match-data (org-babel-parse-inline-src-block-match)))
         (params (nth 2 info))
         (replacement
          (save-match-data
        (if (org-babel-in-example-or-verbatim)
            (buffer-substring (match-beginning 0) (match-end 0))
          ;; expand noweb references in the original file
          (setf (nth 1 info)
            (if (and (cdr (assoc :noweb params))
                 (string= "yes" (cdr (assoc :noweb params))))
                (org-babel-expand-noweb-references
                 info (get-file-buffer org-current-export-file))
              (nth 1 info)))
          (org-babel-exp-do-export info 'inline)))))
    (setq end (+ end (- (length replacement) (length (match-string 1)))))
    (replace-match replacement t t nil 1)))))
</t>
<t tx="ekr.20100929212226.14158">
(defun org-exp-res/src-name-cleanup ()
  "Clean up #+results and #+srcname lines for export.
This function should only be called after all block processing
has taken place."
  (interactive)
  (save-excursion
    (goto-char (point-min))
    (while (org-re-search-forward-unprotected
        (concat
         "\\("org-babel-src-name-regexp"\\|"org-babel-result-regexp"\\)")
        nil t)
      (delete-region
       (progn (beginning-of-line) (point))
       (progn (end-of-line) (+ 1 (point)))))))
</t>
<t tx="ekr.20100929212226.14159">
(defun org-babel-in-example-or-verbatim ()
  "Return true if point is in example or verbatim code.
Example and verbatim code include escaped portions of
an org-mode buffer code that should be treated as normal
org-mode text."
  (or (org-in-indented-comment-line)
      (save-excursion
    (save-match-data
      (goto-char (point-at-bol))
      (looking-at "[ \t]*:[ \t]")))
      (org-in-regexps-block-p "^[ \t]*#\\+begin_src" "^[ \t]*#\\+end_src")))
</t>
<t tx="ekr.20100929212226.14160">
(defun org-babel-exp-lob-one-liners (start end)
  "Process Library of Babel calls between START and END for export.
See `org-babel-exp-src-blocks' for export options. Currently the
options are taken from `org-babel-default-header-args'."
  (interactive)
  (let (replacement)
    (save-excursion
      (goto-char start)
      (while (and (&lt; (point) end)
          (re-search-forward org-babel-lob-one-liner-regexp nil t))
    (setq replacement
          (let ((lob-info (org-babel-lob-get-info)))
        (save-match-data
          (org-babel-exp-do-export
           (list "emacs-lisp" "results"
             (org-babel-merge-params
              org-babel-default-header-args
              (org-babel-parse-header-arguments
               (org-babel-clean-text-properties
                (concat ":var results="
                    (mapconcat #'identity
                           (butlast lob-info) " ")))))
             (car (last lob-info)))
           'lob))))
    (setq end (+ end (- (length replacement) (length (match-string 0)))))
    (replace-match replacement t t)))))
</t>
<t tx="ekr.20100929212226.14161">
(defun org-babel-exp-do-export (info type)
  "Return a string with the exported content of a code block.
The function respects the value of the :exports header argument."
  (flet ((silently () (let ((session (cdr (assoc :session (nth 2 info)))))
            (when (and session
                   (not (equal "none" session))
                   (not (assoc :noeval (nth 2 info))))
              (org-babel-exp-results info type 'silent))))
     (clean () (org-babel-remove-result info)))
    (case (intern (or (cdr (assoc :exports (nth 2 info))) "code"))
      ('none (silently) (clean) "")
      ('code (silently) (clean) (org-babel-exp-code info type))
      ('results (org-babel-exp-results info type))
      ('both (concat (org-babel-exp-code info type)
             "\n\n"
             (org-babel-exp-results info type))))))
</t>
<t tx="ekr.20100929212226.14162">
(defvar backend)
(defun org-babel-exp-code (info type)
  "Prepare and return code in the current code block for export.
Code is prepared in a manner suitable for exportat by
org-mode.  This function is called by `org-babel-exp-do-export'.
The code block is not evaluated."
  (let ((lang (nth 0 info))
        (body (nth 1 info))
        (switches (nth 3 info))
        (name (nth 4 info))
        (args (mapcar
           #'cdr
           (org-remove-if-not (lambda (el) (eq :var (car el))) (nth 2 info)))))
    (case type
      ('inline (format "=%s=" body))
      ('block
      (let ((str
         (format "#+BEGIN_SRC %s %s\n%s%s#+END_SRC\n" lang switches body
             (if (and body (string-match "\n$" body))
                 "" "\n"))))
        (when name
          (add-text-properties
           0 (length str)
           (list 'org-caption
             (format "%s(%s)"
                 name
                 (mapconcat #'identity args ", ")))
           str))
        str))
      ('lob
       (let ((call-line (and (string-match "results=" (car args))
                 (substring (car args) (match-end 0)))))
     (cond
      ((eq backend 'html)
       (format "\n#+HTML: &lt;label class=\"org-src-name\"&gt;%s&lt;/label&gt;\n"
           call-line))
      ((format ": %s\n" call-line))))))))
</t>
<t tx="ekr.20100929212226.14163">
(defun org-babel-exp-results (info type &amp;optional silent)
  "Evaluate and return the results of the current code block for export.
Results are prepared in a manner suitable for export by org-mode.
This function is called by `org-babel-exp-do-export'.  The code
block will be evaluated.  Optional argument SILENT can be used to
inhibit insertion of results into the buffer."
  (if org-export-babel-evaluate
      (let ((lang (nth 0 info))
        (body (nth 1 info))
        (params
         ;; lets ensure that we lookup references in the original file
         (mapcar
          (lambda (pair)
        (if (and org-current-export-file
             (eq (car pair) :var)
             (string-match org-babel-ref-split-regexp (cdr pair))
             (equal :ob-must-be-reference
                (org-babel-ref-literal
                 (match-string 2 (cdr pair)))))
            `(:var . ,(concat (match-string 1 (cdr pair))
                      "=" org-current-export-file
                      ":" (match-string 2 (cdr pair))))
          pair))
          (nth 2 info))))
    ;; skip code blocks which we can't evaluate
    (if (fboundp (intern (concat "org-babel-execute:" lang)))
        (case type
          ('inline
        (let ((raw (org-babel-execute-src-block
                nil info '((:results . "silent"))))
              (result-params (split-string
                      (cdr (assoc :results params)))))
          (unless silent
            (cond ;; respect the value of the :results header argument
             ((member "file" result-params)
              (org-babel-result-to-file raw))
             ((or (member "raw" result-params)
              (member "org" result-params))
              (format "%s" raw))
             ((member "code" result-params)
              (format "src_%s{%s}" lang raw))
             (t
              (if (stringp raw)
              (if (= 0 (length raw)) "=(no results)="
                (format "%s" raw))
            (format "%S" raw)))))))
          ('block
          (org-babel-execute-src-block
           nil info (org-babel-merge-params
                 params
                 `((:results . ,(if silent "silent" "replace")))))
        "")
          ('lob
           (save-excursion
         (re-search-backward org-babel-lob-one-liner-regexp nil t)
         (org-babel-execute-src-block
          nil info (org-babel-merge-params
                params
                `((:results . ,(if silent "silent" "replace")))))
         "")))
      ""))
    ""))
</t>
<t tx="ekr.20100929212226.14164">@language lisp
@tabwidth -4
@others

(provide 'ob-gnuplot)

;; arch-tag: 50490ace-a9e1-4b29-a6e5-0db9f16c610b

;;; ob-gnuplot.el ends here
</t>
<t tx="ekr.20100929212226.14165">;;; ob-gnuplot.el --- org-babel functions for gnuplot evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating gnuplot source code.
;;
;; This differs from most standard languages in that
;;
;; 1) we are generally only going to return results of type "file"
;;
;; 2) we are adding the "file" and "cmdline" header arguments

;;; Requirements:

;; - gnuplot :: http://www.gnuplot.info/
;;
;; - gnuplot-mode :: http://cars9.uchicago.edu/~ravel/software/gnuplot-mode.html

;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(eval-when-compile (require 'cl))

(declare-function org-time-string-to-time "org" (s))
(declare-function org-combine-plists "org" (&amp;rest plists))
(declare-function orgtbl-to-generic "org-table" (table params))
(declare-function gnuplot-mode "ext:gnuplot-mode" ())
(declare-function gnuplot-send-string-to-gnuplot "ext:gnuplot-mode" (str txt))
(declare-function gnuplot-send-buffer-to-gnuplot "ext:gnuplot-mode" ())

(defvar org-babel-default-header-args:gnuplot
  '((:results . "file") (:exports . "results") (:session . nil))
  "Default arguments to use when evaluating a gnuplot source block.")

(defvar org-babel-gnuplot-timestamp-fmt nil)

</t>
<t tx="ekr.20100929212226.14166">(defun org-babel-gnuplot-process-vars (params)
  "Extract variables from PARAMS and process the variables.
Dumps all vectors into files and returns an association list
of variable names and the related value to be used in the gnuplot
code."
  (mapcar
   (lambda (pair)
     (cons
      (car pair) ;; variable name
      (if (listp (cdr pair)) ;; variable value
          (org-babel-gnuplot-table-to-data
           (cdr pair) (make-temp-file "org-babel-gnuplot") params)
        (cdr pair))))
   (org-babel-ref-variables params)))
</t>
<t tx="ekr.20100929212226.14167">
(defun org-babel-expand-body:gnuplot (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (save-window-excursion
    (let* ((vars (org-babel-gnuplot-process-vars params))
           (out-file (cdr (assoc :file params)))
           (term (or (cdr (assoc :term params))
                     (when out-file (file-name-extension out-file))))
           (cmdline (cdr (assoc :cmdline params)))
           (title (plist-get params :title))
           (lines (plist-get params :line))
           (sets (plist-get params :set))
           (x-labels (plist-get params :xlabels))
           (y-labels (plist-get params :ylabels))
           (timefmt (plist-get params :timefmt))
           (time-ind (or (plist-get params :timeind)
                         (when timefmt 1)))
           output)
      (flet ((add-to-body (text)
                          (setq body (concat text "\n" body))))
        ;; append header argument settings to body
        (when title (add-to-body (format "set title '%s'" title))) ;; title
        (when lines (mapc (lambda (el) (add-to-body el)) lines)) ;; line
        (when sets
          (mapc (lambda (el) (add-to-body (format "set %s" el))) sets))
        (when x-labels
          (add-to-body
           (format "set xtics (%s)"
                   (mapconcat (lambda (pair)
                                (format "\"%s\" %d" (cdr pair) (car pair)))
                              x-labels ", "))))
        (when y-labels
          (add-to-body
           (format "set ytics (%s)"
                   (mapconcat (lambda (pair)
                                (format "\"%s\" %d" (cdr pair) (car pair)))
                              y-labels ", "))))
        (when time-ind
          (add-to-body "set xdata time")
          (add-to-body (concat "set timefmt \""
                               (or timefmt
                                   "%Y-%m-%d-%H:%M:%S") "\"")))
        (when out-file (add-to-body (format "set output \"%s\"" out-file)))
        (when term (add-to-body (format "set term %s" term)))
        ;; insert variables into code body: this should happen last
        ;; placing the variables at the *top* of the code in case their
        ;; values are used later
        (add-to-body (mapconcat
                      (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
                      vars "\n"))
        ;; replace any variable names preceded by '$' with the actual
        ;; value of the variable
        (mapc (lambda (pair)
                (setq body (replace-regexp-in-string
                            (format "\\$%s" (car pair)) (cdr pair) body)))
              vars))
      body)))
</t>
<t tx="ekr.20100929212226.14168">
(defun org-babel-execute:gnuplot (body params)
  "Execute a block of Gnuplot code.
This function is called by `org-babel-execute-src-block'."
  (require 'gnuplot)
  (let ((session (cdr (assoc :session params)))
        (result-type (cdr (assoc :results params)))
        (out-file (cdr (assoc :file params)))
        (body (org-babel-expand-body:gnuplot body params))
    output)
    (save-window-excursion
      ;; evaluate the code body with gnuplot
      (if (string= session "none")
          (let ((script-file (make-temp-file "org-babel-gnuplot-script")))
            (with-temp-file script-file
              (insert (concat body "\n")))
            (message "gnuplot \"%s\"" script-file)
            (setq output
                  (shell-command-to-string (format "gnuplot \"%s\"" script-file)))
            (message output))
        (with-temp-buffer
          (insert (concat body "\n"))
          (gnuplot-mode)
          (gnuplot-send-buffer-to-gnuplot)))
      (if (member "output" (split-string result-type))
          output
        out-file))))
</t>
<t tx="ekr.20100929212226.14169">
(defun org-babel-prep-session:gnuplot (session params)
  "Prepare SESSION according to the header arguments in PARAMS."
  (let* ((session (org-babel-gnuplot-initiate-session session))
         (vars (org-babel-ref-variables params))
         (var-lines (mapcar
                     (lambda (pair) (format "%s = \"%s\"" (car pair) (cdr pair)))
                     vars)))
    (message "%S" session)
    (org-babel-comint-in-buffer session
      (mapc (lambda (var-line)
              (insert var-line) (comint-send-input nil t)
              (org-babel-comint-wait-for-output session)
              (sit-for .1) (goto-char (point-max))) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14170">
(defun org-babel-load-session:gnuplot (session body params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:gnuplot session params)))
      (with-current-buffer buffer
        (goto-char (process-mark (get-buffer-process (current-buffer))))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14171">
(defvar gnuplot-buffer)
(defun org-babel-gnuplot-initiate-session (&amp;optional session params)
  "Initiate a gnuplot session.
If there is not a current inferior-process-buffer in SESSION
then create one.  Return the initialized session.  The current
`gnuplot-mode' doesn't provide support for multiple sessions."
  (require 'gnuplot)
  (unless (string= session "none")
    (save-window-excursion
      (gnuplot-send-string-to-gnuplot "" "line")
      gnuplot-buffer)))
</t>
<t tx="ekr.20100929212226.14172">
(defun org-babel-gnuplot-quote-timestamp-field (s)
  "Convert S from timestamp to Unix time and export to gnuplot."
  (format-time-string org-babel-gnuplot-timestamp-fmt (org-time-string-to-time s)))
</t>
<t tx="ekr.20100929212226.14173">
(defvar org-table-number-regexp)
(defvar org-ts-regexp3)
(defun org-babel-gnuplot-quote-tsv-field (s)
  "Quote S for export to gnuplot."
  (unless (stringp s)
    (setq s (format "%s" s)))
  (if (string-match org-table-number-regexp s) s
    (if (string-match org-ts-regexp3 s)
    (org-babel-gnuplot-quote-timestamp-field s)
      (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\""))))
</t>
<t tx="ekr.20100929212226.14174">
(defun org-babel-gnuplot-table-to-data (table data-file params)
  "Export TABLE to DATA-FILE in a format readable by gnuplot.
Pass PARAMS through to `orgtbl-to-generic' when exporting TABLE."
  (with-temp-file data-file
    (make-local-variable 'org-babel-gnuplot-timestamp-fmt)
    (setq org-babel-gnuplot-timestamp-fmt (or
                                           (plist-get params :timefmt)
                                           "%Y-%m-%d-%H:%M:%S"))
    (insert (orgtbl-to-generic
         table
         (org-combine-plists
          '(:sep "\t" :fmt org-babel-gnuplot-quote-tsv-field)
          params))))
  data-file)
</t>
<t tx="ekr.20100929212226.14175">@language lisp
@tabwidth -4
@others

(provide 'ob-haskell)

;; arch-tag: b53f75f3-ba1a-4b05-82d9-a2a0d4e70804

;;; ob-haskell.el ends here
</t>
<t tx="ekr.20100929212226.14176">;;; ob-haskell.el --- org-babel functions for haskell evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating haskell source code.  This one will
;; be sort of tricky because haskell programs must be compiled before
;; they can be run, but haskell code can also be run through an
;; interactive interpreter.
;;
;; For now lets only allow evaluation using the haskell interpreter.

;;; Requirements:

;; - haskell-mode :: http://www.iro.umontreal.ca/~monnier/elisp/#haskell-mode
;;
;; - inf-haskell :: http://www.iro.umontreal.ca/~monnier/elisp/#haskell-mode
;;
;; - (optionally) lhs2tex :: http://people.cs.uu.nl/andres/lhs2tex/

;;; Code:
(require 'ob)
(require 'ob-comint)
(require 'comint)
(eval-when-compile (require 'cl))

(declare-function org-remove-indentation "org" (code &amp;optional n))
(declare-function haskell-mode "ext:haskell-mode" ())
(declare-function run-haskell "ext:inf-haskell" (&amp;optional arg))
(declare-function inferior-haskell-load-file
          "ext:inf-haskell" (&amp;optional reload))

(add-to-list 'org-babel-tangle-lang-exts '("haskell" . "hs"))

(defvar org-babel-default-header-args:haskell '())

(defvar org-babel-haskell-lhs2tex-command "lhs2tex")

(defvar org-babel-haskell-eoe "\"org-babel-haskell-eoe\"")

</t>
<t tx="ekr.20100929212226.14177">(defun org-babel-expand-body:haskell (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
    (concat
     (mapconcat
      (lambda (pair) (format "let %s = %s"
            (car pair)
            (org-babel-haskell-var-to-haskell (cdr pair))))
      vars "\n") "\n" body "\n")))
</t>
<t tx="ekr.20100929212226.14178">
(defun org-babel-execute:haskell (body params)
  "Execute a block of Haskell code."
  (let* ((processed-params (org-babel-process-params params))
         (session (nth 0 processed-params))
         (vars (nth 1 processed-params))
         (result-type (nth 3 processed-params))
         (full-body (org-babel-expand-body:haskell body params processed-params))
         (session (org-babel-haskell-initiate-session session params))
         (raw (org-babel-comint-with-output
          (session org-babel-haskell-eoe t full-body)
                (insert (org-babel-trim full-body))
                (comint-send-input nil t)
                (insert org-babel-haskell-eoe)
                (comint-send-input nil t)))
         (results (mapcar
                   #'org-babel-haskell-read-string
                   (cdr (member org-babel-haskell-eoe
                                (reverse (mapcar #'org-babel-trim raw)))))))
    (org-babel-reassemble-table
     (cond
      ((equal result-type 'output)
       (mapconcat #'identity (reverse (cdr results)) "\n"))
      ((equal result-type 'value)
       (org-babel-haskell-table-or-string (car results))))
     (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
     (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params))))))
</t>
<t tx="ekr.20100929212226.14179">
(defun org-babel-haskell-read-string (string)
  "Strip \\\"s from around a haskell string."
  (if (string-match "^\"\\([^\000]+\\)\"$" string)
      (match-string 1 string)
    string))
</t>
<t tx="ekr.20100929212226.14180">
(defun org-babel-haskell-initiate-session (&amp;optional session params)
  "Initiate a haskell session.
If there is not a current inferior-process-buffer in SESSION
then create one.  Return the initialized session."
  (require 'inf-haskell)
  (or (get-buffer "*haskell*")
      (save-window-excursion (run-haskell) (sleep-for 0.25) (current-buffer))))
</t>
<t tx="ekr.20100929212226.14181">
(defun org-babel-load-session:haskell
  (session body params &amp;optional processed-params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let* ((buffer (org-babel-prep-session:haskell
            session params processed-params))
           (load-file (concat (make-temp-file "org-babel-haskell-load") ".hs")))
      (with-temp-buffer
        (insert body) (write-file load-file)
        (haskell-mode) (inferior-haskell-load-file))
      buffer)))
</t>
<t tx="ekr.20100929212226.14182">
(defun org-babel-prep-session:haskell
  (session params &amp;optional processed-params)
  "Prepare SESSION according to the header arguments in PARAMS."
  (save-window-excursion
    (let ((pp (or processed-params (org-babel-process-params params)))
      (buffer (org-babel-haskell-initiate-session session)))
      (org-babel-comint-in-buffer buffer
        (mapc
         (lambda (pair)
           (insert (format "let %s = %s"
                   (car pair)
                   (org-babel-haskell-var-to-haskell (cdr pair))))
           (comint-send-input nil t))
         (nth 1 pp)))
      (current-buffer))))
</t>
<t tx="ekr.20100929212226.14183">
(defun org-babel-haskell-table-or-string (results)
  "Convert RESULTS to an Emacs-lisp table or string.
If RESULTS look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  (org-babel-read
   (if (and (stringp results) (string-match "^\\[.+\\]$" results))
       (org-babel-read
        (concat "'"
                (replace-regexp-in-string
                 "\\[" "(" (replace-regexp-in-string
                            "\\]" ")" (replace-regexp-in-string
                                       "," " " (replace-regexp-in-string
                                                "'" "\"" results))))))
     results)))
</t>
<t tx="ekr.20100929212226.14184">
(defun org-babel-haskell-var-to-haskell (var)
  "Convert an elisp value VAR into a haskell variable.
The elisp VAR is converted to a string of haskell source code
specifying a variable of the same value."
  (if (listp var)
      (concat "[" (mapconcat #'org-babel-haskell-var-to-haskell var ", ") "]")
    (format "%S" var)))
</t>
<t tx="ekr.20100929212226.14185">
(defvar org-src-preserve-indentation)
(defun org-babel-haskell-export-to-lhs (&amp;optional arg)
  "Export to a .lhs file with all haskell code blocks escaped.
When called with a prefix argument the resulting
.lhs file will be exported to a .tex file.  This function will
create two new files, base-name.lhs and base-name.tex where
base-name is the name of the current org-mode file.

Note that all standard Babel literate programming
constructs (header arguments, no-web syntax etc...) are ignored."
  (interactive "P")
  (let* ((contents (buffer-string))
         (haskell-regexp
          (concat "^\\([ \t]*\\)#\\+begin_src[ \t]haskell*\\(.*\\)?[\r\n]"
                  "\\([^\000]*?\\)[\r\n][ \t]*#\\+end_src.*"))
         (base-name (file-name-sans-extension (buffer-file-name)))
         (tmp-file (make-temp-file "ob-haskell"))
         (tmp-org-file (concat tmp-file ".org"))
         (tmp-tex-file (concat tmp-file ".tex"))
         (lhs-file (concat base-name ".lhs"))
         (tex-file (concat base-name ".tex"))
         (command (concat org-babel-haskell-lhs2tex-command " " lhs-file " &gt; " tex-file))
         (preserve-indentp org-src-preserve-indentation)
         indentation)
    ;; escape haskell source-code blocks
    (with-temp-file tmp-org-file
      (insert contents)
      (goto-char (point-min))
      (while (re-search-forward haskell-regexp nil t)
        (save-match-data (setq indentation (length (match-string 1))))
        (replace-match (save-match-data
                         (concat
                          "#+begin_latex\n\\begin{code}\n"
                          (if (or preserve-indentp
                                  (string-match "-i" (match-string 2)))
                              (match-string 3)
                            (org-remove-indentation (match-string 3)))
                          "\n\\end{code}\n#+end_latex\n"))
                       t t)
        (indent-code-rigidly (match-beginning 0) (match-end 0) indentation)))
    (save-excursion
      ;; export to latex w/org and save as .lhs
      (find-file tmp-org-file) (funcall 'org-export-as-latex nil)
      (kill-buffer)
      (delete-file tmp-org-file)
      (find-file tmp-tex-file)
      (goto-char (point-min)) (forward-line 2)
      (insert "%include polycode.fmt\n")
      ;; ensure all \begin/end{code} statements start at the first column
      (while (re-search-forward "^[ \t]+\\\\begin{code}[^\000]+\\\\end{code}" nil t)
        (replace-match (save-match-data (org-remove-indentation (match-string 0)))
                       t t))
      (setq contents (buffer-string))
      (save-buffer) (kill-buffer))
    (delete-file tmp-tex-file)
    ;; save org exported latex to a .lhs file
    (with-temp-file lhs-file (insert contents))
    (if (not arg)
        (find-file lhs-file)
      ;; process .lhs file with lhs2tex
      (message "running %s" command) (shell-command command) (find-file tex-file))))
</t>
<t tx="ekr.20100929212226.14186">@language lisp
@tabwidth -4
@others

(defvar org-babel-key-bindings
  '(("p" . org-babel-previous-src-block)
    ("\C-p" . org-babel-previous-src-block)
    ("n" . org-babel-next-src-block)
    ("\C-n" . org-babel-next-src-block)
    ("e" . org-babel-execute-src-block)
    ("\C-e" . org-babel-execute-src-block)
    ("o" . org-babel-open-src-block-result)
    ("\C-o" . org-babel-open-src-block-result)
    ("\C-v" . org-babel-expand-src-block)
    ("v" . org-babel-expand-src-block)
    ("g" . org-babel-goto-named-src-block)
    ("r" . org-babel-goto-named-result)
    ("\C-r" . org-babel-goto-named-result)
    ("\C-b" . org-babel-execute-buffer)
    ("b" . org-babel-execute-buffer)
    ("\C-s" . org-babel-execute-subtree)
    ("s" . org-babel-execute-subtree)
    ("\C-t" . org-babel-tangle)
    ("t" . org-babel-tangle)
    ("\C-f" . org-babel-tangle-file)
    ("f" . org-babel-tangle-file)
    ("\C-l" . org-babel-lob-ingest)
    ("l" . org-babel-lob-ingest)
    ("\C-z" . org-babel-switch-to-session)
    ("z" . org-babel-switch-to-session)
    ("\C-a" . org-babel-sha1-hash)
    ("a" . org-babel-sha1-hash)
    ("h" . org-babel-describe-bindings))
  "Alist of key bindings and interactive Babel functions.
This list associates interactive Babel functions
with keys.  Each element of this list will add an entry to the
`org-babel-map' using the letter key which is the `car' of the
a-list placed behind the generic `org-babel-key-prefix'.")

(provide 'ob-keys)

;; arch-tag: 01e348ee-4906-46fa-839a-6b7b6f989048

;;; ob-keys.el ends here
</t>
<t tx="ekr.20100929212226.14187">;;; ob-keys.el --- key bindings for org-babel

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Add org-babel keybindings to the org-mode keymap for exposing
;; org-babel functions.  These will all share a common prefix.  See
;; the value of `org-babel-key-bindings' for a list of interactive
;; functions and their associated keys.

;;; Code:
(require 'ob)

(defvar org-babel-key-prefix "\C-c\C-v"
  "The key prefix for Babel interactive key-bindings.
See `org-babel-key-bindings' for the list of interactive babel
functions which are assigned key bindings, and see
`org-babel-map' for the actual babel keymap.")

(defvar org-babel-map (make-sparse-keymap)
  "The keymap for interactive Babel functions.")

</t>
<t tx="ekr.20100929212226.14188">;;;###autoload
(defun org-babel-describe-bindings ()
  "Describe all keybindings behind `org-babel-key-prefix'."
  (interactive)
  (describe-bindings org-babel-key-prefix))
</t>
<t tx="ekr.20100929212226.14189">@language lisp
@tabwidth -4
@others

(provide 'ob-latex)

;; arch-tag: 1f13f7e2-26de-4c24-9274-9f331d4c6ff3

;;; ob-latex.el ends here
</t>
<t tx="ekr.20100929212226.14190">;;; ob-latex.el --- org-babel functions for latex "evaluation"

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating LaTeX source code.
;;
;; Currently on evaluation this returns raw LaTeX code, unless a :file
;; header argument is given in which case small png or pdf files will
;; be created directly form the latex source code.

;;; Code:
(require 'ob)

(declare-function org-create-formula-image "org" (string tofile options buffer))
(declare-function org-splice-latex-header "org"
          (tpl def-pkg pkg snippets-p &amp;optional extra))
(declare-function org-export-latex-fix-inputenc "org-latex" ())

(add-to-list 'org-babel-tangle-lang-exts '("latex" . "tex"))

(defvar org-babel-default-header-args:latex
  '((:results . "latex") (:exports . "results"))
  "Default arguments to use when evaluating a LaTeX source block.")

</t>
<t tx="ekr.20100929212226.14191">(defun org-babel-expand-body:latex (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (mapc (lambda (pair) ;; replace variables
          (setq body
                (replace-regexp-in-string
                 (regexp-quote (format "%S" (car pair)))
                 (if (stringp (cdr pair))
                     (cdr pair) (format "%S" (cdr pair)))
                 body))) (nth 1 (org-babel-process-params params)))
  body)
</t>
<t tx="ekr.20100929212226.14192">
(defvar org-format-latex-options)
(defvar org-export-latex-packages-alist)
(defun org-babel-execute:latex (body params)
  "Execute a block of Latex code with Babel.
This function is called by `org-babel-execute-src-block'."
  (setq body (org-babel-expand-body:latex body params))
  (if (cdr (assoc :file params))
      (let ((out-file (cdr (assoc :file params)))
            (tex-file (make-temp-file "org-babel-latex" nil ".tex"))
            (pdfheight (cdr (assoc :pdfheight params)))
            (pdfwidth (cdr (assoc :pdfwidth params)))
            (in-buffer (not (string= "no" (cdr (assoc :buffer params)))))
            (org-export-latex-packages-alist
             (append (cdr (assoc :packages params))
                     org-export-latex-packages-alist)))
        (cond
         ((string-match "\\.png$" out-file)
          (org-create-formula-image
           body out-file org-format-latex-options in-buffer))
         ((string-match "\\.pdf$" out-file)
          (org-babel-latex-body-to-tex-file tex-file body pdfheight pdfwidth)
          (when (file-exists-p out-file) (delete-file out-file))
          (rename-file (org-babel-latex-tex-to-pdf tex-file) out-file))
         ((string-match "\\.\\([^\\.]+\\)$" out-file)
          (error "can not create %s files, please specify a .png or .pdf file"
         (match-string 1 out-file))))
        out-file)
    body))
</t>
<t tx="ekr.20100929212226.14193">
(defvar org-format-latex-header)
(defvar org-format-latex-header-extra)
(defvar org-export-latex-packages-alist)
(defvar org-export-latex-default-packages-alist)
(defun org-babel-latex-body-to-tex-file (tex-file body &amp;optional height width)
  "Place the contents of BODY into TEX-FILE.
Extracted from `org-create-formula-image' in org.el."
  (with-temp-file tex-file
    (insert (org-splice-latex-header
           org-format-latex-header
           (delq
        nil
        (mapcar
         (lambda (el) (unless (and (listp el) (string= "hyperref" (cadr el)))
               el))
         org-export-latex-default-packages-alist))
           org-export-latex-packages-alist
           org-format-latex-header-extra)
            (if height (concat "\n" (format "\\pdfpageheight %s" height)) "")
            (if width (concat "\n" (format "\\pdfpagewidth %s" width)) "")
            (if org-format-latex-header-extra
                (concat "\n" org-format-latex-header-extra)
              "")
            "\n\\begin{document}\n" body "\n\\end{document}\n")
    (org-export-latex-fix-inputenc)))
</t>
<t tx="ekr.20100929212226.14194">
(defvar org-export-pdf-logfiles)
(defvar org-latex-to-pdf-process)
(defvar org-export-pdf-remove-logfiles)
(defun org-babel-latex-tex-to-pdf (tex-file)
  "Generate a pdf file according to the contents TEX-FILE.
Extracted from `org-export-as-pdf' in org-latex.el."
  (let* ((wconfig (current-window-configuration))
         (default-directory (file-name-directory tex-file))
         (base (file-name-sans-extension tex-file))
         (pdffile (concat base ".pdf"))
         (cmds org-latex-to-pdf-process)
         (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
         cmd)
    (if (and cmds (symbolp cmds))
        (funcall cmds tex-file)
      (while cmds
        (setq cmd (pop cmds))
        (while (string-match "%b" cmd)
          (setq cmd (replace-match
                     (save-match-data
                       (shell-quote-argument base))
                     t t cmd)))
        (while (string-match "%s" cmd)
          (setq cmd (replace-match
                     (save-match-data
                       (shell-quote-argument tex-file))
                     t t cmd)))
        (shell-command cmd outbuf outbuf)))
    (if (not (file-exists-p pdffile))
        (error "PDF file was not produced from %s" tex-file)
      (set-window-configuration wconfig)
      (when org-export-pdf-remove-logfiles
        (dolist (ext org-export-pdf-logfiles)
          (setq tex-file (concat base "." ext))
          (and (file-exists-p tex-file) (delete-file tex-file))))
      pdffile)))
</t>
<t tx="ekr.20100929212226.14195">
(defun org-babel-prep-session:latex (session params)
  "Return an error because LaTeX doesn't support sesstions."
  (error "LaTeX does not support sessions"))
</t>
<t tx="ekr.20100929212226.14196">@language lisp
@tabwidth -4
@others

(provide 'ob-lob)

;; arch-tag: ce0712c9-2147-4019-ba3f-42341b8b474b

;;; ob-lob.el ends here
</t>
<t tx="ekr.20100929212226.14197">;;; ob-lob.el --- functions supporting the Library of Babel

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; See the online documentation for more information
;;
;;   http://orgmode.org/worg/org-contrib/babel/

;;; Code:
(require 'ob)
(require 'ob-table)

(defvar org-babel-library-of-babel nil
  "Library of source-code blocks.
This is an association list.  Populate the library by adding
files to `org-babel-lob-files'.")

(defcustom org-babel-lob-files '()
  "Files used to populate the `org-babel-library-of-babel'.
To add files to this list use the `org-babel-lob-ingest' command."
  :group 'org-babel
  :type 'list)

</t>
<t tx="ekr.20100929212226.14198">;;;###autoload
(defun org-babel-lob-ingest (&amp;optional file)
  "Add all source-blocks defined in FILE to `org-babel-library-of-babel'."
  (interactive "f")
  (org-babel-map-src-blocks file
    (let* ((info (org-babel-get-src-block-info))
       (source-name (intern (nth 4 info))))
      (when source-name
        (setq org-babel-library-of-babel
              (cons (cons source-name info)
                    (assq-delete-all source-name org-babel-library-of-babel)))))))
</t>
<t tx="ekr.20100929212226.14199">
(defconst org-babel-lob-call-aliases '("lob" "call")
  "Aliases to call a source block function.
If you change the value of this variable then your files may
  become unusable by other org-babel users, and vice versa.")

(defconst org-babel-lob-one-liner-regexp
  (concat
   "^\\([ \t]*\\)#\\+\\(?:"
   (mapconcat #'regexp-quote org-babel-lob-call-aliases "\\|")
   "\\):[ \t]+\\([^\(\)\n]+\\)\(\\([^\n]*\\)\)\\(\\[.+\\]\\)[ \t]*\\([^\n]*\\)")
  "Regexp to match calls to predefined source block functions.")

;; functions for executing lob one-liners
;;;###autoload
(defun org-babel-lob-execute-maybe ()
  "Execute a Library of Babel source block, if appropriate.
Detect if this is context for a Library Of Babel source block and
if so then run the appropriate source block from the Library."
  (interactive)
  (let ((info (org-babel-lob-get-info)))
    (if (nth 0 info) (progn (org-babel-lob-execute info) t) nil)))
</t>
<t tx="ekr.20100929212226.14200">
(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-lob-execute-maybe)

;;;###autoload
(defun org-babel-lob-get-info ()
  "Return a Library of Babel function call as a string.

This function is analogous to org-babel-get-src-block-name. For
both functions, after they are called, (match-string 1) matches
the function name, and (match-string 2) matches the function
arguments inside the parentheses. I think perhaps these functions
should be renamed to bring out this similarity, perhaps involving
the word 'call'."
  (let ((case-fold-search t))
    (save-excursion
      (beginning-of-line 1)
      (if (looking-at org-babel-lob-one-liner-regexp)
          (append
       (mapcar #'org-babel-clean-text-properties
           (list
            (format "%s(%s)%s"
                (match-string 2) (match-string 3) (match-string 4))
            (match-string 5)))
       (list (length (match-string 1))))))))
</t>
<t tx="ekr.20100929212226.14201">
(defun org-babel-lob-execute (info)
  "Execute the lob call specified by INFO."
  (let ((params (org-babel-merge-params
         org-babel-default-header-args
         (org-babel-params-from-buffer)
                 (org-babel-params-from-properties)
         (org-babel-parse-header-arguments
          (org-babel-clean-text-properties
           (concat ":var results="
               (mapconcat #'identity (butlast info) " ")))))))
    (org-babel-execute-src-block
     nil (list "emacs-lisp" "results" params nil nil (nth 2 info)))))
</t>
<t tx="ekr.20100929212226.14202">@language lisp
@tabwidth -4
@others
;; arch-tag: 6b234299-c1f7-4eb1-ace8-7b93344065ac

;;; ob-matlab.el ends here
</t>
<t tx="ekr.20100929212226.14203">;;; ob-matlab.el --- org-babel support for matlab evaluation

;; Copyright (C) 2010  Free Software Foundation, Inc.

;; Author: Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Functions that are common to org-babel support for matlab and
;; octave are in org-babel-octave.el

;;; Requirements:

;; Matlab

;; matlab.el required for interactive emacs sessions and matlab-mode
;; major mode for source code editing buffer
;; http://matlab-emacs.sourceforge.net/

;;; Code:
(require 'ob)
(require 'ob-octave)

;; see ob-octave for matlab implementation

(provide 'ob-matlab)

</t>
<t tx="ekr.20100929212226.14204">@language lisp
@tabwidth -4
@others

(provide 'ob-mscgen)

;; arch-tag: 74695b1e-715f-4b5a-a3a9-d78ee39ba5c8

;;; ob-msc.el ends here
</t>
<t tx="ekr.20100929212226.14205">;;; ob-msc.el --- org-babel functions for mscgen evaluation

;; Copyright (C) 2010  Free Software Foundation, Inc.

;; Author: Juan Pechiar
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:
;;
;; This software provides EMACS org-babel export support for message
;; sequence charts. The mscgen utility is used for processing the
;; sequence definition, and must therefore be installed in the system.
;;
;; Mscgen is available and documented at
;; http://www.mcternan.me.uk/mscgen/index.html
;;
;; This code is directly inspired by Eric Schulte's ob-dot.el
;;
;; Example:
;;
;; #+begin_src mscgen :file example.png
;; msc {
;;  A,B;
;;  A -&gt; B [ label = "send message" ];
;;  A &lt;- B [ label = "get answer" ];
;; }
;; #+end_src
;;
;; Header for alternative file type:
;;
;; #+begin_src mscgen :file ex2.svg :filetype svg

;; This differs from most standard languages in that
;;
;; 1) there is no such thing as a "session" in mscgen
;; 2) we are generally only going to return results of type "file"
;; 3) we are adding the "file" and "filetype" header arguments
;; 4) there are no variables

;;; Code:
(require 'ob)
(require 'ob-eval)

(defvar org-babel-default-header-args:mscgen
  '((:results . "file") (:exports . "results"))
  "Default arguments to use when evaluating a mscgen source block.")

</t>
<t tx="ekr.20100929212226.14206">(defun org-babel-expand-body:mscgen (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14207">
(defun org-babel-execute:mscgen (body params)
  "Execute a block of Mscgen code with Babel.
This function is called by `org-babel-execute-src-block'.
Default filetype is png. Modify by setting :filetype parameter to
mscgen supported formats."
  (let* ((out-file (or (cdr (assoc :file params)) "output.png" ))
         (filetype (or (cdr (assoc :filetype params)) "png" )))
    (unless (cdr (assoc :file params))
      (error "
ERROR: no output file specified. Add \":file name.png\" to the src header"))
    (org-babel-eval (concat "mscgen -T " filetype " -o " out-file) body)
    out-file))
</t>
<t tx="ekr.20100929212226.14208">
(defun org-babel-prep-session:mscgen (session params)
  "Raise an error because Mscgen doesn't support sessions."
  (error "Mscgen does not support sessions"))
</t>
<t tx="ekr.20100929212226.14209">@language lisp
@tabwidth -4
@others

(provide 'ob-ocaml)

;; arch-tag: 2e815f4d-365e-4d69-b1df-dd17fdd7b7b7

;;; ob-ocaml.el ends here
</t>
<t tx="ekr.20100929212226.14210">;;; ob-ocaml.el --- org-babel functions for ocaml evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating ocaml source code.  This one will
;; be sort of tricky because ocaml programs must be compiled before
;; they can be run, but ocaml code can also be run through an
;; interactive interpreter.
;;
;; For now lets only allow evaluation using the ocaml interpreter.

;;; Requirements:

;; - tuareg-mode :: http://www-rocq.inria.fr/~acohen/tuareg/

;;; Code:
(require 'ob)
(require 'ob-comint)
(require 'comint)
(eval-when-compile (require 'cl))

(declare-function tuareg-run-caml "ext:tuareg" ())
(declare-function tuareg-interactive-send-input "ext:tuareg" ())

(add-to-list 'org-babel-tangle-lang-exts '("ocaml" . "ml"))

(defvar org-babel-default-header-args:ocaml '())

(defvar org-babel-ocaml-eoe-indicator "\"org-babel-ocaml-eoe\";;")
(defvar org-babel-ocaml-eoe-output "org-babel-ocaml-eoe")

</t>
<t tx="ekr.20100929212226.14211">(defun org-babel-expand-body:ocaml (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
    (concat
     (mapconcat
      (lambda (pair) (format "let %s = %s;;" (car pair)
            (org-babel-ocaml-elisp-to-ocaml (cdr pair))))
      vars "\n") "\n" body "\n")))
</t>
<t tx="ekr.20100929212226.14212">
(defun org-babel-execute:ocaml (body params)
  "Execute a block of Ocaml code with Babel."
  (let* ((processed-params (org-babel-process-params params))
         (vars (nth 1 processed-params))
         (full-body (org-babel-expand-body:ocaml body params processed-params))
         (session (org-babel-prep-session:ocaml
           (cdr (assoc :session params)) params))
         (raw (org-babel-comint-with-output
          (session org-babel-ocaml-eoe-output t full-body)
        (insert
         (concat
          (org-babel-chomp full-body)"\n"org-babel-ocaml-eoe-indicator))
        (tuareg-interactive-send-input)))
     (clean
      (car (let ((re (regexp-quote org-babel-ocaml-eoe-output)) out)
         (delq nil (mapcar (lambda (line)
                     (if out
                     (progn (setq out nil) line)
                       (when (string-match re line)
                     (progn (setq out t) nil))))
                 (mapcar #'org-babel-trim (reverse raw))))))))
    (org-babel-reassemble-table
     (org-babel-ocaml-parse-output (org-babel-trim clean))
     (org-babel-pick-name
      (nth 4 processed-params) (cdr (assoc :colnames params)))
     (org-babel-pick-name
      (nth 5 processed-params) (cdr (assoc :rownames params))))))
</t>
<t tx="ekr.20100929212226.14213">
(defvar tuareg-interactive-buffer-name)
(defun org-babel-prep-session:ocaml (session params)
  "Prepare SESSION according to the header arguments in PARAMS."
  (require 'tuareg)
  (let ((tuareg-interactive-buffer-name (if (and (not (string= session "none"))
                                                 (not (string= session "default"))
                                                 (stringp session))
                                            session
                                          tuareg-interactive-buffer-name)))
    (save-window-excursion (tuareg-run-caml)
                           (get-buffer tuareg-interactive-buffer-name))))
</t>
<t tx="ekr.20100929212226.14214">
(defun org-babel-ocaml-elisp-to-ocaml (val)
  "Return a string of ocaml code which evaluates to VAL."
  (if (listp val)
      (concat "[|" (mapconcat #'org-babel-ocaml-elisp-to-ocaml val "; ") "|]")
    (format "%S" val)))
</t>
<t tx="ekr.20100929212226.14215">
(defun org-babel-ocaml-parse-output (output)
  "Parse OUTPUT.
OUTPUT is string output from an ocaml process."
  (let ((regexp "%s = \\(.+\\)$"))
    (cond
     ((string-match (format regexp "string") output)
      (org-babel-read (match-string 1 output)))
     ((or (string-match (format regexp "int") output)
          (string-match (format regexp "float") output))
      (string-to-number (match-string 1 output)))
     ((string-match (format regexp "list") output)
      (org-babel-ocaml-read-list (match-string 1 output)))
     ((string-match (format regexp "array") output)
      (org-babel-ocaml-read-array (match-string 1 output)))
     (t (message "don't recognize type of %s" output) output))))
</t>
<t tx="ekr.20100929212226.14216">
(defun org-babel-ocaml-read-list (results)
  "Convert RESULTS into an elisp table or string.
If the results look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  (org-babel-read
   (if (and (stringp results) (string-match "^\\[.+\\]$" results))
       (org-babel-read
        (replace-regexp-in-string
         "\\[" "(" (replace-regexp-in-string
                    "\\]" ")" (replace-regexp-in-string
                               "; " " " (replace-regexp-in-string
                                         "'" "\"" results)))))
     results)))
</t>
<t tx="ekr.20100929212226.14217">
(defun org-babel-ocaml-read-array (results)
  "Convert RESULTS into an elisp table or string.
If the results look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  (org-babel-read
   (if (and (stringp results) (string-match "^\\[.+\\]$" results))
       (org-babel-read
    (concat
     "'" (replace-regexp-in-string
          "\\[|" "(" (replace-regexp-in-string
              "|\\]" ")" (replace-regexp-in-string
                      "; " " " (replace-regexp-in-string
                        "'" "\"" results))))))
     results)))
</t>
<t tx="ekr.20100929212226.14218">@language lisp
@tabwidth -4
@others

(provide 'ob-octave)

;; arch-tag: d8e5f68b-ba13-440a-a495-b653e989e704

;;; ob-octave.el ends here
</t>
<t tx="ekr.20100929212226.14219">;;; ob-octave.el --- org-babel functions for octave and matlab evaluation

;; Copyright (C) 2010  Free Software Foundation, Inc.

;; Author: Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;;; Requirements:

;; octave
;; octave-mode.el and octave-inf.el come with GNU emacs

;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(declare-function matlab-shell "ext:matlab-mode")
(declare-function matlab-shell-run-region "ext:matlab-mode")

(defvar org-babel-default-header-args:matlab '())
(defvar org-babel-default-header-args:octave '())

(defvar org-babel-matlab-shell-command "matlab -nosplash"
  "Shell command to run matlab as an external process.")
(defvar org-babel-octave-shell-command "octave -q"
  "Shell command to run octave as an external process.")

</t>
<t tx="ekr.20100929212226.14220">(defun org-babel-expand-body:matlab (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (org-babel-expand-body:octave body params processed-params))
</t>
<t tx="ekr.20100929212226.14221">(defun org-babel-expand-body:octave (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
    (concat
     (mapconcat
      (lambda (pair)
        (format "%s=%s"
                (car pair)
                (org-babel-octave-var-to-octave (cdr pair))))
      vars "\n") "\n" body "\n")))
</t>
<t tx="ekr.20100929212226.14222">
(defvar org-babel-matlab-with-emacs-link nil
  "If non-nil use matlab-shell-run-region for session evaluation.
  This will use EmacsLink if (matlab-with-emacs-link) evaluates
  to a non-nil value.")

(defvar org-babel-matlab-emacs-link-wrapper-method
   "%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
else, save -ascii %s ans
end
delete('%s')
")
(defvar org-babel-octave-wrapper-method
  "%s
if ischar(ans), fid = fopen('%s', 'w'); fprintf(fid, '%%s\\n', ans); fclose(fid);
else, save -ascii %s ans
end")

(defvar org-babel-octave-eoe-indicator "\'org_babel_eoe\'")

(defvar org-babel-octave-eoe-output "ans = org_babel_eoe")

(defun org-babel-execute:matlab (body params)
  "Execute a block of matlab code with Babel."
  (require 'matlab)
  (org-babel-execute:octave body params 'matlab))
</t>
<t tx="ekr.20100929212226.14223">(defun org-babel-execute:octave (body params &amp;optional matlabp)
  "Execute a block of octave code with Babel."
  (let* ((processed-params (org-babel-process-params params))
         (session
      (funcall (intern (format "org-babel-%s-initiate-session"
                   (if matlabp "matlab" "octave")))
           (nth 0 processed-params) params))
         (vars (nth 1 processed-params))
         (result-params (nth 2 processed-params))
         (result-type (nth 3 processed-params))
     (out-file (cdr (assoc :file params)))
     (augmented-body
      (org-babel-expand-body:octave body params processed-params))
     (result (org-babel-octave-evaluate
          session augmented-body result-type matlabp)))
    (or out-file
        (org-babel-reassemble-table
         result
         (org-babel-pick-name
      (nth 4 processed-params) (cdr (assoc :colnames params)))
         (org-babel-pick-name
      (nth 5 processed-params) (cdr (assoc :rownames params)))))))
</t>
<t tx="ekr.20100929212226.14224">
(defun org-babel-prep-session:matlab (session params)
  "Prepare SESSION according to PARAMS."
  (require 'matlab)
  (org-babel-prep-session:octave session params 'matlab))
</t>
<t tx="ekr.20100929212226.14225">(defun org-babel-octave-var-to-octave (var)
  "Convert an emacs-lisp value into an octave variable.
Converts an emacs-lisp variable into a string of octave code
specifying a variable of the same value."
  (if (listp var)
      (concat "[" (mapconcat #'org-babel-octave-var-to-octave var ", ") "]")
    (format "%S" var)))
</t>
<t tx="ekr.20100929212226.14226">
(defun org-babel-prep-session:octave (session params &amp;optional matlabp)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  (let* ((session (org-babel-octave-initiate-session session params matlabp))
         (vars (org-babel-ref-variables params))
         (var-lines (mapcar
                     (lambda (pair)
                       (format "%s=%s"
                               (car pair)
                               (org-babel-octave-var-to-octave (cdr pair))))
                     vars)))
    (org-babel-comint-in-buffer session
      (mapc (lambda (var)
              (end-of-line 1) (insert var) (comint-send-input nil t)
              (org-babel-comint-wait-for-output session)) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14227">
(defun org-babel-matlab-initiate-session (&amp;optional session params)
  "Create a matlab inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
  (require 'matlab)
  (org-babel-octave-initiate-session session params 'matlab))
</t>
<t tx="ekr.20100929212226.14228">(defun org-babel-octave-initiate-session (&amp;optional session params matlabp)
  "Create an octave inferior process buffer.
If there is not a current inferior-process-buffer in SESSION then
create. Return the initialized session."
  (require 'octave-inf)
  (unless (string= session "none")
    (let ((session (or session
               (if matlabp "*Inferior Matlab*" "*Inferior Octave*"))))
      (if (org-babel-comint-buffer-livep session) session
    (save-window-excursion
      (if matlabp (unless org-babel-matlab-with-emacs-link (matlab-shell))
        (run-octave))
      (rename-buffer (if (bufferp session) (buffer-name session)
               (if (stringp session) session (buffer-name))))
      (current-buffer))))))
</t>
<t tx="ekr.20100929212226.14229">
(defun org-babel-octave-evaluate
  (session body result-type lang &amp;optional matlabp)
  "Pass BODY to the octave process in SESSION.
If RESULT-TYPE equals 'output then return the outputs of the
statements in BODY, if RESULT-TYPE equals 'value then return the
value of the last statement in BODY, as elisp."
  (if session
      (org-babel-octave-evaluate-session session body result-type matlabp)
    (org-babel-octave-evaluate-external-process body result-type matlabp)))
</t>
<t tx="ekr.20100929212226.14230">
(defun org-babel-octave-evaluate-external-process (body result-type matlabp)
  "Evaluate BODY in an external octave process."
  (let ((cmd (if matlabp
         org-babel-matlab-shell-command
           org-babel-octave-shell-command)))
    (case result-type
      (output (org-babel-eval cmd body))
      (value (let ((tmp-file (make-temp-file "org-babel-results-")))
           (org-babel-eval
        cmd
        (format org-babel-octave-wrapper-method body tmp-file tmp-file))
           (org-babel-eval-read-file tmp-file))))))
</t>
<t tx="ekr.20100929212226.14231">
(defun org-babel-octave-evaluate-session
  (session body result-type &amp;optional matlabp)
  "Evaluate BODY in SESSION."
  (let* ((tmp-file (make-temp-file "org-babel-results-"))
     (wait-file (make-temp-file "org-babel-matlab-emacs-link-wait-signal-"))
     (full-body
      (case result-type
        (output
         (mapconcat
          #'org-babel-chomp
          (list body org-babel-octave-eoe-indicator) "\n"))
        (value
         (if (and matlabp org-babel-matlab-with-emacs-link)
         (concat
          (format org-babel-matlab-emacs-link-wrapper-method
              body tmp-file tmp-file wait-file) "\n")
           (mapconcat
        #'org-babel-chomp
        (list (format org-babel-octave-wrapper-method
                  body tmp-file tmp-file)
              org-babel-octave-eoe-indicator) "\n")))))
     (raw (if (and matlabp org-babel-matlab-with-emacs-link)
          (save-window-excursion
            (with-temp-buffer
              (insert full-body)
              (write-region "" 'ignored wait-file nil nil nil 'excl)
              (matlab-shell-run-region (point-min) (point-max))
              (message "Waiting for Matlab Emacs Link")
              (while (file-exists-p wait-file) (sit-for 0.01))
              "")) ;; matlab-shell-run-region doesn't seem to
               ;; make *matlab* buffer contents easily
               ;; available, so :results output currently
               ;; won't work
        (org-babel-comint-with-output
            (session
             (if matlabp
             org-babel-octave-eoe-indicator
               org-babel-octave-eoe-output)
             t full-body)
          (insert full-body) (comint-send-input nil t)))) results)
    (case result-type
      (value
       (org-babel-octave-import-elisp-from-file
    (org-babel-maybe-remote-file tmp-file)))
      (output
       (progn
     (setq results
           (if matlabp
           (cdr (reverse (delq "" (mapcar
                       #'org-babel-octave-read-string
                       (mapcar #'org-babel-trim raw)))))
         (cdr (member org-babel-octave-eoe-output
                  (reverse (mapcar
                    #'org-babel-octave-read-string
                    (mapcar #'org-babel-trim raw)))))))
     (mapconcat #'identity (reverse results) "\n"))))))
</t>
<t tx="ekr.20100929212226.14232">
(defun org-babel-octave-import-elisp-from-file (file-name)
  "Import data from FILE-NAME.
This removes initial blank and comment lines and then calls
`org-babel-import-elisp-from-file'."
  (let ((temp-file (make-temp-file "org-babel-results-")) beg end)
    (with-temp-file temp-file
      (insert-file-contents file-name)
      (re-search-forward "^[ \t]*[^# \t]" nil t)
      (if (&lt; (setq beg (point-min))
         (setq end (point-at-bol)))
      (delete-region beg end)))
    (org-babel-import-elisp-from-file temp-file)))
</t>
<t tx="ekr.20100929212226.14233">
(defun org-babel-octave-read-string (string)
  "Strip \\\"s from around octave string"
  (if (string-match "^\"\\([^\000]+\\)\"$" string)
      (match-string 1 string)
    string))
</t>
<t tx="ekr.20100929212226.14234">@language lisp
@tabwidth -4
@others

(provide 'ob-perl)

;; arch-tag: 88ef9396-d857-4dc3-8946-5a72bdfa2337

;;; ob-perl.el ends here
</t>
<t tx="ekr.20100929212226.14235">;;; ob-perl.el --- org-babel functions for perl evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation

;; Author: Dan Davison, Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating perl source code.

;;; Code:
(require 'ob)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(add-to-list 'org-babel-tangle-lang-exts '("perl" . "pl"))

(defvar org-babel-default-header-args:perl '())

(defvar org-babel-perl-command "perl"
  "Name of command to use for executing perl code.")

</t>
<t tx="ekr.20100929212226.14236">(defun org-babel-expand-body:perl (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
    (concat
     (mapconcat ;; define any variables
      (lambda (pair)
        (format "$%s=%s;"
                (car pair)
                (org-babel-perl-var-to-perl (cdr pair))))
      vars "\n") "\n" (org-babel-trim body) "\n")))
</t>
<t tx="ekr.20100929212226.14237">
(defun org-babel-execute:perl (body params)
  "Execute a block of Perl code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((processed-params (org-babel-process-params params))
         (session (nth 0 processed-params))
         (vars (nth 1 processed-params))
         (result-params (nth 2 processed-params))
         (result-type (nth 3 processed-params))
         (full-body (org-babel-expand-body:perl
                     body params processed-params))
    (session (org-babel-perl-initiate-session session)))
    (org-babel-reassemble-table
     (org-babel-perl-evaluate session full-body result-type)
     (org-babel-pick-name
      (nth 4 processed-params) (cdr (assoc :colnames params)))
     (org-babel-pick-name
      (nth 5 processed-params) (cdr (assoc :rownames params))))))
</t>
<t tx="ekr.20100929212226.14238">
(defun org-babel-prep-session:perl (session params)
  "Prepare SESSION according to the header arguments in PARAMS."
  (error "Sessions are not supported for Perl."))
</t>
<t tx="ekr.20100929212226.14239">
;; helper functions

(defun org-babel-perl-var-to-perl (var)
  "Convert an elisp value to a perl variable.
The elisp value, VAR, is converted to a string of perl source code
specifying a var of the same value."
  (if (listp var)
      (concat "[" (mapconcat #'org-babel-perl-var-to-perl var ", ") "]")
    (format "%S" var)))
</t>
<t tx="ekr.20100929212226.14240">
(defvar org-babel-perl-buffers '(:default . nil))

(defun org-babel-perl-initiate-session (&amp;optional session params)
  "Return nil because sessions are not supported by perl"
nil)
</t>
<t tx="ekr.20100929212226.14241">
(defvar org-babel-perl-wrapper-method
  "
sub main {
%s
}
@r = main;
open(o, \"&gt;%s\");
print o join(\"\\n\", @r), \"\\n\"")

(defvar org-babel-perl-pp-wrapper-method
  nil)

(defun org-babel-perl-evaluate (session body &amp;optional result-type)
  "Pass BODY to the Perl process in SESSION.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY, as elisp."
  (when session (error "Sessions are not supported for Perl."))
  (case result-type
    (output (org-babel-eval org-babel-perl-command body))
    (value (let ((tmp-file (make-temp-file "org-babel-perl-results-")))
         (org-babel-eval
          org-babel-perl-command
          (format org-babel-perl-wrapper-method body tmp-file))
         (org-babel-eval-read-file tmp-file)))))
</t>
<t tx="ekr.20100929212226.14242">@language lisp
@tabwidth -4
@others

(provide 'ob-python)

;; arch-tag: f19b6c3d-dfcb-4a1a-9ce0-45ade1ebc212

;;; ob-python.el ends here
</t>
<t tx="ekr.20100929212226.14243">;;; ob-python.el --- org-babel functions for python evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating python source code.

;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(declare-function org-remove-indentation "org" )
(declare-function py-shell "ext:python-mode" (&amp;optional argprompt))
(declare-function run-python "ext:python" (&amp;optional cmd noshow new))

(add-to-list 'org-babel-tangle-lang-exts '("python" . "py"))

(defvar org-babel-default-header-args:python '())

(defvar org-babel-python-command "python"
  "Name of command for executing python code.")

(defvar org-babel-python-mode (if (featurep 'xemacs) 'python-mode 'python)
  "Preferred python mode for use in running python interactively.")

</t>
<t tx="ekr.20100929212226.14244">(defun org-babel-expand-body:python (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (concat
   (mapconcat ;; define any variables
    (lambda (pair)
      (format "%s=%s"
              (car pair)
              (org-babel-python-var-to-python (cdr pair))))
    (nth 1 (or processed-params (org-babel-process-params params))) "\n")
   "\n" (org-babel-trim body) "\n"))
</t>
<t tx="ekr.20100929212226.14245">
(defun org-babel-execute:python (body params)
  "Execute a block of Python code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((processed-params (org-babel-process-params params))
         (session (org-babel-python-initiate-session (first processed-params)))
         (result-params (nth 2 processed-params))
         (result-type (nth 3 processed-params))
         (full-body (org-babel-expand-body:python
                     body params processed-params))
         (result (org-babel-python-evaluate
          session full-body result-type result-params)))
    (or (cdr (assoc :file params))
        (org-babel-reassemble-table
         result
         (org-babel-pick-name (nth 4 processed-params)
                  (cdr (assoc :colnames params)))
         (org-babel-pick-name (nth 5 processed-params)
                  (cdr (assoc :rownames params)))))))
</t>
<t tx="ekr.20100929212226.14246">
(defun org-babel-prep-session:python (session params)
  "Prepare SESSION according to the header arguments in PARAMS."
  (let* ((session (org-babel-python-initiate-session session))
         (vars (org-babel-ref-variables params))
         (var-lines (mapcar ;; define any variables
                     (lambda (pair)
                       (format "%s=%s"
                               (car pair)
                               (org-babel-python-var-to-python (cdr pair))))
                     vars)))
    (org-babel-comint-in-buffer session
      (mapc (lambda (var)
              (end-of-line 1) (insert var) (comint-send-input)
              (org-babel-comint-wait-for-output session)) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14247">
(defun org-babel-load-session:python (session body params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:python session params)))
      (with-current-buffer buffer
        (goto-char (process-mark (get-buffer-process (current-buffer))))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14248">
;; helper functions

(defun org-babel-python-var-to-python (var)
  "Convert an elisp value to a python variable.
Convert an elisp value, VAR, into a string of python source code
specifying a variable of the same value."
  (if (listp var)
      (concat "[" (mapconcat #'org-babel-python-var-to-python var ", ") "]")
    (if (equal var 'hline)
    "None"
      (format
       (if (and (stringp var) (string-match "[\n\r]" var)) "\"\"%S\"\"" "%S")
       var))))
</t>
<t tx="ekr.20100929212226.14249">
(defun org-babel-python-table-or-string (results)
  "Convert RESULTS into an appropriate elisp value.
If the results look like a list or tuple, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  ((lambda (res)
     (if (listp res)
     (mapcar (lambda (el) (if (equal el 'None) 'hline el)) res)
       res))
   (org-babel-read
   (if (or (string-match "^\\[.+\\]$" results)
       (string-match "^(.+)$" results))
       (org-babel-read
        (concat "'"
                (replace-regexp-in-string
                 "\\[" "(" (replace-regexp-in-string
                            "\\]" ")" (replace-regexp-in-string
                                       ", " " " (replace-regexp-in-string
                                                 "'" "\"" results t))))))
     results))))
</t>
<t tx="ekr.20100929212226.14250">
(defvar org-babel-python-buffers '((:default . nil)))

(defun org-babel-python-session-buffer (session)
  "Return the buffer associated with SESSION."
  (cdr (assoc session org-babel-python-buffers)))
</t>
<t tx="ekr.20100929212226.14251">
(defun org-babel-python-initiate-session-by-key (&amp;optional session)
  "Initiate a python session.
If there is not a current inferior-process-buffer in SESSION
then create.  Return the initialized session."
  (require org-babel-python-mode)
  (save-window-excursion
    (let* ((session (if session (intern session) :default))
           (python-buffer (org-babel-python-session-buffer session)))
      (cond
       ((and (equal 'python org-babel-python-mode)
         (fboundp 'run-python)) ; python.el
    (run-python))
       ((and (equal 'python-mode org-babel-python-mode)
         (fboundp 'py-shell)) ; python-mode.el
    ;; `py-shell' creates a buffer whose name is the value of
    ;; `py-which-bufname' with '*'s at the beginning and end
    (let* ((bufname (if python-buffer
                (replace-regexp-in-string ;; zap surrounding *
                 "^\\*\\([^*]+\\)\\*$" "\\1" python-buffer)
              (concat "Python-" (symbol-name session))))
           (py-which-bufname bufname))
      (py-shell)
      (setq python-buffer (concat "*" bufname "*"))))
       (t
    (error "No function available for running an inferior python.")))
      (setq org-babel-python-buffers
        (cons (cons session python-buffer)
          (assq-delete-all session org-babel-python-buffers)))
      session)))
</t>
<t tx="ekr.20100929212226.14252">
(defun org-babel-python-initiate-session (&amp;optional session params)
  "Create a session named SESSION according to PARAMS."
  (unless (string= session "none")
    (org-babel-python-session-buffer
     (org-babel-python-initiate-session-by-key session))))
</t>
<t tx="ekr.20100929212226.14253">
(defvar org-babel-python-eoe-indicator "'org_babel_python_eoe'"
  "A string to indicate that evaluation has completed.")
(defvar org-babel-python-wrapper-method
  "
def main():
%s

open('%s', 'w').write( str(main()) )")
(defvar org-babel-python-pp-wrapper-method
  "
import pprint
def main():
%s

open('%s', 'w').write( pprint.pformat(main()) )")

(defun org-babel-python-evaluate
  (buffer body &amp;optional result-type result-params)
  "Pass BODY to the Python process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY, as elisp."
  (if (not buffer)
      ;; external process evaluation
      (case result-type
    (output (org-babel-eval org-babel-python-command body))
    (value (let ((tmp-file (make-temp-file "org-babel-python-results-")))
         (org-babel-eval org-babel-python-command
                 (format
                  (if (member "pp" result-params)
                      org-babel-python-pp-wrapper-method
                    org-babel-python-wrapper-method)
                  (mapconcat
                   (lambda (line) (format "\t%s" line))
                   (split-string
                    (org-remove-indentation
                     (org-babel-trim body))
                    "[\r\n]") "\n")
                  tmp-file))
         ((lambda (raw)
            (if (or (member "code" result-params)
                (member "pp" result-params))
            raw
              (org-babel-python-table-or-string raw)))
          (org-babel-eval-read-file tmp-file)))))
    ;; comint session evaluation
    (flet ((dump-last-value (tmp-file pp)
        (mapc
         (lambda (statement) (insert statement) (comint-send-input))
         (if pp
         (list
          "import pp"
          (format "open('%s', 'w').write(pprint.pformat(_))" tmp-file))
           (list (format "open('%s', 'w').write(str(_))" tmp-file)))))
       (input-body (body)
        (mapc (lambda (statement) (insert statement) (comint-send-input))
          (split-string (org-babel-trim body) "[\r\n]+"))
        (comint-send-input) (comint-send-input)))
      (case result-type
    (output
     (mapconcat
      #'org-babel-trim
      (butlast
       (org-babel-comint-with-output
           (buffer org-babel-python-eoe-indicator t body)
         (let ((comint-process-echoes nil))
           (input-body body)
           (insert org-babel-python-eoe-indicator)
           (comint-send-input))) 2) "\n"))
    (value
     ((lambda (results)
        (if (or (member "code" result-params) (member "pp" result-params))
        results
          (org-babel-python-table-or-string results)))
      (let ((tmp-file (make-temp-file "org-babel-python-results-")))
        (org-babel-comint-with-output
        (buffer org-babel-python-eoe-indicator t body)
          (let ((comint-process-echoes nil))
        (input-body body)
        (dump-last-value tmp-file (member "pp" result-params))
        (comint-send-input) (comint-send-input)
        (insert org-babel-python-eoe-indicator)
        (comint-send-input)))
        (org-babel-eval-read-file tmp-file))))))))
</t>
<t tx="ekr.20100929212226.14254">
(defun org-babel-python-read-string (string)
  "Strip 's from around python string"
  (if (string-match "^'\\([^\000]+\\)'$" string)
      (match-string 1 string)
    string))
</t>
<t tx="ekr.20100929212226.14255">@language lisp
@tabwidth -4
@others

(provide 'ob-R)

;; arch-tag: cd4c7298-503b-450f-a3c2-f3e74b630237

;;; ob-R.el ends here
</t>
<t tx="ekr.20100929212226.14256">;;; ob-R.el --- org-babel functions for R code evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research, R, statistics
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating R code

;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(declare-function orgtbl-to-tsv "ob-table" (table params))
(declare-function R "ext:essd-r" (&amp;optional start-args))
(declare-function inferior-ess-send-input "ext:ess-inf" ())

(defconst org-babel-header-arg-names:R
  '(width height bg units pointsize antialias quality compression
      res type family title fonts version paper encoding
      pagecentre colormodel useDingbats horizontal)
  "R-specific header arguments.")

(defvar org-babel-default-header-args:R '())

(defvar org-babel-R-command "R --slave --no-save"
  "Name of command to use for executing R code.")

</t>
<t tx="ekr.20100929212226.14257">(defun org-babel-expand-body:R (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let* ((processed-params (or processed-params
                               (org-babel-process-params params)))
     (vars (mapcar
        (lambda (i)
          (cons (car (nth i (nth 1 processed-params)))
            (org-babel-reassemble-table
             (cdr (nth i (nth 1 processed-params)))
             (cdr (nth i (nth 4 processed-params)))
             (cdr (nth i (nth 5 processed-params))))))
        (number-sequence 0 (1- (length (nth 1 processed-params))))))
         (out-file (cdr (assoc :file params))))
    (mapconcat ;; define any variables
     #'org-babel-trim
     ((lambda (inside)
    (if out-file
        (append
         (list (org-babel-R-construct-graphics-device-call out-file params))
         inside
         (list "dev.off()"))
      inside))
      (append
       (mapcar
    (lambda (pair)
      (org-babel-R-assign-elisp
       (car pair) (cdr pair)
       (equal "yes" (cdr (assoc :colnames params)))
       (equal "yes" (cdr (assoc :rownames params)))))
    vars)
       (list body))) "\n")))
</t>
<t tx="ekr.20100929212226.14258">
(defun org-babel-execute:R (body params)
  "Execute a block of R code.
This function is called by `org-babel-execute-src-block'."
  (save-excursion
    (let* ((processed-params (org-babel-process-params params))
           (result-type (nth 3 processed-params))
           (session (org-babel-R-initiate-session
             (first processed-params) params))
       (colnames-p (cdr (assoc :colnames params)))
       (rownames-p (cdr (assoc :rownames params)))
       (out-file (cdr (assoc :file params)))
       (full-body (org-babel-expand-body:R body params processed-params))
       (result
        (org-babel-R-evaluate
         session full-body result-type
         (or (equal "yes" colnames-p)
         (org-babel-pick-name (nth 4 processed-params) colnames-p))
         (or (equal "yes" rownames-p)
         (org-babel-pick-name (nth 5 processed-params) rownames-p)))))
      (message "result is %S" result)
      (or out-file result))))
</t>
<t tx="ekr.20100929212226.14259">
(defun org-babel-prep-session:R (session params)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  (let* ((session (org-babel-R-initiate-session session params))
     (vars (org-babel-ref-variables params))
     (var-lines
      (mapcar
       (lambda (pair) (org-babel-R-assign-elisp
              (car pair) (cdr pair)
              (equal (cdr (assoc :colnames params)) "yes")
              (equal (cdr (assoc :rownames params)) "yes")))
       vars)))
    (org-babel-comint-in-buffer session
      (mapc (lambda (var)
              (end-of-line 1) (insert var) (comint-send-input nil t)
              (org-babel-comint-wait-for-output session)) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14260">
(defun org-babel-load-session:R (session body params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:R session params)))
      (with-current-buffer buffer
        (goto-char (process-mark (get-buffer-process (current-buffer))))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14261">
;; helper functions

(defun org-babel-R-quote-tsv-field (s)
  "Quote field S for export to R."
  (if (stringp s)
      (concat "\"" (mapconcat 'identity (split-string s "\"") "\"\"") "\"")
    (format "%S" s)))
</t>
<t tx="ekr.20100929212226.14262">
(defun org-babel-R-assign-elisp (name value colnames-p rownames-p)
  "Construct R code assigning the elisp VALUE to a variable named NAME."
  (if (listp value)
      (let ((transition-file (make-temp-file "org-babel-R-import")))
        ;; ensure VALUE has an orgtbl structure (depth of at least 2)
        (unless (listp (car value)) (setq value (list value)))
        (with-temp-file (org-babel-maybe-remote-file transition-file)
          (insert (orgtbl-to-tsv value '(:fmt org-babel-R-quote-tsv-field)))
          (insert "\n"))
        (format "%s &lt;- read.table(\"%s\", header=%s, row.names=%s, sep=\"\\t\", as.is=TRUE)"
                name transition-file
        (if (or (eq (nth 1 value) 'hline) colnames-p) "TRUE" "FALSE")
        (if rownames-p "1" "NULL")))
    (format "%s &lt;- %s" name (org-babel-R-quote-tsv-field value))))
</t>
<t tx="ekr.20100929212226.14263">
(defun org-babel-R-initiate-session (session params)
  "If there is not a current R process then create one."
  (unless (string= session "none")
    (let ((session (or session "*R*"))
      (ess-ask-for-ess-directory (not (cdr (assoc :dir params)))))
      (if (org-babel-comint-buffer-livep session)
      session
    (save-window-excursion
      (require 'ess) (R)
      (rename-buffer
       (if (bufferp session)
           (buffer-name session)
         (if (stringp session)
         session
           (buffer-name))))
      (current-buffer))))))
</t>
<t tx="ekr.20100929212226.14264">
(defun org-babel-R-construct-graphics-device-call (out-file params)
  "Construct the call to the graphics device."
  (let ((devices
     '((:bmp . "bmp")
       (:jpg . "jpeg")
       (:jpeg . "jpeg")
       (:tiff . "tiff")
       (:png . "png")
       (:svg . "svg")
       (:pdf . "pdf")
       (:ps . "postscript")
       (:postscript . "postscript")))
    (allowed-args '(:width :height :bg :units :pointsize
                   :antialias :quality :compression :res
                   :type :family :title :fonts :version
                   :paper :encoding :pagecentre :colormodel
                   :useDingbats :horizontal))
    (device (and (string-match ".+\\.\\([^.]+\\)" out-file)
             (match-string 1 out-file)))
    (extra-args (cdr (assq :R-dev-args params))) filearg args)
    (setq device (or (and device (cdr (assq (intern (concat ":" device))
                        devices))) "png"))
    (setq filearg
      (if (member device '("pdf" "postscript" "svg")) "file" "filename"))
    (setq args (mapconcat
        (lambda (pair)
          (if (member (car pair) allowed-args)
              (format ",%s=%s"
                  (substring (symbol-name (car pair)) 1)
                  (cdr pair)) ""))
        params ""))
    (format "%s(%s=\"%s\"%s%s%s)"
        device filearg out-file args
        (if extra-args "," "") (or extra-args ""))))
</t>
<t tx="ekr.20100929212226.14265">
(defvar org-babel-R-eoe-indicator "'org_babel_R_eoe'")
(defvar org-babel-R-eoe-output "[1] \"org_babel_R_eoe\"")
(defvar org-babel-R-wrapper-method "main &lt;- function ()\n{\n%s\n}
write.table(main(), file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE)")
(defvar org-babel-R-wrapper-lastvar "write.table(.Last.value, file=\"%s\", sep=\"\\t\", na=\"nil\",row.names=%s, col.names=%s, quote=FALSE)")

(defun org-babel-R-evaluate
  (session body result-type column-names-p row-names-p)
  "Pass BODY to the R process in SESSION.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY, as elisp."
  (if (not session)
      ;; external process evaluation
      (case result-type
    (output (org-babel-eval org-babel-R-command body))
    (value
     (let ((tmp-file (make-temp-file "org-babel-R-results-")))
       (org-babel-eval org-babel-R-command
               (format org-babel-R-wrapper-method
                   body tmp-file
                   (if row-names-p "TRUE" "FALSE")
                   (if column-names-p
                       (if row-names-p "NA" "TRUE")
                     "FALSE")))
       (org-babel-R-process-value-result
        (org-babel-import-elisp-from-file
         (org-babel-maybe-remote-file tmp-file)) column-names-p))))
    ;; comint session evaluation
    (case result-type
      (value
       (let ((tmp-file (make-temp-file "org-babel-R"))
         broke)
     (org-babel-comint-with-output (session org-babel-R-eoe-output)
       (insert (mapconcat
            #'org-babel-chomp
            (list
             body
             (format org-babel-R-wrapper-lastvar
                 tmp-file
                 (if row-names-p "TRUE" "FALSE")
                 (if column-names-p
                 (if row-names-p "NA" "TRUE")
                   "FALSE"))
             org-babel-R-eoe-indicator) "\n"))
       (inferior-ess-send-input))
     (org-babel-R-process-value-result
      (org-babel-import-elisp-from-file
       (org-babel-maybe-remote-file tmp-file))  column-names-p)))
      (output
       (mapconcat
    #'org-babel-chomp
    (butlast
     (delq nil
           (mapcar
        #'identity
        (org-babel-comint-with-output (session org-babel-R-eoe-output)
          (insert (mapconcat #'org-babel-chomp
                     (list body org-babel-R-eoe-indicator)
                     "\n"))
          (inferior-ess-send-input)))) 2) "\n")))))
</t>
<t tx="ekr.20100929212226.14266">
(defun org-babel-R-process-value-result (result column-names-p)
  "R-specific processing of return value.
Insert hline if column names in output have been requested."
  (if column-names-p
      (cons (car result) (cons 'hline (cdr result)))
    result))
</t>
<t tx="ekr.20100929212226.14267">@language lisp
@tabwidth -4
@others

(provide 'ob-ref)

;; arch-tag: ace4a4f4-ea38-4dac-8fe6-6f52fcc43b6d

;;; ob-ref.el ends here
</t>
<t tx="ekr.20100929212226.14268">;;; ob-ref.el --- org-babel functions for referencing external data

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Functions for referencing data from the header arguments of a
;; org-babel block.  The syntax of such a reference should be

;;   #+VAR: variable-name=file:resource-id

;; - variable-name :: the name of the variable to which the value
;;                    will be assigned

;; - file :: path to the file containing the resource, or omitted if
;;           resource is in the current file

;; - resource-id :: the id or name of the resource

;; So an example of a simple src block referencing table data in the
;; same file would be

;;  #+TBLNAME: sandbox
;;  | 1 |         2 | 3 |
;;  | 4 | org-babel | 6 |
;;
;;  #+begin_src emacs-lisp :var table=sandbox
;;    (message table)
;;  #+end_src

;;; Code:
(require 'ob)
(eval-when-compile
  (require 'cl))

(declare-function org-remove-if-not "org" (predicate seq))
(declare-function org-at-table-p "org" (&amp;optional table-type))
(declare-function org-count "org" (CL-ITEM CL-SEQ))

</t>
<t tx="ekr.20100929212226.14269">(defun org-babel-ref-variables (params)
  "Convert PARAMS to variable names and values.
Takes a parameter alist, and return an alist of variable names,
and the emacs-lisp representation of the related value."
  (let ((assignments
     (delq nil (mapcar (lambda (pair) (if (eq (car pair) :var) (cdr pair))) params)))
    (others
         (delq nil (mapcar (lambda (pair) (unless (eq :var (car pair)) pair)) params))))
    (mapcar (lambda (assignment) (org-babel-ref-parse assignment)) assignments)))
</t>
<t tx="ekr.20100929212226.14270">
(defvar org-babel-ref-split-regexp
  "[ \f\t\n\r\v]*\\(.+?\\)[ \f\t\n\r\v]*=[ \f\t\n\r\v]*\\(.+\\)[ \f\t\n\r\v]*")

(defun org-babel-ref-parse (assignment &amp;optional params)
  "Parse a variable ASSIGNMENT in a header argument.
If the right hand side of the assignment has a literal value
return that value, otherwise interpret as a reference to an
external resource and find it's value using
`org-babel-ref-resolve-reference'.  Return a list with two
elements.  The first element of the list will be the name of the
variable, and the second will be an emacs-lisp representation of
the value of the variable."
  (if (string-match org-babel-ref-split-regexp assignment)
      (let ((var (match-string 1 assignment))
            (ref (match-string 2 assignment)))
        (cons (intern var)
          ((lambda (val)
         (if (equal :ob-must-be-reference val)
             (org-babel-ref-resolve-reference ref params)
           val)) (org-babel-ref-literal ref))))))
</t>
<t tx="ekr.20100929212226.14271">
(defun org-babel-ref-literal (ref)
  "Return the value of REF if it is a literal value.
Determine if the right side of a header argument variable
assignment is a literal value or is a reference to some external
resource.  REF should be a string of the right hand side of the
assignment.  If REF is literal then return it's value, otherwise
return nil."
  (let ((out (org-babel-read ref)))
    (if (equal out ref)
        (if (string-match "^\".+\"$" ref)
            (read ref)
      :ob-must-be-reference)
      out)))
</t>
<t tx="ekr.20100929212226.14272">
(defvar org-babel-library-of-babel)
(defun org-babel-ref-resolve-reference (ref &amp;optional params)
  "Resolve the reference REF and return its value."
  (save-excursion
    (let ((case-fold-search t)
          type args new-refere new-referent result lob-info split-file split-ref
          index index-row index-col)
      ;; if ref is indexed grab the indices -- beware nested indices
      (when (and (string-match "\\[\\(.+\\)\\]" ref)
         (let ((str (substring ref 0 (match-beginning 0))))
           (= (org-count ?( str) (org-count ?) str))))
        (setq index (match-string 1 ref))
        (setq ref (substring ref 0 (match-beginning 0))))
      ;; assign any arguments to pass to source block
      (when (string-match "^\\(.+?\\)\(\\(.*\\)\)$" ref)
        (setq new-refere (match-string 1 ref))
        (setq new-referent (match-string 2 ref))
        ;; (message "new-refere=%S, new-referent=%S" new-refere new-referent) ;; debugging
        (when (&gt; (length new-refere) 0)
          (if (&gt; (length new-referent) 0)
              (setq args (mapcar (lambda (ref) (cons :var ref))
                                 (org-babel-ref-split-args new-referent))))
          ;; (message "args=%S" args) ;; debugging
          (setq ref new-refere)))
      (when (string-match "^\\(.+\\):\\(.+\\)$" ref)
        (setq split-file (match-string 1 ref))
        (setq split-ref (match-string 2 ref))
        (find-file split-file) (setq ref split-ref))
      (save-restriction
    (widen)
    (goto-char (point-min))
    (if (let ((result_regexp (concat "^[ \t]*#\\+\\(TBLNAME\\|RESNAME\\|RESULTS\\):[ \t]*"
                     (regexp-quote ref) "[ \t]*$"))
          (regexp (concat org-babel-src-name-regexp
                  (regexp-quote ref) "\\(\(.*\)\\)?" "[ \t]*$")))
          ;; goto ref in the current buffer
          (or (and (not args)
               (or (re-search-forward result_regexp nil t)
               (re-search-backward result_regexp nil t)))
          (re-search-forward regexp nil t)
          (re-search-backward regexp nil t)
          ;; check the Library of Babel
          (setq lob-info (cdr (assoc (intern ref) org-babel-library-of-babel)))))
        (unless lob-info (goto-char (match-beginning 0)))
      ;; ;; TODO: allow searching for names in other buffers
      ;; (setq id-loc (org-id-find ref 'marker)
      ;;       buffer (marker-buffer id-loc)
      ;;       loc (marker-position id-loc))
      ;; (move-marker id-loc nil)
      (error "reference '%s' not found in this buffer" ref))
    (if lob-info
        (setq type 'lob)
      (while (not (setq type (org-babel-ref-at-ref-p)))
        (forward-line 1)
        (beginning-of-line)
        (if (or (= (point) (point-min)) (= (point) (point-max)))
        (error "reference not found"))))
    (setq params (org-babel-merge-params params args '((:results . "silent"))))
    (setq result
          (case type
        ('results-line (org-babel-read-result))
        ('table (org-babel-read-table))
        ('file (org-babel-read-link))
        ('source-block (org-babel-execute-src-block nil nil params))
        ('lob (org-babel-execute-src-block nil lob-info params))))
    (if (symbolp result)
        (format "%S" result)
      (if (and index (listp result))
          (org-babel-ref-index-list index result)
        result))))))
</t>
<t tx="ekr.20100929212226.14273">
(defun org-babel-ref-index-list (index lis)
  "Return the subset of LIS indexed by INDEX.

Indices are 0 based and negative indices count from the end of
LIS, so 0 references the first element of LIS and -1 references
the last.  If INDEX is separated by \",\"s then each \"portion\"
is assumed to index into the next deepest nesting or dimension.

A valid \"portion\" can consist of either an integer index, two
integers separated by a \":\" in which case the entire range is
returned, or an empty string or \"*\" both of which are
interpreted to mean the entire range and as such are equivalent
to \"0:-1\"."
  (if (and (&gt; (length index) 0) (string-match "^\\([^,]*\\),?" index))
      (let ((ind-re "\\(\\([-[:digit:]]+\\):\\([-[:digit:]]+\\)\\|\*\\)")
        (length (length lis))
            (portion (match-string 1 index))
            (remainder (substring index (match-end 0))))
        (flet ((wrap (num) (if (&lt; num 0) (+ length num) num))
               (open (ls) (if (and (listp ls) (= (length ls) 1)) (car ls) ls)))
          (open
           (mapcar
            (lambda (sub-lis) (org-babel-ref-index-list remainder sub-lis))
            (if (or (= 0 (length portion)) (string-match ind-re portion))
                (mapcar
         (lambda (n) (nth n lis))
         (apply 'number-sequence
            (if (and (&gt; (length portion) 0) (match-string 2 portion))
                (list
                 (wrap (string-to-number (match-string 2 portion)))
                 (wrap (string-to-number (match-string 3 portion))))
              (list (wrap 0) (wrap -1)))))
              (list (nth (wrap (string-to-number portion)) lis)))))))
    lis))
</t>
<t tx="ekr.20100929212226.14274">
(defun org-babel-ref-split-args (arg-string)
  "Split ARG-STRING into top-level arguments of balanced parenthesis."
  (let ((index 0) (depth 0) (buffer "") holder return)
    ;; crawl along string, splitting at any ","s which are on the top level
    (while (&lt; index (length arg-string))
      (setq holder (substring arg-string index (+ 1 index)))
      (setq buffer (concat buffer holder))
      (setq index (+ 1 index))
      (cond
       ((string= holder ",")
        (when (= depth 0)
          (setq return (reverse (cons (substring buffer 0 -1) return)))
          (setq buffer "")))
       ((or (string= holder "(") (string= holder "[")) (setq depth (+ depth 1)))
       ((or (string= holder ")") (string= holder "]")) (setq depth (- depth 1)))))
    (mapcar #'org-babel-trim (reverse (cons buffer return)))))
</t>
<t tx="ekr.20100929212226.14275">
(defvar org-bracket-link-regexp)
(defun org-babel-ref-at-ref-p ()
  "Return the type of reference located at point.
Return nil if none of the supported reference types are found.
Supported reference types are tables and source blocks."
  (cond ((org-at-table-p) 'table)
        ((looking-at "^[ \t]*#\\+BEGIN_SRC") 'source-block)
        ((looking-at org-bracket-link-regexp) 'file)
        ((looking-at org-babel-result-regexp) 'results-line)))
</t>
<t tx="ekr.20100929212226.14276">@language lisp
@tabwidth -4
@others

(provide 'ob-ruby)

;; arch-tag: 3e9726db-4520-49e2-b263-e8f571ac88f5

;;; ob-ruby.el ends here
</t>
<t tx="ekr.20100929212226.14277">;;; ob-ruby.el --- org-babel functions for ruby evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating ruby source code.

;;; Requirements:

;; - ruby and irb executables :: http://www.ruby-lang.org/
;;
;; - ruby-mode :: Can be installed through ELPA, or from
;;   http://github.com/eschulte/rinari/raw/master/util/ruby-mode.el
;;
;; - inf-ruby mode :: Can be installed through ELPA, or from
;;   http://github.com/eschulte/rinari/raw/master/util/inf-ruby.el

;;; Code:
(require 'ob)
(require 'ob-ref)
(require 'ob-comint)
(require 'ob-eval)
(eval-when-compile (require 'cl))

(declare-function run-ruby "ext:inf-ruby" (&amp;optional command name))

(add-to-list 'org-babel-tangle-lang-exts '("ruby" . "rb"))

(defvar org-babel-default-header-args:ruby '())

(defvar org-babel-ruby-command "ruby"
  "Name of command to use for executing ruby code.")

</t>
<t tx="ekr.20100929212226.14278">(defun org-babel-expand-body:ruby (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (require 'inf-ruby)
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params)))))
    (concat
     (mapconcat ;; define any variables
      (lambda (pair)
        (format "%s=%s"
                (car pair)
                (org-babel-ruby-var-to-ruby (cdr pair))))
      vars "\n") "\n" body "\n")))
</t>
<t tx="ekr.20100929212226.14279">
(defun org-babel-execute:ruby (body params)
  "Execute a block of Ruby code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((processed-params (org-babel-process-params params))
         (session (org-babel-ruby-initiate-session (first processed-params)))
         (result-params (nth 2 processed-params))
         (result-type (nth 3 processed-params))
         (full-body (org-babel-expand-body:ruby
                     body params processed-params))
         (result (org-babel-ruby-evaluate
          session full-body result-type result-params)))
    (or (cdr (assoc :file params))
        (org-babel-reassemble-table
         result
         (org-babel-pick-name (nth 4 processed-params)
                  (cdr (assoc :colnames params)))
         (org-babel-pick-name (nth 5 processed-params)
                  (cdr (assoc :rownames params)))))))
</t>
<t tx="ekr.20100929212226.14280">
(defun org-babel-prep-session:ruby (session params)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  ;; (message "params=%S" params) ;; debugging
  (let* ((session (org-babel-ruby-initiate-session session))
         (vars (org-babel-ref-variables params))
         (var-lines (mapcar ;; define any variables
                     (lambda (pair)
                       (format "%s=%s"
                               (car pair)
                               (org-babel-ruby-var-to-ruby (cdr pair))))
                     vars)))
    (org-babel-comint-in-buffer session
      (sit-for .5) (goto-char (point-max))
      (mapc (lambda (var)
              (insert var) (comint-send-input nil t)
              (org-babel-comint-wait-for-output session)
              (sit-for .1) (goto-char (point-max))) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14281">
(defun org-babel-load-session:ruby (session body params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:ruby session params)))
      (with-current-buffer buffer
        (goto-char (process-mark (get-buffer-process (current-buffer))))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14282">
;; helper functions

(defun org-babel-ruby-var-to-ruby (var)
  "Convert VAR into a ruby variable.
Convert an elisp value into a string of ruby source code
specifying a variable of the same value."
  (if (listp var)
      (concat "[" (mapconcat #'org-babel-ruby-var-to-ruby var ", ") "]")
    (format "%S" var)))
</t>
<t tx="ekr.20100929212226.14283">
(defun org-babel-ruby-table-or-string (results)
  "Convert RESULTS into an appropriate elisp value.
If RESULTS look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  (org-babel-read
   (if (and (stringp results) (string-match "^\\[.+\\]$" results))
       (org-babel-read
        (concat "'"
                (replace-regexp-in-string
                 "\\[" "(" (replace-regexp-in-string
                            "\\]" ")" (replace-regexp-in-string
                                       ", " " " (replace-regexp-in-string
                         "'" "\"" results))))))
     results)))
</t>
<t tx="ekr.20100929212226.14284">
(defun org-babel-ruby-initiate-session (&amp;optional session params)
  "Initiate a ruby session.
If there is not a current inferior-process-buffer in SESSION
then create one.  Return the initialized session."
  (require 'inf-ruby)
  (unless (string= session "none")
    (let ((session-buffer (save-window-excursion
                (run-ruby nil session) (current-buffer))))
      (if (org-babel-comint-buffer-livep session-buffer)
      (progn (sit-for .25) session-buffer)
        (sit-for .5)
        (org-babel-ruby-initiate-session session)))))
</t>
<t tx="ekr.20100929212226.14285">
(defvar org-babel-ruby-eoe-indicator ":org_babel_ruby_eoe"
  "String to indicate that evaluation has completed.")
(defvar org-babel-ruby-f-write
  "File.open('%s','w'){|f| f.write((_.class == String) ? _ : _.inspect)}")
(defvar org-babel-ruby-pp-f-write
  "File.open('%s','w'){|f| $stdout = f; pp(results); $stdout = orig_out}")
(defvar org-babel-ruby-wrapper-method
  "
def main()
%s
end
results = main()
File.open('%s', 'w'){ |f| f.write((results.class == String) ? results : results.inspect) }
")
(defvar org-babel-ruby-pp-wrapper-method
  "
require 'pp'
def main()
%s
end
results = main()
File.open('%s', 'w') do |f|
  $stdout = f
  pp results
end
")

(defun org-babel-ruby-evaluate
  (buffer body &amp;optional result-type result-params)
  "Pass BODY to the Ruby process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY, as elisp."
  (if (not buffer)
      ;; external process evaluation
      (case result-type
    (output (org-babel-eval org-babel-ruby-command body))
    (value (let ((tmp-file (make-temp-file "org-babel-ruby-results-")))
         (org-babel-eval org-babel-ruby-command
                 (format (if (member "pp" result-params)
                         org-babel-ruby-pp-wrapper-method
                       org-babel-ruby-wrapper-method)
                     body tmp-file))
         ((lambda (raw)
            (if (or (member "code" result-params)
                (member "pp" result-params))
            raw
              (org-babel-ruby-table-or-string raw)))
          (org-babel-eval-read-file tmp-file)))))
    ;; comint session evaluation
    (case result-type
      (output
       (mapconcat
    #'identity
    (butlast
     (split-string
      (mapconcat
       #'org-babel-trim
       (butlast
        (org-babel-comint-with-output
        (buffer org-babel-ruby-eoe-indicator t body)
          (mapc
           (lambda (line)
         (insert (org-babel-chomp line)) (comint-send-input nil t))
           (list body org-babel-ruby-eoe-indicator))
          (comint-send-input nil t)) 2)
       "\n") "[\r\n]")) "\n"))
      (value
       ((lambda (results)
      (if (or (member "code" result-params) (member "pp" result-params))
          results
        (org-babel-ruby-table-or-string results)))
    (let* ((tmp-file (make-temp-file "org-babel-ruby-results-"))
           (ppp (or (member "code" result-params)
            (member "pp" result-params))))
      (org-babel-comint-with-output
          (buffer org-babel-ruby-eoe-indicator t body)
        (when ppp (insert "require 'pp';") (comint-send-input nil t))
        (mapc
         (lambda (line)
           (insert (org-babel-chomp line)) (comint-send-input nil t))
         (append
          (list body)
          (if (not ppp)
          (list (format org-babel-ruby-f-write tmp-file))
        (list
         "results=_" "require 'pp'" "orig_out = $stdout"
         (format org-babel-ruby-pp-f-write tmp-file)))
          (list org-babel-ruby-eoe-indicator)))
        (comint-send-input nil t))
      (org-babel-eval-read-file tmp-file)))))))
</t>
<t tx="ekr.20100929212226.14286">
(defun org-babel-ruby-read-string (string)
  "Strip \\\"s from around a ruby string."
  (if (string-match "^\"\\([^\000]+\\)\"$" string)
      (match-string 1 string)
    string))
</t>
<t tx="ekr.20100929212226.14287">@language lisp
@tabwidth -4
@others

(provide 'ob-sass)

;; arch-tag: 2954b169-eef4-45ce-a8e5-3e619f0f07ac

;;; ob-sass.el ends here
</t>
<t tx="ekr.20100929212226.14288">;;; ob-sass.el --- org-babel functions for the sass css generation language

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; For more information on sass see http://sass-lang.com/
;;
;; This accepts a 'file' header argument which is the target of the
;; compiled sass.  The default output type for sass evaluation is
;; either file (if a 'file' header argument was given) or scalar if no
;; such header argument was supplied.
;;
;; A 'cmdline' header argument can be supplied to pass arguments to
;; the sass command line.

;;; Requirements:

;; - sass-mode :: http://github.com/nex3/haml/blob/master/extra/sass-mode.el

;;; Code:
(require 'ob)

(defvar org-babel-default-header-args:sass '())

</t>
<t tx="ekr.20100929212226.14289">(defun org-babel-expand-body:sass (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14290">
(defun org-babel-execute:sass (body params)
  "Execute a block of Sass code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
         (file (cdr (assoc :file params)))
         (out-file (or file (make-temp-file "org-babel-sass-out")))
         (cmdline (cdr (assoc :cmdline params)))
         (in-file (make-temp-file "org-babel-sass-in"))
         (cmd (concat "sass " (or cmdline "") in-file " " out-file)))
    (with-temp-file in-file
      (insert (org-babel-expand-body:sass body params))) (shell-command cmd)
    (or file (with-temp-buffer (insert-file-contents out-file) (buffer-string)))))
</t>
<t tx="ekr.20100929212226.14291">
(defun org-babel-prep-session:sass (session params)
  "Raise an error because sass does not support sessions."
  (error "Sass does not support sessions"))
</t>
<t tx="ekr.20100929212226.14292">@language lisp
@tabwidth -4
@others

(provide 'ob-screen)

;; arch-tag: 908e5afe-89a0-4f27-b982-23f1f2e3bac9

;;; ob-screen.el ends here
</t>
<t tx="ekr.20100929212226.14293">;;; ob-screen.el --- org-babel support for interactive terminal

;; Copyright (C) 2009, 2010  Free Software Foundation

;; Author: Benjamin Andresen
;; Keywords: literate programming, interactive shell
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for interactive terminals. Mostly shell scripts.
;; Heavily inspired by 'eev' from Eduardo Ochs
;;
;; Adding :cmd and :terminal as header arguments
;; :terminal must support the -T (title) and -e (command) parameter
;;
;; You can test the default setup. (xterm + sh) with
;; M-x org-babel-screen-test RET

;;; Code:
(require 'ob)
(require 'ob-ref)

(defvar org-babel-screen-location "screen"
  "The command location for screen.
In case you want to use a different screen than one selected by your $PATH")

(defvar org-babel-default-header-args:screen
  '((:results . "silent") (:session . "default") (:cmd . "sh") (:terminal . "xterm"))
  "Default arguments to use when running screen source blocks.")

</t>
<t tx="ekr.20100929212226.14294">(defun org-babel-expand-body:screen (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14295">
(defun org-babel-execute:screen (body params)
  "Send a block of code via screen to a terminal using Babel.
\"default\" session is be used when none is specified."
  (message "Sending source code block to interactive terminal session...")
  (save-window-excursion
    (let* ((processed-params (org-babel-process-params params))
           (session (nth 0 processed-params))
           (socket (org-babel-screen-session-socketname session)))
      (unless socket (org-babel-prep-session:screen session params))
      (org-babel-screen-session-execute-string
       session (org-babel-expand-body:screen body params)))))
</t>
<t tx="ekr.20100929212226.14296">
(defun org-babel-prep-session:screen (session params)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  (let* ((processed-params (org-babel-process-params params))
         (session (nth 0 processed-params))
         (vars (nth 1 processed-params))
         (socket (org-babel-screen-session-socketname session))
         (vars (org-babel-ref-variables params))
         (cmd (cdr (assoc :cmd params)))
         (terminal (cdr (assoc :terminal params)))
         (process-name (concat "org-babel: terminal (" session ")")))
    (apply 'start-process process-name "*Messages*"
           terminal `("-T" ,(concat "org-babel: " session) "-e" ,org-babel-screen-location
                           "-c" "/dev/null" "-mS" ,(concat "org-babel-session-" session)
                           ,cmd))
    ;; XXX: Is there a better way than the following?
    (while (not (org-babel-screen-session-socketname session))
      ;; wait until screen session is available before returning
      )))
</t>
<t tx="ekr.20100929212226.14297">
;; helper functions

(defun org-babel-screen-session-execute-string (session body)
  "If SESSION exists, send BODY to it."
  (let ((socket (org-babel-screen-session-socketname session)))
    (when socket
      (let ((tmpfile (org-babel-screen-session-write-temp-file session body)))
        (apply 'start-process (concat "org-babel: screen (" session ")") "*Messages*"
               org-babel-screen-location
               `("-S" ,socket "-X" "eval" "msgwait 0"
                      ,(concat "readreg z " tmpfile)
                      "paste z"))))))
</t>
<t tx="ekr.20100929212226.14298">
(defun org-babel-screen-session-socketname (session)
  "Check if SESSION exists by parsing output of \"screen -ls\"."
  (let* ((screen-ls (shell-command-to-string "screen -ls"))
         (sockets (delq
           nil
                   (mapcar
            (lambda (x)
              (when (string-match (rx (or "(Attached)" "(Detached)")) x)
            x))
            (split-string screen-ls "\n"))))
         (match-socket (car
            (delq
             nil
             (mapcar
              (lambda (x)
                (when (string-match
                   (concat "org-babel-session-" session) x)
                  x))
              sockets)))))
    (when match-socket (car (split-string match-socket)))))
</t>
<t tx="ekr.20100929212226.14299">
(defun org-babel-screen-session-write-temp-file (session body)
  "Save BODY in a temp file that is named after SESSION."
  (let ((tmpfile (concat "/tmp/screen.org-babel-session-" session)))
    (with-temp-file tmpfile
      (insert body)

      ;; org-babel has superflous spaces
      (goto-char (point-min))
      (delete-matching-lines "^ +$"))
    tmpfile))
</t>
<t tx="ekr.20100929212226.14300">
(defun org-babel-screen-test ()
  "Test if the default setup works.
The terminal should shortly flicker."
  (interactive)
  (let* ((session "org-babel-testing")
         (random-string (format "%s" (random 99999)))
         (tmpfile "/tmp/org-babel-screen.test")
         (body (concat "echo '" random-string "' &gt; " tmpfile "\nexit\n"))
         process tmp-string)
    (org-babel-execute:screen body org-babel-default-header-args:screen)
    ;; XXX: need to find a better way to do the following
    (while (not (file-readable-p tmpfile))
      ;; do something, otherwise this will be optimized away
      (format "org-babel-screen: File not readable yet."))
    (setq tmp-string (with-temp-buffer
                       (insert-file-contents-literally tmpfile)
                       (buffer-substring (point-min) (point-max))))
    (delete-file tmpfile)
    (message (concat "org-babel-screen: Setup "
                     (if (string-match random-string tmp-string)
                         "WORKS."
                         "DOESN'T work.")))))
</t>
<t tx="ekr.20100929212226.14301">@language lisp
@tabwidth -4
@others

(provide 'ob-sh)

;; arch-tag: 416dd531-c230-4b0a-a5bf-8d948f990f2d

;;; ob-sh.el ends here
</t>
<t tx="ekr.20100929212226.14302">;;; ob-sh.el --- org-babel functions for shell evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating shell source code.

;;; Code:
(require 'ob)
(require 'ob-comint)
(require 'ob-eval)
(require 'shell)
(eval-when-compile (require 'cl))

(declare-function org-babel-ref-variables "ob-ref" (params))
(declare-function org-babel-comint-in-buffer "ob-comint" (buffer &amp;rest body))
(declare-function org-babel-comint-wait-for-output "ob-comint" (buffer))
(declare-function org-babel-comint-buffer-livep "ob-comint" (buffer))
(declare-function org-babel-comint-with-output "ob-comint" (meta &amp;rest body))
(declare-function orgtbl-to-generic "org-table" (table params))

(defvar org-babel-default-header-args:sh '())

(defvar org-babel-sh-command "sh"
  "Command used to invoke a shell.
This will be passed to  `shell-command-on-region'")

</t>
<t tx="ekr.20100929212226.14303">(defun org-babel-expand-body:sh (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body."
  (let ((vars (nth 1 (or processed-params (org-babel-process-params params))))
        (sep (cdr (assoc :separator params))))
    (concat
   (mapconcat ;; define any variables
    (lambda (pair)
      (format "%s=%s"
              (car pair)
              (org-babel-sh-var-to-sh (cdr pair) sep)))
    vars "\n") "\n" body "\n\n")))
</t>
<t tx="ekr.20100929212226.14304">
(defun org-babel-execute:sh (body params)
  "Execute a block of Shell commands with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((processed-params (org-babel-process-params params))
         (session (org-babel-sh-initiate-session (nth 0 processed-params)))
         (result-params (nth 2 processed-params))
         (full-body (org-babel-expand-body:sh
                     body params processed-params)))
    (org-babel-reassemble-table
     (org-babel-sh-evaluate session full-body result-params)
     (org-babel-pick-name
      (nth 4 processed-params) (cdr (assoc :colnames params)))
     (org-babel-pick-name
      (nth 5 processed-params) (cdr (assoc :rownames params))))))
</t>
<t tx="ekr.20100929212226.14305">
(defun org-babel-prep-session:sh (session params)
  "Prepare SESSION according to the header arguments specified in PARAMS."
  (let* ((session (org-babel-sh-initiate-session session))
         (vars (org-babel-ref-variables params))
         (sep (cdr (assoc :separator params)))
         (var-lines (mapcar ;; define any variables
                     (lambda (pair)
                       (format "%s=%s"
                               (car pair)
                               (org-babel-sh-var-to-sh (cdr pair) sep)))
                     vars)))
    (org-babel-comint-in-buffer session
      (mapc (lambda (var)
              (insert var) (comint-send-input nil t)
              (org-babel-comint-wait-for-output session)) var-lines))
    session))
</t>
<t tx="ekr.20100929212226.14306">
(defun org-babel-load-session:sh (session body params)
  "Load BODY into SESSION."
  (save-window-excursion
    (let ((buffer (org-babel-prep-session:sh session params)))
      (with-current-buffer buffer
        (goto-char (process-mark (get-buffer-process (current-buffer))))
        (insert (org-babel-chomp body)))
      buffer)))
</t>
<t tx="ekr.20100929212226.14307">
;; helper functions

(defun org-babel-sh-var-to-sh (var &amp;optional sep)
  "Convert an elisp value to a shell variable.
Convert an elisp var into a string of shell commands specifying a
var of the same value."
  (if (listp var)
      (flet ((deep-string (el)
                          (if (listp el)
                              (mapcar #'deep-string el)
                (org-babel-sh-var-to-sh el sep))))
    (format "$(cat &lt;&lt;BABEL_TABLE\n%s\nBABEL_TABLE\n)"
        (orgtbl-to-generic
         (deep-string var) (list :sep (or sep "\t")))))
    (if (stringp var)
    (if (string-match "[\n\r]" var)
        (format "$(cat &lt;&lt;BABEL_STRING\n%s\nBABEL_STRING\n)" var)
      (format "%s" var))
      (format "%S" var))))
</t>
<t tx="ekr.20100929212226.14308">
(defun org-babel-sh-table-or-results (results)
  "Convert RESULTS to an appropriate elisp value.
If the results look like a table, then convert them into an
Emacs-lisp table, otherwise return the results as a string."
  (org-babel-read
   (if (string-match "^\\[.+\\]$" results)
       (org-babel-read
        (concat "'"
                (replace-regexp-in-string
                 "\\[" "(" (replace-regexp-in-string
                            "\\]" ")" (replace-regexp-in-string
                                       ", " " " (replace-regexp-in-string
                                                 "'" "\"" results))))))
     results)))
</t>
<t tx="ekr.20100929212226.14309">
(defun org-babel-sh-initiate-session (&amp;optional session params)
  "Initiate a session named SESSION according to PARAMS."
  (when (and session (not (string= session "none")))
    (save-window-excursion
      (or (org-babel-comint-buffer-livep session)
          (progn (shell session) (get-buffer (current-buffer)))))))
</t>
<t tx="ekr.20100929212226.14310">
(defvar org-babel-sh-eoe-indicator "echo 'org_babel_sh_eoe'"
  "String to indicate that evaluation has completed.")
(defvar org-babel-sh-eoe-output "org_babel_sh_eoe"
  "String to indicate that evaluation has completed.")

(defun org-babel-sh-evaluate (session body &amp;optional result-params)
  "Pass BODY to the Shell process in BUFFER.
If RESULT-TYPE equals 'output then return a list of the outputs
of the statements in BODY, if RESULT-TYPE equals 'value then
return the value of the last statement in BODY."
  ((lambda (results)
     (if (or (member "scalar" result-params)
         (member "output" result-params))
     results
       (let ((tmp-file (make-temp-file "org-babel-sh")))
     (with-temp-file tmp-file (insert results))
     (org-babel-import-elisp-from-file tmp-file))))
   (if (not session)
       (org-babel-eval org-babel-sh-command (org-babel-trim body))
     (let ((tmp-file (make-temp-file "org-babel-sh")))
       (mapconcat
    #'org-babel-sh-strip-weird-long-prompt
    (mapcar
     #'org-babel-trim
     (butlast
      (org-babel-comint-with-output
          (session org-babel-sh-eoe-output t body)
        (mapc
         (lambda (line)
           (insert line) (comint-send-input nil t) (sleep-for 0.25))
         (append
          (split-string (org-babel-trim body) "\n")
          (list org-babel-sh-eoe-indicator))))
      2)) "\n")))))
</t>
<t tx="ekr.20100929212226.14311">
(defun org-babel-sh-strip-weird-long-prompt (string)
  "Remove prompt cruft from a string of shell output."
  (while (string-match "^% +[\r\n$]+ *" string)
    (setq string (substring string (match-end 0))))
  string)
</t>
<t tx="ekr.20100929212226.14312">@language lisp
@tabwidth -4
@others

(provide 'ob-sql)

;; arch-tag: a43ff944-6de1-4566-a83c-626814e3dad2

;;; ob-sql.el ends here
</t>
<t tx="ekr.20100929212226.14313">;;; ob-sql.el --- org-babel functions for sql evaluation

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating sql source code.
;;
;; SQL is somewhat unique in that there are many different engines for
;; the evaluation of sql (Mysql, PostgreSQL, etc...), so much of this
;; file will have to be implemented engine by engine.
;;
;; Also SQL evaluation generally takes place inside of a database.
;;
;; For now lets just allow a generic ':cmdline' header argument.
;;
;; TODO:
;;
;; - support for sessions
;; - add more useful header arguments (user, passwd, database, etc...)
;; - support for more engines (currently only supports mysql)
;; - what's a reasonable way to drop table data into SQL?
;;

;;; Code:
(require 'ob)
(eval-when-compile (require 'cl))

(declare-function org-table-import "org-table" (file arg))

(defvar org-babel-default-header-args:sql '())

</t>
<t tx="ekr.20100929212226.14314">(defun org-babel-expand-body:sql (body params &amp;optional processed-params)
  "Expand BODY according to PARAMS, return the expanded body." body)
</t>
<t tx="ekr.20100929212226.14315">
(defun org-babel-execute:sql (body params)
  "Execute a block of Sql code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let* ((result-params (split-string (or (cdr (assoc :results params)) "")))
     (processed-params (org-babel-process-params params))
         (cmdline (cdr (assoc :cmdline params)))
         (engine (cdr (assoc :engine params)))
         (in-file (make-temp-file "org-babel-sql-in"))
         (out-file (or (cdr (assoc :out-file params))
                       (make-temp-file "org-babel-sql-out")))
         (command (case (intern engine)
                    ('mysql (format "mysql %s -e \"source %s\" &gt; %s"
                                    (or cmdline "") in-file out-file))
                    (t (error "no support for the %s sql engine" engine)))))
    (with-temp-file in-file
      (insert (org-babel-expand-body:sql body params)))
    (message command)
    (shell-command command)
    (with-temp-buffer
      (org-table-import out-file nil)
      (org-babel-reassemble-table
       (org-table-to-lisp)
       (org-babel-pick-name (nth 4 processed-params) (cdr (assoc :colnames params)))
       (org-babel-pick-name (nth 5 processed-params) (cdr (assoc :rownames params)))))))
</t>
<t tx="ekr.20100929212226.14316">

(defun org-babel-prep-session:sql (session params)
  "Raise an error because Sql sessions aren't implemented."
  (error "sql sessions not yet implemented"))
</t>
<t tx="ekr.20100929212226.14317">@language lisp
@tabwidth -4
@others

(provide 'ob-sqlite)

;; arch-tag: 5c03d7f2-0f72-48b8-bbd1-35aafea248ac

;;; ob-sqlite.el ends here
</t>
<t tx="ekr.20100929212226.14318">;;; ob-sqlite.el --- org-babel functions for sqlite database interaction

;; Copyright (C) 2010  Free Software Foundation

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Org-Babel support for evaluating sqlite source code.

;;; Code:
(require 'ob)
(require 'ob-ref)

(declare-function org-fill-template "org" (template alist))
(declare-function org-table-convert-region "org-table"
          (beg0 end0 &amp;optional separator))
(declare-function orgtbl-to-csv "org-table" (TABLE PARAMS))

(defvar org-babel-default-header-args:sqlite '())

(defvar org-babel-header-arg-names:sqlite
  '(db header echo bail csv column html line list separator nullvalue)
  "Sqlite specific header args.")

</t>
<t tx="ekr.20100929212226.14319">(defun org-babel-expand-body:sqlite (body params &amp;optional processed-params)
  (org-babel-sqlite-expand-vars
   body (or (nth 1 processed-params) (org-babel-ref-variables params))))
</t>
<t tx="ekr.20100929212226.14320">
(defvar org-babel-sqlite3-command "sqlite3")

(defun org-babel-execute:sqlite (body params)
  "Execute a block of Sqlite code with Babel.
This function is called by `org-babel-execute-src-block'."
  (let ((result-params (split-string (or (cdr (assoc :results params)) "")))
    (vars (org-babel-ref-variables params))
    (db (cdr (assoc :db params)))
    (separator (cdr (assoc :separator params)))
    (nullvalue (cdr (assoc :nullvalue params)))
    (headers-p (equal "yes" (cdr (assoc :colnames params))))
    (others (delq nil (mapcar
               (lambda (arg) (car (assoc arg params)))
               (list :header :echo :bail :column
                 :csv :html :line :list))))
    exit-code)
    (unless db (error "ob-sqlite: can't evaluate without a database."))
    (with-temp-buffer
      (insert
       (shell-command-to-string
    (org-fill-template
     "%cmd -init %body %header %separator %nullvalue %others %csv %db "
     (list
      (cons "body" ((lambda (sql-file)
              (with-temp-file sql-file
                (insert (org-babel-expand-body:sqlite
                     body nil (list nil vars))))
              sql-file)
            (make-temp-file "ob-sqlite-sql")))
      (cons "cmd" org-babel-sqlite3-command)
      (cons "header" (if headers-p "-header" "-noheader"))
      (cons "separator"
        (if separator (format "-separator %s" separator) ""))
      (cons "nullvalue"
        (if nullvalue (format "-nullvalue %s" nullvalue) ""))
      (cons "others"
        (mapconcat
         (lambda (arg) (format "-%s" (substring (symbol-name arg) 1)))
         others " "))
      ;; for easy table parsing, default header type should be -csv
      (cons "csv" (if (or (member :csv others) (member :column others)
                  (member :line others) (member :list others)
                  (member :html others) separator)
              ""
            "-csv"))
      (cons "db " db)))))
      (if (or (member "scalar" result-params)
          (member "html" result-params)
          (member "code" result-params)
          (equal (point-min) (point-max)))
      (buffer-string)
    (org-table-convert-region (point-min) (point-max))
    (org-babel-sqlite-table-or-scalar
     (org-babel-sqlite-offset-colnames
      (org-table-to-lisp) headers-p))))))
</t>
<t tx="ekr.20100929212226.14321">
(defun org-babel-sqlite-expand-vars (body vars)
  "Expand the variables held in VARS in BODY."
  (mapc
   (lambda (pair)
     (setq body
       (replace-regexp-in-string
        (format "\$%s" (car pair))
        ((lambda (val)
           (if (listp val)
           ((lambda (data-file)
              (with-temp-file data-file
            (insert (orgtbl-to-csv
                 val '(:fmt (lambda (el) (if (stringp el)
                            el
                              (format "%S" el)))))))
              data-file)
            (make-temp-file "ob-sqlite-data"))
         (format "%S" val)))
         (cdr pair))
        body)))
   vars)
  body)
</t>
<t tx="ekr.20100929212226.14322">
(defun org-babel-sqlite-table-or-scalar (result)
  "If RESULT looks like a trivial table, then unwrap it."
  (if (and (equal 1 (length result))
       (equal 1 (length (car result))))
      (org-babel-read (caar result))
    (mapcar (lambda (row)
          (if (equal 'hline row)
          'hline
        (mapcar #'org-babel-read row))) result)))
</t>
<t tx="ekr.20100929212226.14323">
(defun org-babel-sqlite-offset-colnames (table headers-p)
  "If HEADERS-P is non-nil then offset the first row as column names."
  (if headers-p
      (cons (car table) (cons 'hline (cdr table)))
    table))
</t>
<t tx="ekr.20100929212226.14324">
(defun org-babel-prep-session:sqlite (session params)
  "Raise an error because support for sqlite sessions isn't implemented.
Prepare SESSION according to the header arguments specified in PARAMS."
  (error "sqlite sessions not yet implemented"))
</t>
<t tx="ekr.20100929212226.14325">@language lisp
@tabwidth -4
@others

(defmacro sbe (source-block &amp;rest variables)
  "Return the results of calling SOURCE-BLOCK with VARIABLES.
Each element of VARIABLES should be a two
element list, whose first element is the name of the variable and
second element is a string of its value.  The following call to
`sbe' would be equivalent to the following source code block.

 (sbe 'source-block (n $2) (m 3))

#+begin_src emacs-lisp :var results=source-block(n=val_at_col_2, m=3) :results silent
results
#+end_src

NOTE: by default string variable names are interpreted as
references to source-code blocks, to force interpretation of a
cell's value as a string, prefix the identifier with two \"$\"s
rather than a single \"$\" (i.e. \"$$2\" instead of \"$2\" in the
example above."
  (let ((variables (mapcar
                    (lambda (var)
                      (if (and (= 3 (length var)) (eq (nth 1 var) '$))
                          (list (car var) (format "\"%s\"" (last var)))
                        var))
                    variables)))
    (unless (stringp source-block) (setq source-block (symbol-name source-block)))
    (org-babel-table-truncate-at-newline ;; org-table cells can't be multi-line
     (if (and source-block (&gt; (length source-block) 0))
         (let ((params
                (eval `(org-babel-parse-header-arguments
                        (concat ":var results="
                                ,source-block
                                "("
                                (mapconcat (lambda (var-spec)
                                             (format "%S=%s" (nth 0 var-spec) (nth 1 var-spec)))
                                           ',variables ", ")
                                ")")))))
           (org-babel-execute-src-block
            nil (list "emacs-lisp" "results"
                      (org-babel-merge-params '((:results . "silent")) params))))
       ""))))

(provide 'ob-table)

;; arch-tag: 4234cc7c-4fc8-4e92-abb0-2892de1a493b

;;; ob-table.el ends here
</t>
<t tx="ekr.20100929212226.14326">;;; ob-table.el --- support for calling org-babel functions from tables

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Should allow calling functions from org-mode tables using the
;; function `sbe' as so...

;; #+begin_src emacs-lisp :results silent
;;   (defun fibbd (n) (if (&lt; n 2) 1 (+ (fibbd (- n 1)) (fibbd (- n 2)))))
;; #+end_src

;; #+srcname: fibbd
;; #+begin_src emacs-lisp :var n=2 :results silent
;; (fibbd n)
;; #+end_src

;; | original | fibbd  |
;; |----------+--------|
;; |        0 |        |
;; |        1 |        |
;; |        2 |        |
;; |        3 |        |
;; |        4 |        |
;; |        5 |        |
;; |        6 |        |
;; |        7 |        |
;; |        8 |        |
;; |        9 |        |
;; #+TBLFM: $2='(sbe 'fibbd (n $1))

;;; Code:
(require 'ob)

</t>
<t tx="ekr.20100929212226.14327">(defun org-babel-table-truncate-at-newline (string)
  "Replace newline character with ellipses.
If STRING ends in a newline character, then remove the newline
character and replace it with ellipses."
  (if (and (stringp string) (string-match "[\n\r]" string))
      (concat (substring string 0 (match-beginning 0)) "...")
    string))
</t>
<t tx="ekr.20100929212226.14328">@language lisp
@tabwidth -4
@others

(provide 'ob-tangle)

;; arch-tag: 413ced93-48f5-4216-86e4-3fc5df8c8f24

;;; ob-tangle.el ends here
</t>
<t tx="ekr.20100929212226.14329">;;; ob-tangle.el --- extract source code from org-mode files

;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Extract the code from source blocks out into raw source-code files.

;;; Code:
(require 'ob)
(require 'org-src)
(eval-when-compile
  (require 'cl))

(declare-function org-link-escape "org" (text &amp;optional table))
(declare-function org-heading-components "org" ())

(defcustom org-babel-tangle-lang-exts
  '(("emacs-lisp" . "el"))
  "Alist mapping languages to their file extensions.
The key is the language name, the value is the string that should
be inserted as the extension commonly used to identify files
written in this language.  If no entry is found in this list,
then the name of the language is used."
  :group 'org-babel-tangle
  :type '(repeat
      (cons
       (string "Language name")
       (string "File Extension"))))

(defcustom org-babel-post-tangle-hook nil
  "Hook run in code files tangled by `org-babel-tangle'."
  :group 'org-babel
  :type 'hook)

(defmacro org-babel-with-temp-filebuffer (file &amp;rest body)
  "Open FILE into a temporary buffer execute BODY there like
`progn', then kill the FILE buffer returning the result of
evaluating BODY."
  (declare (indent 1))
  (let ((temp-result (make-symbol "temp-result"))
    (temp-file (make-symbol "temp-file")))
    `(let (,temp-result ,temp-file)
       (find-file ,file)
       (setf ,temp-file (current-buffer))
       (setf ,temp-result (progn ,@body))
       (kill-buffer ,temp-file)
       ,temp-result)))

</t>
<t tx="ekr.20100929212226.14330">;;;###autoload
(defun org-babel-load-file (file)
  "Load Emacs Lisp source code blocks in the Org-mode FILE.
This function exports the source code using
`org-babel-tangle' and then loads the resulting file using
`load-file'."
  (flet ((age (file)
              (float-time
               (time-subtract (current-time)
                              (nth 5 (or (file-attributes (file-truename file))
                                         (file-attributes file)))))))
    (let* ((base-name (file-name-sans-extension file))
           (exported-file (concat base-name ".el")))
      ;; tangle if the org-mode file is newer than the elisp file
      (unless (and (file-exists-p exported-file)
           (&gt; (age file) (age exported-file)))
        (org-babel-tangle-file file exported-file "emacs-lisp"))
      (load-file exported-file)
      (message "loaded %s" exported-file))))
</t>
<t tx="ekr.20100929212226.14331">
;;;###autoload
(defun org-babel-tangle-file (file &amp;optional target-file lang)
  "Extract the bodies of source code blocks in FILE.
Source code blocks are extracted with `org-babel-tangle'.
Optional argument TARGET-FILE can be used to specify a default
export file for all source blocks.  Optional argument LANG can be
used to limit the exported source code blocks by language."
  (interactive "fFile to tangle: \nP")
  (let ((visited-p (get-file-buffer (expand-file-name file)))
    to-be-removed)
    (save-window-excursion
      (find-file file)
      (setq to-be-removed (current-buffer))
      (org-babel-tangle target-file lang))
    (unless visited-p
      (kill-buffer to-be-removed))))
</t>
<t tx="ekr.20100929212226.14332">
(defun org-babel-tangle-publish (_ filename pub-dir)
  "Tangle FILENAME and place the results in PUB-DIR."
  (mapc (lambda (el) (copy-file el pub-dir t)) (org-babel-tangle-file filename)))
</t>
<t tx="ekr.20100929212226.14333">
;;;###autoload
(defun org-babel-tangle (&amp;optional target-file lang)
  "Write code blocks to source-specific files.
Extract the bodies of all source code blocks from the current
file into their own source-specific files.  Optional argument
TARGET-FILE can be used to specify a default export file for all
source blocks.  Optional argument LANG can be used to limit the
exported source code blocks by language."
  (interactive)
  (save-buffer)
  (save-excursion
    (let ((block-counter 0)
      (org-babel-default-header-args
       (if target-file
           (org-babel-merge-params org-babel-default-header-args
                       (list (cons :tangle target-file)))
         org-babel-default-header-args))
          path-collector)
      (mapc ;; map over all languages
       (lambda (by-lang)
         (let* ((lang (car by-lang))
                (specs (cdr by-lang))
        (ext (or (cdr (assoc lang org-babel-tangle-lang-exts)) lang))
                (lang-f (intern
             (concat
              (or (and (cdr (assoc lang org-src-lang-modes))
                   (symbol-name
                    (cdr (assoc lang org-src-lang-modes))))
                  lang)
              "-mode")))
                she-banged)
           (mapc
            (lambda (spec)
              (flet ((get-spec (name)
                               (cdr (assoc name (nth 2 spec)))))
                (let* ((tangle (get-spec :tangle))
                       (she-bang ((lambda (sheb) (when (&gt; (length sheb) 0) sheb))
                  (get-spec :shebang)))
                       (base-name (cond
                   ((string= "yes" tangle)
                    (file-name-sans-extension
                     (buffer-file-name)))
                   ((string= "no" tangle) nil)
                   ((&gt; (length tangle) 0) tangle)))
                       (file-name (when base-name
                                    ;; decide if we want to add ext to base-name
                                    (if (and ext (string= "yes" tangle))
                                        (concat base-name "." ext) base-name))))
                  (when file-name
                    ;; delete any old versions of file
                    (when (and (file-exists-p file-name)
                               (not (member file-name path-collector)))
                      (delete-file file-name))
                    ;; drop source-block to file
                    (with-temp-buffer
                      (when (fboundp lang-f) (funcall lang-f))
                      (when (and she-bang (not (member file-name she-banged)))
                        (insert (concat she-bang "\n"))
                        (setq she-banged (cons file-name she-banged)))
                      (org-babel-spec-to-string spec)
              ;; We avoid append-to-file as it does not work with tramp.
              (let ((content (buffer-string)))
            (with-temp-buffer
              (if (file-exists-p file-name)
                  (insert-file-contents file-name))
              (goto-char (point-max))
              (insert content)
              (write-region nil nil file-name))))
            ;; if files contain she-bangs, then make the executable
            (when she-bang (set-file-modes file-name ?\755))
                    ;; update counter
                    (setq block-counter (+ 1 block-counter))
                    (add-to-list 'path-collector file-name)))))
            specs)))
       (org-babel-tangle-collect-blocks lang))
      (message "tangled %d code block%s" block-counter
               (if (= block-counter 1) "" "s"))
      ;; run `org-babel-post-tangle-hook' in all tangled files
      (when org-babel-post-tangle-hook
    (mapc
     (lambda (file)
       (org-babel-with-temp-filebuffer file
         (run-hooks 'org-babel-post-tangle-hook)))
     path-collector))
      path-collector)))
</t>
<t tx="ekr.20100929212226.14334">
(defun org-babel-tangle-clean ()
  "Remove comments inserted by `org-babel-tangle'.
Call this function inside of a source-code file generated by
`org-babel-tangle' to remove all comments inserted automatically
by `org-babel-tangle'.  Warning, this comment removes any lines
containing constructs which resemble org-mode file links or noweb
references."
  (interactive)
  (goto-char (point-min))
  (while (or (re-search-forward "\\[\\[file:.*\\]\\[.*\\]\\]" nil t)
@verbatim
             (re-search-forward "&lt;&lt;[^[:space:]]*&gt;&gt;" nil t))
    (delete-region (save-excursion (beginning-of-line 1) (point))
                   (save-excursion (end-of-line 1) (forward-char 1) (point)))))
</t>
<t tx="ekr.20100929212226.14335">
(defvar org-stored-links)
(defun org-babel-tangle-collect-blocks (&amp;optional lang)
  "Collect source blocks in the current Org-mode file.
Return an association list of source-code block specifications of
the form used by `org-babel-spec-to-string' grouped by language.
Optional argument LANG can be used to limit the collected source
code blocks by language."
  (let ((block-counter 1) (current-heading "") blocks)
    (org-babel-map-src-blocks (buffer-file-name)
      ((lambda (new-heading)
     (if (not (string= new-heading current-heading))
         (progn
           (setq block-counter 1)
           (setq current-heading new-heading))
       (setq block-counter (+ 1 block-counter))))
       (replace-regexp-in-string "[ \t]" "-"
                 (nth 4 (org-heading-components))))
      (let* ((link (progn (call-interactively 'org-store-link)
                          (org-babel-clean-text-properties
               (car (pop org-stored-links)))))
             (info (org-babel-get-src-block-info))
             (source-name (intern (or (nth 4 info)
                                      (format "%s:%d"
                          current-heading block-counter))))
             (src-lang (nth 0 info))
         (expand-cmd (intern (concat "org-babel-expand-body:" src-lang)))
             (params (nth 2 info))
             by-lang)
        (unless (string= (cdr (assoc :tangle params)) "no") ;; skip
          (unless (and lang (not (string= lang src-lang))) ;; limit by language
            ;; add the spec for this block to blocks under it's language
            (setq by-lang (cdr (assoc src-lang blocks)))
            (setq blocks (delq (assoc src-lang blocks) blocks))
            (setq blocks
                  (cons
                   (cons src-lang
                         (cons (list link source-name params
                                     ((lambda (body)
                                        (if (assoc :no-expand params)
                                            body
                                          (funcall
                       (if (fboundp expand-cmd)
                           expand-cmd
                         'org-babel-expand-body:generic)
                                           body
                                           params)))
                                      (if (and (cdr (assoc :noweb params))
                                               (string=
                        "yes"
                        (cdr (assoc :noweb params))))
                                          (org-babel-expand-noweb-references
                       info)
                    (nth 1 info))))
                               by-lang)) blocks))))))
    ;; ensure blocks in the correct order
    (setq blocks
          (mapcar
       (lambda (by-lang) (cons (car by-lang) (reverse (cdr by-lang))))
       blocks))
    blocks))
</t>
<t tx="ekr.20100929212226.14336">
(defun org-babel-spec-to-string (spec)
  "Insert SPEC into the current file.
Insert the source-code specified by SPEC into the current
source code file.  This function uses `comment-region' which
assumes that the appropriate major-mode is set.  SPEC has the
form

  (link source-name params body)"
  (let ((link (nth 0 spec))
    (source-name (nth 1 spec))
    (body (nth 3 spec))
    (commentable (string= (cdr (assoc :comments (nth 2 spec))) "yes")))
    (flet ((insert-comment (text)
               (when commentable
                 (insert "\n")
                 (comment-region (point)
                         (progn (insert text) (point)))
                 (end-of-line nil)
                 (insert "\n"))))
      (insert-comment (format "[[%s][%s]]" (org-link-escape link) source-name))
      (insert (format "\n%s\n" (replace-regexp-in-string
                "^," "" (org-babel-chomp body))))
      (insert-comment (format "%s ends here" source-name)))))
</t>
<t tx="ekr.20100929212226.14337">;;; ob.el --- working with code blocks in org-mode

@language lisp
@tabwidth -4
@others

(provide 'ob)

;; arch-tag: 01a7ebee-06c5-4ee4-a709-e660d28c0af1

;;; ob.el ends here
</t>
<t tx="ekr.20100929212226.14338">;; Copyright (C) 2009, 2010  Free Software Foundation, Inc.

;; Author: Eric Schulte, Dan Davison
;; Keywords: literate programming, reproducible research
;; Homepage: http://orgmode.org
;; Version: 7.01h

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; See the online documentation for more information
;;
;;   http://orgmode.org/worg/org-contrib/babel/

;;; Code:
(eval-when-compile (require 'cl))
(require 'org-macs)

(defvar org-babel-call-process-region-original)
(declare-function show-all "outline" ())
(declare-function tramp-compat-make-temp-file "tramp" (filename &amp;optional dir-flag))
(declare-function tramp-dissect-file-name "tramp" (name &amp;optional nodefault))
(declare-function tramp-file-name-user "tramp" (vec))
(declare-function tramp-file-name-host "tramp" (vec))
(declare-function org-icompleting-read "org" (&amp;rest args))
(declare-function org-edit-src-code "org" (context code edit-buffer-name))
(declare-function org-open-at-point "org" (&amp;optional in-emacs reference-buffer))
(declare-function org-save-outline-visibility "org" (use-markers &amp;rest body))
(declare-function org-narrow-to-subtree "org" ())
(declare-function org-entry-get "org" (pom property &amp;optional inherit))
(declare-function org-make-options-regexp "org" (kwds &amp;optional extra))
(declare-function org-match-string-no-properties "org" (num &amp;optional string))
(declare-function org-do-remove-indentation "org" (&amp;optional n))
(declare-function org-show-context "org" (&amp;optional key))
(declare-function org-at-table-p "org" (&amp;optional table-type))
(declare-function org-cycle "org" (&amp;optional arg))
(declare-function org-uniquify "org" (list))
(declare-function org-table-import "org" (file arg))
(declare-function org-add-hook "org-compat" (hook function &amp;optional append local))
(declare-function org-table-align "org-table" ())
(declare-function org-table-end "org-table" (&amp;optional table-type))
(declare-function orgtbl-to-generic "org-table" (table params))
(declare-function orgtbl-to-orgtbl "org-table" (table params))
(declare-function org-babel-lob-get-info "ob-lob" nil)
(declare-function org-babel-ref-split-args "ob-ref" (arg-string))
(declare-function org-babel-ref-variables "ob-ref" (params))
(declare-function org-babel-ref-resolve-reference "ob-ref" (ref &amp;optional params))

(defgroup org-babel nil
  "Code block evaluation and management in `org-mode' documents."
  :tag "Babel"
  :group 'org)

(defcustom org-confirm-babel-evaluate t
  "Confirm before evaluation.
Require confirmation before interactively evaluating code
blocks in Org-mode buffers.  The default value of this variable
is t, meaning confirmation is required for any code block
evaluation.  This variable can be set to nil to inhibit any
future confirmation requests.  This variable can also be set to a
function which takes two arguments the language of the code block
and the body of the code block.  Such a function should then
return a non-nil value if the user should be prompted for
execution or nil if no prompt is required.

Warning: Disabling confirmation may result in accidental
evaluation of potentially harmful code.  It may be advisable
remove code block execution from C-c C-c as further protection
against accidental code block evaluation.  The
`org-babel-no-eval-on-ctrl-c-ctrl-c' variable can be used to
remove code block execution from the C-c C-c keybinding."
    :group 'org-babel
    :type '(choice boolean function))
;; don't allow this variable to be changed through file settings
(put 'org-confirm-babel-evaluate 'safe-local-variable (lambda (x) (eq x t)))

(defcustom org-babel-no-eval-on-ctrl-c-ctrl-c nil
  "Remove code block evaluation from the C-c C-c key binding."
  :group 'org-babel
  :type 'boolean)

(defvar org-babel-src-name-regexp
  "^[ \t]*#\\+\\(srcname\\|source\\|function\\):[ \t]*"
  "Regular expression used to match a source name line.")

(defvar org-babel-src-name-w-name-regexp
  (concat org-babel-src-name-regexp
      "\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)")
  "Regular expression matching source name lines with a name.")

(defvar org-babel-src-block-regexp
  (concat
   ;; (1) indentation                     (2) lang
   "^\\([ \t]*\\)#\\+begin_src[ \t]+\\([^ \f\t\n\r\v]+\\)[ \t]*"
   ;; (3) switches
   "\\([^\":\n]*\"[^\"\n*]*\"[^\":\n]*\\|[^\":\n]*\\)"
   ;; (4) header arguments
   "\\([^\n]*\\)\n"
   ;; (5) body
   "\\([^\000]+?\n\\)[ \t]*#\\+end_src")
  "Regexp used to identify code blocks.")

(defvar org-babel-inline-src-block-regexp
  (concat
   ;; (1) replacement target (2) lang
   "[ \f\t\n\r\v]\\(src_\\([^ \f\t\n\r\v]+\\)"
   ;; (3,4) (unused, headers)
   "\\(\\|\\[\\(.*?\\)\\]\\)"
   ;; (5) body
   "{\\([^\f\n\r\v]+?\\)}\\)")
  "Regexp used to identify inline src-blocks.")

</t>
<t tx="ekr.20100929212226.14339">(defun org-babel-get-src-block-info (&amp;optional header-vars-only)
  "Get information on the current source block.

Returns a list
 (language body header-arguments-alist switches name function-args indent).
Unless HEADER-VARS-ONLY is non-nil, any variable
references provided in 'function call style' (i.e. in a
parenthesised argument list following the src block name) are
added to the header-arguments-alist."
  (let ((case-fold-search t) head info args indent)
    (if (setq head (org-babel-where-is-src-block-head))
        (save-excursion
      (goto-char head)
      (setq info (org-babel-parse-src-block-match))
      (setq indent (car (last info)))
      (setq info (butlast info))
      (forward-line -1)
      (if (and (looking-at org-babel-src-name-w-name-regexp)
           (match-string 2))
          (progn
        (setq info (append info (list (org-babel-clean-text-properties
                           (match-string 2)))))
        ;; Note that e.g. "name()" and "name( )" result in
        ;; ((:var . "")).  We maintain that behaviour, and the
        ;; resulting non-nil sixth element is relied upon in
        ;; org-babel-exp-code to detect a functional-style
        ;; block in those cases. However, "name" without any
        ;; parentheses would result in the same thing, so we
        ;; explicitly avoid that.
        (if (setq args (match-string 4))
            (setq info
              (append info (list
                    (mapcar
                     (lambda (ref) (cons :var ref))
                     (org-babel-ref-split-args args))))))
        (unless header-vars-only
          (setf (nth 2 info)
            (org-babel-merge-params (nth 5 info) (nth 2 info)))))
        (setq info (append info (list nil nil))))
      (append info (list indent)))
      (if (save-excursion ;; inline source block
            (re-search-backward "[ \f\t\n\r\v]" nil t)
            (looking-at org-babel-inline-src-block-regexp))
          (org-babel-parse-inline-src-block-match)
        nil))))
</t>
<t tx="ekr.20100929212226.14340">
(defun org-babel-confirm-evaluate (info)
  "Confirm evaluation of the code block INFO.
This behavior can be suppressed by setting the value of
`org-confirm-babel-evaluate' to nil, in which case all future
interactive code block evaluations will proceed without any
confirmation from the user.

Note disabling confirmation may result in accidental evaluation
of potentially harmful code."
  (let* ((eval (cdr (assoc :eval (nth 2 info))))
     (query (or (equal eval "query")
            (and (functionp org-confirm-babel-evaluate)
             (funcall org-confirm-babel-evaluate
                  (nth 0 info) (nth 1 info)))
            org-confirm-babel-evaluate)))
    (when (or (equal eval "never")
          (and query
           (not (yes-or-no-p
             (format "Evaluate this%scode on your system? "
                 (if info (format " %s " (nth 0 info)) " "))))))
      (error "evaluation aborted"))))
</t>
<t tx="ekr.20100929212226.14341">
;;;###autoload
(defun org-babel-execute-src-block-maybe ()
  "Conditionally execute a source block.
Detect if this is context for a Babel src-block and if so
then run `org-babel-execute-src-block'."
  (interactive)
  (if (not org-babel-no-eval-on-ctrl-c-ctrl-c)
      (let ((info (org-babel-get-src-block-info)))
    (if info
        (progn (org-babel-execute-src-block current-prefix-arg info) t) nil))
    nil))
</t>
<t tx="ekr.20100929212226.14342">(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-execute-src-block-maybe)

;;;###autoload
(defun org-babel-expand-src-block-maybe ()
  "Conditionally expand a source block.
Detect if this is context for a org-babel src-block and if so
then run `org-babel-expand-src-block'."
  (interactive)
  (let ((info (org-babel-get-src-block-info)))
    (if info
    (progn (org-babel-expand-src-block current-prefix-arg info) t)
      nil)))
</t>
<t tx="ekr.20100929212226.14343">
;;;###autoload
(defun org-babel-load-in-session-maybe ()
  "Conditionally load a source block in a session.
Detect if this is context for a org-babel src-block and if so
then run `org-babel-load-in-session'."
  (interactive)
  (let ((info (org-babel-get-src-block-info)))
    (if info
    (progn (org-babel-load-in-session current-prefix-arg info) t)
      nil)))
</t>
<t tx="ekr.20100929212226.14344">
(add-hook 'org-metaup-hook 'org-babel-load-in-session-maybe)

;;;###autoload
(defun org-babel-pop-to-session-maybe ()
  "Conditionally pop to a session.
Detect if this is context for a org-babel src-block and if so
then run `org-babel-pop-to-session'."
  (interactive)
  (let ((info (org-babel-get-src-block-info)))
    (if info (progn (org-babel-pop-to-session current-prefix-arg info) t) nil)))
</t>
<t tx="ekr.20100929212226.14345">
(add-hook 'org-metadown-hook 'org-babel-pop-to-session-maybe)

(defconst org-babel-header-arg-names
  '(cache cmdline colnames dir exports file noweb results
      session tangle var noeval comments)
  "Common header arguments used by org-babel.
Note that individual languages may define their own language
specific header arguments as well.")

(defvar org-babel-default-header-args
  '((:session . "none") (:results . "replace") (:exports . "code")
    (:cache . "no") (:noweb . "no") (:hlines . "no") (:tangle . "no"))
  "Default arguments to use when evaluating a source block.")

(defvar org-babel-default-inline-header-args
  '((:session . "none") (:results . "silent") (:exports . "results"))
  "Default arguments to use when evaluating an inline source block.")

(defvar org-babel-current-buffer-properties)
(make-variable-buffer-local 'org-babel-current-buffer-properties)

(defvar org-babel-result-regexp
  "^[ \t]*#\\+res\\(ults\\|name\\)\\(\\[\\([[:alnum:]]+\\)\\]\\)?\\:[ \t]*"
  "Regular expression used to match result lines.
If the results are associated with a hash key then the hash will
be saved in the second match data.")

(defvar org-babel-result-w-name-regexp
  (concat org-babel-result-regexp
      "\\([^ ()\f\t\n\r\v]+\\)\\(\(\\(.*\\)\)\\|\\)"))

(defvar org-babel-min-lines-for-block-output 10
  "The minimum number of lines for block output.
If number of lines of output is equal to or exceeds this
value, the output is placed in a #+begin_example...#+end_example
block. Otherwise the output is marked as literal by inserting
colons at the starts of the lines. This variable only takes
effect if the :results output option is in effect.")

(defvar org-babel-noweb-error-langs nil
  "Languages for which Babel will raise literate programming errors.
List of languages for which errors should be raised when the
source code block satisfying a noweb reference in this language
can not be resolved.")

(defvar org-babel-hash-show 4
  "Number of initial characters to show of a hidden results hash.")

(defvar org-babel-after-execute-hook nil
  "Hook for functions to be called after `org-babel-execute-src-block'")
(defun org-babel-named-src-block-regexp-for-name (name)
  "This generates a regexp used to match a src block named NAME."
  (concat org-babel-src-name-regexp (regexp-quote name) "[ \t\n]*"
      (substring org-babel-src-block-regexp 1)))
</t>
<t tx="ekr.20100929212226.14346">
;;; functions
(defvar call-process-region)
;;;###autoload
(defun org-babel-execute-src-block (&amp;optional arg info params)
  "Execute the current source code block.
Insert the results of execution into the buffer.  Source code
execution and the collection and formatting of results can be
controlled through a variety of header arguments.

Optionally supply a value for INFO in the form returned by
`org-babel-get-src-block-info'.

Optionally supply a value for PARAMS which will be merged with
the header arguments specified at the front of the source code
block."
  (interactive)
  (let* ((info (or info (org-babel-get-src-block-info)))
     ;; note the `evaluation-confirmed' variable is currently not
     ;; used, but could be used later to avoid the need for
     ;; chaining confirmations
     (evaluation-confirmed (org-babel-confirm-evaluate info))
         (lang (nth 0 info))
     (params (setf (nth 2 info)
                       (sort (org-babel-merge-params (nth 2 info) params)
                             (lambda (el1 el2) (string&lt; (symbol-name (car el1))
                                                   (symbol-name (car el2)))))))
         (new-hash
          (if (and (cdr (assoc :cache params))
                   (string= "yes" (cdr (assoc :cache params))))
              (org-babel-sha1-hash info)))
         (old-hash (org-babel-result-hash info))
         (body (setf (nth 1 info)
             (if (and (cdr (assoc :noweb params))
                              (string= "yes" (cdr (assoc :noweb params))))
                         (org-babel-expand-noweb-references info)
               (nth 1 info))))
         (result-params (split-string (or (cdr (assoc :results params)) "")))
         (result-type (cond ((member "output" result-params) 'output)
                ((member "value" result-params) 'value)
                (t 'value)))
         (cmd (intern (concat "org-babel-execute:" lang)))
     (dir (cdr (assoc :dir params)))
     (default-directory
       (or (and dir (file-name-as-directory dir)) default-directory))
     (org-babel-call-process-region-original
      (if (boundp 'org-babel-call-process-region-original) org-babel-call-process-region-original
        (symbol-function 'call-process-region)))
     (indent (car (last info)))
         result)
    (unwind-protect
        (flet ((call-process-region (&amp;rest args)
                 (apply 'org-babel-tramp-handle-call-process-region args)))
          (unless (fboundp cmd)
            (error "No org-babel-execute function for %s!" lang))
          (if (and (not arg) new-hash (equal new-hash old-hash))
              (save-excursion ;; return cached result
                (goto-char (org-babel-where-is-src-block-result nil info))
                (end-of-line 1) (forward-char 1)
                (setq result (org-babel-read-result))
                (message (replace-regexp-in-string "%" "%%"
                                                   (format "%S" result))) result)
            (message "executing %s code block%s..."
             (capitalize lang)
             (if (nth 4 info) (format " (%s)" (nth 4 info)) ""))
        (setq result (funcall cmd body params))
            (if (eq result-type 'value)
                (setq result (if (and (or (member "vector" result-params)
                                          (member "table" result-params))
                                      (not (listp result)))
                                 (list (list result))
                               result)))
            (org-babel-insert-result
         result result-params info new-hash indent lang)
            (run-hooks 'org-babel-after-execute-hook)
            result))
      (setq call-process-region 'org-babel-call-process-region-original))))
</t>
<t tx="ekr.20100929212226.14347">
(defun org-babel-expand-body:generic (body params &amp;optional processed-params)
  "Expand BODY with PARAMS.
Expand a block of code with org-babel according to it's header
arguments.  This generic implementation of body expansion is
called for languages which have not defined their own specific
org-babel-expand-body:lang function." body)
</t>
<t tx="ekr.20100929212226.14348">
;;;###autoload
(defun org-babel-expand-src-block (&amp;optional arg info params)
  "Expand the current source code block.
Expand according to the source code block's header
arguments and pop open the results in a preview buffer."
  (interactive)
  (let* ((info (or info (org-babel-get-src-block-info)))
         (lang (nth 0 info))
     (params (setf (nth 2 info)
                       (sort (org-babel-merge-params (nth 2 info) params)
                             (lambda (el1 el2) (string&lt; (symbol-name (car el1))
                                                   (symbol-name (car el2)))))))
         (body (setf (nth 1 info)
             (if (and (cdr (assoc :noweb params))
                              (string= "yes" (cdr (assoc :noweb params))))
             (org-babel-expand-noweb-references info) (nth 1 info))))
         (cmd (intern (concat "org-babel-expand-body:" lang)))
         (expanded (funcall (if (fboundp cmd) cmd 'org-babel-expand-body:generic)
                            body params)))
    (org-edit-src-code
     nil expanded (concat "*Org-Babel Preview " (buffer-name) "[ " lang " ]*"))))
</t>
<t tx="ekr.20100929212226.14349">
;;;###autoload
(defun org-babel-load-in-session (&amp;optional arg info)
  "Load the body of the current source-code block.
Evaluate the header arguments for the source block before
entering the session.  After loading the body this pops open the
session."
  (interactive)
  (let* ((info (or info (org-babel-get-src-block-info)))
         (lang (nth 0 info))
         (body (nth 1 info))
         (params (nth 2 info))
         (session (cdr (assoc :session params)))
     (cmd (intern (concat "org-babel-load-session:" lang))))
    (unless (fboundp cmd)
      (error "No org-babel-load-session function for %s!" lang))
    (pop-to-buffer (funcall cmd session body params))
    (end-of-line 1)))
</t>
<t tx="ekr.20100929212226.14350">
;;;###autoload
(defun org-babel-switch-to-session (&amp;optional arg info)
  "Switch to the session of the current source-code block.
If called with a prefix argument then evaluate the header arguments
for the source block before entering the session. Copy the body
of the source block to the kill ring."
  (interactive)
  (let* ((info (or info (org-babel-get-src-block-info)))
         (lang (nth 0 info))
         (body (nth 1 info))
         (params (nth 2 info))
         (session (cdr (assoc :session params)))
     (dir (cdr (assoc :dir params)))
     (default-directory
       (or (and dir (file-name-as-directory dir)) default-directory))
     (cmd (intern (format "org-babel-%s-initiate-session" lang)))
     (cmd2 (intern (concat "org-babel-prep-session:" lang))))
    (unless (fboundp cmd)
      (error "No org-babel-initiate-session function for %s!" lang))
    ;; copy body to the kill ring
    (with-temp-buffer (insert (org-babel-trim body))
                      (copy-region-as-kill (point-min) (point-max)))
    ;; if called with a prefix argument, then process header arguments
    (unless (fboundp cmd2)
      (error "No org-babel-prep-session function for %s!" lang))
    (when arg (funcall cmd2 session params))
    ;; just to the session using pop-to-buffer
    (pop-to-buffer (funcall cmd session params))
    (end-of-line 1)))
</t>
<t tx="ekr.20100929212226.14351">
(defalias 'org-babel-pop-to-session 'org-babel-switch-to-session)

(defvar org-bracket-link-regexp)
;;;###autoload
(defun org-babel-open-src-block-result (&amp;optional re-run)
  "If `point' is on a src block then open the results of the
source code block, otherwise return nil.  With optional prefix
argument RE-RUN the source-code block is evaluated even if
results already exist."
  (interactive "P")
  (when (org-babel-get-src-block-info)
    (save-excursion
      ;; go to the results, if there aren't any then run the block
      (goto-char (or (and (not re-run) (org-babel-where-is-src-block-result))
                     (progn (org-babel-execute-src-block)
                            (org-babel-where-is-src-block-result))))
      (end-of-line 1)
      (while (looking-at "[\n\r\t\f ]") (forward-char 1))
      ;; open the results
      (if (looking-at org-bracket-link-regexp)
          ;; file results
          (org-open-at-point)
        (let ((results (org-babel-read-result)))
          (flet ((echo-res (result)
                           (if (stringp result) result (format "%S" result))))
            (pop-to-buffer (get-buffer-create "org-babel-results"))
            (delete-region (point-min) (point-max))
            (if (listp results)
                ;; table result
                (insert (orgtbl-to-generic results '(:sep "\t" :fmt echo-res)))
              ;; scalar result
              (insert (echo-res results))))))
      t)))
</t>
<t tx="ekr.20100929212226.14352">
;;;###autoload
(defun org-babel-execute-buffer (&amp;optional arg)
  "Execute source code blocks in a buffer.
Call `org-babel-execute-src-block' on every source block in
the current buffer."
  (interactive "P")
  (save-excursion
    (org-save-outline-visibility t
      (goto-char (point-min))
      (show-all)
      (while (re-search-forward org-babel-src-block-regexp nil t)
    (let ((pos-end (match-end 0)))
      (goto-char (match-beginning 0))
      (org-babel-execute-src-block arg)
      (goto-char pos-end))))))
</t>
<t tx="ekr.20100929212226.14353">
;;;###autoload
(defun org-babel-execute-subtree (&amp;optional arg)
  "Execute source code blocks in a subtree.
Call `org-babel-execute-src-block' on every source block in
the current subtree."
  (interactive "P")
  (save-restriction
    (save-excursion
      (org-narrow-to-subtree)
      (org-babel-execute-buffer)
      (widen))))
</t>
<t tx="ekr.20100929212226.14354">
;;;###autoload
(defun org-babel-sha1-hash (&amp;optional info)
  "Generate an sha1 hash based on the value of info."
  (interactive)
  (let* ((info (or info (org-babel-get-src-block-info)))
         (hash (sha1 (format "%s-%s" (mapconcat (lambda (arg) (format "%S" arg))
                                                (nth 2 info) ":")
                             (nth 1 info)))))
    (when (interactive-p) (message hash))
    hash))
</t>
<t tx="ekr.20100929212226.14355">
(defun org-babel-result-hash (&amp;optional info)
  "Return the in-buffer hash associated with INFO."
  (org-babel-where-is-src-block-result nil info)
  (org-babel-clean-text-properties (match-string 3)))
</t>
<t tx="ekr.20100929212226.14356">
(defun org-babel-hide-hash ()
  "Hide the hash in the current results line.
Only the initial `org-babel-hash-show' characters of the hash
will remain visible."
  (add-to-invisibility-spec '(org-babel-hide-hash . t))
  (save-excursion
    (when (and (re-search-forward org-babel-result-regexp nil t)
               (match-string 3))
      (let* ((start (match-beginning 3))
             (hide-start (+ org-babel-hash-show start))
             (end (match-end 3))
             (hash (match-string 3))
             ov1 ov2)
        (setq ov1 (make-overlay start hide-start))
        (setq ov2 (make-overlay hide-start end))
        (overlay-put ov2 'invisible 'org-babel-hide-hash)
        (overlay-put ov1 'babel-hash hash)))))
</t>
<t tx="ekr.20100929212226.14357">
(defun org-babel-hide-all-hashes ()
  "Hide the hash in the current buffer.
Only the initial `org-babel-hash-show' characters of each hash
will remain visible.  This function should be called as part of
the `org-mode-hook'."
  (save-excursion
    (while (re-search-forward org-babel-result-regexp nil t)
      (goto-char (match-beginning 0))
      (org-babel-hide-hash)
      (goto-char (match-end 0)))))
</t>
<t tx="ekr.20100929212226.14358">(add-hook 'org-mode-hook 'org-babel-hide-all-hashes)

(defun org-babel-hash-at-point (&amp;optional point)
  "Return the value of the hash at POINT.
The hash is also added as the last element of the kill ring.
This can be called with C-c C-c."
  (interactive)
  (let ((hash (car (delq nil (mapcar
                  (lambda (ol) (overlay-get ol 'babel-hash))
                              (overlays-at (or point (point))))))))
    (when hash (kill-new hash) (message hash))))
</t>
<t tx="ekr.20100929212226.14359">(add-hook 'org-ctrl-c-ctrl-c-hook 'org-babel-hash-at-point)

(defun org-babel-result-hide-spec ()
  "Hide portions of results lines.
Add `org-babel-hide-result' as an invisibility spec for hiding
portions of results lines."
  (add-to-invisibility-spec '(org-babel-hide-result . t)))
</t>
<t tx="ekr.20100929212226.14360">(add-hook 'org-mode-hook 'org-babel-result-hide-spec)

(defvar org-babel-hide-result-overlays nil
  "Overlays hiding results.")

(defun org-babel-result-hide-all ()
  "Fold all results in the current buffer."
  (interactive)
  (org-babel-show-result-all)
  (save-excursion
    (while (re-search-forward org-babel-result-regexp nil t)
      (save-excursion (goto-char (match-beginning 0))
                      (org-babel-hide-result-toggle-maybe)))))
</t>
<t tx="ekr.20100929212226.14361">
(defun org-babel-show-result-all ()
  "Unfold all results in the current buffer."
  (mapc 'delete-overlay org-babel-hide-result-overlays)
  (setq org-babel-hide-result-overlays nil))
</t>
<t tx="ekr.20100929212226.14362">
;;;###autoload
(defun org-babel-hide-result-toggle-maybe ()
  "Toggle visibility of result at point."
  (interactive)
  (let ((case-fold-search t))
    (if (save-excursion
          (beginning-of-line 1)
          (looking-at org-babel-result-regexp))
        (progn (org-babel-hide-result-toggle)
               t) ;; to signal that we took action
      nil))) ;; to signal that we did not

(defun org-babel-hide-result-toggle (&amp;optional force)
  "Toggle the visibility of the current result."
  (interactive)
  (save-excursion
    (beginning-of-line)
    (if (re-search-forward org-babel-result-regexp nil t)
        (let ((start (progn (beginning-of-line 2) (- (point) 1)))
              (end (progn (goto-char (- (org-babel-result-end) 1)) (point)))
              ov)
          (if (memq t (mapcar (lambda (overlay)
                                (eq (overlay-get overlay 'invisible)
                    'org-babel-hide-result))
                              (overlays-at start)))
              (if (or (not force) (eq force 'off))
                  (mapc (lambda (ov)
                          (when (member ov org-babel-hide-result-overlays)
                            (setq org-babel-hide-result-overlays
                                  (delq ov org-babel-hide-result-overlays)))
                          (when (eq (overlay-get ov 'invisible)
                                    'org-babel-hide-result)
                            (delete-overlay ov)))
                        (overlays-at start)))
            (setq ov (make-overlay start end))
            (overlay-put ov 'invisible 'org-babel-hide-result)
            ;; make the block accessible to isearch
            (overlay-put
             ov 'isearch-open-invisible
             (lambda (ov)
               (when (member ov org-babel-hide-result-overlays)
                 (setq org-babel-hide-result-overlays
                       (delq ov org-babel-hide-result-overlays)))
               (when (eq (overlay-get ov 'invisible)
                         'org-babel-hide-result)
                 (delete-overlay ov))))
            (push ov org-babel-hide-result-overlays)))
      (error "Not looking at a result line"))))
</t>
<t tx="ekr.20100929212226.14363">
;; org-tab-after-check-for-cycling-hook
(add-hook 'org-tab-first-hook 'org-babel-hide-result-toggle-maybe)
;; Remove overlays when changing major mode
(add-hook 'org-mode-hook
      (lambda () (org-add-hook 'change-major-mode-hook
                  'org-babel-show-result-all 'append 'local)))

(defmacro org-babel-map-src-blocks (file &amp;rest body)
  "Evaluate BODY forms on each source-block in FILE."
  (declare (indent 1))
  `(let ((visited-p (get-file-buffer (expand-file-name ,file)))
     to-be-removed)
     (save-window-excursion
       (find-file ,file)
       (setq to-be-removed (current-buffer))
       (goto-char (point-min))
       (while (re-search-forward org-babel-src-block-regexp nil t)
         (goto-char (match-beginning 0))
         (save-match-data ,@body)
         (goto-char (match-end 0))))
     (unless visited-p
       (kill-buffer to-be-removed))))

(defvar org-file-properties)
(defun org-babel-params-from-properties (&amp;optional lang)
  "Retrieve parameters specified as properties.
Return an association list of any source block params which
may be specified in the properties of the current outline entry."
  (save-match-data
    (let (val sym)
      (delq nil
        (mapcar
         (lambda (header-arg)
           (and (setq val
              (or (condition-case nil
                  (org-entry-get (point) header-arg t)
                (error nil))
                  (cdr (assoc header-arg org-file-properties))))
            (cons (intern (concat ":" header-arg)) val)))
         (mapcar
          'symbol-name
          (append
           org-babel-header-arg-names
           (progn
         (setq sym (intern (concat "org-babel-header-arg-names:" lang)))
         (and (boundp sym) (eval sym))))))))))
</t>
<t tx="ekr.20100929212226.14364">
(defun org-babel-params-from-buffer ()
  "Retrieve per-buffer parameters.
 Return an association list of any source block params which
may be specified at the top of the current buffer."
  (or org-babel-current-buffer-properties
      (setq org-babel-current-buffer-properties
        (save-match-data
          (save-excursion
        (save-restriction
          (widen)
          (goto-char (point-min))
          (when (re-search-forward
             (org-make-options-regexp (list "BABEL")) nil t)
            (org-babel-parse-header-arguments
             (org-match-string-no-properties 2)))))))))
</t>
<t tx="ekr.20100929212226.14365">
(defvar org-src-preserve-indentation)
(defun org-babel-parse-src-block-match ()
  "Parse the results from a match of the `org-babel-src-block-regexp'."
  (let* ((block-indentation (length (match-string 1)))
     (lang (org-babel-clean-text-properties (match-string 2)))
         (lang-headers (intern (concat "org-babel-default-header-args:" lang)))
     (switches (match-string 3))
         (body (org-babel-clean-text-properties (match-string 5)))
     (preserve-indentation (or org-src-preserve-indentation
                   (string-match "-i\\&gt;" switches))))
    (list lang
          ;; get block body less properties, protective commas, and indentation
          (with-temp-buffer
            (save-match-data
              (insert (org-babel-strip-protective-commas body))
          (unless preserve-indentation (org-do-remove-indentation))
              (buffer-string)))
      (org-babel-merge-params
       org-babel-default-header-args
       (org-babel-params-from-buffer)
           (org-babel-params-from-properties lang)
       (if (boundp lang-headers) (eval lang-headers) nil)
       (org-babel-parse-header-arguments
            (org-babel-clean-text-properties (or (match-string 4) ""))))
      switches
      block-indentation)))
</t>
<t tx="ekr.20100929212226.14366">
(defun org-babel-parse-inline-src-block-match ()
  "Parse the results from a match of the `org-babel-inline-src-block-regexp'."
  (let* ((lang (org-babel-clean-text-properties (match-string 2)))
         (lang-headers (intern (concat "org-babel-default-header-args:" lang))))
    (list lang
          (org-babel-strip-protective-commas
           (org-babel-clean-text-properties (match-string 5)))
          (org-babel-merge-params
           org-babel-default-inline-header-args
       (org-babel-params-from-buffer)
           (org-babel-params-from-properties lang)
           (if (boundp lang-headers) (eval lang-headers) nil)
           (org-babel-parse-header-arguments
            (org-babel-clean-text-properties (or (match-string 4) "")))))))
</t>
<t tx="ekr.20100929212226.14367">
(defun org-babel-parse-header-arguments (arg-string)
  "Parse a string of header arguments returning an alist."
  (if (&gt; (length arg-string) 0)
      (delq nil
        (mapcar
         (lambda (arg)
           (if (string-match
                    "\\([^ \f\t\n\r\v]+\\)[ \f\t\n\r\v]+\\([^ \f\t\n\r\v]+.*\\)"
                    arg)
           (cons (intern (concat ":" (match-string 1 arg)))
                         (let ((raw (org-babel-chomp (match-string 2 arg))))
                           (if (org-babel-number-p raw)
                               raw (org-babel-read raw))))
         (cons (intern (concat ":" arg)) nil)))
         (split-string (concat " " arg-string) "[ \f\t\n\r\v]+:" t)))))
</t>
<t tx="ekr.20100929212226.14368">
(defun org-babel-process-params (params)
  "Parse params and resolve references.

Return a list (session vars result-params result-type colnames rownames)."
  (let* ((session (cdr (assoc :session params)))
         (vars-and-names (org-babel-disassemble-tables
                          (org-babel-ref-variables params)
                          (cdr (assoc :hlines params))
                          (cdr (assoc :colnames params))
                          (cdr (assoc :rownames params))))
         (vars     (car   vars-and-names))
         (colnames (cadr  vars-and-names))
         (rownames (caddr vars-and-names))
     (result-params (split-string (or (cdr (assoc :results params)) "")))
     (result-type (cond ((member "output" result-params) 'output)
                ((member "value" result-params) 'value)
                (t 'value))))
    (list session vars result-params result-type colnames rownames)))
</t>
<t tx="ekr.20100929212226.14369">
;; row and column names
(defun org-babel-del-hlines (table)
  "Remove all 'hlines from TABLE."
  (remove 'hline table))
</t>
<t tx="ekr.20100929212226.14370">
(defun org-babel-get-colnames (table)
  "Return the column names of 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 (nth 1 table))
      (cons (cddr table) (car table))
    (cons (cdr table) (car table))))
</t>
<t tx="ekr.20100929212226.14371">
(defun org-babel-get-rownames (table)
  "Return the row names of 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* ((width (apply 'max (mapcar (lambda (el) (if (listp el) (length el) 0)) table)))
           (table (trans (mapcar (lambda (row)
                                   (if (not (equal row 'hline))
                                       row
                                     (setq row '())
                                     (dotimes (n width) (setq row (cons 'hline row)))
                                     row))
                                 table))))
      (cons (mapcar (lambda (row) (if (equal (car row) 'hline) 'hline row))
                    (trans (cdr table)))
            (remove 'hline (car table))))))
</t>
<t tx="ekr.20100929212226.14372">
(defun org-babel-put-colnames (table colnames)
  "Add COLNAMES to TABLE if they exist."
  (if colnames (apply 'list colnames 'hline table) table))
</t>
<t tx="ekr.20100929212226.14373">
(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))
</t>
<t tx="ekr.20100929212226.14374">
(defun org-babel-pick-name (names selector)
  "Select one out of an alist of row or column names."
  (when names
    (if (and selector (symbolp selector) (not (equal t selector)))
        (cdr (assoc selector names))
      (if (integerp selector)
          (nth (- selector 1) names)
        (cdr (car (last names)))))))
</t>
<t tx="ekr.20100929212226.14375">
(defun org-babel-disassemble-tables (vars hlines colnames rownames)
  "Parse tables for further processing.
Process the variables in VARS according to the HLINES,
ROWNAMES and COLNAMES header arguments.  Return a list consisting
of the vars, cnames and rnames."
  (let (cnames rnames)
    (list
     (mapcar
      (lambda (var)
        (when (listp (cdr var))
          (when (and (not (equal colnames "no"))
                     (or colnames (and (equal (nth 1 (cdr var)) 'hline)
                                       (not (member 'hline (cddr (cdr var)))))))
            (let ((both (org-babel-get-colnames (cdr var))))
              (setq cnames (cons (cons (car var) (cdr both))
                                 cnames))
              (setq var (cons (car var) (car both)))))
          (when (and rownames (not (equal rownames "no")))
            (let ((both (org-babel-get-rownames (cdr var))))
              (setq rnames (cons (cons (car var) (cdr both))
                                 rnames))
              (setq var (cons (car var) (car both)))))
          (when (and hlines (not (equal hlines "yes")))
            (setq var (cons (car var) (org-babel-del-hlines (cdr var))))))
        var)
      vars)
     cnames rnames)))
</t>
<t tx="ekr.20100929212226.14376">
(defun org-babel-reassemble-table (table colnames rownames)
  "Add column and row names to a table.
Given a TABLE and set of COLNAMES and ROWNAMES add the names
to the table for reinsertion to org-mode."
  (if (listp table)
      ((lambda (table)
         (if (and colnames (listp (car table)) (= (length (car table))
                                                  (length colnames)))
             (org-babel-put-colnames table colnames) table))
       (if (and rownames (= (length table) (length rownames)))
           (org-babel-put-rownames table rownames) table))
    table))
</t>
<t tx="ekr.20100929212226.14377">
(defun org-babel-where-is-src-block-head ()
  "Find where the current source block begins.
Return the point at the beginning of the current source
block.  Specifically at the beginning of the #+BEGIN_SRC line.
If the point is not on a source block then return nil."
  (let ((initial (point)) top bottom)
    (or
     (save-excursion ;; on a source name line
       (beginning-of-line 1)
       (and (looking-at org-babel-src-name-regexp) (forward-line 1)
            (looking-at org-babel-src-block-regexp)
            (point)))
     (save-excursion ;; on a #+begin_src line
       (beginning-of-line 1)
       (and (looking-at org-babel-src-block-regexp)
            (point)))
     (save-excursion ;; inside a src block
       (and
        (re-search-backward "^[ \t]*#\\+begin_src" nil t) (setq top (point))
        (re-search-forward "^[ \t]*#\\+end_src" nil t) (setq bottom (point))
        (&lt; top initial) (&lt; initial bottom)
        (progn (goto-char top) (beginning-of-line 1)
           (looking-at org-babel-src-block-regexp))
        (point))))))
</t>
<t tx="ekr.20100929212226.14378">
;;;###autoload
(defun org-babel-goto-named-src-block (name)
  "Go to a named source-code block."
  (interactive
   (let ((completion-ignore-case t))
     (list (org-icompleting-read "source-block name: "
                 (org-babel-src-block-names) nil t))))
  (let ((point (org-babel-find-named-block name)))
    (if point
        ;; taken from `org-open-at-point'
        (progn (goto-char point) (org-show-context))
      (message "source-code block '%s' not found in this buffer" name))))
</t>
<t tx="ekr.20100929212226.14379">
(defun org-babel-find-named-block (name)
  "Find a named source-code block.
Return the location of the source block identified by source
NAME, or nil if no such block exists. Set match data according to
org-babel-named-src-block-regexp."
  (save-excursion
    (let ((case-fold-search t)
      (regexp (org-babel-named-src-block-regexp-for-name name)) msg)
      (goto-char (point-min))
      (when (or (re-search-forward regexp nil t)
                (re-search-backward regexp nil t))
        (match-beginning 0)))))
</t>
<t tx="ekr.20100929212226.14380">
(defun org-babel-src-block-names (&amp;optional file)
  "Returns the names of source blocks in FILE or the current buffer."
  (save-excursion
    (when file (find-file file)) (goto-char (point-min))
    (let (names)
      (while (re-search-forward org-babel-src-name-w-name-regexp nil t)
    (setq names (cons (org-babel-clean-text-properties (match-string 2))
              names)))
      names)))
</t>
<t tx="ekr.20100929212226.14381">
;;;###autoload
(defun org-babel-goto-named-result (name)
  "Go to a named result."
  (interactive
   (let ((completion-ignore-case t))
     (list (org-icompleting-read "source-block name: "
                 (org-babel-result-names) nil t))))
  (let ((point (org-babel-find-named-result name)))
    (if point
        ;; taken from `org-open-at-point'
        (progn (goto-char point) (org-show-context))
      (message "result '%s' not found in this buffer" name))))
</t>
<t tx="ekr.20100929212226.14382">
(defun org-babel-find-named-result (name)
  "Find a named result.
Return the location of the result named NAME in the current
buffer or nil if no such result exists."
  (save-excursion
    (goto-char (point-min))
    (when (re-search-forward
           (concat org-babel-result-regexp
                   "[ \t]" (regexp-quote name) "[ \t\n\f\v\r]") nil t)
      (beginning-of-line 0) (point))))
</t>
<t tx="ekr.20100929212226.14383">
(defun org-babel-result-names (&amp;optional file)
  "Returns the names of results in FILE or the current buffer."
  (save-excursion
    (when file (find-file file)) (goto-char (point-min))
    (let (names)
      (while (re-search-forward org-babel-result-w-name-regexp nil t)
    (setq names (cons (org-babel-clean-text-properties (match-string 4))
              names)))
      names)))
</t>
<t tx="ekr.20100929212226.14384">
;;;###autoload
(defun org-babel-next-src-block (&amp;optional arg)
  "Jump to the next source block.
With optional prefix argument ARG, jump forward ARG many source blocks."
  (interactive "P")
  (when (looking-at org-babel-src-block-regexp) (forward-char 1))
  (re-search-forward org-babel-src-block-regexp nil nil (or arg 1))
  (goto-char (match-beginning 0)) (org-show-context))
</t>
<t tx="ekr.20100929212226.14385">
;;;###autoload
(defun org-babel-previous-src-block (&amp;optional arg)
  "Jump to the previous source block.
With optional prefix argument ARG, jump backward ARG many source blocks."
  (interactive "P")
  (re-search-backward org-babel-src-block-regexp nil nil (or arg 1))
  (goto-char (match-beginning 0)) (org-show-context))
</t>
<t tx="ekr.20100929212226.14386">
(defvar org-babel-lob-one-liner-regexp)
(defun org-babel-where-is-src-block-result (&amp;optional insert info hash indent)
  "Find where the current source block results begin.
Return the point at the beginning of the result of the current
source block.  Specifically at the beginning of the results line.
If no result exists for this block then create a results line
following the source block."
  (save-excursion
    (let* ((on-lob-line (progn (beginning-of-line 1)
                   (looking-at org-babel-lob-one-liner-regexp)))
       (name (if on-lob-line
             (nth 0 (org-babel-lob-get-info))
           (nth 4 (or info (org-babel-get-src-block-info)))))
       (head (unless on-lob-line (org-babel-where-is-src-block-head)))
       found beg end)
      (when head (goto-char head))
      (setq
       found ;; was there a result (before we potentially insert one)
       (or
    (and
     ;; named results:
     ;; - return t if it is found, else return nil
     ;; - if it does not need to be rebuilt, then don't set end
     ;; - if it does need to be rebuilt then do set end
     name (setq beg (org-babel-find-named-result name))
     (prog1 beg
       (when (and hash (not (string= hash (match-string 3))))
         (goto-char beg) (setq end beg) ;; beginning of result
         (forward-line 1)
         (delete-region end (org-babel-result-end)) nil)))
    (and
     ;; unnamed results:
     ;; - return t if it is found, else return nil
     ;; - if it is found, and the hash doesn't match, delete and set end
     (or on-lob-line (re-search-forward "^[ \t]*#\\+end_src" nil t))
     (progn (end-of-line 1)
        (if (eobp) (insert "\n") (forward-char 1))
        (setq end (point))
        (or (and (not name)
             (progn ;; unnamed results line already exists
               (re-search-forward "[^ \f\t\n\r\v]" nil t)
               (beginning-of-line 1)
               (looking-at
                (concat org-babel-result-regexp "\n")))
             (prog1 (point)
               ;; must remove and rebuild if hash!=old-hash
               (if (and hash (not (string= hash (match-string 3))))
                   (prog1 nil
                 (forward-line 1)
                 (delete-region
                  end (org-babel-result-end)))
                 (setq end nil)))))))))
      (if (and insert end)
      (progn
        (goto-char end)
        (unless beg
          (if (looking-at "[\n\r]") (forward-char 1) (insert "\n")))
        (insert (concat
             (if indent
             (mapconcat
              (lambda (el) " ")
              (number-sequence 1 indent) "")
               "")
             "#+results"
             (when hash (concat "["hash"]"))
             ":"
             (when name (concat " " name)) "\n"))
        (unless beg (insert "\n") (backward-char))
        (beginning-of-line 0)
        (if hash (org-babel-hide-hash))
        (point))
    found))))
</t>
<t tx="ekr.20100929212226.14387">
(defvar org-block-regexp)
(defun org-babel-read-result ()
  "Read the result at `point' into emacs-lisp."
  (let ((case-fold-search t) result-string)
    (cond
     ((org-at-table-p) (org-babel-read-table))
     ((looking-at org-bracket-link-regexp) (org-babel-read-link))
     ((looking-at org-block-regexp) (org-babel-trim (match-string 4)))
     ((looking-at "^[ \t]*: ")
      (setq result-string
        (org-babel-trim
         (mapconcat (lambda (line)
                          (if (and (&gt; (length line) 1)
                                   (string-match "^[ \t]*: \\(.+\\)" line))
                              (match-string 1 line)
                            line))
            (split-string
             (buffer-substring
                          (point) (org-babel-result-end)) "[\r\n]+")
            "\n")))
      (or (org-babel-number-p result-string) result-string))
     ((looking-at org-babel-result-regexp)
      (save-excursion (forward-line 1) (org-babel-read-result))))))
</t>
<t tx="ekr.20100929212226.14388">
(defun org-babel-read-table ()
  "Read the table at `point' into emacs-lisp."
  (mapcar (lambda (row)
            (if (and (symbolp row) (equal row 'hline)) row
              (mapcar #'org-babel-read row)))
          (org-table-to-lisp)))
</t>
<t tx="ekr.20100929212226.14389">
(defvar org-link-types-re)
(defun org-babel-read-link ()
  "Read the link at `point' into emacs-lisp.
If the path of the link is a file path it is expanded using
`expand-file-name'."
  (let* ((case-fold-search t)
         (raw (and (looking-at org-bracket-link-regexp)
                   (org-babel-clean-text-properties (match-string 1))))
         (type (and (string-match org-link-types-re raw)
                    (match-string 1 raw))))
    (cond
     ((not type) (expand-file-name raw))
     ((string= type "file")
      (and (string-match "file\\(.*\\):\\(.+\\)" raw)
           (expand-file-name (match-string 2 raw))))
     (t raw))))
</t>
<t tx="ekr.20100929212226.14390">
(defun org-babel-insert-result
  (result &amp;optional result-params info hash indent lang)
  "Insert RESULT into the current buffer.
By default RESULT is inserted after the end of the
current source block.  With optional argument RESULT-PARAMS
controls insertion of results in the org-mode file.
RESULT-PARAMS can take the following values...

replace - (default option) insert results after the source block
          replacing any previously inserted results

silent -- no results are inserted

file ---- the results are interpreted as a file path, and are
          inserted into the buffer using the Org-mode file syntax

raw ----- results are added directly to the org-mode file.  This
          is a good option if you code block will output org-mode
          formatted text.

org ----- this is the same as the 'raw' option

html ---- results are added inside of a #+BEGIN_HTML block.  This
          is a good option if you code block will output html
          formatted text.

latex --- results are added inside of a #+BEGIN_LATEX block.
          This is a good option if you code block will output
          latex formatted text.

code ---- the results are extracted in the syntax of the source
          code of the language being evaluated and are added
          inside of a #+BEGIN_SRC block with the source-code
          language set appropriately.  Note this relies on the
          optional LANG argument."
  (if (stringp result)
      (progn
        (setq result (org-babel-clean-text-properties result))
        (when (member "file" result-params)
          (setq result (org-babel-result-to-file result))))
    (unless (listp result) (setq result (format "%S" result))))
  (if (= (length result) 0)
      (if (member "value" result-params)
      (message "No result returned by source block")
    (message "Source block produced no output"))
    (if (and result-params (member "silent" result-params))
        (progn
      (message (replace-regexp-in-string "%" "%%" (format "%S" result)))
      result)
      (when (and (stringp result) ;; ensure results end in a newline
                 (not (or (string-equal (substring result -1) "\n")
                          (string-equal (substring result -1) "\r"))))
        (setq result (concat result "\n")))
      (save-excursion
    (let ((existing-result (org-babel-where-is-src-block-result
                t info hash indent))
          (results-switches
               (cdr (assoc :results_switches (nth 2 info))))
          beg end)
      (when existing-result
        (goto-char existing-result)
        (save-excursion
          (re-search-forward "#" nil t)
          (setq indent (- (current-column) 1)))
        (forward-line 1)
        (setq beg (point))
        (cond
         ((member "replace" result-params)
          (delete-region (point) (org-babel-result-end)))
         ((member "append" result-params)
          (goto-char (org-babel-result-end)) (setq beg (point)))
         ((member "prepend" result-params) ;; already there
          )))
      (setq results-switches
                (if results-switches (concat " " results-switches) ""))
      (cond
       ;; assume the result is a table if it's not a string
       ((not (stringp result))
        (insert (concat (orgtbl-to-orgtbl
                 (if (or (eq 'hline (car result))
                     (and (listp (car result))
                      (listp (cdr (car result)))))
                 result (list result))
                 '(:fmt (lambda (cell) (format "%s" cell)))) "\n"))
        (goto-char beg) (when (org-at-table-p) (org-table-align)))
       ((member "file" result-params)
        (insert result))
       ((member "html" result-params)
        (insert (format "#+BEGIN_HTML%s\n%s#+END_HTML\n"
                            results-switches result)))
       ((member "latex" result-params)
        (insert (format "#+BEGIN_LaTeX%s\n%s#+END_LaTeX\n"
                            results-switches result)))
       ((member "code" result-params)
        (insert (format "#+BEGIN_SRC %s%s\n%s#+END_SRC\n"
                            (or lang "none") results-switches result)))
       ((or (member "raw" result-params) (member "org" result-params))
        (save-excursion (insert result)) (if (org-at-table-p) (org-cycle)))
       (t
        (org-babel-examplize-region
         (point) (progn (insert result) (point)) results-switches)))
      ;; possibly indent the results to match the #+results line
      (setq end (if (listp result) (org-table-end) (point)))
      (when (and indent (&gt; indent 0)
             ;; in this case `table-align' does the work for us
             (not (and (listp result)
                   (member "append" result-params))))
        (indent-rigidly beg end indent))))
      (message "finished"))))
</t>
<t tx="ekr.20100929212226.14391">
(defun org-babel-remove-result (&amp;optional info)
  "Remove the result of the current source block."
  (interactive)
  (let ((location (org-babel-where-is-src-block-result nil info)) start)
    (when location
      (save-excursion
        (goto-char location) (setq start (point)) (forward-line 1)
        (delete-region start (org-babel-result-end))))))
</t>
<t tx="ekr.20100929212226.14392">
(defun org-babel-result-end ()
  "Return the point at the end of the current set of results"
  (save-excursion
    (if (org-at-table-p)
        (progn (goto-char (org-table-end)) (point))
      (let ((case-fold-search t))
        (cond
         ((looking-at "[ \t]*#\\+begin_latex")
          (re-search-forward "[ \t]*#\\+end_latex" nil t)
          (forward-line 1))
         ((looking-at "[ \t]*#\\+begin_html")
          (re-search-forward "[ \t]*#\\+end_html" nil t)
          (forward-line 1))
         ((looking-at "[ \t]*#\\+begin_example")
          (re-search-forward "[ \t]*#\\+end_example" nil t)
          (forward-line 1))
         ((looking-at "[ \t]*#\\+begin_src")
          (re-search-forward "[ \t]*#\\+end_src" nil t)
          (forward-line 1))
         (t (progn (while (looking-at "[ \t]*\\(: \\|\\[\\[\\)")
                     (forward-line 1))))))
      (point))))
</t>
<t tx="ekr.20100929212226.14393">
(defun org-babel-result-to-file (result)
  "Convert RESULT into an `org-mode' link.
If the `default-directory' is different from the containing
file's directory then expand relative links."
  (format
   "[[file:%s]]"
   (if (and default-directory
            buffer-file-name
            (not (string= (expand-file-name default-directory)
                          (expand-file-name
                           (file-name-directory buffer-file-name)))))
       (expand-file-name result default-directory)
     result)))
</t>
<t tx="ekr.20100929212226.14394">
(defun org-babel-examplize-region (beg end &amp;optional results-switches)
  "Comment out region using the ': ' org example quote."
  (interactive "*r")
  (let ((size (count-lines beg end)))
    (save-excursion
      (cond ((= size 0)
         (error (concat "This should be impossible:"
                            "a newline was appended to result if missing")))
        ((&lt; size org-babel-min-lines-for-block-output)
         (goto-char beg)
         (dotimes (n size)
           (beginning-of-line 1) (insert ": ") (forward-line 1)))
        (t
         (goto-char beg)
         (insert (if results-switches
                         (format "#+begin_example%s\n" results-switches)
                       "#+begin_example\n"))
         (forward-char (- end beg))
         (insert "#+end_example\n"))))))
</t>
<t tx="ekr.20100929212226.14395">
(defun org-babel-merge-params (&amp;rest plists)
  "Combine all parameter association lists in PLISTS.
Later elements of PLISTS override the values of previous element.
This takes into account some special considerations for certain
parameters when merging lists."
  (let ((results-exclusive-groups
     '(("file" "vector" "table" "scalar" "raw" "org"
            "html" "latex" "code" "pp")
       ("replace" "silent" "append" "prepend")
       ("output" "value")))
    (exports-exclusive-groups
     '(("code" "results" "both" "none")))
    params results exports tangle noweb cache vars var ref shebang comments)
    (flet ((e-merge (exclusive-groups &amp;rest result-params)
             ;; maintain exclusivity of mutually exclusive parameters
             (let (output)
               (mapc (lambda (new-params)
                       (mapc (lambda (new-param)
                               (mapc (lambda (exclusive-group)
                                       (when (member new-param exclusive-group)
                                         (mapcar (lambda (excluded-param)
                                                   (setq output
                                                         (delete
                                                          excluded-param
                                                          output)))
                                                 exclusive-group)))
                                     exclusive-groups)
                               (setq output (org-uniquify
                                             (cons new-param output))))
                             new-params))
                     result-params)
               output)))
      (mapc (lambda (plist)
              (mapc (lambda (pair)
                      (case (car pair)
                        (:var
                         ;; we want only one specification per variable
                         (when (string-match
                                (concat "^\\([^= \f\t\n\r\v]+\\)[ \t]*="
                                        "[ \t]*\\([^\f\n\r\v]+\\)$") (cdr pair))
                           ;; TODO: When is this not true?
                           (setq var (intern (match-string 1 (cdr pair)))
                                 ref (match-string 2 (cdr pair))
                                 vars (cons (cons var ref)
                                            (assq-delete-all var vars)))))
                        (:results
                         (setq results
                   (e-merge results-exclusive-groups
                                        results (split-string (cdr pair)))))
            (:file
             (when (cdr pair)
               (setq results (e-merge results-exclusive-groups
                                                  results '("file")))
               (unless (or (member "both" exports)
                                       (member "none" exports)
                                       (member "code" exports))
                 (setq exports (e-merge exports-exclusive-groups
                                                    exports '("results"))))
               (setq params
                                 (cons pair
                                       (assq-delete-all (car pair) params)))))
                        (:exports
                         (setq exports
                               (e-merge exports-exclusive-groups
                                        exports (split-string (cdr pair)))))
                        (:tangle ;; take the latest -- always overwrite
                         (setq tangle (or (list (cdr pair)) tangle)))
                        (:noweb
                         (setq noweb
                               (e-merge '(("yes" "no")) noweb
                                        (split-string (or (cdr pair) "")))))
                        (:cache
                         (setq cache
                               (e-merge '(("yes" "no")) cache
                                        (split-string (or (cdr pair) "")))))
                        (:shebang ;; take the latest -- always overwrite
                         (setq shebang (or (list (cdr pair)) shebang)))
                        (:comments
                         (setq comments
                               (e-merge '(("yes" "no")) comments
                                        (split-string (or (cdr pair) "")))))
                        (t ;; replace: this covers e.g. :session
                         (setq params
                               (cons pair
                                     (assq-delete-all (car pair) params))))))
                    plist))
            plists))
    (setq vars (mapcar (lambda (pair) (format "%s=%s" (car pair) (cdr pair))) vars))
    (while vars (setq params (cons (cons :var (pop vars)) params)))
    (cons (cons :comments (mapconcat 'identity comments " "))
          (cons (cons :shebang (mapconcat 'identity shebang " "))
                (cons (cons :cache (mapconcat 'identity cache " "))
                      (cons (cons :noweb (mapconcat 'identity noweb " "))
                            (cons (cons :tangle (mapconcat 'identity tangle " "))
                                  (cons (cons :exports
                                              (mapconcat 'identity exports " "))
                                        (cons
                                         (cons :results
                                               (mapconcat 'identity results " "))
                                         params)))))))))
</t>
<t tx="ekr.20100929212226.14396">
(defun org-babel-expand-noweb-references (&amp;optional info parent-buffer)
  "Expand Noweb references in the body of the current source code block.

For example the following reference would be replaced with the
body of the source-code block named 'example-block'.

@verbatim
&lt;&lt;example-block&gt;&gt;

@verbatim
Note that any text preceding the &lt;&lt;foo&gt;&gt; construct on a line will
be interposed between the lines of the replacement text.  So for
@verbatim
example if &lt;&lt;foo&gt;&gt; is placed behind a comment, then the entire
replacement text will also be commented.

This function must be called from inside of the buffer containing
the source-code block which holds BODY.

In addition the following syntax can be used to insert the
results of evaluating the source-code block named 'example-block'.

@verbatim
&lt;&lt;example-block()&gt;&gt;

Any optional arguments can be passed to example-block by placing
the arguments inside the parenthesis following the convention
defined by `org-babel-lob'.  For example

@verbatim
&lt;&lt;example-block(a=9)&gt;&gt;

would set the value of argument \"a\" equal to \"9\".  Note that
these arguments are not evaluated in the current source-code
block but are passed literally to the \"example-block\"."
  (let* ((parent-buffer (or parent-buffer (current-buffer)))
         (info (or info (org-babel-get-src-block-info)))
         (lang (nth 0 info))
         (body (nth 1 info))
         (new-body "") index source-name evaluate prefix)
    (flet ((nb-add (text)
                   (setq new-body (concat new-body text))))
      (with-temp-buffer
        (insert body) (goto-char (point-min))
        (setq index (point))
@verbatim
        (while (and (re-search-forward "&lt;&lt;\\(.+?\\)&gt;&gt;" nil t))
          (save-match-data (setf source-name (match-string 1)))
          (save-match-data (setq evaluate (string-match "\(.*\)" source-name)))
          (save-match-data
            (setq prefix
                  (buffer-substring (match-beginning 0)
                                    (save-excursion
                                      (beginning-of-line 1) (point)))))
          ;; add interval to new-body (removing noweb reference)
          (goto-char (match-beginning 0))
          (nb-add (buffer-substring index (point)))
          (goto-char (match-end 0))
          (setq index (point))
          (nb-add (with-current-buffer parent-buffer
            (mapconcat ;; interpose PREFIX between every line
                     #'identity
                     (split-string
                      (if evaluate
                          (let ((raw (org-babel-ref-resolve-reference
                                      source-name nil)))
                            (if (stringp raw) raw (format "%S" raw)))
            (save-restriction
              (widen)
              (let ((point (org-babel-find-named-block
                    source-name)))
                (if point
                (save-excursion
                  (goto-char point)
                  (org-babel-trim
                   (org-babel-expand-noweb-references
                    (org-babel-get-src-block-info))))
                  ;; optionally raise an error if named
                  ;; source-block doesn't exist
                  (if (member lang org-babel-noweb-error-langs)
                  (error "%s"
                     (concat
@verbatim
                      "&lt;&lt;" source-name "&gt;&gt; "
                      "could not be resolved (see "
                      "`org-babel-noweb-error-langs')"))
                "")))))
              "[\n\r]") (concat "\n" prefix)))))
        (nb-add (buffer-substring index (point-max)))))
    new-body))
</t>
<t tx="ekr.20100929212226.14397">
(defun org-babel-clean-text-properties (text)
  "Strip all properties from text return."
  (when text
    (set-text-properties 0 (length text) nil text) text))
</t>
<t tx="ekr.20100929212226.14398">
(defun org-babel-strip-protective-commas (body)
  "Strip protective commas from bodies of source blocks."
  (replace-regexp-in-string "^,#" "#" body))
</t>
<t tx="ekr.20100929212226.14399">
(defun org-babel-read (cell)
  "Convert the string value of CELL to a number if appropriate.
Otherwise if cell looks like lisp (meaning it starts with a
\"(\" or a \"'\") then read it as lisp, otherwise return it
unmodified as a string.

This is taken almost directly from `org-read-prop'."
  (if (and (stringp cell) (not (equal cell "")))
      (or (org-babel-number-p cell)
          (if (or (equal "(" (substring cell 0 1))
                  (equal "'" (substring cell 0 1))
                  (equal "`" (substring cell 0 1)))
              (eval (read cell))
            (progn (set-text-properties 0 (length cell) nil cell) cell)))
    cell))
</t>
<t tx="ekr.20100929212226.14400">
(defun org-babel-number-p (string)
  "Return t if STRING represents a number."
  (if (and (string-match "^-?[0-9]*\\.?[0-9]*$" string)
           (= (length (substring string (match-beginning 0)
                 (match-end 0)))
          (length string)))
      (string-to-number string)))
</t>
<t tx="ekr.20100929212226.14401">
(defun org-babel-import-elisp-from-file (file-name)
  "Read the results located at FILE-NAME into an elisp table.
If the table is trivial, then return it as a scalar."
  (let (result)
    (save-window-excursion
      (with-temp-buffer
    (condition-case nil
        (progn
          (org-table-import file-name nil)
          (delete-file file-name)
          (setq result (mapcar (lambda (row)
                     (mapcar #'org-babel-string-read row))
                   (org-table-to-lisp))))
      (error nil)))
      (if (null (cdr result)) ;; if result is trivial vector, then scalarize it
      (if (consp (car result))
          (if (null (cdr (car result)))
          (caar result)
        result)
        (car result))
    result))))
</t>
<t tx="ekr.20100929212226.14402">
(defun org-babel-string-read (cell)
  "Strip nested \"s from around strings."
  (org-babel-read (or (and (stringp cell)
                           (string-match "\\\"\\(.+\\)\\\"" cell)
                           (match-string 1 cell))
                      cell)))
</t>
<t tx="ekr.20100929212226.14403">
(defun org-babel-reverse-string (string)
  "Return the reverse of STRING."
  (apply 'string (reverse (string-to-list string))))
</t>
<t tx="ekr.20100929212226.14404">
(defun org-babel-chomp (string &amp;optional regexp)
  "Strip trailing spaces and carriage returns from STRING.
Default regexp used is \"[ \f\t\n\r\v]\" but can be
overwritten by specifying a regexp as a second argument."
  (let ((regexp (or regexp "[ \f\t\n\r\v]")))
    (while (and (&gt; (length string) 0)
                (string-match regexp (substring string -1)))
      (setq string (substring string 0 -1)))
    string))
</t>
<t tx="ekr.20100929212226.14405">
(defun org-babel-trim (string &amp;optional regexp)
  "Strip leading and trailing spaces and carriage returns from STRING.
Like `org-babel-chomp' only it runs on both the front and back
of the string."
  (org-babel-chomp (org-babel-reverse-string
                    (org-babel-chomp (org-babel-reverse-string string) regexp))
                   regexp))
</t>
<t tx="ekr.20100929212226.14406">
(defvar org-babel-org-babel-call-process-region-original nil)
(defun org-babel-tramp-handle-call-process-region
  (start end program &amp;optional delete buffer display &amp;rest args)
  "Use tramp to handle call-process-region.
Fixes a bug in `tramp-handle-call-process-region'."
  (if (and (featurep 'tramp) (file-remote-p default-directory))
      (let ((tmpfile (tramp-compat-make-temp-file "")))
    (write-region start end tmpfile)
    (when delete (delete-region start end))
    (unwind-protect
        ;;  (apply 'call-process program tmpfile buffer display args)
            ;; bug in tramp
        (apply 'process-file program tmpfile buffer display args)
      (delete-file tmpfile)))
    ;; org-babel-call-process-region-original is the original emacs definition. It
    ;; is in scope from the let binding in org-babel-execute-src-block
    (apply org-babel-call-process-region-original
           start end program delete buffer display args)))
</t>
<t tx="ekr.20100929212226.14407">
(defun org-babel-maybe-remote-file (file)
  "Conditionally parse information on a remote connnection.
If FILE specifies a remove file, then parse the information on
the remote connection."
  (if (file-remote-p default-directory)
      (let* ((vec (tramp-dissect-file-name default-directory))
             (user (tramp-file-name-user vec))
             (host (tramp-file-name-host vec)))
        (concat "/" user (when user "@") host ":" file))
    file))
</t>
<t tx="ekr.20100929212226.14408"></t>
<t tx="ekr.20100929212226.14409"></t>
<t tx="ekr.20100929212226.14410">@language lisp
@tabwidth -4
@others

(provide 'org-bbdb)

;; arch-tag: 9e4f275d-d080-48c1-b040-62247f66b5c2

;;; org-bbdb.el ends here
</t>
<t tx="ekr.20100929212226.14411">;;; org-bbdb.el --- Support for links to BBDB entries from within Org-mode

;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Carsten Dominik &lt;carsten at orgmode dot org&gt;,
;;         Thomas Baumann &lt;thomas dot baumann at ch dot tum dot de&gt;
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;; This file implements links to BBDB database entries from within Org-mode.
;; Org-mode loads this module by default - if this is not what you want,
;; configure the variable `org-modules'.

;; It also implements an interface (based on Ivar Rummelhoff's
;; bbdb-anniv.el) for those org-mode users, who do not use the diary
;; but who do want to include the anniversaries stored in the BBDB
;; into the org-agenda.  If you already include the `diary' into the
;; agenda, you might want to prefer to include the anniversaries in
;; the diary using bbdb-anniv.el.
;;
;; Put the following in /somewhere/at/home/diary.org and make sure
;; that this file is in `org-agenda-files`
;;
;; %%(org-bbdb-anniversaries)
;;
;; For example my diary.org looks like:
;; * Anniversaries
;; #+CATEGORY: Anniv
;; %%(org-bbdb-anniversaries)
;;
;;
;; To add an anniversary to a BBDB record, press `C-o' in the record.
;; You will be prompted for the field name, in this case it must be
;; "anniversary".  If this is the first time you are using this field,
;; you need to confirm that it should be created.
;;
;; The format of an anniversary field stored in BBDB is the following
;; (items in {} are optional):
;;
;;     YYYY-MM-DD{ CLASS-OR-FORMAT-STRING}
;;     {\nYYYY-MM-DD CLASS-OR-FORMAT-STRING}...
;;
;; CLASS-OR-FORMAT-STRING is one of two things:
;;
;;  - an identifier for a class of anniversaries (eg. birthday or
;;    wedding) from `org-bbdb-anniversary-format-alist' which then
;;    defines the format string for this class
;;  - the (format) string displayed in the diary.
;;
;; You can enter multiple anniversaries for a single BBDB record by
;; separating them with a newline character.  At the BBDB prompt for
;; the field value, type `C-q C-j' to enter a newline between two
;; anniversaries.
;;
;; If you omit the CLASS-OR-FORMAT-STRING entirely, it defaults to the
;; value of `org-bbdb-default-anniversary-format' ("birthday" by
;; default).
;;
;; The substitutions in the format string are (in order):
;;  - the name of the record containing this anniversary
;;  - the number of years
;;  - an ordinal suffix (st, nd, rd, th) for the year
;;
;; See the documentation of `org-bbdb-anniversary-format-alist' for
;; further options.
;;
;; Example
;;
;;       1973-06-22
;;       20??-??-?? wedding
;;       1998-03-12 %s created bbdb-anniv.el %d years ago
;;
;; From Org's agenda, you can use `C-c C-o' to jump to the BBDB
;; link from which the entry at point originates.
;;
;;; Code:

(require 'org)
(eval-when-compile
  (require 'cl))

;; Declare external functions and variables

(declare-function bbdb "ext:bbdb-com" (string elidep))
(declare-function bbdb-company "ext:bbdb-com" (string elidep))
(declare-function bbdb-current-record "ext:bbdb-com"
          (&amp;optional planning-on-modifying))
(declare-function bbdb-name "ext:bbdb-com" (string elidep))
(declare-function bbdb-completing-read-record "ext:bbdb-com"
          (prompt &amp;optional omit-records))
(declare-function bbdb-record-getprop "ext:bbdb" (record property))
(declare-function bbdb-record-name "ext:bbdb" (record))
(declare-function bbdb-records "ext:bbdb"
          (&amp;optional dont-check-disk already-in-db-buffer))
(declare-function bbdb-split "ext:bbdb" (string separators))
(declare-function bbdb-string-trim "ext:bbdb" (string))

(declare-function calendar-leap-year-p "calendar" (year))
(declare-function diary-ordinal-suffix "diary-lib" (n))

(defvar date)   ;; dynamically scoped from Org

;; Customization

(defgroup org-bbdb-anniversaries nil
  "Customizations for including anniversaries from BBDB into Agenda."
  :group 'org-bbdb)

(defcustom org-bbdb-default-anniversary-format "birthday"
  "Default anniversary class."
  :type  'string
  :group 'org-bbdb-anniversaries
  :require 'bbdb)

(defcustom org-bbdb-anniversary-format-alist
  '(("birthday" lambda
     (name years suffix)
     (concat "Birthday: [[bbdb:" name "][" name " ("
         (number-to-string years)
         suffix ")]]"))
    ("wedding" lambda
     (name years suffix)
     (concat "[[bbdb:" name "][" name "'s "
         (number-to-string years)
         suffix " wedding anniversary]]")))
  "How different types of anniversaries should be formatted.
An alist of elements (STRING . FORMAT) where STRING is the name of an
anniversary class and format is either:
1) A format string with the following substitutions (in order):
    * the name of the record containing this anniversary
    * the number of years
    * an ordinal suffix (st, nd, rd, th) for the year

2) A function to be called with three arguments: NAME YEARS SUFFIX
   (string int string) returning a string for the diary or nil.

3) An Emacs Lisp form that should evaluate to a string (or nil) in the
   scope of variables NAME, YEARS and SUFFIX (among others)."
  :type 'sexp
  :group 'org-bbdb-anniversaries
  :require 'bbdb)

(defcustom org-bbdb-anniversary-field 'anniversary
  "The BBDB field which contains anniversaries.
The anniversaries are stored in the following format

YYYY-MM-DD Class-or-Format-String

where class is one of the customized classes for anniversaries;
birthday and wedding are predefined.  Format-String can take three
substitutions 1) the name of the record containing this
anniversary, 2) the number of years, and 3) an ordinal suffix for
the year.

Multiple anniversaries can be separated by \\n."
  :type    'symbol
  :group   'org-bbdb-anniversaries
  :require 'bbdb)

(defcustom org-bbdb-extract-date-fun 'org-bbdb-anniv-extract-date
  "How to retrieve `month date year' from the anniversary field.

Customize if you have already filled your BBDB with dates
different from YYYY-MM-DD.  The function must return a list (month
date year)."
  :type 'function
  :group 'org-bbdb-anniversaries
  :require 'bbdb)


;; Install the link type
(org-add-link-type "bbdb" 'org-bbdb-open 'org-bbdb-export)
(add-hook 'org-store-link-functions 'org-bbdb-store-link)

</t>
<t tx="ekr.20100929212226.14412">;; Implementation
(defun org-bbdb-store-link ()
  "Store a link to a BBDB database entry."
  (when (eq major-mode 'bbdb-mode)
    ;; This is BBDB, we make this link!
    (let* ((name (bbdb-record-name (bbdb-current-record)))
       (company (bbdb-record-getprop (bbdb-current-record) 'company))
       (link (org-make-link "bbdb:" name)))
      (org-store-link-props :type "bbdb" :name name :company company
                :link link :description name)
      link)))
</t>
<t tx="ekr.20100929212226.14413">
(defun org-bbdb-export (path desc format)
  "Create the export version of a BBDB link specified by PATH or DESC.
If exporting to either HTML or LaTeX FORMAT the link will be
italicized, in all other cases it is left unchanged."
  (cond
   ((eq format 'html) (format "&lt;i&gt;%s&lt;/i&gt;" (or desc path)))
   ((eq format 'latex) (format "\\textit{%s}" (or desc path)))
   (t (or desc path))))
</t>
<t tx="ekr.20100929212226.14414">
(defun org-bbdb-open (name)
  "Follow a BBDB link to NAME."
  (require 'bbdb)
  (let ((inhibit-redisplay (not debug-on-error))
    (bbdb-electric-p nil))
    (catch 'exit
      ;; Exact match on name
      (bbdb-name (concat "\\`" name "\\'") nil)
      (if (&lt; 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
      ;; Exact match on name
      (bbdb-company (concat "\\`" name "\\'") nil)
      (if (&lt; 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
      ;; Partial match on name
      (bbdb-name name nil)
      (if (&lt; 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
      ;; Partial match on company
      (bbdb-company name nil)
      (if (&lt; 0 (buffer-size (get-buffer "*BBDB*"))) (throw 'exit nil))
      ;; General match including network address and notes
      (bbdb name nil)
      (when (= 0 (buffer-size (get-buffer "*BBDB*")))
    (delete-window (get-buffer-window "*BBDB*"))
    (error "No matching BBDB record")))))
</t>
<t tx="ekr.20100929212226.14415">
(defun org-bbdb-anniv-extract-date (time-str)
  "Convert YYYY-MM-DD to (month date year).
Argument TIME-STR is the value retrieved from BBDB."
  (multiple-value-bind (y m d) (values-list (bbdb-split time-str "-"))
    (list (string-to-number m)
      (string-to-number d)
      (string-to-number y))))
</t>
<t tx="ekr.20100929212226.14416">
(defun org-bbdb-anniv-split (str)
  "Split multiple entries in the BBDB anniversary field.
Argument STR is the anniversary field in BBDB."
  (let ((pos (string-match "[ \t]" str)))
    (if pos (list (substring str 0 pos)
          (bbdb-string-trim (substring str pos)))
      (list str nil))))
</t>
<t tx="ekr.20100929212226.14417">
(defvar org-bbdb-anniv-hash nil
  "A hash holding anniversaries extracted from BBDB.
The hash table is created on first use.")

(defvar org-bbdb-updated-p t
  "This is non-nil if BBDB has been updated since we last built the hash.")

(defun org-bbdb-make-anniv-hash ()
  "Create a hash with anniversaries extracted from BBDB, for fast access.
The anniversaries are assumed to be stored `org-bbdb-anniversary-field'."

  (let (split tmp annivs)
    (clrhash org-bbdb-anniv-hash)
    (dolist (rec (bbdb-records))
      (when (setq annivs (bbdb-record-getprop
                          rec org-bbdb-anniversary-field))
        (setq annivs (bbdb-split annivs "\n"))
        (while annivs
          (setq split (org-bbdb-anniv-split (pop annivs)))
          (multiple-value-bind (m d y)
              (values-list (funcall org-bbdb-extract-date-fun (car split)))
            (setq tmp (gethash (list m d) org-bbdb-anniv-hash))
            (puthash (list m d) (cons (list y
                                            (bbdb-record-name rec)
                                            (cadr split))
                                      tmp)
                     org-bbdb-anniv-hash))))))
  (setq org-bbdb-updated-p nil))
</t>
<t tx="ekr.20100929212226.14418">
(defun org-bbdb-updated (rec)
  "Record the fact that BBDB has been updated.
This is used by Org to re-create the anniversary hash table."
  (setq org-bbdb-updated-p t))
</t>
<t tx="ekr.20100929212226.14419">
(add-hook 'bbdb-after-change-hook 'org-bbdb-updated)

;;;###autoload
(defun org-bbdb-anniversaries()
  "Extract anniversaries from BBDB for display in the agenda."
  (require 'bbdb)
  (require 'diary-lib)
  (unless (hash-table-p org-bbdb-anniv-hash)
    (setq org-bbdb-anniv-hash
      (make-hash-table :test 'equal :size 366)))

  (when (or org-bbdb-updated-p
            (= 0 (hash-table-count org-bbdb-anniv-hash)))
    (org-bbdb-make-anniv-hash))

  (let* ((m (car date))    ; month
         (d (nth 1 date))  ; day
         (y (nth 2 date))  ; year
         (annivs (gethash (list m d) org-bbdb-anniv-hash))
         (text ())
         rec recs)

    ;; we don't want to miss people born on Feb. 29th
    (when (and (= m 3) (= d 1)
               (not (null (gethash (list 2 29) org-bbdb-anniv-hash)))
               (not (calendar-leap-year-p y)))
      (setq recs (gethash (list 2 29) org-bbdb-anniv-hash))
      (while (setq rec (pop recs))
        (push rec annivs)))

    (when annivs
      (while (setq rec (pop annivs))
        (when rec
          (let* ((class (or (nth 2 rec)
                            org-bbdb-default-anniversary-format))
                 (form (or (cdr (assoc class
                                       org-bbdb-anniversary-format-alist))
                           class))  ; (as format string)
                 (name (nth 1 rec))
                 (years (- y (car rec)))
                 (suffix (diary-ordinal-suffix years))
                 (tmp (cond
                       ((functionp form)
                        (funcall form name years suffix))
                       ((listp form) (eval form))
                       (t (format form name years suffix)))))
        (org-add-props tmp nil 'org-bbdb-name name)
            (if text
                (setq text (append text (list tmp)))
              (setq text (list tmp)))))
        ))
    (when text
      (mapconcat 'identity text "; "))))
</t>
<t tx="ekr.20100929212226.14420">
(defun org-bbdb-complete-link ()
  "Read a bbdb link with name completion."
  (require 'bbdb-com)
  (concat "bbdb:"
      (bbdb-record-name (car (bbdb-completing-read-record "Name: ")))))
</t>
<t tx="ekr.20100929212226.14421">
(defun org-bbdb-anniv-export-ical ()
  "Extract anniversaries from BBDB and convert them to icalendar format."
  (require 'bbdb)
  (require 'diary-lib)
  (unless (hash-table-p org-bbdb-anniv-hash)
    (setq org-bbdb-anniv-hash
      (make-hash-table :test 'equal :size 366)))
  (when (or org-bbdb-updated-p
        (= 0 (hash-table-count org-bbdb-anniv-hash)))
    (org-bbdb-make-anniv-hash))
  (maphash 'org-bbdb-format-vevent org-bbdb-anniv-hash))
</t>
<t tx="ekr.20100929212226.14422">
(defun org-bbdb-format-vevent (key recs)
  (let (rec categ)
    (while (setq rec (pop recs))
      (setq categ (or (nth 2 rec) org-bbdb-default-anniversary-format))
      (princ (format "BEGIN:VEVENT
UID: ANNIV-%4i%02i%02i-%s
DTSTART:%4i%02i%02i
SUMMARY:%s
DESCRIPTION:%s
CATEGORIES:%s
RRULE:FREQ=YEARLY
END:VEVENT\n"
             (nth 0 rec) (nth 0 key) (nth 1 key)
             (mapconcat 'identity
                (org-split-string (nth 1 rec) "[^a-zA-Z0-90]+")
                "-")
             (nth 0 rec) (nth 0 key) (nth 1 key)
             (nth 1 rec)
             (concat (capitalize categ) " " (nth 1 rec))
             categ)))))
</t>
<t tx="ekr.20100929212226.14423">@language lisp
@tabwidth -4
@others

;; Finally add the link search function to the right hook.
(add-hook 'org-execute-file-search-functions 'org-execute-file-search-in-bibtex)

(provide 'org-bibtex)

;; arch-tag: 83987d5a-01b8-41c7-85bc-77700f1285f5

;;; org-bibtex.el ends here
</t>
<t tx="ekr.20100929212226.14424">;;; org-bibtex.el --- Org links to BibTeX entries
;;
;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;;
;; Author: Bastien Guerry &lt;bzg at altern dot org&gt;
;;         Carsten Dominik &lt;carsten dot dominik at gmail dot com&gt;
;; Keywords: org, wp, remember
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
;;
;;; Commentary:
;;
;; This file implements links to database entries in BibTeX files.
;; Instead of defining a special link prefix, it uses the normal file
;; links combined with a custom search mechanism to find entries
;; by reference key.  And it constructs a nice description tag for
;; the link that contains the author name, the year and a short title.
;;
;; It also stores detailed information about the entry so that
;; remember templates can access and enter this information easily.
;;
;; The available properties for each entry are listed here:
;;
;; :author        :publisher      :volume      :pages
;; :editor        :url            :number      :journal
;; :title         :year           :series      :address
;; :booktitle     :month          :annote      :abstract
;; :key           :btype
;;
;; Here is an example of a remember template that use some of this
;; information (:author :year :title :journal :pages):
;;
;; (setq org-remember-templates
;;   '((?b "* READ %?\n\n%a\n\n%:author (%:year): %:title\n   \
;;          In %:journal, %:pages.")))
;;
;; Let's say you want to remember this BibTeX entry:
;;
;; @Article{dolev83,
;;   author =        {Danny Dolev and Andrew C. Yao},
;;   title =         {On the security of public-key protocols},
;;   journal =       {IEEE Transaction on Information Theory},
;;   year =          1983,
;;   volume =        2,
;;   number =        29,
;;   pages =         {198--208},
;;   month =         {Mars}
;; }
;;
;; M-x `org-remember' on this entry will produce this buffer:
;;
;; =====================================================================
;; * READ &lt;== [point here]
;;
;; [[file:/file.bib::dolev83][Dolev &amp; Yao 1983: security of public key protocols]]
;;
;; Danny Dolev and Andrew C. Yao (1983): On the security of public-key protocols
;; In IEEE Transaction on Information Theory, 198--208.
;; =====================================================================
;;
;;; History:
;;
;; The link creation part has been part of Org-mode for a long time.
;;
;; Creating better remember template information was inspired by a request
;; of Austin Frank: http://article.gmane.org/gmane.emacs.orgmode/4112
;; and then implemented by Bastien Guerry.
;;
;; Org-mode loads this module by default - if this is not what you want,
;; configure the variable `org-modules'.

;;; Code:

(require 'org)

(defvar description nil) ; dynamically scoped from org.el

(declare-function bibtex-beginning-of-entry "bibtex" ())
(declare-function bibtex-generate-autokey "bibtex" ())
(declare-function bibtex-parse-entry "bibtex" (&amp;optional content))
(declare-function bibtex-url "bibtex" (&amp;optional pos no-browse))

(org-add-link-type "bibtex" 'org-bibtex-open)
(add-hook 'org-store-link-functions 'org-bibtex-store-link)

</t>
<t tx="ekr.20100929212226.14425">;; (defun org-bibtex-publish (path)
;;   "Build the description of the BibTeX entry for publishing."
;;   (let* ((search (when (string-match "::\\(.+\\)\\'" path)
;;             (match-string 1 path)))
;;   (path (substring path 0 (match-beginning 0)))
;;   key)
;;     (with-temp-buffer
;;       (org-open-file path t nil search)
;;       (setq key (org-create-file-search-functions)))
;;     (or description key)))

(defun org-bibtex-open (path)
  "Visit the bibliography entry on PATH."
  (let* ((search (when (string-match "::\\(.+\\)\\'" path)
           (match-string 1 path)))
     (path (substring path 0 (match-beginning 0))))
    (org-open-file path t nil search)))
</t>
<t tx="ekr.20100929212226.14426">
(defun org-bibtex-store-link ()
  "Store a link to a BibTeX entry."
  (when (eq major-mode 'bibtex-mode)
    (let* ((search (org-create-file-search-in-bibtex))
       (link (concat "file:" (abbreviate-file-name buffer-file-name)
             "::" search))
       (entry (mapcar ; repair strings enclosed in "..." or {...}
           (lambda(c)
             (if (string-match
              "^\\(?:{\\|\"\\)\\(.*\\)\\(?:}\\|\"\\)$" (cdr c))
             (cons (car c) (match-string 1 (cdr c))) c))
           (save-excursion
             (bibtex-beginning-of-entry)
             (bibtex-parse-entry)))))
      (org-store-link-props
       :key (cdr (assoc "=key=" entry))
       :author (or (cdr (assoc "author" entry)) "[no author]")
       :editor (or (cdr (assoc "editor" entry)) "[no editor]")
       :title (or (cdr (assoc "title" entry)) "[no title]")
       :booktitle (or (cdr (assoc "booktitle" entry)) "[no booktitle]")
       :journal (or (cdr (assoc "journal" entry)) "[no journal]")
       :publisher (or (cdr (assoc "publisher" entry)) "[no publisher]")
       :pages (or (cdr (assoc "pages" entry)) "[no pages]")
       :url (or (cdr (assoc "url" entry)) "[no url]")
       :year (or (cdr (assoc "year" entry)) "[no year]")
       :month (or (cdr (assoc "month" entry)) "[no month]")
       :address (or (cdr (assoc "address" entry)) "[no address]")
       :volume (or (cdr (assoc "volume" entry)) "[no volume]")
       :number (or (cdr (assoc "number" entry)) "[no number]")
       :annote (or (cdr (assoc "annote" entry)) "[no annotation]")
       :series (or (cdr (assoc "series" entry)) "[no series]")
       :abstract (or (cdr (assoc "abstract" entry)) "[no abstract]")
       :btype (or (cdr (assoc "=type=" entry)) "[no type]")
       :type "bibtex"
       :link link
       :description description))))
</t>
<t tx="ekr.20100929212226.14427">
(defun org-create-file-search-in-bibtex ()
  "Create the search string and description for a BibTeX database entry."
  ;; Make a good description for this entry, using names, year and the title
  ;; Put it into the `description' variable which is dynamically scoped.
  (let ((bibtex-autokey-names 1)
    (bibtex-autokey-names-stretch 1)
    (bibtex-autokey-name-case-convert-function 'identity)
    (bibtex-autokey-name-separator " &amp; ")
    (bibtex-autokey-additional-names " et al.")
    (bibtex-autokey-year-length 4)
    (bibtex-autokey-name-year-separator " ")
    (bibtex-autokey-titlewords 3)
    (bibtex-autokey-titleword-separator " ")
    (bibtex-autokey-titleword-case-convert-function 'identity)
    (bibtex-autokey-titleword-length 'infty)
    (bibtex-autokey-year-title-separator ": "))
    (setq description (bibtex-generate-autokey)))
  ;; Now parse the entry, get the key and return it.
  (save-excursion
    (bibtex-beginning-of-entry)
    (cdr (assoc "=key=" (bibtex-parse-entry)))))
</t>
<t tx="ekr.20100929212226.14428">
(defun org-execute-file-search-in-bibtex (s)
  "Find the link search string S as a key for a database entry."
  (when (eq major-mode 'bibtex-mode)
    ;; Yes, we want to do the search in this file.
    ;; We construct a regexp that searches for "@entrytype{" followed by the key
    (goto-char (point-min))
    (and (re-search-forward (concat "@[a-zA-Z]+[ \t\n]*{[ \t\n]*"
                    (regexp-quote s) "[ \t\n]*,") nil t)
     (goto-char (match-beginning 0)))
    (if (and (match-beginning 0) (equal current-prefix-arg '(16)))
    ;; Use double prefix to indicate that any web link should be browsed
    (let ((b (current-buffer)) (p (point)))
      ;; Restore the window configuration because we just use the web link
      (set-window-configuration org-window-config-before-follow-link)
      (with-current-buffer b
        (goto-char p)
        (bibtex-url)))
      (recenter 0))  ; Move entry start to beginning of window
  ;; return t to indicate that the search is done.
    t))
</t>
<t tx="ekr.20100929212226.14429">@language lisp
@tabwidth -4
@others

(provide 'org-capture)

;; arch-tag: 986bf41b-8ada-4e28-bf20-e8388a7205a0

;;; org-capture.el ends here


</t>
<t tx="ekr.20100929212226.14430">;;; org-capture.el --- Fast note taking in Org-mode

;; Copyright (C) 2010  Free Software Foundation, Inc.

;; Author: Carsten Dominik &lt;carsten at orgmode dot org&gt;
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;; This file contains an alternative implementation of the same functionality
;; that is also provided by org-remember.el.  The implementation is more
;; streamlined, can produce more target types (e.g. plain list items or
;; table lines).  Also, it does not use a temporary buffer for editing
;; the captured entry - instead it uses an indirect buffer that visits
;; the new entry already in the target buffer (this was an idea by Samuel
;; Wales).  John Wiegley's excellent `remember.el' is not needed for this
;; implementation, even though we borrow heavily from its ideas.

;; This implementation heavily draws on ideas by James TD Smith and
;; Samuel Wales, and, of cause, uses John Wiegley's remember.el as inspiration.

;;; TODO

;; - find a clever way to not always insert an annotation maybe a
;;   predicate function that can check for conditions for %a to be
;;   used.  This could be one of the properties.

;; - Should there be plist members that arrange for properties to be
;;   asked for, like James proposed in his RFC?

;;; Code:

(eval-when-compile
  (require 'cl))
(require 'org)
(require 'org-mks)

(declare-function org-datetree-find-date-create "org-datetree"
          (DATE &amp;optional KEEP-RESTRICTION))
(declare-function org-table-get-specials "org-table" ())
(declare-function org-table-goto-line "org-table" (N))
(defvar org-remember-default-headline)
(defvar org-remember-templates)
(defvar org-table-hlines)

(defvar org-capture-clock-was-started nil
  "Internal flag, noting if the clock was started.")

(defvar org-capture-last-stored-marker (make-marker)
  "Marker pointing to the entry most recently stored with `org-capture'.")

;; The following variable is scoped dynamically by org-protocol
;; to indicate that the link properties have already been stored
(defvar org-capture-link-is-already-stored nil)

(defgroup org-capture nil
  "Options concerning capturing new entries."
  :tag "Org Capture"
  :group 'org)

(defcustom org-capture-templates nil
  "Templates for the creation of new entries.

Each entry is a list with the following items:

keys         The keys that will select the template, as a string, characters
             only, for example \"a\" for a template to be selected with a
             single key, or \"bt\" for selection with two keys.  When using
             several keys, keys using the same prefix key must be together
             in the list and preceded by a 2-element entry explaining the
             prefix key, for example

                     (\"b\" \"Templates for marking stuff to buy\")

             The \"C\" key is used by default for quick access to the
             customization of the template variable.  But if you want to use
             that key for a template, you can.

description  A short string describing the template, will be shown during
             selection.

type         The type of entry.  Valid types are:
               entry       an Org-mode node, with a headline. Will be
                           filed as the child of the target entry or as
                           a top-level entry.
               item        a plain list item, will be placed in the
                           first plain list at the target
                           location.
               checkitem   a checkbox item.  This differs from the
                           plain list item only is so far as it uses a
                           different default template.
               table-line  a new line in the first table at target location.
               plain       text to be inserted as it is.

target       Specification of where the captured item should be placed.
             In Org-mode files, targets usually define a node.  Entries will
             become children of this node, other types will be added to the
             table or list in the body of this node.

             Valid values are:

             (file \"path/to/file\")
                 Text will be placed at the beginning or end of that file

             (id \"id of existing org entry\")
                 File as child of this entry, or in the body of the entry

             (file+headline \"path/to/file\" \"node headline\")
                 Fast configuration if the target heading is unique in the file

             (file+olp \"path/to/file\" \"Level 1 heading\" \"Level 2\" ...)
                 For non-unique headings, the full path is safer

             (file+regexp  \"path/to/file\" \"regexp to find location\")
                 File to the entry matching regexp

             (file+datetree \"path/to/file\")
                 Will create a heading in a date tree

             (file+function \"path/to/file\" function-finding-location)
                 A function to find the right location in the file

             (clock)
                File to the entry that is currently being clocked

             (function function-finding-location)
                Most general way, write your own function to find both
                file and location

template     The template for creating the capture item.  If you leave this
             empty, an appropriate default template will be used.  See below
             for more details.  Instead of a string, this may also be one of

                 (file \"/path/to/template-file\")
                 (function function-returning-the-template)

             in order to get a template from a file, or dynamically
             from a function.

The rest of the entry is a property list of additional options.  Recognized
properties are:

 :prepend            Normally newly captured information will be appended at
                     the target location (last child, last table line,
                     last list item...).  Setting this property will
                     change that.

 :immediate-finish   When set, do not offer to edit the information, just
                     file it away immediately.  This makes sense if the
                     template only needs information that can be added
                     automatically.

 :empty-lines        Set this to the number of lines the should be inserted
                     before and after the new item.  Default 0, only common
                     other value is 1.

 :clock-in           Start the clock in this item.

 :clock-resume       Start the interrupted clock when finishing the capture.

 :unnarrowed         Do not narrow the target buffer, simply show the
                     full buffer.  Default is to narrow it so that you
                     only see the new stuff.

 :table-line-pos     Specification of the location in the table where the
                     new line should be inserted.  It looks like \"II-3\"
                     which means that the new line should become the third
                     line before the second horizontal separator line.

The template defines the text to be inserted.  Often this is an org-mode
entry (so the first line should start with a star) that will be filed as a
child of the target headline.  It can also be freely formatted text.
Furthermore, the following %-escapes will be replaced with content:

  %^{prompt}  prompt the user for a string and replace this sequence with it.
              A default value and a completion table ca be specified like this:
              %^{prompt|default|completion2|completion3|...}
  %t          time stamp, date only
  %T          time stamp with date and time
  %u, %U      like the above, but inactive time stamps
  %^t         like %t, but prompt for date.  Similarly %^T, %^u, %^U.
              You may define a prompt like %^{Please specify birthday
  %n          user name (taken from `user-full-name')
  %a          annotation, normally the link created with `org-store-link'
  %i          initial content, copied from the active region.  If %i is
              indented, the entire inserted text will be indented as well.
  %c          current kill ring head
  %x          content of the X clipboard
  %^C         interactive selection of which kill or clip to use
  %^L         like %^C, but insert as link
  %k          title of currently clocked task
  %K          link to currently clocked task
  %^g         prompt for tags, with completion on tags in target file
  %^G         prompt for tags, with completion on all tags in all agenda files
  %^{prop}p   prompt the user for a value for property `prop'
  %:keyword   specific information for certain link types, see below
  %[pathname] insert the contents of the file given by `pathname'
  %(sexp)     evaluate elisp `(sexp)' and replace with the result

  %?          After completing the template, position cursor here.

Apart from these general escapes, you can access information specific to the
link type that is created.  For example, calling `org-capture' in emails
or gnus will record the author and the subject of the message, which you
can access with \"%:author\" and \"%:subject\", respectively.  Here is a
complete list of what is recorded for each link type.

Link type          |  Available information
-------------------+------------------------------------------------------
bbdb               |  %:type %:name %:company
vm, wl, mh, rmail  |  %:type %:subject %:message-id
                   |  %:from %:fromname %:fromaddress
                   |  %:to   %:toname   %:toaddress
                   |  %:fromto (either \"to NAME\" or \"from NAME\")
gnus               |  %:group, for messages also all email fields
w3, w3m            |  %:type %:url
info               |  %:type %:file %:node
calendar           |  %:type %:date"
  :group 'org-capture
  :type
  '(repeat
    (choice :value ("" "" entry (file "~/org/notes.org") "")
     (list :tag "Multikey description"
       (string :tag "Keys       ")
       (string :tag "Description"))
     (list :tag "Template entry"
       (string :tag "Keys           ")
       (string :tag "Description    ")
       (choice :tag "Capture Type   " :value entry
           (const :tag "Org entry" entry)
           (const :tag "Plain list item" item)
           (const :tag "Checkbox item" checkitem)
           (const :tag "Plain text" plain)
           (const :tag "Table line" table-line))
       (choice :tag "Target location"
           (list :tag "File"
             (const :format "" file)
             (file :tag "  File"))
           (list :tag "ID"
             (const :format "" id)
             (string :tag "  ID"))
           (list :tag "File &amp; Headline"
             (const :format "" file+headline)
             (file   :tag "  File    ")
             (string :tag "  Headline"))
           (list :tag "File &amp; Outline path"
             (const :format "" file+olp)
             (file   :tag "  File    ")
             (repeat :tag "Outline path" :inline t
                 (string :tag "Headline")))
           (list :tag "File &amp; Regexp"
             (const :format "" file+regexp)
             (file   :tag "  File  ")
             (regexp :tag "  Regexp"))
           (list :tag "File &amp; Date tree"
             (const :format "" file+datetree)
             (file :tag "  File"))
           (list :tag "File &amp; function"
             (const :format "" file+function)
             (file :tag "  File    ")
             (sexp :tag "  Function"))
           (list :tag "Current clocking task"
             (const :format "" clock))
           (list :tag "Function"
             (const :format "" function)
             (sexp :tag "  Function")))
       (choice :tag "Template"
           (string)
           (list :tag "File"
             (const :format "" file)
             (file :tag "Template file"))
           (list :tag "Function"
             (const :format "" function)
             (function :tag "Template function")))
       (plist :inline t
          ;; Give the most common options as checkboxes
          :options (((const :format "%v " :prepend) (const t))
                ((const :format "%v " :immediate-finish) (const t))
                ((const :format "%v " :empty-lines) (const 1))
                ((const :format "%v " :clock-in) (const t))
                ((const :format "%v " :clock-resume) (const t))
                ((const :format "%v " :unnarrowed) (const t))))))))

(defcustom org-capture-before-finalize-hook nil
  "Hook that is run right before a remember process is finalized.
The remember buffer is still current when this hook runs."
  :group 'org-capture
  :type 'hook)

;;; The property list for keeping information about the capture process

(defvar org-capture-plist nil
  "Plist for the current capture process, global, to avoid having to pass it.")
(defvar org-capture-current-plist nil
  "Local variable holding the plist in a capture buffer.
This is used to store the plist for use when finishing a capture process.
Another such process might have changed the global variable by then.")

</t>
<t tx="ekr.20100929212226.14431">(defun org-capture-put (&amp;rest stuff)
  (while stuff
    (setq org-capture-plist (plist-put org-capture-plist
                       (pop stuff) (pop stuff)))))
</t>
<t tx="ekr.20100929212226.14432">(defun org-capture-get (prop &amp;optional local)
  (plist-get (if local org-capture-current-plist org-capture-plist) prop))
</t>
<t tx="ekr.20100929212226.14433">
(defun org-capture-member (prop)
  (plist-get org-capture-plist prop))
</t>
<t tx="ekr.20100929212226.14434">
;;; The minor mode

(defvar org-capture-mode-map (make-sparse-keymap)
  "Keymap for `org-capture-mode', a minor mode.
Use this map to set additional keybindings for when Org-mode is used
for a Remember buffer.")

(defvar org-capture-mode-hook nil
  "Hook for the minor `org-capture-mode'.")

(define-minor-mode org-capture-mode
  "Minor mode for special key bindings in a remember buffer."
  nil " Rem" org-capture-mode-map
  (org-set-local
   'header-line-format
   "Capture buffer.  Finish `C-c C-c', refile `C-c C-w', abort `C-c C-k'.")
  (run-hooks 'org-capture-mode-hook))
(define-key org-capture-mode-map "\C-c\C-c" 'org-capture-finalize)
(define-key org-capture-mode-map "\C-c\C-k" 'org-capture-kill)
(define-key org-capture-mode-map "\C-c\C-w" 'org-capture-refile)

;;; The main commands

;;;###autoload
(defun org-capture (&amp;optional goto keys)
  "Capture something.
\\&lt;org-capture-mode-map&gt;
This will let you select a template from `org-capture-templates', and then
file the newly captured information.  The text is immediately inserted
at the target location, and an indirect buffer is shown where you can
edit it.  Pressing \\[org-capture-finalize] brings you back to the previous state
of Emacs, so that you can continue your work.

When called interactively with a \\[universal-argument] prefix argument GOTO, don't capture
anything, just go to the file/headline where the selected template
stores its notes.  With a double prefix argument \
\\[universal-argument] \\[universal-argument], go to the last note
stored.

When called with a `C-0' (zero) prefix, insert a template at point.

Lisp programs can set KEYS to a string associated with a template in
`org-capture-templates'.  In this case, interactive selection will be
bypassed."
  (interactive "P")
  (cond
   ((equal goto '(4)) (org-capture-goto-target))
   ((equal goto '(16)) (org-capture-goto-last-stored))
   (t
    ;; FIXME: Are these needed?
    (let* ((orig-buf (current-buffer))
       (annotation (if (and (boundp 'org-capture-link-is-already-stored)
                org-capture-link-is-already-stored)
               (plist-get org-store-link-plist :annotation)
             (org-store-link nil)))
       (initial (and (org-region-active-p)
             (buffer-substring (point) (mark))))
       (entry (org-capture-select-template keys)))
      (cond
       ((equal entry "C")
    (customize-variable 'org-capture-templates))
       ((equal entry "q")
    (error "Abort"))
       (t
    (org-capture-set-plist entry)
    (org-capture-get-template)
    (org-capture-put :original-buffer orig-buf :annotation annotation
             :initial initial)
    (org-capture-put :default-time
             (or org-overriding-default-time
                 (org-current-time)))
    (org-capture-set-target-location)
    (condition-case error
        (org-capture-put :template (org-capture-fill-template))
      ((error quit)
       (if (get-buffer "*Capture*") (kill-buffer "*Capture*"))
       (error "Capture abort: %s" error)))

    (if (equal goto 0)
        ;;insert at point
        (org-capture-insert-template-here)
      (condition-case error
          (org-capture-place-template)
        ((error quit)
         (if (and (buffer-base-buffer (current-buffer))
              (string-match "\\`CAPTURE-" (buffer-name)))
         (kill-buffer (current-buffer)))
         (set-window-configuration (org-capture-get :return-to-wconf))
         (error "Capture template `%s': %s"
            (org-capture-get :key)
            (nth 1 error))))
      (if (org-capture-get :immediate-finish)
          (org-capture-finalize)
        (if (and (org-mode-p)
             (org-capture-get :clock-in))
        (condition-case nil
            (progn
              (if (org-clock-is-active)
              (org-capture-put :interrupted-clock
                       (copy-marker org-clock-marker)))
              (org-clock-in)
              (org-set-local 'org-capture-clock-was-started t))
          (error
           "Could not start the clock in this capture buffer")))))))))))
</t>
<t tx="ekr.20100929212226.14435">

(defun org-capture-get-template ()
  "Get the template from a file or a function if necessary."
  (let ((txt (org-capture-get :template)) file)
    (cond
     ((and (listp txt) (eq (car txt) 'file))
      (if (file-exists-p
       (setq file (expand-file-name (nth 1 txt) org-directory)))
      (setq txt (org-file-contents file))
    (setq txt (format "* Template file %s not found" (nth 1 txt)))))
     ((and (listp txt) (eq (car txt) 'function))
      (if (fboundp (nth 1 txt))
      (setq txt (funcall (nth 1 txt)))
    (setq txt (format "* Template function %s not found" (nth 1 txt)))))
     ((not txt) (setq txt ""))
     ((stringp txt))
     (t (setq txt "* Invalid capture template")))
    (org-capture-put :template txt)))
</t>
<t tx="ekr.20100929212226.14436">
(defun org-capture-finalize ()
  "Finalize the capture process."
  (interactive)
  (unless (and org-capture-mode
           (buffer-base-buffer (current-buffer)))
    (error "This does not seem to be a capture buffer for Org-mode"))

  ;; Did we start the clock in this capture buffer?
  (when (and org-capture-clock-was-started
         org-clock-marker (marker-buffer org-clock-marker)
         (equal (marker-buffer org-clock-marker) (buffer-base-buffer))
         (&gt; org-clock-marker (point-min))
         (&lt; org-clock-marker (point-max)))
    ;; Looks like the clock we started is still running.  Clock out.
    (let (org-log-note-clock-out) (org-clock-out))
    (when (and (org-capture-get :clock-resume 'local)
           (markerp (org-capture-get :interrupted-clock 'local))
           (buffer-live-p (marker-buffer
                   (org-capture-get :interrupted-clock 'local))))
      (org-with-point-at (org-capture-get :interrupted-clock 'local)
    (org-clock-in))
      (message "Interrupted clock has been resumed")))

  (let ((beg (point-min))
    (end (point-max))
    (abort-note nil))
    (widen)

    (if org-note-abort
    (let ((m1 (org-capture-get :begin-marker 'local))
          (m2 (org-capture-get :end-marker 'local)))
      (if (and m1 m2 (= m1 beg) (= m2 end))
          (progn
        (setq abort-note 'clean)
        (kill-region m1 m2))
        (setq abort-note 'dirty)))

      ;; Make sure that the empty lines after are correct
      (when (and (&gt; (point-max) end) ; indeed, the buffer was still narrowed
         (member (org-capture-get :type 'local)
             '(entry item checkitem plain)))
    (save-excursion
      (goto-char end)
      (or (bolp) (newline))
      (org-capture-empty-lines-after
       (or (org-capture-get :empty-lines 'local) 0))))
      ;; Postprocessing:  Update Statistics cookies, do the sorting
      (when (org-mode-p)
    (save-excursion
      (when (ignore-errors (org-back-to-heading))
        (org-update-parent-todo-statistics)
        (org-update-checkbox-count)))
    ;; FIXME Here we should do the sorting
    ;; If we have added a table line, maybe recompute?
    (when (and (eq (org-capture-get :type 'local) 'table-line)
           (org-at-table-p))
      (if (org-table-get-stored-formulas)
          (org-table-recalculate 'all) ;; FIXME: Should we iterate???
        (org-table-align)))
    )
      ;; Store this place as the last one where we stored something
      ;; Do the marking in the base buffer, so that it makes sense after
      ;; the indirect buffer has been killed.
      (org-capture-bookmark-last-stored-position)

      ;; Run the hook
      (run-hooks 'org-capture-before-finalize-hook)
      )

    ;; Kill the indirect buffer
    (save-buffer)
    (let ((return-wconf (org-capture-get :return-to-wconf 'local)))
      (kill-buffer (current-buffer))
      ;; Restore the window configuration before capture
      (set-window-configuration return-wconf))
    (when abort-note
      (cond
       ((equal abort-note 'clean)
    (message "Capture process aborted and target file cleaned up"))
       ((equal abort-note 'dirty)
    (error "Capture process aborted, but target buffer could not be cleaned up correctly"))))))
</t>
<t tx="ekr.20100929212226.14437">
(defun org-capture-refile ()
  "Finalize the current capture and then refile the entry.
Refiling is done from the base buffer, because the indirect buffer is then
already gone."
  (interactive)
  (unless (eq (org-capture-get :type 'local) 'entry)
    (error
     "Refiling from a capture buffer makes only sense for `entry'-type templates"))
  (let ((pos (point))
    (base (buffer-base-buffer (current-buffer)))
    (org-refile-for-capture t))
    (org-capture-finalize)
    (save-window-excursion
      (with-current-buffer (or base (current-buffer))
    (save-excursion
      (save-restriction
        (widen)
        (goto-char pos)
        (call-interactively 'org-refile)))))))
</t>
<t tx="ekr.20100929212226.14438">
(defun org-capture-kill ()
  "Abort the current capture process."
  (interactive)
  ;; FIXME: This does not do the right thing, we need to remove the new stuff
  ;; By hand it is easy: undo, then kill the buffer
  (let ((org-note-abort t) (org-capture-before-finalize-hook nil))
    (org-capture-finalize)))
</t>
<t tx="ekr.20100929212226.14439">
(defun org-capture-goto-last-stored ()
  "Go to the location where the last remember note was stored."
  (interactive)
  (org-goto-marker-or-bmk org-capture-last-stored-marker
              "org-capture-last-stored")
  (message "This is the last note stored by a capture process"))
</t>
<t tx="ekr.20100929212226.14440">
;;; Supporting functions for handling the process

(defun org-capture-set-target-location (&amp;optional target)
  "Find target buffer and position and store then in the property list."
  (let ((target-entry-p t))
    (setq target (or target (org-capture-get :target)))
    (save-excursion
      (cond
       ((eq (car target) 'file)
    (set-buffer (org-capture-target-buffer (nth 1 target)))
    (setq target-entry-p nil))

       ((eq (car target) 'id)
    (let ((loc (org-id-find (nth 1 target))))
      (if (not loc)
          (error "Cannot find target ID \"%s\"" (nth 1 target))
        (set-buffer (org-capture-target-buffer (car loc)))
        (goto-char (cdr loc)))))

       ((eq (car target) 'file+headline)
    (set-buffer (org-capture-target-buffer (nth 1 target)))
    (let ((hd (nth 2 target)))
      (goto-char (point-min))
      (if (re-search-forward
           (format org-complex-heading-regexp-format (regexp-quote hd))
           nil t)
          (goto-char (point-at-bol))
        (goto-char (point-max))
        (or (bolp) (insert "\n"))
        (insert "* " hd "\n")
        (beginning-of-line 0))))

       ((eq (car target) 'file+olp)
    (let ((m (org-find-olp (cdr target))))
      (set-buffer (marker-buffer m))
      (goto-char m)))

       ((eq (car target) 'file+regexp)
    (set-buffer (org-capture-target-buffer (nth 1 target)))
    (goto-char (point-min))
    (if (re-search-forward (nth 2 target) nil t)
        (progn
          (goto-char (if (org-capture-get :prepend)
                 (match-beginning 0) (match-end 0)))
          (org-capture-put :exact-position (point))
          (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))
      (error "No match for target regexp in file %s" (nth 1 target))))

       ((eq (car target) 'file+datetree)
    (require 'org-datetree)
    (set-buffer (org-capture-target-buffer (nth 1 target)))
    ;; Make a date tree entry, with the current date (or yesterday,
    ;; if we are extending dates for a couple of hours)
    (org-datetree-find-date-create
     (calendar-gregorian-from-absolute
      (if org-overriding-default-time
          (time-to-days org-overriding-default-time)
        (time-to-days
         (time-subtract (current-time)
                (list 0 (* 3600 org-extend-today-until) 0)))))))

       ((eq (car target) 'file+function)
    (set-buffer (org-capture-target-buffer (nth 1 target)))
    (funcall (nth 2 target))
    (org-capture-put :exact-position (point))
    (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))

       ((eq (car target) 'function)
    (funcall (nth 1 target))
    (org-capture-put :exact-position (point))
    (setq target-entry-p (and (org-mode-p) (org-at-heading-p))))

       ((eq (car target) 'clock)
    (if (and (markerp org-clock-hd-marker)
         (marker-buffer org-clock-hd-marker))
        (progn (set-buffer (marker-buffer org-clock-hd-marker))
           (goto-char org-clock-hd-marker))
      (error "No running clock that could be used as capture target")))

       (t (error "Invalid capture target specification")))

      (org-capture-put :buffer (current-buffer) :pos (point)
               :target-entry-p target-entry-p))))
</t>
<t tx="ekr.20100929212226.14441">
(defun org-capture-target-buffer (file)
  "Get a buffer for FILE."
  (setq file (or (org-string-nw-p file) org-default-notes-file))
  (or (org-find-base-buffer-visiting file)
      (find-file-noselect (expand-file-name file org-directory))))
</t>
<t tx="ekr.20100929212226.14442">
(defun org-capture-steal-local-variables (buffer)
  "Install Org-mode local variables."
  (mapc (lambda (v)
      (ignore-errors (org-set-local (car v) (cdr v))))
    (buffer-local-variables buffer)))
</t>
<t tx="ekr.20100929212226.14443">
(defun org-capture-place-template ()
  "Insert the template at the target location, and display the buffer."
  (org-capture-put :return-to-wconf (current-window-configuration))
  (delete-other-windows)
  (org-switch-to-buffer-other-window
   (org-capture-get-indirect-buffer (org-capture-get :buffer) "CAPTURE"))
  (show-all)
  (goto-char (org-capture-get :pos))
  (org-set-local 'org-capture-target-marker
         (move-marker (make-marker) (point)))
  (let* ((template (org-capture-get :template))
     (type (org-capture-get :type)))
    (case type
      ((nil entry) (org-capture-place-entry))
      (table-line (org-capture-place-table-line))
      (plain (org-capture-place-plain-text))
      (item  (org-capture-place-item))))
  (org-capture-mode 1)
  (org-set-local 'org-capture-current-plist org-capture-plist))
</t>
<t tx="ekr.20100929212226.14444">
(defun org-capture-place-entry ()
  "Place the template as a new Org entry."
  (let* ((txt (org-capture-get :template))
     (reversed (org-capture-get :prepend))
     (target-entry-p (org-capture-get :target-entry-p))
     level beg end file)

    (cond
     ((org-capture-get :exact-position)
      (goto-char (org-capture-get :exact-position)))
     ((not target-entry-p)
      ;; Insert as top-level entry, either at beginning or at end of file
      (setq level 1)
      (if reversed
      (progn (goto-char (point-min))
         (outline-next-heading))
    (goto-char (point-max))
    (or (bolp) (insert "\n"))))
     (t
      ;; Insert as a child of the current entry
      (and (looking-at "\\*+")
       (setq level (- (match-end 0) (match-beginning 0))))
      (setq level (org-get-valid-level (or level 1) 1))
      (if reversed
      (progn
        (outline-next-heading)
        (or (bolp) (insert "\n")))
    (org-end-of-subtree t t)
    (or (bolp) (insert "\n")))))
    (org-capture-empty-lines-before)
    (setq beg (point))
    (org-paste-subtree level txt 'for-yank)
    (org-capture-empty-lines-after 1)
    (org-capture-position-for-last-stored beg)
    (outline-next-heading)
    (setq end (point))
    (org-capture-mark-kill-region beg (1- end))
    (org-capture-narrow beg (1- end))
    (if (re-search-forward "%\\?" end t) (replace-match ""))))
</t>
<t tx="ekr.20100929212226.14445">
(defun org-capture-place-item ()
  "Place the template as a new plain list item."
  (let* ((txt (org-capture-get :template))
     (target-entry-p (org-capture-get :target-entry-p))
     (ind 0)
     beg end)
    (cond
     ((org-capture-get :exact-position)
      (goto-char (org-capture-get :exact-position)))
     ((not target-entry-p)
      ;; Insert as top-level entry, either at beginning or at end of file
      (setq beg (point-min) end (point-max)))
     (t
      (setq beg (1+ (point-at-eol))
        end (save-excursion (outline-next-heading) (point)))))
    (if (org-capture-get :prepend)
    (progn
      (goto-char beg)
      (if (re-search-forward (concat "^" (org-item-re)) nil t)
          (progn
        (goto-char (match-beginning 0))
        (setq ind (org-get-indentation)))
        (goto-char end)
        (setq ind 0)))
      (goto-char end)
      (if (re-search-backward (concat "^" (org-item-re)) nil t)
      (progn
        (setq ind (org-get-indentation))
        (org-end-of-item))
    (setq ind 0)))
    ;; Remove common indentation
    (setq txt (org-remove-indentation txt))
    ;; Make sure this is indeed an item
    (unless (string-match (concat "\\`" (org-item-re)) txt)
      (setq txt (concat "- "
            (mapconcat 'identity (split-string txt "\n")
                   "\n  "))))
    ;; Set the correct indentation, depending on context
    (setq ind (make-string ind ?\ ))
    (setq txt (concat ind
              (mapconcat 'identity (split-string txt "\n")
                 (concat "\n" ind))
              "\n"))
    ;; Insert, with surrounding empty lines
    (org-capture-empty-lines-before)
    (setq beg (point))
    (insert txt)
    (or (bolp) (insert "\n"))
    (org-capture-empty-lines-after 1)
    (org-capture-position-for-last-stored beg)
    (forward-char 1)
    (setq end (point))
    (org-capture-mark-kill-region beg (1- end))
    (org-capture-narrow beg (1- end))
    (if (re-search-forward "%\\?" end t) (replace-match ""))))
</t>
<t tx="ekr.20100929212226.14446">
(defun org-capture-place-table-line ()
  "Place the template as a table line."
  (require 'org-table)
  (let* ((txt (org-capture-get :template))
     (target-entry-p (org-capture-get :target-entry-p))
     (table-line-pos (org-capture-get :table-line-pos))
     ind beg end)
    (cond
     ((org-capture-get :exact-position)
      (goto-char (org-capture-get :exact-position)))
     ((not target-entry-p)
      ;; Table is not necessarily under a heading
      (setq beg (point-min) end (point-max)))
     (t
      ;; WE are at a heading, limit search to the body
      (setq beg (1+ (point-at-eol))
        end (save-excursion (outline-next-heading) (point)))))
    (if (re-search-forward org-table-dataline-regexp end t)
    (let ((b (org-table-begin)) (e (org-table-end)))
      (goto-char e)
      (if (looking-at "[ \t]*#\\+TBLFM:")
          (forward-line 1))
      (narrow-to-region b (point)))
      (goto-char end)
      (insert "\n|   |\n|----|\n|    |\n")
      (narrow-to-region (1+ end) (point)))
    ;; We are narrowed to the table, or to an empty line if there was no table

    ;; Check if the template is good
    (if (not (string-match org-table-dataline-regexp txt))
    (setq txt "| %?Bad template |\n"))
    (cond
     ((and table-line-pos
       (string-match "\\(I+\\)\\([-+][0-9]\\)" table-line-pos))
      ;; we have a complex line specification
      (goto-char (point-min))
      (let ((nh (- (match-end 1) (match-beginning 1)))
        (delta (string-to-number (match-string 2 table-line-pos)))
        ll)
    ;; The user wants a special position in the table
    (org-table-get-specials)
    (setq ll (ignore-errors (aref org-table-hlines nh)))
    (unless ll (error "Invalid table line specification \"%s\""
              table-line-pos))
    (setq ll (+ ll delta (if (&lt; delta 0) 0 -1)))
    (org-goto-line ll)
    (org-table-insert-row 'below)
    (beginning-of-line 1)
    (delete-region (point) (1+ (point-at-eol)))
    (setq beg (point))
    (insert txt)
    (setq end (point))))
     ((org-capture-get :prepend)
      (goto-char (point-min))
      (re-search-forward org-table-hline-regexp nil t)
      (beginning-of-line 1)
      (re-search-forward org-table-dataline-regexp nil t)
      (beginning-of-line 1)
      (setq beg (point))
      (org-table-insert-row)
      (beginning-of-line 1)
      (delete-region (point) (1+ (point-at-eol)))
      (insert txt)
      (setq end (point)))
     (t
      (goto-char (point-max))
      (re-search-backward org-table-dataline-regexp nil t)
      (beginning-of-line 1)
      (org-table-insert-row 'below)
      (beginning-of-line 1)
      (delete-region (point) (1+ (point-at-eol)))
      (setq beg (point))
      (insert txt)
      (setq end (point))))
    (goto-char beg)
    (org-capture-position-for-last-stored 'table-line)
    (if (re-search-forward "%\\?" end t) (replace-match ""))
    (org-table-align)))
</t>
<t tx="ekr.20100929212226.14447">
(defun org-capture-place-plain-text ()
  "Place the template plainly."
  (let* ((txt (org-capture-get :template))
     beg end)
    (goto-char (cond
        ((org-capture-get :exact-position))
        ((org-capture-get :prepend) (point-min))
        (t (point-max))))
    (or (bolp) (newline))
    (org-capture-empty-lines-before)
    (setq beg (point))
    (insert txt)
    (org-capture-empty-lines-after 1)
    (org-capture-position-for-last-stored beg)
    (setq end (point))
    (org-capture-mark-kill-region beg (1- end))
    (org-capture-narrow beg (1- end))
    (if (re-search-forward "%\\?" end t) (replace-match ""))))
</t>
<t tx="ekr.20100929212226.14448">
(defun org-capture-mark-kill-region (beg end)
  "Mark the region that will have to be killed when aborting capture."
  (let ((m1 (move-marker (make-marker) beg))
    (m2 (move-marker (make-marker) end)))
    (org-capture-put :begin-marker m1)
    (org-capture-put :end-marker m2)))
</t>
<t tx="ekr.20100929212226.14449">
(defun org-capture-position-for-last-stored (where)
  "Memorize the position that should later become the position of last capture."
  (cond
   ((integerp where)
    (org-capture-put :position-for-last-stored
             (move-marker (make-marker) where
                  (or (buffer-base-buffer (current-buffer))
                      (current-buffer)))))
   ((eq where 'table-line)
    (org-capture-put :position-for-last-stored
             (list 'table-line
               (org-table-current-dline))))
   (t (error "This should not happen"))))
</t>
<t tx="ekr.20100929212226.14450">
(defun org-capture-bookmark-last-stored-position ()
  "Bookmark the last-captured position."
  (let* ((where (org-capture-get :position-for-last-stored 'local))
     (pos (cond
           ((markerp where)
        (prog1 (marker-position where)
          (move-marker where nil)))
           ((and (listp where) (eq (car where) 'table-line))
        (if (org-at-table-p)
            (save-excursion
              (org-table-goto-line (nth 1 where))
              (point-at-bol))
          (point))))))
    (with-current-buffer (buffer-base-buffer (current-buffer))
      (save-excursion
    (save-restriction
      (widen)
      (goto-char pos)
      (bookmark-set "org-capture-last-stored")
      (move-marker org-capture-last-stored-marker (point)))))))
</t>
<t tx="ekr.20100929212226.14451">
(defun org-capture-narrow (beg end)
  "Narrow, unless configuration says not to narrow."
  (unless (org-capture-get :unnarrowed)
    (narrow-to-region beg end)
    (goto-char beg)))
</t>
<t tx="ekr.20100929212226.14452">
(defun org-capture-empty-lines-before (&amp;optional n)
  "Arrange for the correct number of empty lines before the insertion point.
Point will be after the empty lines, so insertion can directly be done."
  (setq n (or n (org-capture-get :empty-lines) 0))
  (let ((pos (point)))
    (org-back-over-empty-lines)
    (delete-region (point) pos)
    (newline n)))
</t>
<t tx="ekr.20100929212226.14453">
(defun org-capture-empty-lines-after (&amp;optional n)
  "Arrange for the correct number of empty lines after the inserted string.
Point will remain at the first line after the inserted text."
  (setq n (or n (org-capture-get :empty-lines) 0))
  (org-back-over-empty-lines)
  (while (looking-at "[ \t]*\n") (replace-match ""))
  (let ((pos (point)))
    (newline n)
    (goto-char pos)))
</t>
<t tx="ekr.20100929212226.14454">
(defvar org-clock-marker) ; Defined in org.el
;;;###autoload
(defun org-capture-insert-template-here ()
  (let* ((template (org-capture-get :template))
     (type  (org-capture-get :type))
     beg end pp)
    (or (bolp) (newline))
    (setq beg (point))
    (cond
     ((and (eq type 'entry) (org-mode-p))
      (org-paste-subtree nil template t))
     ((and (memq type '(item checkitem))
       (org-mode-p)
       (save-excursion (skip-chars-backward " \t\n")
               (setq pp (point))
               (org-in-item-p)))
      (goto-char pp)
      (org-insert-item)
      (skip-chars-backward " ")
      (skip-chars-backward "-+*0123456789).")
      (delete-region (point) (point-at-eol))
      (setq beg (point))
      (org-remove-indentation template)
      (insert template)
      (org-capture-empty-lines-after)
      (goto-char beg)
      (org-maybe-renumber-ordered-list)
      (org-end-of-item)
      (setq end (point)))
     (t (insert template)))
    (setq end (point))
    (goto-char beg)
    (if (re-search-forward "%\\?" end t)
    (replace-match ""))))
</t>
<t tx="ekr.20100929212226.14455">
(defun org-capture-set-plist (entry)
  "Initialize the property list from the template definition."
  (setq org-capture-plist (copy-sequence (nthcdr 5 entry)))
  (org-capture-put :key (car entry) :description (nth 1 entry)
           :target (nth 3 entry))
  (let ((txt (nth 4 entry)) (type (or (nth 2 entry) 'entry)))
    (when (or (not txt) (and (stringp txt) (not (string-match "\\S-" txt))))
      ;; The template may be empty or omitted for special types.
      ;; Here we insert the default templates for such cases.
      (cond
       ((eq type 'item) (setq txt "- %?"))
       ((eq type 'checkitem) (setq txt "- [ ] %?"))
       ((eq type 'table-line) (setq txt "| %? |"))
       ((member type '(nil entry)) (setq txt "* %?\n  %a"))))
    (org-capture-put :template txt :type type)))
</t>
<t tx="ekr.20100929212226.14456">
(defun org-capture-goto-target (&amp;optional template-key)
  "Go to the target location of a capture template.
The user is queried for the template."
  (interactive)
  (let* (org-select-template-temp-major-mode
     (entry (org-capture-select-template template-key)))
    (unless entry
      (error "No capture template selected"))
    (org-capture-set-plist entry)
    (org-capture-set-target-location)
    (switch-to-buffer (org-capture-get :buffer))
    (goto-char (org-capture-get :pos))))
</t>
<t tx="ekr.20100929212226.14457">
(defun org-capture-get-indirect-buffer (&amp;optional buffer prefix)
  "Make an indirect buffer for a capture process.
Use PREFIX as a prefix for the name of the indirect buffer."
  (setq buffer (or buffer (current-buffer)))
  (let ((n 1) (base (buffer-name buffer)) bname)
    (setq bname (concat prefix "-" base))
    (while (buffer-live-p (get-buffer bname))
      (setq bname (concat prefix "-" (number-to-string (incf n)) "-" base)))
    (condition-case nil
        (make-indirect-buffer buffer bname 'clone)
      (error (make-indirect-buffer buffer bname)))))
</t>
<t tx="ekr.20100929212226.14458">

;;; The template code

(defun org-capture-select-template (&amp;optional keys)
  "Select a capture template.
Lisp programs can force the template by setting KEYS to a string."
  (when org-capture-templates
    (if keys
    (or (assoc keys org-capture-templates)
        (error "No capture template referred to by \"%s\" keys" keys))
      (if (= 1 (length org-capture-templates))
      (car org-capture-templates)
    (org-mks org-capture-templates
         "Select a capture template\n========================="
         "Template key: "
         '(("C" "Customize org-capture-templates")
           ("q" "Abort")))))))
</t>
<t tx="ekr.20100929212226.14459">
(defun org-capture-fill-template (&amp;optional template initial annotation)
  "Fill a template and return the filled template as a string.
The template may still contain \"%?\" for cursor positioning."
  (setq template (or template (org-capture-get :template)))
  (when (stringp initial)
    (setq initial (org-no-properties initial))
    (remove-text-properties 0 (length initial) '(read-only t) initial))
  (let* ((buffer (org-capture-get :buffer))
     (file (buffer-file-name (or (buffer-base-buffer buffer) buffer)))
     (ct (org-capture-get :default-time))
     (dct (decode-time ct))
     (ct1
      (if (&lt; (nth 2 dct) org-extend-today-until)
          (encode-time 0 59 23 (1- (nth 3 dct)) (nth 4 dct) (nth 5 dct))
        ct))
     (plist-p (if org-store-link-plist t nil))
     (v-c (and (&gt; (length kill-ring) 0) (current-kill 0)))
     (v-x (or (org-get-x-clipboard 'PRIMARY)
          (org-get-x-clipboard 'CLIPBOARD)
          (org-get-x-clipboard 'SECONDARY)))
     (v-t (format-time-string (car org-time-stamp-formats) ct))
     (v-T (format-time-string (cdr org-time-stamp-formats) ct))
     (v-u (concat "[" (substring v-t 1 -1) "]"))
     (v-U (concat "[" (substring v-T 1 -1) "]"))
     ;; `initial' and `annotation' might habe been passed.
     ;; But if the property list has them, we prefer those values
     (v-i (or (plist-get org-store-link-plist :initial)
          initial
          (org-capture-get :initial)
          ""))
     (v-a (or (plist-get org-store-link-plist :annotation)
          annotation
          (org-capture-get :annotation)
          ""))
     ;; Is the link empty?  Then we do not want it...
     (v-a (if (equal v-a "[[]]") "" v-a))
     (clipboards (remove nil (list v-i
                       (org-get-x-clipboard 'PRIMARY)
                       (org-get-x-clipboard 'CLIPBOARD)
                       (org-get-x-clipboard 'SECONDARY)
                       v-c)))
     (v-A (if (and v-a
               (string-match
            "\\[\\(\\[.*?\\]\\)\\(\\[.*?\\]\\)?\\]" v-a))
          (replace-match "[\\1[%^{Link description}]]" nil nil v-a)
        v-a))
     (v-n user-full-name)
     (v-k (if (marker-buffer org-clock-marker)
          (org-substring-no-properties org-clock-heading)))
     (v-K (if (marker-buffer org-clock-marker)
          (org-make-link-string
           (buffer-file-name (marker-buffer org-clock-marker))
           org-clock-heading)))
     v-I
     (org-startup-folded nil)
     (org-inhibit-startup t)
     org-time-was-given org-end-time-was-given x
     prompt completions char time pos default histvar)

    (setq org-store-link-plist
      (plist-put org-store-link-plist :annotation v-a)
      org-store-link-plist
      (plist-put org-store-link-plist :initial v-i))

    (unless template (setq template "") (message "No template") (ding)
        (sit-for 1))
    (save-window-excursion
      (delete-other-windows)
      (switch-to-buffer (get-buffer-create "*Capture*"))
      (erase-buffer)
      (insert template)
      (goto-char (point-min))
      (org-capture-steal-local-variables buffer)
      (setq buffer-file-name nil)

      ;; %[] Insert contents of a file.
      (goto-char (point-min))
      (while (re-search-forward "%\\[\\(.+\\)\\]" nil t)
    (unless (org-capture-escaped-%)
      (let ((start (match-beginning 0))
        (end (match-end 0))
        (filename (expand-file-name (match-string 1))))
        (goto-char start)
        (delete-region start end)
        (condition-case error
        (insert-file-contents filename)
          (error (insert (format "%%[Couldn't insert %s: %s]"
                     filename error)))))))
      ;; %() embedded elisp
      (goto-char (point-min))
      (while (re-search-forward "%\\((.+)\\)" nil t)
    (unless (org-capture-escaped-%)
      (goto-char (match-beginning 0))
      (let ((template-start (point)))
        (forward-char 1)
        (let ((result
           (condition-case error
               (eval (read (current-buffer)))
             (error (format "%%[Error: %s]" error)))))
          (delete-region template-start (point))
          (insert result)))))

      ;; Simple %-escapes
      (while (re-search-forward "%\\([tTuUaiAcxkKI]\\)" nil t)
    (unless (org-capture-escaped-%)
      (when (and initial (equal (match-string 0) "%i"))
        (save-match-data
          (let* ((lead (buffer-substring
                (point-at-bol) (match-beginning 0))))
        (setq v-i (mapconcat 'identity
                     (org-split-string initial "\n")
                     (concat "\n" lead))))))
      (replace-match
       (or (eval (intern (concat "v-" (match-string 1)))) "")
       t t)))

      ;; From the property list
      (when plist-p
    (goto-char (point-min))
    (while (re-search-forward "%\\(:[-a-zA-Z]+\\)" nil t)
      (unless (org-capture-escaped-%)
        (and (setq x (or (plist-get org-store-link-plist
                    (intern (match-string 1))) ""))
         (replace-match x t t)))))

      ;; Turn on org-mode in temp buffer, set local variables
      ;; This is to support completion in interactive prompts
      (let ((org-inhibit-startup t)) (org-mode))
      ;; Interactive template entries
      (goto-char (point-min))
      (while (re-search-forward "%^\\({\\([^}]*\\)}\\)?\\([gGtTuUCLp]\\)?"
                nil t)
    (unless (org-capture-escaped-%)
      (setq char (if (match-end 3) (match-string 3))
        prompt (if (match-end 2) (match-string 2)))
      (goto-char (match-beginning 0))
      (replace-match "")
      (setq completions nil default nil)
      (when prompt
        (setq completions (org-split-string prompt "|")
          prompt (pop completions)
          default (car completions)
          histvar (intern (concat
                   "org-capture-template-prompt-history::"
                   (or prompt "")))
          completions (mapcar 'list completions)))
      (cond
       ((member char '("G" "g"))
        (let* ((org-last-tags-completion-table
            (org-global-tags-completion-table
             (if (equal char "G")
             (org-agenda-files)
               (and file (list file)))))
           (org-add-colon-after-tag-completion t)
           (ins (org-icompleting-read
             (if prompt (concat prompt ": ") "Tags: ")
             'org-tags-completion-function nil nil nil
             'org-tags-history)))
          (setq ins (mapconcat 'identity
                   (org-split-string
                    ins (org-re "[^[:alnum:]_@]+"))
                       ":"))
          (when (string-match "\\S-" ins)
        (or (equal (char-before) ?:) (insert ":"))
        (insert ins)
        (or (equal (char-after) ?:) (insert ":")))))
       ((equal char "C")
        (cond ((= (length clipboards) 1) (insert (car clipboards)))
          ((&gt; (length clipboards) 1)
           (insert (read-string "Clipboard/kill value: "
                    (car clipboards) '(clipboards . 1)
                    (car clipboards))))))
       ((equal char "L")
        (cond ((= (length clipboards) 1)
           (org-insert-link 0 (car clipboards)))
          ((&gt; (length clipboards) 1)
           (org-insert-link 0 (read-string "Clipboard/kill value: "
                           (car clipboards)
                           '(clipboards . 1)
                           (car clipboards))))))
       ((equal char "p")
        (let*
        ((prop (org-substring-no-properties prompt))
         (pall (concat prop "_ALL"))
         (allowed
          (with-current-buffer
              (get-buffer (file-name-nondirectory file))
            (or (cdr (assoc pall org-file-properties))
            (cdr (assoc pall org-global-properties))
            (cdr (assoc pall org-global-properties-fixed)))))
         (existing (with-current-buffer
                   (get-buffer (file-name-nondirectory file))
                 (mapcar 'list (org-property-values prop))))
         (propprompt (concat "Value for " prop ": "))
         (val (if allowed
              (org-completing-read
               propprompt
               (mapcar 'list (org-split-string allowed
                               "[ \t]+"))
               nil 'req-match)
            (org-completing-read-no-i propprompt
                          existing nil nil
                          "" nil ""))))
          (org-set-property prop val)))
       (char
        ;; These are the date/time related ones
        (setq org-time-was-given (equal (upcase char) char))
        (setq time (org-read-date (equal (upcase char) char) t nil
                      prompt))
        (if (equal (upcase char) char) (setq org-time-was-given t))
        (org-insert-time-stamp time org-time-was-given
                   (member char '("u" "U"))
                   nil nil (list org-end-time-was-given)))
       (t
        (let (org-completion-use-ido)
          (insert (org-completing-read-no-i
               (concat (if prompt prompt "Enter string")
                   (if default (concat " [" default "]"))
                   ": ")
               completions nil nil nil histvar default)))))))
      ;; Make sure there are no empty lines before the text, and that
      ;; it ends with a newline character
      (goto-char (point-min))
      (while (looking-at "[ \t]*\n") (replace-match ""))
      (if (re-search-forward "[ \t\n]*\\'" nil t) (replace-match "\n"))
      ;; Return the expanded tempate and kill the temporary buffer
      (untabify (point-min) (point-max))
      (set-buffer-modified-p nil)
      (prog1 (buffer-string) (kill-buffer (current-buffer))))))
</t>
<t tx="ekr.20100929212226.14460">
(defun org-capture-escaped-% ()
  "Check if % was escaped - if yes, unescape it now."
  (if (equal (char-before (match-beginning 0)) ?\\)
      (progn
    (delete-region (1- (match-beginning 0)) (match-beginning 0))
    t)
    nil))
</t>
<t tx="ekr.20100929212226.14461">
;;;###autoload
(defun org-capture-import-remember-templates ()
  "Set org-capture-templates to be similar to `org-remember-templates'."
  (interactive)
  (when (and (yes-or-no-p
          "Import old remember templates into org-capture-templates? ")
         (yes-or-no-p
          "Note that this will remove any templates currently defined in `org-capture-templates'.  Do you still want to go ahead? "))
    (require 'org-remember)
    (setq org-capture-templates
      (mapcar
       (lambda (entry)
         (let ((desc (car entry))
           (key (char-to-string (nth 1 entry)))
           (template (nth 2 entry))
           (file (or (nth 3 entry) org-default-notes-file))
           (position (or (nth 4 entry) org-remember-default-headline))
           (type 'entry)
           (prepend org-reverse-note-order)
           immediate target)
           (cond
        ((member position '(top bottom))
         (setq target (list 'file file)
               prepend (eq position 'top)))
        ((eq position 'date-tree)
         (setq target (list 'file+datetree file)
               prepend nil))
        (t (setq target (list 'file+headline file position))))

           (when (string-match "%!" template)
         (setq template (replace-match "" t t template)
               immediate t))

           (append (list key desc type target template)
               (if prepend '(:prepend t))
               (if immediate '(:immediate-finish t)))))

       org-remember-templates))))
</t>
<t tx="ekr.20100929212226.14462">@language lisp
@tabwidth -4
@others

(add-hook 'org-reveal-start-hook 'org-decrypt-entry)

(provide 'org-crypt)

;; arch-tag: 8202ed2c-221e-4001-9e4b-54674a7e846e

;;; org-crypt.el ends here
</t>
<t tx="ekr.20100929212226.14463">;;; org-crypt.el --- Public key encryption for org-mode entries

;; Copyright (C) 2007, 2009, 2010  Free Software Foundation, Inc.

;; Emacs Lisp Archive Entry
;; Filename: org-crypt.el
;; Version: 7.01h
;; Keywords: org-mode
;; Author: John Wiegley &lt;johnw@gnu.org&gt;
;; Maintainer: Peter Jones &lt;pjones@pmade.com&gt;
;; Description: Adds public key encryption to org-mode buffers
;; URL: http://www.newartisans.com/software/emacs.html
;; Compatibility: Emacs22

;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:

;; Right now this is just a set of functions to play with.  It depends
;; on the epg library.  Here's how you would use it:
;;
;; 1. To mark an entry for encryption, tag the heading with "crypt".
;;    You can change the tag to any complex tag matching string by
;;    setting the `org-crypt-tag-matcher' variable.
;;
;; 2. Set the encryption key to use in the `org-crypt-key' variable,
;;    or use `M-x org-set-property' to set the property CRYPTKEY to
;;    any address in your public keyring.  The text of the entry (but
;;    not its properties or headline) will be encrypted for this user.
;;    For them to read it, the corresponding secret key must be
;;    located in the secret key ring of the account where you try to
;;    decrypt it.  This makes it possible to leave secure notes that
;;    only the intended recipient can read in a shared-org-mode-files
;;    scenario.
;;    If the key is not set, org-crypt will default to symmetric encryption.
;;
;; 3. To later decrypt an entry, use `org-decrypt-entries' or
;;    `org-decrypt-entry'.  It might be useful to bind this to a key,
;;    like C-c C-/.  I hope that in the future, C-c C-r can be might
;;    overloaded to also decrypt an entry if it's encrypted, since
;;    that fits nicely with the meaning of "reveal".
;;
;; 4. To automatically encrypt all necessary entries when saving a
;;    file, call `org-crypt-use-before-save-magic' after loading
;;    org-crypt.el.
;;
;; TODO:
;;   - Allow symmetric encryption as well

;;; Thanks:

;; - Carsten Dominik
;; - Vitaly Ostanin

(require 'org)

;;; Code:

(declare-function epg-decrypt-string "epg" (context cipher))
(declare-function epg-list-keys "epg" (context &amp;optional name mode))
(declare-function epg-make-context "epg"
          (&amp;optional protocol armor textmode include-certs
                 cipher-algorithm digest-algorithm
                 compress-algorithm))
(declare-function epg-encrypt-string "epg"
          (context plain recipients &amp;optional sign always-trust))

(defgroup org-crypt nil
  "Org Crypt"
  :tag "Org Crypt" :group 'org)

(defcustom org-crypt-tag-matcher "crypt"
  "The tag matcher used to find headings whose contents should be encrypted.

See the \"Match syntax\" section of the org manual for more details."
  :type 'string :group 'org-crypt)

(defcustom org-crypt-key nil
  "The default key to use when encrypting the contents of a heading.

This setting can also be overridden in the CRYPTKEY property."
  :type 'string :group 'org-crypt)

</t>
<t tx="ekr.20100929212226.14464">(defun org-crypt-key-for-heading ()
  "Return the encryption key for the current heading."
  (save-excursion
    (org-back-to-heading t)
    (or (org-entry-get nil "CRYPTKEY" 'selective)
        org-crypt-key
        (and (boundp 'epa-file-encrypt-to) epa-file-encrypt-to)
        (message "No crypt key set, using symmetric encryption."))))
</t>
<t tx="ekr.20100929212226.14465">
(defun org-encrypt-entry ()
  "Encrypt the content of the current headline."
  (interactive)
  (require 'epg)
  (save-excursion
    (org-back-to-heading t)
    (let ((start-heading (point)))
      (forward-line)
      (when (not (looking-at "-----BEGIN PGP MESSAGE-----"))
        (let ((folded (org-invisible-p))
              (epg-context (epg-make-context nil t t))
              (crypt-key (org-crypt-key-for-heading))
              (beg (point))
              end encrypted-text)
          (goto-char start-heading)
          (org-end-of-subtree t t)
          (org-back-over-empty-lines)
          (setq end (point)
                encrypted-text
                (epg-encrypt-string
                 epg-context
                 (buffer-substring-no-properties beg end)
                 (epg-list-keys epg-context crypt-key)))
          (delete-region beg end)
          (insert encrypted-text)
          (when folded
            (goto-char start-heading)
            (hide-subtree))
          nil)))))
</t>
<t tx="ekr.20100929212226.14466">
(defun org-decrypt-entry ()
  "Decrypt the content of the current headline."
  (interactive)
  (require 'epg)
  (unless (org-before-first-heading-p)
    (save-excursion
      (org-back-to-heading t)
      (forward-line)
      (when (looking-at "-----BEGIN PGP MESSAGE-----")
    (let* ((beg (point))
           (end (save-excursion
              (search-forward "-----END PGP MESSAGE-----")
              (forward-line)
              (point)))
           (epg-context (epg-make-context nil t t))
           (decrypted-text
        (decode-coding-string
         (epg-decrypt-string
          epg-context
          (buffer-substring-no-properties beg end))
         'utf-8)))
      (delete-region beg end)
      (insert decrypted-text)
      nil)))))
</t>
<t tx="ekr.20100929212226.14467">
(defun org-encrypt-entries ()
  "Encrypt all top-level entries in the current buffer."
  (interactive)
  (org-scan-tags
   'org-encrypt-entry
   (cdr (org-make-tags-matcher org-crypt-tag-matcher))))
</t>
<t tx="ekr.20100929212226.14468">
(defun org-decrypt-entries ()
  "Decrypt all entries in the current buffer."
  (interactive)
  (org-scan-tags
   'org-decrypt-entry
   (cdr (org-make-tags-matcher org-crypt-tag-matcher))))
</t>
<t tx="ekr.20100929212226.14469">
(defun org-crypt-use-before-save-magic ()
  "Add a hook to automatically encrypt entries before a file is saved to disk."
  (add-hook
   'org-mode-hook
   (lambda () (add-hook 'before-save-hook 'org-encrypt-entries nil t))))
</t>
<t tx="ekr.20100929212226.14470">@language lisp
@tabwidth -4
@others


(org-ctags-enable)

(provide 'org-ctags)

;; arch-tag: 4b1ddd5a-8529-4b17-bcde-96a922d26343
;;; org-ctags.el ends here
</t>
<t tx="ekr.20100929212226.14471">;;; org-ctags.el - Integrate Emacs "tags" facility with org mode.
;;
;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.

;; Author: Paul Sexton &lt;eeeickythump@gmail.com&gt;
;; Version: 7.01h

;; Keywords: org, wp
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;
;; Synopsis
;; ========
;;
;; Allows org-mode to make use of the Emacs `etags' system. Defines tag
;; destinations in org-mode files as any text between &lt;&lt;double angled
;; brackets&gt;&gt;. This allows the tags-generation program `exuberant ctags' to
;; parse these files and create tag tables that record where these
;; destinations are found. Plain [[links]] in org mode files which do not have
@verbatim
;; &lt;&lt;matching destinations&gt;&gt; within the same file will then be interpreted as
;; links to these 'tagged' destinations, allowing seamless navigation between
;; multiple org-mode files. Topics can be created in any org mode file and
;; will always be found by plain links from other files. Other file types
;; recognised by ctags (source code files, latex files, etc) will also be
;; available as destinations for plain links, and similarly, org-mode links
;; will be available as tags from source files. Finally, the function
;; `org-ctags-find-tag-interactive' lets you choose any known tag, using
;; autocompletion, and quickly jump to it.
;;
;; Installation
;; ============
;;
;; Install org mode
;; Ensure org-ctags.el is somewhere in your emacs load path.
;; Download and install Exuberant ctags -- "http://ctags.sourceforge.net/"
;; Edit your .emacs file (see next section) and load emacs.

;; To put in your init file (.emacs):
;; ==================================
;;
;; Assuming you already have org mode installed and set up:
;;
;;    (setq org-ctags-path-to-ctags "/path/to/ctags/executable")
;;    (add-hook 'org-mode-hook
;;      (lambda ()
;;        (define-key org-mode-map "\C-co" 'org-ctags-find-tag-interactive)))
;;
;; By default, with org-ctags loaded, org will first try and visit the tag
;; with the same name as the link; then, if unsuccessful, ask the user if
;; he/she wants to rebuild the 'TAGS' database and try again; then ask if
;; the user wishes to append 'tag' as a new toplevel heading at the end of
;; the buffer; and finally, defer to org's default behaviour which is to
;; search the entire text of the current buffer for 'tag'.
;;
;; This behaviour can be modified by changing the value of
;; ORG-CTAGS-OPEN-LINK-FUNCTIONS. For example I have the following in my
;; .emacs, which describes the same behaviour as the above paragraph with
;; one difference:
;;
;; (setq org-ctags-open-link-functions
;;       '(org-ctags-find-tag
;;         org-ctags-ask-rebuild-tags-file-then-find-tag
;;         org-ctags-ask-append-topic
;;         org-ctags-fail-silently))  ; &lt;-- prevents org default behaviour
;;
;;
;; Usage
;; =====
;;
@verbatim
;; When you click on a link "[[foo]]" and org cannot find a matching "&lt;&lt;foo&gt;&gt;"
;; in the current buffer, the tags facility will take over. The file TAGS in
;; the active directory is examined to see if the tags facility knows about
@verbatim
;; "&lt;&lt;foo&gt;&gt;" in any other files. If it does, the matching file will be opened
@verbatim
;; and the cursor will jump to the position of "&lt;&lt;foo&gt;&gt;" in that file.
;;
;; User-visible functions:
;; - `org-ctags-find-tag-interactive': type a tag (plain link) name and visit
;;   it. With autocompletion. Bound to ctrl-O in the above setup.
;; - All the etags functions should work. These include:
;;
;;      M-.    `find-tag' -- finds the tag at point
;;
;;      C-M-.  find-tag based on regular expression
;;
;;      M-x tags-search RET -- like C-M-. but searches through ENTIRE TEXT
;;             of ALL the files referenced in the TAGS file. A quick way to
;;             search through an entire 'project'.
;;
;;      M-*    "go back" from a tag jump. Like `org-mark-ring-goto'.
;;             You may need to bind this key yourself with (eg)
;;             (global-set-key (kbd "&lt;M-kp-multiply&gt;") 'pop-tag-mark)
;;
;;      (see etags chapter in Emacs manual for more)
;;
;;
;; Keeping the TAGS file up to date
;; ================================
;;
;; Tags mode has no way of knowing that you have created new tags by typing in
;; your org-mode buffer.  New tags make it into the TAGS file in 3 ways:
;;
;; 1. You re-run (org-ctags-create-tags "directory") to rebuild the file.
;; 2. You put the function `org-ctags-ask-rebuild-tags-file-then-find-tag' in
;;    your `org-open-link-functions' list, as is done in the setup
;;    above. This will cause the TAGS file to be rebuilt whenever a link
;;    cannot be found. This may be slow with large file collections however.
;; 3. You run the following from the command line (all 1 line):
;;
;;      ctags --langdef=orgmode --langmap=orgmode:.org
@verbatim
;;        --regex-orgmode="/&lt;&lt;([^&gt;]+)&gt;&gt;/\1/d,definition/"
;;          -f /your/path/TAGS -e -R /your/path/*.org
;;
;; If you are paranoid, you might want to run (org-ctags-create-tags
;; "/path/to/org/files") at startup, by including the following toplevel form
;; in .emacs. However this can cause a pause of several seconds if ctags has
;; to scan lots of files.
;;
;;     (progn
;;       (message "-- rebuilding tags tables...")
;;       (mapc 'org-create-tags tags-table-list))

;;; Code:

(eval-when-compile (require 'cl))

(require 'org)

(defgroup org-ctags nil
  "Options concerning use of ctags within org mode."
  :tag "Org-Ctags"
  :group 'org-link)

(defvar org-ctags-enabled-p t
  "Activate ctags support in org mode?")

@verbatim
(defvar org-ctags-tag-regexp "/&lt;&lt;([^&gt;]+)&gt;&gt;/\\1/d,definition/"
  "Regexp expression used by ctags external program.
The regexp matches tag destinations in org-mode files.
Format is: /REGEXP/TAGNAME/FLAGS,TAGTYPE/
See the ctags documentation for more information.")

(defcustom org-ctags-path-to-ctags
  (case system-type
    (windows-nt "ctags.exe")
    (darwin "ctags-exuberant")
    (t "ctags-exuberant"))
  "Full path to the ctags executable file."
  :group 'org-ctags
  :type 'file)

(defcustom org-ctags-open-link-functions
  '(org-ctags-find-tag
    org-ctags-ask-rebuild-tags-file-then-find-tag
    org-ctags-ask-append-topic)
  "List of functions to be prepended to ORG-OPEN-LINK-FUNCTIONS when ORG-CTAGS is active."
  :group 'org-ctags
  :type 'hook
  :options '(org-ctags-find-tag
             org-ctags-ask-rebuild-tags-file-then-find-tag
             org-ctags-rebuild-tags-file-then-find-tag
             org-ctags-ask-append-topic
             org-ctags-append-topic
             org-ctags-ask-visit-buffer-or-file
             org-ctags-visit-buffer-or-file
             org-ctags-fail-silently))


(defvar org-ctags-tag-list nil
  "List of all tags in the active TAGS file.
Created as a local variable in each buffer.")

(defcustom org-ctags-new-topic-template
@verbatim
  "* &lt;&lt;%t&gt;&gt;\n\n\n\n\n\n"
  "Text to insert when creating a new org file via opening a hyperlink.
The following patterns are replaced in the string:
    `%t' - replaced with the capitalized title of the hyperlink"
  :group 'org-ctags
  :type 'string)


(add-hook 'org-mode-hook
          (lambda ()
            (when (and org-ctags-enabled-p
                       (buffer-file-name))
              ;; Make sure this file's directory is added to default
              ;; directories in which to search for tags.
              (let ((tags-filename
                     (expand-file-name
                      (concat (file-name-directory (buffer-file-name))
                              "/TAGS"))))
                (when (file-exists-p tags-filename)
                  (visit-tags-table tags-filename))))))


(defadvice visit-tags-table (after org-ctags-load-tag-list activate compile)
  (when (and org-ctags-enabled-p tags-file-name)
    (set (make-local-variable 'org-ctags-tag-list)
         (org-ctags-all-tags-in-current-tags-table))))


</t>
<t tx="ekr.20100929212226.14472">(defun org-ctags-enable ()
  (put 'org-mode 'find-tag-default-function 'org-ctags-find-tag-at-point)
  (setq org-ctags-enabled-p t)
  (dolist (fn org-ctags-open-link-functions)
    (add-hook 'org-open-link-functions fn t)))
</t>
<t tx="ekr.20100929212226.14473">

;;; General utility functions.  ===============================================
;; These work outside org-ctags mode.

(defun org-ctags-get-filename-for-tag (tag)
  "TAG is a string.  Search the active TAGS file for a matching tag.
If the tag is found, return a list containing the filename, line number, and
buffer position where the tag is found."
  (interactive "sTag: ")
  (unless tags-file-name
    (call-interactively (visit-tags-table)))
  (save-excursion
    (visit-tags-table-buffer 'same)
    (when tags-file-name
      (with-current-buffer (get-file-buffer tags-file-name)
        (goto-char (point-min))
        (cond
         ((re-search-forward (format "^.*%s \\([0-9]+\\),\\([0-9]+\\)$"
                                     (regexp-quote tag)) nil t)
          (let ((line (string-to-number (match-string 1)))
                (pos (string-to-number (match-string 2))))
            (cond
             ((re-search-backward " \n\\(.*\\),[0-9]+\n")
              (list (match-string 1) line pos))
             (t              ; can't find a file name preceding the matched
                             ; tag??
              (error "Malformed TAGS file: %s" (buffer-name))))))
         (t                               ; tag not found
          nil))))))
</t>
<t tx="ekr.20100929212226.14474">

(defun org-ctags-all-tags-in-current-tags-table ()
  "Read all tags defined in the active TAGS file, into a list of strings.
Return the list."
  (interactive)
  (let ((taglist nil))
    (unless tags-file-name
      (call-interactively (visit-tags-table)))
    (save-excursion
      (visit-tags-table-buffer 'same)
      (with-current-buffer (get-file-buffer tags-file-name)
        (goto-char (point-min))
        (while (re-search-forward "^.*\\(.*\\) \\([0-9]+\\),\\([0-9]+\\)$"
                                  nil t)
          (push (substring-no-properties (match-string 1)) taglist)))
      taglist)))
</t>
<t tx="ekr.20100929212226.14475">

(defun org-ctags-string-search-and-replace (search replace string)
  "Replace all instances of SEARCH with REPLACE in STRING."
  (replace-regexp-in-string (regexp-quote search) replace string t t))
</t>
<t tx="ekr.20100929212226.14476">

(defun y-or-n-minibuffer (prompt)
  (let ((use-dialog-box nil))
    (y-or-n-p prompt)))
</t>
<t tx="ekr.20100929212226.14477">

;;; Internal functions =======================================================


(defun org-ctags-open-file (name &amp;optional title)
  "Visit or create a file called `NAME.org', and insert a new topic.
The new topic will be titled NAME (or TITLE if supplied)."
  (interactive "sFile name: ")
  (let ((filename (substitute-in-file-name (expand-file-name name))))
    (condition-case v
        (progn
          (org-open-file name t)
          (message "Opened file OK")
          (goto-char (point-max))
          (insert (org-ctags-string-search-and-replace
                   "%t" (capitalize (or title name))
                   org-ctags-new-topic-template))
          (message "Inserted new file text OK")
          (org-mode-restart))
      (error (error "Error %S in org-ctags-open-file" v)))))
</t>
<t tx="ekr.20100929212226.14478">

;;;; Misc interoperability with etags system =================================


(defadvice find-tag (before org-ctags-set-org-mark-before-finding-tag
                activate compile)
  "Before trying to find a tag, save our current position on org mark ring."
  (save-excursion
    (if (and (org-mode-p) org-ctags-enabled-p)
        (org-mark-ring-push))))



(defun org-ctags-find-tag-at-point ()
  "Determine default tag to search for, based on text at point.
If there is no plausible default, return nil."
  (let (from to bound)
    (when (or (ignore-errors
        ;; Look for hyperlink around `point'.
        (save-excursion
          (search-backward "[[") (setq from (+ 2 (point))))
        (save-excursion
                  (goto-char from)
          (search-forward "]") (setq to (- (point) 1)))
        (and (&gt; to from) (&gt;= (point) from) (&lt;= (point) to)))
              (progn
        ;; Look at text around `point'.
        (save-excursion
          (skip-syntax-backward "w_") (setq from (point)))
        (save-excursion
          (skip-syntax-forward "w_") (setq to (point)))
        (&gt; to from))
          ;; Look between `line-beginning-position' and `point'.
          (save-excursion
        (and (setq bound (line-beginning-position))
             (skip-syntax-backward "^w_" bound)
             (&gt; (setq to (point)) bound)
             (skip-syntax-backward "w_")
             (setq from (point))))
          ;; Look between `point' and `line-end-position'.
          (save-excursion
        (and (setq bound (line-end-position))
             (skip-syntax-forward "^w_" bound)
             (&lt; (setq from (point)) bound)
             (skip-syntax-forward "w_")
             (setq to (point)))))
      (buffer-substring-no-properties from to))))
</t>
<t tx="ekr.20100929212226.14479">

;;; Functions for use with 'org-open-link-functions' hook =================


(defun org-ctags-find-tag (name)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Look for a tag called `NAME' in the current TAGS table.  If it is found,
visit the file and location where the tag is found."
  (interactive "sTag: ")
  (let ((old-buf (current-buffer))
        (old-pnt (point-marker))
        (old-mark (copy-marker (mark-marker))))
    (condition-case nil
        (progn (find-tag name)
               t)
      (error
       ;; only restore old location if find-tag raises error
       (set-buffer old-buf)
       (goto-char old-pnt)
       (set-marker (mark-marker) old-mark)
       nil))))
</t>
<t tx="ekr.20100929212226.14480">

(defun org-ctags-visit-buffer-or-file (name &amp;optional create)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Visit buffer named `NAME.org'.  If there is no such buffer, visit the file
with the same name if it exists.  If the file does not exist, then behavior
depends on the value of CREATE.

If CREATE is nil (default), then return nil.  Do not create a new file.
If CREATE is t, create the new file and visit it.
If CREATE is the symbol `ask', then ask the user if they wish to create
the new file."
  (interactive)
  (let ((filename (concat (substitute-in-file-name
                           (expand-file-name name))
                          ".org")))
    (cond
     ((get-buffer (concat name ".org"))
      ;; Buffer is already open
      (switch-to-buffer (get-buffer (concat name ".org"))))
     ((file-exists-p filename)
      ;; File exists but is not open --&gt; open it
      (message "Opening existing org file `%S'..."
               filename)
      (org-open-file filename t))
     ((or (eql create t)
          (and (eql create 'ask)
               (y-or-n-p (format "File `%s.org' not found; create?" name))))
      (org-ctags-open-file filename name))
     (t ;; File does not exist, and we don't want to create it.
      nil))))
</t>
<t tx="ekr.20100929212226.14481">

(defun org-ctags-ask-visit-buffer-or-file (name)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Wrapper for org-ctags-visit-buffer-or-file, which ensures the user is
asked before creating a new file."
  (org-ctags-visit-buffer-or-file name 'ask))
</t>
<t tx="ekr.20100929212226.14482">

(defun org-ctags-append-topic (name &amp;optional narrowp)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Append a new toplevel heading to the end of the current buffer. The
@verbatim
heading contains NAME surrounded by &lt;&lt;angular brackets&gt;&gt;, thus making
the heading a destination for the tag `NAME'."
  (interactive "sTopic: ")
  (widen)
  (goto-char (point-max))
  (newline 2)
  (message "Adding topic in buffer %s" (buffer-name))
  (insert (org-ctags-string-search-and-replace
           "%t" (capitalize name) org-ctags-new-topic-template))
  (backward-char 4)
  (org-update-radio-target-regexp)
  (end-of-line)
  (forward-line 2)
  (when narrowp
    ;;(org-tree-to-indirect-buffer 1)  ;; opens new frame
    (org-narrow-to-subtree))
  t)
</t>
<t tx="ekr.20100929212226.14483">

(defun org-ctags-ask-append-topic (name &amp;optional narrowp)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Wrapper for org-ctags-append-topic, which first asks the user if they want
to append a new topic."
  (if (y-or-n-p (format "Topic `%s' not found; append to end of buffer?"
                        name))
      (org-ctags-append-topic name narrowp)
    nil))
</t>
<t tx="ekr.20100929212226.14484">

(defun org-ctags-rebuild-tags-file-then-find-tag (name)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Like ORG-CTAGS-FIND-TAG, but calls the external ctags program first,
to rebuild (update) the TAGS file."
  (unless tags-file-name
    (call-interactively (visit-tags-table)))
  (when (buffer-file-name)
    (org-ctags-create-tags))
  (org-ctags-find-tag name))
</t>
<t tx="ekr.20100929212226.14485">

(defun org-ctags-ask-rebuild-tags-file-then-find-tag (name)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Wrapper for org-ctags-rebuild-tags-file-then-find-tag."
  (if (and (buffer-file-name)
             (y-or-n-p
              (format
               "Tag `%s' not found.  Rebuild table `%s/TAGS' and look again?"
               name
               (file-name-directory (buffer-file-name)))))
    (org-ctags-rebuild-tags-file-then-find-tag name)
    nil))
</t>
<t tx="ekr.20100929212226.14486">

(defun org-ctags-fail-silently (name)
  "This function is intended to be used in ORG-OPEN-LINK-FUNCTIONS.
Put as the last function in the list if you want to prevent org's default
behavior of free text search."
  t)
</t>
<t tx="ekr.20100929212226.14487">

;;; User-visible functions ===================================================


(defun org-ctags-create-tags (&amp;optional directory-name)
  "(Re)create tags file in the directory of the active buffer.
The file will contain tag definitions for all the files in the
directory and its subdirectories which are recognized by ctags.
This will include files ending in `.org' as well as most other
source files (.C, .H, .EL, .LISP, etc).  All the resulting tags
end up in one file, called TAGS, located in the directory.  This
function may take several seconds to finish if the directory or
its subdirectories contain large numbers of taggable files."
  (interactive)
  (assert (buffer-file-name))
  (let ((dir-name (or directory-name
                      (file-name-directory (buffer-file-name))))
        (exitcode nil))
    (save-excursion
      (setq exitcode
            (shell-command
             (format (concat "%s --langdef=orgmode --langmap=orgmode:.org "
                             "--regex-orgmode=\"%s\" -f \"%s\" -e -R \"%s\"")
                     org-ctags-path-to-ctags
                     org-ctags-tag-regexp
                     (expand-file-name (concat dir-name "/TAGS"))
                     (expand-file-name (concat dir-name "/*")))))
      (cond
       ((eql 0 exitcode)
        (set (make-local-variable 'org-ctags-tag-list)
             (org-ctags-all-tags-in-current-tags-table)))
       (t
        ;; This seems to behave differently on Linux, so just ignore
        ;; error codes for now
        ;;(error "Calling ctags executable resulted in error code: %s"
        ;;       exitcode)
        nil)))))
</t>
<t tx="ekr.20100929212226.14488">

(defvar org-ctags-find-tag-history nil
  "History of tags visited by org-ctags-find-tag-interactive.")

(defun org-ctags-find-tag-interactive ()
  "Prompt for the name of a tag, with autocompletion, then visit the named tag.
Uses `ido-mode' if available.
If the user enters a string that does not match an existing tag, create
a new topic."
  (interactive)
  (let* ((completing-read-fn (if (fboundp 'ido-completing-read)
                                 'ido-completing-read
                               'completing-read))
         (tag (funcall completing-read-fn "Topic: " org-ctags-tag-list
                       nil 'confirm nil 'org-ctags-find-tag-history)))
    (when tag
      (cond
       ((member tag org-ctags-tag-list)
        ;; Existing tag
        (push tag org-ctags-find-tag-history)
        (find-tag tag))
       (t
        ;; New tag
        (run-hook-with-args-until-success
        'org-open-link-functions tag))))))
</t>
<t tx="ekr.20100929212226.14489"></t>
<t tx="ekr.20100929212226.14490">@language lisp
@tabwidth -4
@others

(provide 'org-docbook)

;; arch-tag: a24a127c-d365-4c2a-9e9b-f7dcb0ebfdc3
;;; org-docbook.el ends here
</t>
<t tx="ekr.20100929212226.14491">;;; org-docbook.el --- DocBook exporter for org-mode
;;
;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;;
;; Emacs Lisp Archive Entry
;; Filename: org-docbook.el
;; Version: 7.01h
;; Author: Baoqiu Cui &lt;cbaoqiu AT yahoo DOT com&gt;
;; Maintainer: Baoqiu Cui &lt;cbaoqiu AT yahoo DOT com&gt;
;; Keywords: org, wp, docbook
;; Description: Converts an org-mode buffer into DocBook
;; URL:

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:
;;
;; This library implements a DocBook exporter for org-mode.  The basic
;; idea and design is very similar to what `org-export-as-html' has.
;; Code prototype was also started with `org-export-as-html'.
;;
;; Put this file into your load-path and the following line into your
;; ~/.emacs:
;;
;;   (require 'org-docbook)
;;
;; The interactive functions are similar to those of the HTML and LaTeX
;; exporters:
;;
;; M-x `org-export-as-docbook'
;; M-x `org-export-as-docbook-pdf'
;; M-x `org-export-as-docbook-pdf-and-open'
;; M-x `org-export-as-docbook-batch'
;; M-x `org-export-as-docbook-to-buffer'
;; M-x `org-export-region-as-docbook'
;; M-x `org-replace-region-by-docbook'
;;
;; Note that, in order to generate PDF files using the DocBook XML files
;; created by DocBook exporter, the following two variables have to be
;; set based on what DocBook tools you use for XSLT processor and XSL-FO
;; processor:
;;
;;   org-export-docbook-xslt-proc-command
;;   org-export-docbook-xsl-fo-proc-command
;;
;; Check the document of these two variables to see examples of how they
;; can be set.
;;
;; If the Org file to be exported contains special characters written in
;; TeX-like syntax, like \alpha and \beta, you need to include the right
;; entity file(s) in the DOCTYPE declaration for the DocBook XML file.
;; This is required to make the DocBook XML file valid.  The DOCTYPE
;; declaration string can be set using the following variable:
;;
;;   org-export-docbook-doctype
;;
;;; Code:

(eval-when-compile
  (require 'cl))

(require 'footnote)
(require 'org)
(require 'org-exp)
(require 'org-html)
(require 'format-spec)

;;; Variables:

(defvar org-docbook-para-open nil)
(defvar org-export-docbook-inline-images t)
(defvar org-export-docbook-link-org-files-as-docbook nil)

(declare-function org-id-find-id-file "org-id" (id))

;;; User variables:

(defgroup org-export-docbook nil
  "Options for exporting Org-mode files to DocBook."
  :tag "Org Export DocBook"
  :group 'org-export)

(defcustom org-export-docbook-extension ".xml"
  "Extension of DocBook XML files."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-header "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n"
  "Header of DocBook XML files."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-doctype nil
  "DOCTYPE declaration string for DocBook XML files.
This can be used to include entities that are needed to handle
special characters in Org files.

For example, if the Org file to be exported contains XHTML
entities, you can set this variable to:

\"&lt;!DOCTYPE article [
&lt;!ENTITY % xhtml1-symbol PUBLIC
\"-//W3C//ENTITIES Symbol for HTML//EN//XML\"
\"http://www.w3.org/2003/entities/2007/xhtml1-symbol.ent\"
&gt;
%xhtml1-symbol;
]&gt;
\"

If you want to process DocBook documents without an Internet
connection, it is suggested that you download the required entity
file(s) and use system identifier(s) (external files) in the
DOCTYPE declaration."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-article-header "&lt;article xmlns=\"http://docbook.org/ns/docbook\"
         xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"5.0\" xml:lang=\"en\"&gt;"
  "Article header of DocBook XML files."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-section-id-prefix "sec-"
  "Prefix of section IDs used during exporting.
This can be set before exporting to avoid same set of section IDs
being used again and again, which can be a problem when multiple
people work on the same document."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-footnote-id-prefix "fn-"
  "The prefix of footnote IDs used during exporting.
Like `org-export-docbook-section-id-prefix', this variable can help
avoid same set of footnote IDs being used multiple times."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-emphasis-alist
  `(("*" "&lt;emphasis role=\"bold\"&gt;" "&lt;/emphasis&gt;")
    ("/" "&lt;emphasis&gt;" "&lt;/emphasis&gt;")
    ("_" "&lt;emphasis role=\"underline\"&gt;" "&lt;/emphasis&gt;")
    ("=" "&lt;code&gt;" "&lt;/code&gt;")
    ("~" "&lt;literal&gt;" "&lt;/literal&gt;")
    ("+" "&lt;emphasis role=\"strikethrough\"&gt;" "&lt;/emphasis&gt;"))
  "A list of DocBook expressions to convert emphasis fontifiers.
Each element of the list is a list of three elements.
The first element is the character used as a marker for fontification.
The second element is a formatting string to wrap fontified text with.
The third element decides whether to protect converted text from other
conversions."
  :group 'org-export-docbook
  :type 'alist)

(defcustom org-export-docbook-default-image-attributes
  `(("align" . "\"center\"")
    ("valign". "\"middle\""))
  "Alist of default DocBook image attributes.
These attributes will be inserted into element &lt;imagedata&gt; by
default, but users can override them using `#+ATTR_DocBook:'."
  :group 'org-export-docbook
  :type 'alist)

(defcustom org-export-docbook-inline-image-extensions
  '("jpeg" "jpg" "png" "gif" "svg")
  "Extensions of image files that can be inlined into DocBook."
  :group 'org-export-docbook
  :type '(repeat (string :tag "Extension")))

(defcustom org-export-docbook-coding-system nil
  "Coding system for DocBook XML files."
  :group 'org-export-docbook
  :type 'coding-system)

(defcustom org-export-docbook-xslt-stylesheet nil
  "File name of the XSLT stylesheet used by DocBook exporter.
This XSLT stylesheet is used by
`org-export-docbook-xslt-proc-command' to generate the Formatting
Object (FO) files.  You can use either `fo/docbook.xsl' that
comes with DocBook, or any customization layer you may have."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-xslt-proc-command nil
  "Format of XSLT processor command used by DocBook exporter.
This command is used to process a DocBook XML file to generate
the Formatting Object (FO) file.

The value of this variable should be a format control string that
includes three arguments: `%i', `%o', and `%s'.  During exporting
time, `%i' is replaced by the input DocBook XML file name, `%o'
is replaced by the output FO file name, and `%s' is replaced by
`org-export-docbook-xslt-stylesheet' (or the #+XSLT option if it
is specified in the Org file).

For example, if you use Saxon as the XSLT processor, you may want
to set the variable to

  \"java com.icl.saxon.StyleSheet -o %o %i %s\"

If you use Xalan, you can set it to

  \"java org.apache.xalan.xslt.Process -out %o -in %i -xsl %s\"

For xsltproc, the following string should work:

  \"xsltproc --output %o %s %i\"

You can include additional stylesheet parameters in this command.
Just make sure that they meet the syntax requirement of each
processor."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-xsl-fo-proc-command nil
  "Format of XSL-FO processor command used by DocBook exporter.
This command is used to process a Formatting Object (FO) file to
generate the PDF file.

The value of this variable should be a format control string that
includes two arguments: `%i' and `%o'.  During exporting time,
`%i' is replaced by the input FO file name, and `%o' is replaced
by the output PDF file name.

For example, if you use FOP as the XSL-FO processor, you can set
the variable to

  \"fop %i %o\""
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-keywords-markup "&lt;literal&gt;%s&lt;/literal&gt;"
  "A printf format string to be applied to keywords by DocBook exporter."
  :group 'org-export-docbook
  :type 'string)

(defcustom org-export-docbook-timestamp-markup "&lt;emphasis&gt;%s&lt;/emphasis&gt;"
  "A printf format string to be applied to time stamps by DocBook exporter."
  :group 'org-export-docbook
  :type 'string)

;;; Hooks

(defvar org-export-docbook-final-hook nil
  "Hook run at the end of DocBook export, in the new buffer.")

</t>
<t tx="ekr.20100929212226.14492">;;; Autoload functions:

;;;###autoload
(defun org-export-as-docbook-batch ()
  "Call `org-export-as-docbook' in batch style.
This function can be used in batch processing.

For example:

$ emacs --batch
        --load=$HOME/lib/emacs/org.el
        --visit=MyOrgFile.org --funcall org-export-as-docbook-batch"
  (org-export-as-docbook 'hidden))
</t>
<t tx="ekr.20100929212226.14493">
;;;###autoload
(defun org-export-as-docbook-to-buffer ()
  "Call `org-export-as-docbook' with output to a temporary buffer.
No file is created."
  (interactive)
  (org-export-as-docbook nil nil "*Org DocBook Export*")
  (when org-export-show-temporary-export-buffer
    (switch-to-buffer-other-window "*Org DocBook Export*")))
</t>
<t tx="ekr.20100929212226.14494">
;;;###autoload
(defun org-replace-region-by-docbook (beg end)
  "Replace the region from BEG to END with its DocBook export.
It assumes the region has `org-mode' syntax, and then convert it to
DocBook.  This can be used in any buffer.  For example, you could
write an itemized list in `org-mode' syntax in an DocBook buffer and
then use this command to convert it."
  (interactive "r")
  (let (reg docbook buf)
    (save-window-excursion
      (if (org-mode-p)
      (setq docbook (org-export-region-as-docbook
             beg end t 'string))
    (setq reg (buffer-substring beg end)
          buf (get-buffer-create "*Org tmp*"))
    (with-current-buffer buf
      (erase-buffer)
      (insert reg)
      (org-mode)
      (setq docbook (org-export-region-as-docbook
             (point-min) (point-max) t 'string)))
    (kill-buffer buf)))
    (delete-region beg end)
    (insert docbook)))
</t>
<t tx="ekr.20100929212226.14495">
;;;###autoload
(defun org-export-region-as-docbook (beg end &amp;optional body-only buffer)
  "Convert region from BEG to END in `org-mode' buffer to DocBook.
If prefix arg BODY-ONLY is set, omit file header and footer and
only produce the region of converted text, useful for
cut-and-paste operations.  If BUFFER is a buffer or a string,
use/create that buffer as a target of the converted DocBook.  If
BUFFER is the symbol `string', return the produced DocBook as a
string and leave not buffer behind.  For example, a Lisp program
could call this function in the following way:

  (setq docbook (org-export-region-as-docbook beg end t 'string))

When called interactively, the output buffer is selected, and shown
in a window.  A non-interactive call will only return the buffer."
  (interactive "r\nP")
  (when (interactive-p)
    (setq buffer "*Org DocBook Export*"))
  (let ((transient-mark-mode t)
    (zmacs-regions t)
    rtn)
    (goto-char end)
    (set-mark (point)) ;; To activate the region
    (goto-char beg)
    (setq rtn (org-export-as-docbook
           nil nil
           buffer body-only))
    (if (fboundp 'deactivate-mark) (deactivate-mark))
    (if (and (interactive-p) (bufferp rtn))
    (switch-to-buffer-other-window rtn)
      rtn)))
</t>
<t tx="ekr.20100929212226.14496">
;;;###autoload
(defun org-export-as-docbook-pdf (&amp;optional hidden ext-plist
                        to-buffer body-only pub-dir)
  "Export as DocBook XML file, and generate PDF file."
  (interactive "P")
  (if (or (not org-export-docbook-xslt-proc-command)
      (not (string-match "%[ios].+%[ios].+%[ios]" org-export-docbook-xslt-proc-command)))
      (error "XSLT processor command is not set correctly"))
  (if (or (not org-export-docbook-xsl-fo-proc-command)
      (not (string-match "%[io].+%[io]" org-export-docbook-xsl-fo-proc-command)))
      (error "XSL-FO processor command is not set correctly"))
  (message "Exporting to PDF...")
  (let* ((wconfig (current-window-configuration))
     (opt-plist
      (org-export-process-option-filters
       (org-combine-plists (org-default-export-plist)
                   ext-plist
                   (org-infile-export-plist))))
     (docbook-buf (org-export-as-docbook hidden ext-plist
                         to-buffer body-only pub-dir))
     (filename (buffer-file-name docbook-buf))
     (base (file-name-sans-extension filename))
     (fofile (concat base ".fo"))
     (pdffile (concat base ".pdf")))
    (and (file-exists-p pdffile) (delete-file pdffile))
    (message "Processing DocBook XML file...")
    (shell-command (format-spec org-export-docbook-xslt-proc-command
                (format-spec-make
                 ?i (shell-quote-argument filename)
                 ?o (shell-quote-argument fofile)
                 ?s (shell-quote-argument
                     (or (plist-get opt-plist :xslt)
                     org-export-docbook-xslt-stylesheet)))))
    (shell-command (format-spec org-export-docbook-xsl-fo-proc-command
                (format-spec-make
                 ?i (shell-quote-argument fofile)
                 ?o (shell-quote-argument pdffile))))
    (message "Processing DocBook file...done")
    (if (not (file-exists-p pdffile))
    (error "PDF file was not produced")
      (set-window-configuration wconfig)
      (message "Exporting to PDF...done")
      pdffile)))
</t>
<t tx="ekr.20100929212226.14497">
;;;###autoload
(defun org-export-as-docbook-pdf-and-open ()
  "Export as DocBook XML file, generate PDF file, and open it."
  (interactive)
  (let ((pdffile (org-export-as-docbook-pdf)))
    (if pdffile
    (org-open-file pdffile)
      (error "PDF file was not produced"))))
</t>
<t tx="ekr.20100929212226.14498">
;;;###autoload
(defun org-export-as-docbook (&amp;optional hidden ext-plist
                    to-buffer body-only pub-dir)
  "Export the current buffer as a DocBook file.
If there is an active region, export only the region.  When
HIDDEN is obsolete and does nothing.  EXT-PLIST is a
property list with external parameters overriding org-mode's
default settings, but still inferior to file-local settings.
When TO-BUFFER is non-nil, create a buffer with that name and
export to that buffer.  If TO-BUFFER is the symbol `string',
don't leave any buffer behind but just return the resulting HTML
as a string.  When BODY-ONLY is set, don't produce the file
header and footer, simply return the content of the document (all
top-level sections).  When PUB-DIR is set, use this as the
publishing directory."
  (interactive "P")
  (run-hooks 'org-export-first-hook)

  ;; Make sure we have a file name when we need it.
  (when (and (not (or to-buffer body-only))
         (not buffer-file-name))
    (if (buffer-base-buffer)
    (org-set-local 'buffer-file-name
               (with-current-buffer (buffer-base-buffer)
             buffer-file-name))
      (error "Need a file name to be able to export")))

  (message "Exporting...")
  (setq-default org-todo-line-regexp org-todo-line-regexp)
  (setq-default org-deadline-line-regexp org-deadline-line-regexp)
  (setq-default org-done-keywords org-done-keywords)
  (setq-default org-maybe-keyword-time-regexp org-maybe-keyword-time-regexp)
  (let* ((opt-plist
      (org-export-process-option-filters
       (org-combine-plists (org-default-export-plist)
                   ext-plist
                   (org-infile-export-plist))))
     (link-validate (plist-get opt-plist :link-validation-function))
     valid
     (odd org-odd-levels-only)
     (region-p (org-region-active-p))
     (rbeg (and region-p (region-beginning)))
     (rend (and region-p (region-end)))
     (subtree-p
      (if (plist-get opt-plist :ignore-subtree-p)
          nil
        (when region-p
          (save-excursion
        (goto-char rbeg)
        (and (org-at-heading-p)
             (&gt;= (org-end-of-subtree t t) rend))))))
     (level-offset (if subtree-p
               (save-excursion
                 (goto-char rbeg)
                 (+ (funcall outline-level)
                (if org-odd-levels-only 1 0)))
             0))
     (opt-plist (setq org-export-opt-plist
              (if subtree-p
                  (org-export-add-subtree-options opt-plist rbeg)
                opt-plist)))
     ;; The following two are dynamically scoped into other
     ;; routines below.
     (org-current-export-dir
      (or pub-dir (org-export-directory :docbook opt-plist)))
     (org-current-export-file buffer-file-name)
     (level 0) (line "") (origline "") txt todo
     (filename (if to-buffer nil
             (expand-file-name
              (concat
               (file-name-sans-extension
            (or (and subtree-p
                 (org-entry-get (region-beginning)
                        "EXPORT_FILE_NAME" t))
                (file-name-nondirectory buffer-file-name)))
               org-export-docbook-extension)
              (file-name-as-directory
               (or pub-dir (org-export-directory :docbook opt-plist))))))
     (current-dir (if buffer-file-name
              (file-name-directory buffer-file-name)
            default-directory))
     (buffer (if to-buffer
             (cond
              ((eq to-buffer 'string) (get-buffer-create "*Org DocBook Export*"))
              (t (get-buffer-create to-buffer)))
           (find-file-noselect filename)))
     ;; org-levels-open is a global variable
     (org-levels-open (make-vector org-level-max nil))
     (date (plist-get opt-plist :date))
     (author (or (plist-get opt-plist :author)
             user-full-name))
     (email (plist-get opt-plist :email))
     firstname othername surname
     (title (or (and subtree-p (org-export-get-title-from-subtree))
            (plist-get opt-plist :title)
            (and (not
              (plist-get opt-plist :skip-before-1st-heading))
             (org-export-grab-title-from-buffer))
            (and buffer-file-name
             (file-name-sans-extension
              (file-name-nondirectory buffer-file-name)))
            "UNTITLED"))
     ;; We will use HTML table formatter to export tables to DocBook
     ;; format, so need to set html-table-tag here.
     (html-table-tag (plist-get opt-plist :html-table-tag))
     (quote-re0   (concat "^[ \t]*" org-quote-string "\\&gt;"))
     (quote-re    (concat "^\\(\\*+\\)\\([ \t]+" org-quote-string "\\&gt;\\)"))
     (inquote     nil)
     (infixed     nil)
     (inverse     nil)
     (in-local-list nil)
     (local-list-type nil)
     (local-list-indent nil)
     (llt org-plain-list-ordered-item-terminator)
     (email (plist-get opt-plist :email))
     (language (plist-get opt-plist :language))
     (lang-words  nil)
     cnt
     (start 0)
     (coding-system (and (boundp 'buffer-file-coding-system)
                 buffer-file-coding-system))
     (coding-system-for-write (or org-export-docbook-coding-system
                      coding-system))
     (save-buffer-coding-system (or org-export-docbook-coding-system
                    coding-system))
     (charset (and coding-system-for-write
               (fboundp 'coding-system-get)
               (coding-system-get coding-system-for-write
                      'mime-charset)))
     (region
      (buffer-substring
       (if region-p (region-beginning) (point-min))
       (if region-p (region-end) (point-max))))
     (lines
      (org-split-string
       (org-export-preprocess-string
        region
        :emph-multiline t
        :for-docbook t
        :skip-before-1st-heading
        (plist-get opt-plist :skip-before-1st-heading)
        :drawers (plist-get opt-plist :drawers)
        :todo-keywords (plist-get opt-plist :todo-keywords)
        :tags (plist-get opt-plist :tags)
        :priority (plist-get opt-plist :priority)
        :footnotes (plist-get opt-plist :footnotes)
        :timestamps (plist-get opt-plist :timestamps)
        :archived-trees
        (plist-get opt-plist :archived-trees)
        :select-tags (plist-get opt-plist :select-tags)
        :exclude-tags (plist-get opt-plist :exclude-tags)
        :add-text
        (plist-get opt-plist :text)
        :LaTeX-fragments
        (plist-get opt-plist :LaTeX-fragments))
       "[\r\n]"))
     ;; Use literal output to show check boxes.
     (checkbox-start
      (nth 1 (assoc "=" org-export-docbook-emphasis-alist)))
     (checkbox-end
      (nth 2 (assoc "=" org-export-docbook-emphasis-alist)))
     table-open type
     table-buffer table-orig-buffer
     ind item-type starter didclose
     rpl path attr caption label desc descp desc1 desc2 link
     fnc item-tag initial-number
     footref-seen footnote-list
     id-file
     )

    ;; Fine detailed info about author name.
    (if (string-match "\\([^ ]+\\) \\(.+ \\)?\\([^ ]+\\)" author)
    (progn
      (setq firstname (match-string 1 author)
        othername (or (match-string 2 author) "")
        surname (match-string 3 author))))

    ;; Get all footnote text.
    (setq footnote-list
      (org-export-docbook-get-footnotes lines))

    (let ((inhibit-read-only t))
      (org-unmodified
       (remove-text-properties (point-min) (point-max)
                   '(:org-license-to-kill t))))

    (setq org-min-level (org-get-min-level lines level-offset))
    (setq org-last-level org-min-level)
    (org-init-section-numbers)

    ;; Get and save the date.
    (cond
     ((and date (string-match "%" date))
      (setq date (format-time-string date)))
     (date)
     (t (setq date (format-time-string "%Y-%m-%d %T %Z"))))

    ;; Get the language-dependent settings
    (setq lang-words (or (assoc language org-export-language-setup)
             (assoc "en" org-export-language-setup)))

    ;; Switch to the output buffer.  Use fundamental-mode for now.  We
    ;; could turn on nXML mode later and do some indentation.
    (set-buffer buffer)
    (let ((inhibit-read-only t)) (erase-buffer))
    (fundamental-mode)
    (org-install-letbind)

    (and (fboundp 'set-buffer-file-coding-system)
     (set-buffer-file-coding-system coding-system-for-write))

    ;; The main body...
    (let ((case-fold-search nil)
      (org-odd-levels-only odd))

      ;; Create local variables for all options, to make sure all called
      ;; functions get the correct information
      (mapc (lambda (x)
          (set (make-local-variable (nth 2 x))
           (plist-get opt-plist (car x))))
        org-export-plist-vars)

      ;; Insert DocBook file header, title, and author info.
      (unless body-only
    (insert org-export-docbook-header)
    (if org-export-docbook-doctype
        (insert org-export-docbook-doctype))
    (insert "&lt;!-- Date: " date " --&gt;\n")
    (insert (format "&lt;!-- DocBook XML file generated by Org-mode %s Emacs %s --&gt;\n"
            org-version emacs-major-version))
    (insert org-export-docbook-article-header)
    (insert (format
         "\n  &lt;title&gt;%s&lt;/title&gt;
  &lt;info&gt;
    &lt;author&gt;
      &lt;personname&gt;
        &lt;firstname&gt;%s&lt;/firstname&gt; &lt;othername&gt;%s&lt;/othername&gt; &lt;surname&gt;%s&lt;/surname&gt;
      &lt;/personname&gt;
      %s
    &lt;/author&gt;
  &lt;/info&gt;\n"
         (org-docbook-expand title)
         firstname othername surname
         (if (and org-export-email-info
              email (string-match "\\S-" email))
             (concat "&lt;email&gt;" email "&lt;/email&gt;") "")
         )))

      (org-init-section-numbers)

      (org-export-docbook-open-para)

      ;; Loop over all the lines...
      (while (setq line (pop lines) origline line)
    (catch 'nextline

      ;; End of quote section?
      (when (and inquote (string-match "^\\*+ " line))
        (insert "]]&gt;&lt;/programlisting&gt;\n")
        (org-export-docbook-open-para)
        (setq inquote nil))
      ;; Inside a quote section?
      (when inquote
        (insert (org-docbook-protect line) "\n")
        (throw 'nextline nil))

      ;; Fixed-width, verbatim lines (examples)
      (when (and org-export-with-fixed-width
             (string-match "^[ \t]*:\\(\\([ \t]\\|$\\)\\(.*\\)\\)" line))
        (when (not infixed)
          (setq infixed t)
          (org-export-docbook-close-para-maybe)
          (insert "&lt;programlisting&gt;&lt;![CDATA["))
        (insert (match-string 3 line) "\n")
        (when (or (not lines)
              (not (string-match "^[ \t]*\\(:.*\\)"
                     (car lines))))
          (setq infixed nil)
          (insert "]]&gt;&lt;/programlisting&gt;\n")
          (org-export-docbook-open-para))
        (throw 'nextline nil))

      (org-export-docbook-close-lists-maybe line)

      ;; Protected HTML
      (when (get-text-property 0 'org-protected line)
        (let (par (ind (get-text-property 0 'original-indentation line)))
          (when (re-search-backward
             "\\(&lt;para&gt;\\)\\([ \t\r\n]*\\)\\=" (- (point) 100) t)
        (setq par (match-string 1))
        (replace-match "\\2\n"))
          (insert line "\n")
          (while (and lines
              (or (= (length (car lines)) 0)
                  (not ind)
                  (equal ind (get-text-property 0 'original-indentation (car lines))))
              (or (= (length (car lines)) 0)
                  (get-text-property 0 'org-protected (car lines))))
        (insert (pop lines) "\n"))
          (and par (insert "&lt;para&gt;\n")))
        (throw 'nextline nil))

      ;; Start of block quotes and verses
      (when (or (equal "ORG-BLOCKQUOTE-START" line)
            (and (equal "ORG-VERSE-START" line)
             (setq inverse t)))
        (org-export-docbook-close-para-maybe)
        (insert "&lt;blockquote&gt;")
        ;; Check whether attribution for this blockquote exists.
        (let (tmp1
          attribution
          (end (if inverse "ORG-VERSE-END" "ORG-BLOCKQUOTE-END"))
          (quote-lines nil))
          (while (and (setq tmp1 (pop lines))
              (not (equal end tmp1)))
        (push tmp1 quote-lines))
          (push tmp1 lines)         ; Put back quote end mark
          ;; Check the last line in the quote to see if it contains
          ;; the attribution.
          (setq tmp1 (pop quote-lines))
          (if (string-match "\\(^.*\\)\\(--[ \t]+\\)\\(.+\\)$" tmp1)
          (progn
            (setq attribution (match-string 3 tmp1))
            (when (save-match-data
                (string-match "[^ \t]" (match-string 1 tmp1)))
              (push (match-string 1 tmp1) lines)))
        (push tmp1 lines))
          (while (setq tmp1 (pop quote-lines))
        (push tmp1 lines))
          (when attribution
        (insert "&lt;attribution&gt;" attribution "&lt;/attribution&gt;")))
        ;; Insert &lt;literallayout&gt; for verse.
        (if inverse
        (insert "\n&lt;literallayout&gt;")
          (org-export-docbook-open-para))
        (throw 'nextline nil))

      ;; End of block quotes
      (when (equal "ORG-BLOCKQUOTE-END" line)
        (org-export-docbook-close-para-maybe)
        (insert "&lt;/blockquote&gt;\n")
        (org-export-docbook-open-para)
        (throw 'nextline nil))

      ;; End of verses
      (when (equal "ORG-VERSE-END" line)
        (insert "&lt;/literallayout&gt;\n&lt;/blockquote&gt;\n")
        (org-export-docbook-open-para)
        (setq inverse nil)
        (throw 'nextline nil))

      ;; Text centering.  Element &lt;para role="centered"&gt; does not
      ;; seem to work with FOP, so for now we use &lt;informaltable&gt; to
      ;; center the text, which can contain multiple paragraphs.
      (when (equal "ORG-CENTER-START" line)
        (org-export-docbook-close-para-maybe)
        (insert "&lt;informaltable frame=\"none\" colsep=\"0\" rowsep=\"0\"&gt;\n"
            "&lt;tgroup align=\"center\" cols=\"1\"&gt;\n"
            "&lt;tbody&gt;&lt;row&gt;&lt;entry&gt;\n")
        (org-export-docbook-open-para)
        (throw 'nextline nil))

      (when (equal "ORG-CENTER-END" line)
        (org-export-docbook-close-para-maybe)
        (insert "&lt;/entry&gt;&lt;/row&gt;&lt;/tbody&gt;\n"
            "&lt;/tgroup&gt;\n&lt;/informaltable&gt;\n")
        (org-export-docbook-open-para)
        (throw 'nextline nil))

      ;; Make targets to anchors.  Note that currently FOP does not
      ;; seem to support &lt;anchor&gt; tags when generating PDF output,
      ;; but this can be used in DocBook --&gt; HTML conversion.
      (setq start 0)
      (while (string-match
@verbatim
          "&lt;&lt;&lt;?\\([^&lt;&gt;]*\\)&gt;&gt;&gt;?\\((INVISIBLE)\\)?[ \t]*\n?" line start)
        (cond
         ((get-text-property (match-beginning 1) 'org-protected line)
          (setq start (match-end 1)))
         ((match-end 2)
          (setq line (replace-match
              (format "@&lt;anchor xml:id=\"%s\"/&gt;"
                  (org-solidify-link-text (match-string 1 line)))
              t t line)))
         (t
          (setq line (replace-match
              (format "@&lt;anchor xml:id=\"%s\"/&gt;"
                  (org-solidify-link-text (match-string 1 line)))
              t t line)))))

      ;; Put time stamps and related keywords into special mark-up
      ;; elements.
      (setq line (org-export-docbook-handle-time-stamps line))

      ;; Replace "&amp;", "&lt;" and "&gt;" by "&amp;amp;", "&amp;lt;" and "&amp;gt;".
      ;; Handle @&lt;..&gt; HTML tags (replace "@&amp;gt;..&amp;lt;" by "&lt;..&gt;").
      ;; Also handle sub_superscripts and check boxes.
      (or (string-match org-table-hline-regexp line)
          (setq line (org-docbook-expand line)))

      ;; Format the links
      (setq start 0)
      (while (string-match org-bracket-link-analytic-regexp++ line start)
        (setq start (match-beginning 0))
        (setq path (save-match-data (org-link-unescape
                     (match-string 3 line))))
        (setq type (cond
            ((match-end 2) (match-string 2 line))
            ((save-match-data
               (or (file-name-absolute-p path)
                   (string-match "^\\.\\.?/" path)))
             "file")
            (t "internal")))
        (setq path (org-extract-attributes (org-link-unescape path)))
        (setq attr (get-text-property 0 'org-attributes path)
          caption (get-text-property 0 'org-caption path)
          label (get-text-property 0 'org-label path))
        (setq desc1 (if (match-end 5) (match-string 5 line))
          desc2 (if (match-end 2) (concat type ":" path) path)
          descp (and desc1 (not (equal desc1 desc2)))
          desc (or desc1 desc2))
        ;; Make an image out of the description if that is so wanted
        (when (and descp (org-file-image-p
                  desc org-export-docbook-inline-image-extensions))
          (save-match-data
        (if (string-match "^file:" desc)
            (setq desc (substring desc (match-end 0))))))
        ;; FIXME: do we need to unescape here somewhere?
        (cond
         ((equal type "internal")
          (setq rpl (format "&lt;link linkend=\"%s\"&gt;%s&lt;/link&gt;"
                (org-solidify-link-text
                 (save-match-data (org-link-unescape path)) nil)
                (org-export-docbook-format-desc desc))))
         ((and (equal type "id")
           (setq id-file (org-id-find-id-file path)))
          ;; This is an id: link to another file (if it was the same file,
          ;; it would have become an internal link...)
          (save-match-data
        (setq id-file (file-relative-name
                   id-file (file-name-directory org-current-export-file)))
        (setq id-file (concat (file-name-sans-extension id-file)
                      org-export-docbook-extension))
        (setq rpl (format "&lt;link xlink:href=\"%s#%s\"&gt;%s&lt;/link&gt;"
                  id-file path (org-export-docbook-format-desc desc)))))
         ((member type '("http" "https"))
          ;; Standard URL, just check if we need to inline an image
          (if (and (or (eq t org-export-docbook-inline-images)
               (and org-export-docbook-inline-images (not descp)))
               (org-file-image-p
            path org-export-docbook-inline-image-extensions))
          (setq rpl (org-export-docbook-format-image
                 (concat type ":" path)))
        (setq link (concat type ":" path))
        (setq rpl (format "&lt;link xlink:href=\"%s\"&gt;%s&lt;/link&gt;"
                  (org-export-html-format-href link)
                  (org-export-docbook-format-desc desc)))
        ))
         ((member type '("ftp" "mailto" "news"))
          ;; Standard URL
          (setq link (concat type ":" path))
          (setq rpl (format "&lt;link xlink:href=\"%s\"&gt;%s&lt;/link&gt;"
                (org-export-html-format-href link)
                (org-export-docbook-format-desc desc))))
         ((string= type "coderef")
          (setq rpl (format (org-export-get-coderef-format path (and descp desc))
                (cdr (assoc path org-export-code-refs)))))
         ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
          ;; The link protocol has a function for format the link
          (setq rpl
            (save-match-data
              (funcall fnc (org-link-unescape path) desc1 'html))))

         ((string= type "file")
          ;; FILE link
          (let* ((filename path)
             (abs-p (file-name-absolute-p filename))
             thefile file-is-image-p search)
        (save-match-data
          (if (string-match "::\\(.*\\)" filename)
              (setq search (match-string 1 filename)
                filename (replace-match "" t nil filename)))
          (setq valid
            (if (functionp link-validate)
                (funcall link-validate filename current-dir)
              t))
          (setq file-is-image-p
            (org-file-image-p
             filename org-export-docbook-inline-image-extensions))
          (setq thefile (if abs-p (expand-file-name filename) filename))
          ;; Carry over the properties (expand-file-name will
          ;; discard the properties of filename)
          (add-text-properties 0 (1- (length thefile))
                       (list 'org-caption caption
                         'org-attributes attr
                         'org-label label)
                       thefile)
          (when (and org-export-docbook-link-org-files-as-docbook
                 (string-match "\\.org$" thefile))
            (setq thefile (concat (substring thefile 0
                             (match-beginning 0))
                      org-export-docbook-extension))
            (if (and search
                 ;; make sure this is can be used as target search
                 (not (string-match "^[0-9]*$" search))
                 (not (string-match "^\\*" search))
                 (not (string-match "^/.*/$" search)))
            (setq thefile (concat thefile "#"
                          (org-solidify-link-text
                           (org-link-unescape search)))))
            (when (string-match "^file:" desc)
              (setq desc (replace-match "" t t desc))
              (if (string-match "\\.org$" desc)
              (setq desc (replace-match "" t t desc))))))
        (setq rpl (if (and file-is-image-p
                   (or (eq t org-export-docbook-inline-images)
                       (and org-export-docbook-inline-images
                        (not descp))))
                  (progn
                (message "image %s %s" thefile org-docbook-para-open)
                (org-export-docbook-format-image thefile))
                (format "&lt;link xlink:href=\"%s\"&gt;%s&lt;/link&gt;"
                    thefile (org-export-docbook-format-desc desc))))
        (if (not valid) (setq rpl desc))))

         (t
          ;; Just publish the path, as default
          (setq rpl (concat "&amp;lt;" type ":"
                (save-match-data (org-link-unescape path))
                "&amp;gt;"))))
        (setq line (replace-match rpl t t line)
          start (+ start (length rpl))))

      ;; TODO items: can we do something better?!
      (if (and (string-match org-todo-line-regexp line)
           (match-beginning 2))
          (setq line
            (concat (substring line 0 (match-beginning 2))
                "[" (match-string 2 line) "]"
                (substring line (match-end 2)))))

      ;; Does this contain a reference to a footnote?
      (when org-export-with-footnotes
        (setq start 0)
        (while (string-match "\\([^* \t].*?\\)\\[\\([0-9]+\\)\\]" line start)
          (if (get-text-property (match-beginning 2) 'org-protected line)
          (setq start (match-end 2))
        (let* ((num (match-string 2 line))
               (footnote-def (assoc num footnote-list)))
          (if (assoc num footref-seen)
              (setq line (replace-match
                  (format "%s&lt;footnoteref linkend=\"%s%s\"/&gt;"
                      (match-string 1 line)
                      org-export-docbook-footnote-id-prefix num)
                  t t line))
            (setq line (replace-match
                (format "%s&lt;footnote xml:id=\"%s%s\"&gt;&lt;para&gt;%s&lt;/para&gt;&lt;/footnote&gt;"
                    (match-string 1 line)
                    org-export-docbook-footnote-id-prefix
                    num
                    (if footnote-def
                        (save-match-data
                          (org-docbook-expand (cdr footnote-def)))
                      (format "FOOTNOTE DEFINITION NOT FOUND: %s" num)))
                t t line))
            (push (cons num 1) footref-seen))))))

      (cond
       ((string-match "^\\(\\*+\\)[ \t]+\\(.*\\)" line)
        ;; This is a headline
        (setq level (org-tr-level (- (match-end 1) (match-beginning 1)
                     level-offset))
          txt (match-string 2 line))
        (if (string-match quote-re0 txt)
        (setq txt (replace-match "" t t txt)))
        (when in-local-list
          ;; Close any local lists before inserting a new header line
          (while local-list-type
        (let ((listtype (car local-list-type)))
          (org-export-docbook-close-li listtype)
          (insert (cond
               ((equal listtype "o") "&lt;/orderedlist&gt;\n")
               ((equal listtype "u") "&lt;/itemizedlist&gt;\n")
               ((equal listtype "d") "&lt;/variablelist&gt;\n"))))
        (pop local-list-type))
          (setq local-list-indent nil
            in-local-list nil))
        (org-export-docbook-level-start level txt)
        ;; QUOTES
        (when (string-match quote-re line)
          (org-export-docbook-close-para-maybe)
          (insert "&lt;programlisting&gt;&lt;![CDATA[")
          (setq inquote t)))

       ;; Tables: since version 4.3 of DocBook DTD, HTML tables are
       ;; supported.  We can use existing HTML table exporter code
       ;; here.
       ((and org-export-with-tables
         (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)" line))
        (if (not table-open)
        ;; New table starts
        (setq table-open t
              table-buffer nil
              table-orig-buffer nil))
        ;; Accumulate lines
        (setq table-buffer (cons line table-buffer)
          table-orig-buffer (cons origline table-orig-buffer))
        (when (or (not lines)
              (not (string-match "^\\([ \t]*\\)\\(|\\|\\+-+\\+\\)"
                     (car lines))))
          (setq table-open nil
            table-buffer (nreverse table-buffer)
            table-orig-buffer (nreverse table-orig-buffer))
          (org-export-docbook-close-para-maybe)
          (insert (org-export-docbook-finalize-table
               (org-format-table-html table-buffer table-orig-buffer)))))
       (t
        ;; Normal lines
        (when (string-match
           (cond
            ((eq llt t) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+[.)]\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
            ((= llt ?.) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+\\.\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
            ((= llt ?\)) "^\\([ \t]*\\)\\(\\([-+*] \\)\\|\\([0-9]+)\\) \\)?\\( *[^ \t\n\r]\\|[ \t]*$\\)")
            (t (error "Invalid value of `org-plain-list-ordered-item-terminator'")))
           line)
          (setq ind (or (get-text-property 0 'original-indentation line)
                (org-get-string-indentation line))
            item-type (if (match-beginning 4) "o" "u")
            starter (if (match-beginning 2)
                (substring (match-string 2 line) 0 -1))
            line (substring line (match-beginning 5))
            item-tag nil
            initial-number nil)
          (if (string-match "\\`\\[@start:\\([0-9]+\\)\\][ \t]?" line)
          (setq initial-number (match-string 1 line)
            line (replace-match "" t t line)))
          (if (and starter (string-match "\\(.*?\\) ::[ \t]*" line))
          (setq item-type "d"
            item-tag (match-string 1 line)
            line (substring line (match-end 0))))
          (when (and (not (equal item-type "d"))
             (not (string-match "[^ \t]" line)))
        ;; Empty line.  Pretend indentation is large.
        (setq ind (if org-empty-line-terminates-plain-lists
                  0
                (1+ (or (car local-list-indent) 1)))))
          (setq didclose nil)
          (while (and in-local-list
              (or (and (= ind (car local-list-indent))
                   (not starter))
                  (&lt; ind (car local-list-indent))))
        (setq didclose t)
        (let ((listtype (car local-list-type)))
          (org-export-docbook-close-li listtype)
          (insert (cond
               ((equal listtype "o") "&lt;/orderedlist&gt;\n")
               ((equal listtype "u") "&lt;/itemizedlist&gt;\n")
               ((equal listtype "d") "&lt;/variablelist&gt;\n"))))
        (pop local-list-type) (pop local-list-indent)
        (setq in-local-list local-list-indent))
          (cond
           ((and starter
             (or (not in-local-list)
             (&gt; ind (car local-list-indent))))
        ;; Start new (level of) list
        (org-export-docbook-close-para-maybe)
        (insert (cond
             ((equal item-type "u") "&lt;itemizedlist&gt;\n&lt;listitem&gt;\n")
             ((equal item-type "o")
              ;; Check for a specific start number.  If it
              ;; is specified, we use the ``override''
              ;; attribute of element &lt;listitem&gt; to pass the
              ;; info to DocBook.  We could also use the
              ;; ``startingnumber'' attribute of element
              ;; &lt;orderedlist&gt;, but the former works on both
              ;; DocBook 5.0 and prior versions.
              (if initial-number
                  (format "&lt;orderedlist&gt;\n&lt;listitem override=\"%s\"&gt;\n"
                      initial-number)
                "&lt;orderedlist&gt;\n&lt;listitem&gt;\n"))
             ((equal item-type "d")
              (format "&lt;variablelist&gt;\n&lt;varlistentry&gt;&lt;term&gt;%s&lt;/term&gt;&lt;listitem&gt;\n" item-tag))))
        ;; For DocBook, we need to open a para right after tag
        ;; &lt;listitem&gt;.
        (org-export-docbook-open-para)
        (push item-type local-list-type)
        (push ind local-list-indent)
        (setq in-local-list t))
           (starter
        ;; Continue current list
        (let ((listtype (car local-list-type)))
          (org-export-docbook-close-li listtype)
          (insert (cond
               ((equal listtype "o") "&lt;listitem&gt;")
               ((equal listtype "u") "&lt;listitem&gt;")
               ((equal listtype "d") (format
                          "&lt;varlistentry&gt;&lt;term&gt;%s&lt;/term&gt;&lt;listitem&gt;"
                          (or item-tag
                              "???"))))))
        ;; For DocBook, we need to open a para right after tag
        ;; &lt;listitem&gt;.
        (org-export-docbook-open-para))
           (didclose
        ;; We did close a list, normal text follows: need &lt;para&gt;
        (org-export-docbook-open-para)))
          ;; Checkboxes.
          (if (string-match "^[ \t]*\\(\\[[X -]\\]\\)" line)
          (setq line
            (replace-match (concat checkbox-start
                           (match-string 1 line)
                           checkbox-end)
                       t t line))))

        ;; Empty lines start a new paragraph.  If hand-formatted lists
        ;; are not fully interpreted, lines starting with "-", "+", "*"
        ;; also start a new paragraph.
        (if (and (string-match "^ [-+*]-\\|^[ \t]*$" line)
             (not inverse))
        (org-export-docbook-open-para))

        ;; Is this the start of a footnote?
        (when org-export-with-footnotes
          (when (and (boundp 'footnote-section-tag-regexp)
             (string-match (concat "^" footnote-section-tag-regexp)
                       line))
        ;; ignore this line
        (throw 'nextline nil))
          ;; These footnote lines have been read and saved before,
          ;; ignore them at this time.
          (when (string-match "^[ \t]*\\[\\([0-9]+\\)\\]" line)
        (org-export-docbook-close-para-maybe)
        (throw 'nextline nil)))

        ;; FIXME: It might be a good idea to add an option to
        ;; support line break processing instruction &lt;?linebreak?&gt;.
        ;; Org-mode supports line break "\\" in HTML exporter, and
        ;; some DocBook users may also want to force line breaks
        ;; even though DocBook only supports that in
        ;; &lt;literallayout&gt;.

        (insert line "\n")))))

      ;; Properly close all local lists and other lists
      (when inquote
    (insert "]]&gt;&lt;/programlisting&gt;\n")
    (org-export-docbook-open-para))
      (when in-local-list
    ;; Close any local lists before inserting a new header line
    (while local-list-type
      (let ((listtype (car local-list-type)))
        (org-export-docbook-close-li listtype)
        (insert (cond
             ((equal listtype "o") "&lt;/orderedlist&gt;\n")
             ((equal listtype "u") "&lt;/itemizedlist&gt;\n")
             ((equal listtype "d") "&lt;/variablelist&gt;\n"))))
      (pop local-list-type))
    (setq local-list-indent nil
          in-local-list nil))
      ;; Close all open sections.
      (org-export-docbook-level-start 1 nil)

      (unless (plist-get opt-plist :buffer-will-be-killed)
    (normal-mode)
    (if (eq major-mode (default-value 'major-mode))
        (nxml-mode)))

      ;; Remove empty paragraphs and lists.  Replace them with a
      ;; newline.
      (goto-char (point-min))
      (while (re-search-forward
          "[ \r\n\t]*\\(&lt;para&gt;\\)[ \r\n\t]*&lt;/para&gt;[ \r\n\t]*" nil t)
    (when (not (get-text-property (match-beginning 1) 'org-protected))
      (replace-match "\n")
      ;; Avoid empty &lt;listitem&gt;&lt;/listitem&gt; caused by inline tasks.
      ;; We should add an empty para to make everything valid.
      (when (and (looking-at "&lt;/listitem&gt;")
             (save-excursion
               (backward-char (length "&lt;listitem&gt;\n"))
               (looking-at "&lt;listitem&gt;")))
        (insert "&lt;para&gt;&lt;/para&gt;"))
      (backward-char 1)))
      ;; Fill empty sections with &lt;para&gt;&lt;/para&gt;.  This is to make sure
      ;; that the DocBook document generated is valid and well-formed.
      (goto-char (point-min))
      (while (re-search-forward
          "&lt;/title&gt;\\([ \r\n\t]*\\)&lt;/section&gt;" nil t)
    (when (not (get-text-property (match-beginning 0) 'org-protected))
      (replace-match "\n&lt;para&gt;&lt;/para&gt;\n" nil nil nil 1)))
      ;; Insert the last closing tag.
      (goto-char (point-max))
      (unless body-only
    (insert "&lt;/article&gt;"))
      (run-hooks 'org-export-docbook-final-hook)
      (or to-buffer (save-buffer))
      (goto-char (point-min))
      (or (org-export-push-to-kill-ring "DocBook")
      (message "Exporting... done"))
      (if (eq to-buffer 'string)
      (prog1 (buffer-substring (point-min) (point-max))
        (kill-buffer (current-buffer)))
    (current-buffer)))))
</t>
<t tx="ekr.20100929212226.14499">
(defun org-export-docbook-open-para ()
  "Insert &lt;para&gt;, but first close previous paragraph if any."
  (org-export-docbook-close-para-maybe)
  (insert "\n&lt;para&gt;")
  (setq org-docbook-para-open t))
</t>
<t tx="ekr.20100929212226.14500">
(defun org-export-docbook-close-para-maybe ()
  "Close DocBook paragraph if there is one open."
  (when org-docbook-para-open
    (insert "&lt;/para&gt;\n")
    (setq org-docbook-para-open nil)))
</t>
<t tx="ekr.20100929212226.14501">
(defun org-export-docbook-close-li (&amp;optional type)
  "Close list if necessary."
  (org-export-docbook-close-para-maybe)
  (if (equal type "d")
      (insert "&lt;/listitem&gt;&lt;/varlistentry&gt;\n")
    (insert "&lt;/listitem&gt;\n")))
</t>
<t tx="ekr.20100929212226.14502">
(defvar in-local-list)
(defvar local-list-indent)
(defvar local-list-type)
(defun org-export-docbook-close-lists-maybe (line)
  (let ((ind (or (get-text-property 0 'original-indentation line)))
;            (and (string-match "\\S-" line)
;                 (org-get-indentation line))))
    didclose)
    (when ind
      (while (and in-local-list
          (&lt;= ind (car local-list-indent)))
    (setq didclose t)
    (let ((listtype (car local-list-type)))
      (org-export-docbook-close-li listtype)
      (insert (cond
           ((equal listtype "o") "&lt;/orderedlist&gt;\n")
           ((equal listtype "u") "&lt;/itemizedlist&gt;\n")
           ((equal listtype "d") "&lt;/variablelist&gt;\n"))))
    (pop local-list-type) (pop local-list-indent)
    (setq in-local-list local-list-indent))
      (and didclose (org-export-docbook-open-para)))))
</t>
<t tx="ekr.20100929212226.14503">
(defun org-export-docbook-level-start (level title)
  "Insert a new level in DocBook export.
When TITLE is nil, just close all open levels."
  (org-export-docbook-close-para-maybe)
  (let* ((target (and title (org-get-text-property-any 0 'target title)))
     (l org-level-max)
     section-number)
    (while (&gt;= l level)
      (if (aref org-levels-open (1- l))
      (progn
        (insert "&lt;/section&gt;\n")
        (aset org-levels-open (1- l) nil)))
      (setq l (1- l)))
    (when title
      ;; If title is nil, this means this function is called to close
      ;; all levels, so the rest is done only if title is given.
      ;;
      ;; Format tags: put them into a superscript like format.
      (when (string-match (org-re "\\(:[[:alnum:]_@:]+:\\)[ \t]*$") title)
    (setq title
          (replace-match
           (if org-export-with-tags
           (save-match-data
             (concat
              "&lt;superscript&gt;"
              (match-string 1 title)
              "&lt;/superscript&gt;"))
         "")
           t t title)))
      (aset org-levels-open (1- level) t)
      (setq section-number (org-section-number level))
      (insert (format "\n&lt;section xml:id=\"%s%s\"&gt;\n&lt;title&gt;%s&lt;/title&gt;"
              org-export-docbook-section-id-prefix
              (replace-regexp-in-string "\\." "_" section-number)
              title))
      (org-export-docbook-open-para))))
</t>
<t tx="ekr.20100929212226.14504">
(defun org-docbook-expand (string)
  "Prepare STRING for DocBook export.
Applies all active conversions.  If there are links in the
string, don't modify these."
  (let* ((re (concat org-bracket-link-regexp "\\|"
             (org-re "[ \t]+\\(:[[:alnum:]_@:]+:\\)[ \t]*$")))
     m s l res)
    (while (setq m (string-match re string))
      (setq s (substring string 0 m)
        l (match-string 0 string)
        string (substring string (match-end 0)))
      (push (org-docbook-do-expand s) res)
      (push l res))
    (push (org-docbook-do-expand string) res)
    (apply 'concat (nreverse res))))
</t>
<t tx="ekr.20100929212226.14505">
(defun org-docbook-do-expand (s)
  "Apply all active conversions to translate special ASCII to DocBook."
  (setq s (org-html-protect s))
  (while (string-match "@&amp;lt;\\([^&amp;]*\\)&amp;gt;" s)
    (setq s (replace-match "&lt;\\1&gt;" t nil s)))
  (if org-export-with-emphasize
      (setq s (org-export-docbook-convert-emphasize s)))
  (if org-export-with-special-strings
      (setq s (org-export-docbook-convert-special-strings s)))
  (if org-export-with-sub-superscripts
      (setq s (org-export-docbook-convert-sub-super s)))
  (if org-export-with-TeX-macros
      (let ((start 0) wd rep)
    (while (setq start (string-match "\\\\\\([a-zA-Z]+\\)\\({}\\)?"
                     s start))
      (if (get-text-property (match-beginning 0) 'org-protected s)
          (setq start (match-end 0))
        (setq wd (match-string 1 s))
        (if (setq rep (org-entity-get-representation wd 'html))
        (setq s (replace-match rep t t s))
          (setq start (+ start (length wd))))))))
  s)
</t>
<t tx="ekr.20100929212226.14506">
(defun org-export-docbook-format-desc (desc)
  "Make sure DESC is valid as a description in a link."
  (save-match-data
    (org-docbook-do-expand desc)))
</t>
<t tx="ekr.20100929212226.14507">
(defun org-export-docbook-convert-emphasize (string)
  "Apply emphasis for DocBook exporting."
  (let ((s 0) rpl)
    (while (string-match org-emph-re string s)
      (if (not (equal
        (substring string (match-beginning 3) (1+ (match-beginning 3)))
        (substring string (match-beginning 4) (1+ (match-beginning 4)))))
      (setq s (match-beginning 0)
        rpl
        (concat
         (match-string 1 string)
         (nth 1 (assoc (match-string 3 string)
                   org-export-docbook-emphasis-alist))
         (match-string 4 string)
         (nth 2 (assoc (match-string 3 string)
                   org-export-docbook-emphasis-alist))
         (match-string 5 string))
        string (replace-match rpl t t string)
        s (+ s (- (length rpl) 2)))
    (setq s (1+ s))))
    string))
</t>
<t tx="ekr.20100929212226.14508">
(defun org-docbook-protect (string)
  (org-html-protect string))
</t>
<t tx="ekr.20100929212226.14509">
;; For now, simply return string as it is.
(defun org-export-docbook-convert-special-strings (string)
  "Convert special characters in STRING to DocBook."
  string)
</t>
<t tx="ekr.20100929212226.14510">
(defun org-export-docbook-get-footnotes (lines)
  "Given a list of LINES, return a list of alist footnotes."
  (let ((list nil) line)
    (while (setq line (pop lines))
      (if (string-match "^[ \t]*\\[\\([0-9]+\\)\\] \\(.+\\)" line)
      (push (cons (match-string 1 line) (match-string 2 line))
        list)))
    list))
</t>
<t tx="ekr.20100929212226.14511">
(defun org-export-docbook-format-image (src)
  "Create image element in DocBook."
  (save-match-data
    (let* ((caption (org-find-text-property-in-string 'org-caption src))
       (attr (or (org-find-text-property-in-string 'org-attributes src)
             ""))
       (label (org-find-text-property-in-string 'org-label src))
       (default-attr org-export-docbook-default-image-attributes)
       tmp)
      (setq caption (and caption (org-html-do-expand caption)))
      (while (setq tmp (pop default-attr))
    (if (not (string-match (concat (car tmp) "=") attr))
        (setq attr (concat attr " " (car tmp) "=" (cdr tmp)))))
      (format "&lt;mediaobject%s&gt;
&lt;imageobject&gt;\n&lt;imagedata fileref=\"%s\" %s/&gt;\n&lt;/imageobject&gt;
%s&lt;/mediaobject&gt;"
          (if label (concat " xml:id=\"" label "\"") "")
          src attr
          (if caption
          (concat "&lt;caption&gt;\n&lt;para&gt;"
              caption
              "&lt;/para&gt;\n&lt;/caption&gt;\n")
        "")
          ))))
</t>
<t tx="ekr.20100929212226.14512">
(defun org-export-docbook-preprocess (parameters)
  "Extra preprocessing work for DocBook export."
  ;; Merge lines starting with "\par" to one line.  Such lines are
  ;; regarded as the continuation of a long footnote.
  (goto-char (point-min))
  (while (re-search-forward "\n\\(\\\\par\\&gt;\\)" nil t)
    (if (not (get-text-property (match-beginning 1) 'org-protected))
    (replace-match ""))))
</t>
<t tx="ekr.20100929212226.14513">
(defun org-export-docbook-finalize-table (table)
  "Clean up TABLE and turn it into DocBook format.
This function adds a label to the table if it is available, and
also changes TABLE to informaltable if caption does not exist.
TABLE is a string containing the HTML code generated by
`org-format-table-html' for a table in Org-mode buffer."
  (let (table-with-label)
    ;; Get the label if it exists, and move it into the &lt;table&gt; element.
    (setq table-with-label
      (if (string-match
           "^&lt;table \\(\\(.\\|\n\\)+\\)&lt;a name=\"\\(.+\\)\" id=\".+\"&gt;&lt;/a&gt;\n\\(\\(.\\|\n\\)+\\)&lt;/table&gt;"
           table)
          (replace-match (concat "&lt;table xml:id=\"" (match-string 3 table) "\" "
                     (match-string 1 table)
                     (match-string 4 table)
                     "&lt;/table&gt;")
                 nil nil table)
        table))
    ;; Change &lt;table&gt; into &lt;informaltable&gt; if caption does not exist.
    (if (string-match
     "^&lt;table \\(\\(.\\|\n\\)+\\)&lt;caption&gt;&lt;/caption&gt;\n\\(\\(.\\|\n\\)+\\)&lt;/table&gt;"
     table-with-label)
    (replace-match (concat "&lt;informaltable "
                   (match-string 1 table-with-label)
                   (match-string 3 table-with-label)
                   "&lt;/informaltable&gt;")
               nil nil table-with-label)
      table-with-label)))
</t>
<t tx="ekr.20100929212226.14514">
;; Note: This function is very similar to
;; org-export-html-convert-sub-super.  They can be merged in the future.
(defun org-export-docbook-convert-sub-super (string)
  "Convert sub- and superscripts in STRING for DocBook."
  (let (key c (s 0) (requireb (eq org-export-with-sub-superscripts '{})))
    (while (string-match org-match-substring-regexp string s)
      (cond
       ((and requireb (match-end 8)) (setq s (match-end 2)))
       ((get-text-property  (match-beginning 2) 'org-protected string)
    (setq s (match-end 2)))
       (t
    (setq s (match-end 1)
          key (if (string= (match-string 2 string) "_")
              "subscript"
            "superscript")
          c (or (match-string 8 string)
            (match-string 6 string)
            (match-string 5 string))
          string (replace-match
              (concat (match-string 1 string)
                  "&lt;" key "&gt;" c "&lt;/" key "&gt;")
              t t string)))))
    (while (string-match "\\\\\\([_^]\\)" string)
      (setq string (replace-match (match-string 1 string) t t string)))
    string))
</t>
<t tx="ekr.20100929212226.14515">
(defun org-export-docbook-protect-tags (string)
  "Change ``&lt;...&gt;'' in string STRING into ``@&lt;...&gt;''.
This is normally needed when STRING contains DocBook elements
that need to be preserved in later phase of DocBook exporting."
  (let ((start 0))
    (while (string-match "&lt;\\([^&gt;]*\\)&gt;" string start)
      (setq string (replace-match
            "@&lt;\\1&gt;" t nil string)
        start (match-end 0)))
    string))
</t>
<t tx="ekr.20100929212226.14516">
(defun org-export-docbook-handle-time-stamps (line)
  "Format time stamps in string LINE."
  (let (replaced
    (kw-markup (org-export-docbook-protect-tags
            org-export-docbook-keywords-markup))
    (ts-markup (org-export-docbook-protect-tags
            org-export-docbook-timestamp-markup)))
    (while (string-match org-maybe-keyword-time-regexp line)
      (setq replaced
        (concat replaced
            (substring line 0 (match-beginning 0))
            (if (match-end 1)
            (format kw-markup
                (match-string 1 line)))
            " "
            (format ts-markup
                (substring (org-translate-time
                    (match-string 3 line)) 1 -1)))
        line (substring line (match-end 0))))
    (concat replaced line)))
</t>
<t tx="ekr.20100929212226.14517">@language lisp
@tabwidth -4
@others

(provide 'org-icalendar)

;; arch-tag: 2dee2b6e-9211-4aee-8a47-a3c7e5bc30cf
;;; org-icalendar.el ends here
</t>
<t tx="ekr.20100929212226.14518">;;; org-icalendar.el --- iCalendar export for Org-mode

;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Carsten Dominik &lt;carsten at orgmode dot org&gt;
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;;; Code:

(require 'org-exp)

(eval-when-compile
  (require 'cl))

(declare-function org-bbdb-anniv-export-ical "org-bbdb" nil)

(defgroup org-export-icalendar nil
  "Options specific for iCalendar export of Org-mode files."
  :tag "Org Export iCalendar"
  :group 'org-export)

(defcustom org-combined-agenda-icalendar-file "~/org.ics"
  "The file name for the iCalendar file covering all agenda files.
This file is created with the command \\[org-export-icalendar-all-agenda-files].
The file name should be absolute, the file will be overwritten without warning."
  :group 'org-export-icalendar
  :type 'file)

(defcustom org-icalendar-combined-name "OrgMode"
  "Calendar name for the combined iCalendar representing all agenda files."
  :group 'org-export-icalendar
  :type 'string)

(defcustom org-icalendar-combined-description nil
  "Calendar description for the combined iCalendar representing all agenda files."
  :group 'org-export-icalendar
  :type 'string)

(defcustom org-icalendar-use-plain-timestamp t
  "Non-nil means make an event from every plain time stamp."
  :group 'org-export-icalendar
  :type 'boolean)

(defcustom org-icalendar-use-deadline '(event-if-not-todo todo-due)
  "Contexts where iCalendar export should use a deadline time stamp.
This is a list with several symbols in it.  Valid symbol are:

event-if-todo       Deadlines in TODO entries become calendar events.
event-if-not-todo   Deadlines in non-TODO entries become calendar events.
todo-due            Use deadlines in TODO entries as due-dates"
  :group 'org-export-icalendar
  :type '(set :greedy t
          (const :tag "Deadlines in non-TODO entries become events"
             event-if-not-todo)
          (const :tag "Deadline in TODO entries become events"
             event-if-todo)
          (const :tag "Deadlines in TODO entries become due-dates"
             todo-due)))

(defcustom org-icalendar-use-scheduled '(todo-start)
  "Contexts where iCalendar export should use a scheduling time stamp.
This is a list with several symbols in it.  Valid symbol are:

event-if-todo       Scheduling time stamps in TODO entries become an event.
event-if-not-todo   Scheduling time stamps in non-TODO entries become an event.
todo-start          Scheduling time stamps in TODO entries become start date.
                    Some calendar applications show TODO entries only after
                    that date."
  :group 'org-export-icalendar
  :type '(set :greedy t
          (const :tag
             "SCHEDULED timestamps in non-TODO entries become events"
             event-if-not-todo)
          (const :tag "SCHEDULED timestamps in TODO entries become events"
             event-if-todo)
          (const :tag "SCHEDULED in TODO entries become start date"
             todo-start)))

(defcustom org-icalendar-categories '(local-tags category)
  "Items that should be entered into the categories field.
This is a list of symbols, the following are valid:

category    The Org-mode category of the current file or tree
todo-state  The todo state, if any
local-tags  The tags, defined in the current line
all-tags    All tags, including inherited ones."
  :group 'org-export-icalendar
  :type '(repeat
      (choice
       (const :tag "The file or tree category" category)
       (const :tag "The TODO state" todo-state)
       (const :tag "Tags defined in current line" local-tags)
       (const :tag "All tags, including inherited ones" all-tags))))

(defcustom org-icalendar-include-todo nil
  "Non-nil means export to iCalendar files should also cover TODO items.
Valid values are:
nil         don't include any TODO items
t           include all TODO items that are not in a DONE state
unblocked   include all TODO items that are not blocked
all         include both done and not done items."
  :group 'org-export-icalendar
  :type '(choice
      (const :tag "None" nil)
      (const :tag "Unfinished" t)
      (const :tag "Unblocked" unblocked)
      (const :tag "All" all)))

(defvar org-icalendar-verify-function nil
  "Function to verify entries for iCalendar export.
This can be set to a function that will be called at each entry that
is considered for export to iCalendar.  When the function returns nil,
the entry will be skipped.  When it returns a non-nil value, the entry
will be considered for export.
This is used internally when an agenda buffer is exported to an ics file,
to make sure that only entries currently listed in the agenda will end
up in the ics file.  But for normal iCalendar export, you can use this
for whatever you need.")

(defcustom org-icalendar-include-bbdb-anniversaries nil
  "Non-nil means a combined iCalendar files should include anniversaries.
The anniversaries are define in the BBDB database."
  :group 'org-export-icalendar
  :type 'boolean)

(defcustom org-icalendar-include-sexps t
  "Non-nil means export to iCalendar files should also cover sexp entries.
These are entries like in the diary, but directly in an Org-mode file."
  :group 'org-export-icalendar
  :type 'boolean)

(defcustom org-icalendar-include-body 100
  "Amount of text below headline to be included in iCalendar export.
This is a number of characters that should maximally be included.
Properties, scheduling and clocking lines will always be removed.
The text will be inserted into the DESCRIPTION field."
  :group 'org-export-icalendar
  :type '(choice
      (const :tag "Nothing" nil)
      (const :tag "Everything" t)
      (integer :tag "Max characters")))

(defcustom org-icalendar-store-UID nil
  "Non-nil means store any created UIDs in properties.
The iCalendar standard requires that all entries have a unique identifier.
Org will create these identifiers as needed.  When this variable is non-nil,
the created UIDs will be stored in the ID property of the entry.  Then the
next time this entry is exported, it will be exported with the same UID,
superseding the previous form of it.  This is essential for
synchronization services.
This variable is not turned on by default because we want to avoid creating
a property drawer in every entry if people are only playing with this feature,
or if they are only using it locally."
  :group 'org-export-icalendar
  :type 'boolean)

(defcustom org-icalendar-timezone (getenv "TZ")
  "The time zone string for iCalendar export.
When nil of the empty string, use the abbreviation retrieved from Emacs."
  :group 'org-export-icalendar
  :type '(choice
      (const :tag "Unspecified" nil)
      (string :tag "Time zone")))

</t>
<t tx="ekr.20100929212226.14519">;;; iCalendar export

;;;###autoload
(defun org-export-icalendar-this-file ()
  "Export current file as an iCalendar file.
The iCalendar file will be located in the same directory as the Org-mode
file, but with extension `.ics'."
  (interactive)
  (org-export-icalendar nil buffer-file-name))
</t>
<t tx="ekr.20100929212226.14520">
;;;###autoload
(defun org-export-icalendar-all-agenda-files ()
  "Export all files in the variable `org-agenda-files' to iCalendar .ics files.
Each iCalendar file will be located in the same directory as the Org-mode
file, but with extension `.ics'."
  (interactive)
  (apply 'org-export-icalendar nil (org-agenda-files t)))
</t>
<t tx="ekr.20100929212226.14521">
;;;###autoload
(defun org-export-icalendar-combine-agenda-files ()
  "Export all files in `org-agenda-files' to a single combined iCalendar file.
The file is stored under the name `org-combined-agenda-icalendar-file'."
  (interactive)
  (apply 'org-export-icalendar t (org-agenda-files t)))
</t>
<t tx="ekr.20100929212226.14522">
(defun org-export-icalendar (combine &amp;rest files)
  "Create iCalendar files for all elements of FILES.
If COMBINE is non-nil, combine all calendar entries into a single large
file and store it under the name `org-combined-agenda-icalendar-file'."
  (save-excursion
    (org-prepare-agenda-buffers files)
    (let* ((dir (org-export-directory
         :ical (list :publishing-directory
                 org-export-publishing-directory)))
       file ical-file ical-buffer category started org-agenda-new-buffers)
      (and (get-buffer "*ical-tmp*") (kill-buffer "*ical-tmp*"))
      (when combine
    (setq ical-file
          (if (file-name-absolute-p org-combined-agenda-icalendar-file)
          org-combined-agenda-icalendar-file
        (expand-file-name org-combined-agenda-icalendar-file dir))
          ical-buffer (org-get-agenda-file-buffer ical-file))
    (set-buffer ical-buffer) (erase-buffer))
      (while (setq file (pop files))
    (catch 'nextfile
      (org-check-agenda-file file)
      (set-buffer (org-get-agenda-file-buffer file))
      (unless combine
        (setq ical-file (concat (file-name-as-directory dir)
                    (file-name-sans-extension
                     (file-name-nondirectory buffer-file-name))
                    ".ics"))
        (setq ical-buffer (org-get-agenda-file-buffer ical-file))
        (with-current-buffer ical-buffer (erase-buffer)))
      (setq category (or org-category
                 (file-name-sans-extension
                  (file-name-nondirectory buffer-file-name))))
      (if (symbolp category) (setq category (symbol-name category)))
      (let ((standard-output ical-buffer))
        (if combine
        (and (not started) (setq started t)
             (org-start-icalendar-file org-icalendar-combined-name))
          (org-start-icalendar-file category))
        (org-print-icalendar-entries combine)
        (when (or (and combine (not files)) (not combine))
          (when (and combine org-icalendar-include-bbdb-anniversaries)
        (require 'org-bbdb)
        (org-bbdb-anniv-export-ical))
          (org-finish-icalendar-file)
          (set-buffer ical-buffer)
          (run-hooks 'org-before-save-iCalendar-file-hook)
          (save-buffer)
          (run-hooks 'org-after-save-iCalendar-file-hook)
          (and (boundp 'org-wait) (numberp org-wait) (sit-for org-wait))
          ))))
      (org-release-buffers org-agenda-new-buffers))))
</t>
<t tx="ekr.20100929212226.14523">
(defvar org-before-save-iCalendar-file-hook nil
  "Hook run before  an iCalendar file has been saved.
This can be used to modify the result of the export.")

(defvar org-after-save-iCalendar-file-hook nil
  "Hook run after an iCalendar file has been saved.
The iCalendar buffer is still current when this hook is run.
A good way to use this is to tell a desktop calendar application to re-read
the iCalendar file.")

(defvar org-agenda-default-appointment-duration) ; defined in org-agenda.el
(defun org-print-icalendar-entries (&amp;optional combine)
  "Print iCalendar entries for the current Org-mode file to `standard-output'.
When COMBINE is non nil, add the category to each line."
  (require 'org-agenda)
  (let ((re1 (concat org-ts-regexp "\\|&lt;%%([^&gt;\n]+&gt;"))
    (re2 (concat "--?-?\\(" org-ts-regexp "\\)"))
    (dts (org-ical-ts-to-string
          (format-time-string (cdr org-time-stamp-formats) (current-time))
          "DTSTART"))
    hd ts ts2 state status (inc t) pos b sexp rrule
    scheduledp deadlinep todo prefix due start
    tmp pri categories location summary desc uid
    (sexp-buffer (get-buffer-create "*ical-tmp*")))
    (org-refresh-category-properties)
    (save-excursion
      (goto-char (point-min))
      (while (re-search-forward re1 nil t)
    (catch :skip
      (org-agenda-skip)
      (when org-icalendar-verify-function
        (unless (save-match-data (funcall org-icalendar-verify-function))
          (outline-next-heading)
          (backward-char 1)
          (throw :skip nil)))
      (setq pos (match-beginning 0)
        ts (match-string 0)
        inc t
        hd (condition-case nil
               (org-icalendar-cleanup-string
            (org-get-heading))
             (error (throw :skip nil)))
        summary (org-icalendar-cleanup-string
             (org-entry-get nil "SUMMARY"))
        desc (org-icalendar-cleanup-string
              (or (org-entry-get nil "DESCRIPTION")
              (and org-icalendar-include-body (org-get-entry)))
              t org-icalendar-include-body)
        location (org-icalendar-cleanup-string
              (org-entry-get nil "LOCATION" 'selective))
        uid (if org-icalendar-store-UID
            (org-id-get-create)
              (or (org-id-get) (org-id-new)))
        categories (org-export-get-categories)
        deadlinep nil scheduledp nil)
      (if (looking-at re2)
          (progn
        (goto-char (match-end 0))
        (setq ts2 (match-string 1)
              inc (not (string-match "[0-9]\\{1,2\\}:[0-9][0-9]" ts2))))
        (setq tmp (buffer-substring (max (point-min)
                         (- pos org-ds-keyword-length))
                    pos)
          ts2 (if (string-match "[0-9]\\{1,2\\}:[0-9][0-9]-\\([0-9]\\{1,2\\}:[0-9][0-9]\\)" ts)
              (progn
                (setq inc nil)
                (replace-match "\\1" t nil ts))
            ts)
          deadlinep (string-match org-deadline-regexp tmp)
          scheduledp (string-match org-scheduled-regexp tmp)
          todo (org-get-todo-state)
          ;; donep (org-entry-is-done-p)
          ))
      (when (and (not org-icalendar-use-plain-timestamp)
             (not deadlinep) (not scheduledp))
        (throw :skip t))
      (when (and
         deadlinep
         (if todo
             (not (memq 'event-if-todo org-icalendar-use-deadline))
           (not (memq 'event-if-not-todo org-icalendar-use-deadline))))
        (throw :skip t))
      (when (and
         scheduledp
         (if todo
             (not (memq 'event-if-todo org-icalendar-use-scheduled))
           (not (memq 'event-if-not-todo org-icalendar-use-scheduled))))
        (throw :skip t))
      (setq prefix (if deadlinep "DL-" (if scheduledp "SC-" "TS-")))
      (if (or (string-match org-tr-regexp hd)
          (string-match org-ts-regexp hd))
          (setq hd (replace-match "" t t hd)))
      (if (string-match "\\+\\([0-9]+\\)\\([dwmy]\\)&gt;" ts)
          (setq rrule
            (concat "\nRRULE:FREQ="
                (cdr (assoc
                  (match-string 2 ts)
                  '(("d" . "DAILY")("w" . "WEEKLY")
                    ("m" . "MONTHLY")("y" . "YEARLY"))))
                ";INTERVAL=" (match-string 1 ts)))
        (setq rrule ""))
      (setq summary (or summary hd))
      (if (string-match org-bracket-link-regexp summary)
          (setq summary
            (replace-match (if (match-end 3)
                       (match-string 3 summary)
                     (match-string 1 summary))
                   t t summary)))
      (if deadlinep (setq summary (concat "DL: " summary)))
      (if scheduledp (setq summary (concat "S: " summary)))
      (if (string-match "\\`&lt;%%" ts)
          (with-current-buffer sexp-buffer
        (insert (substring ts 1 -1) " " summary "\n"))
        (princ (format "BEGIN:VEVENT
UID: %s
%s
%s%s
SUMMARY:%s%s%s
CATEGORIES:%s
END:VEVENT\n"
               (concat prefix uid)
               (org-ical-ts-to-string ts "DTSTART")
               (org-ical-ts-to-string ts2 "DTEND" inc)
               rrule summary
               (if (and desc (string-match "\\S-" desc))
                   (concat "\nDESCRIPTION: " desc) "")
               (if (and location (string-match "\\S-" location))
                   (concat "\nLOCATION: " location) "")
               categories)))))
      (when (and org-icalendar-include-sexps
         (condition-case nil (require 'icalendar) (error nil))
         (fboundp 'icalendar-export-region))
    ;; Get all the literal sexps
    (goto-char (point-min))
    (while (re-search-forward "^&amp;?%%(" nil t)
      (catch :skip
        (org-agenda-skip)
        (when org-icalendar-verify-function
          (unless (save-match-data (funcall org-icalendar-verify-function))
        (outline-next-heading)
        (backward-char 1)
        (throw :skip nil)))
        (setq b (match-beginning 0))
        (goto-char (1- (match-end 0)))
        (forward-sexp 1)
        (end-of-line 1)
        (setq sexp (buffer-substring b (point)))
        (with-current-buffer sexp-buffer
          (insert sexp "\n"))))
    (princ (org-diary-to-ical-string sexp-buffer))
    (kill-buffer sexp-buffer))

      (when org-icalendar-include-todo
    (setq prefix "TODO-")
    (goto-char (point-min))
    (while (re-search-forward org-todo-line-regexp nil t)
      (catch :skip
        (org-agenda-skip)
        (when org-icalendar-verify-function
          (unless (save-match-data
            (funcall org-icalendar-verify-function))
        (outline-next-heading)
        (backward-char 1)
        (throw :skip nil)))
        (setq state (match-string 2))
        (setq status (if (member state org-done-keywords)
                 "COMPLETED" "NEEDS-ACTION"))
        (when (and state
               (cond
            ;; check if the state is one we should use
            ((eq org-icalendar-include-todo 'all)
             ;; all should be included
             t)
            ((eq org-icalendar-include-todo 'unblocked)
             ;; only undone entries that are not blocked
             (and (member state org-not-done-keywords)
                  (or (not org-blocker-hook)
                  (save-match-data
                    (run-hook-with-args-until-failure
                     'org-blocker-hook
                     (list :type 'todo-state-change
                       :position (point-at-bol)
                       :from 'todo
                       :to 'done))))))
            ((eq org-icalendar-include-todo t)
             ;; include everything that is not done
             (member state org-not-done-keywords))))
          (setq hd (match-string 3)
            summary (org-icalendar-cleanup-string
                 (org-entry-get nil "SUMMARY"))
            desc (org-icalendar-cleanup-string
              (or (org-entry-get nil "DESCRIPTION")
                  (and org-icalendar-include-body (org-get-entry)))
              t org-icalendar-include-body)
            location (org-icalendar-cleanup-string
                  (org-entry-get nil "LOCATION" 'selective))
            due (and (member 'todo-due org-icalendar-use-deadline)
                 (org-entry-get nil "DEADLINE"))
            start (and (member 'todo-start org-icalendar-use-scheduled)
                 (org-entry-get nil "SCHEDULED"))
            categories (org-export-get-categories)
            uid (if org-icalendar-store-UID
                (org-id-get-create)
              (or (org-id-get) (org-id-new))))
          (and due (setq due (org-ical-ts-to-string due "DUE")))
          (and start (setq start (org-ical-ts-to-string start "DTSTART")))

          (if (string-match org-bracket-link-regexp hd)
          (setq hd (replace-match (if (match-end 3) (match-string 3 hd)
                        (match-string 1 hd))
                      t t hd)))
          (if (string-match org-priority-regexp hd)
          (setq pri (string-to-char (match-string 2 hd))
            hd (concat (substring hd 0 (match-beginning 1))
                   (substring hd (match-end 1))))
        (setq pri org-default-priority))
          (setq pri (floor (- 9 (* 8. (/ (float (- org-lowest-priority pri))
                         (- org-lowest-priority org-highest-priority))))))

          (princ (format "BEGIN:VTODO
UID: %s
%s
SUMMARY:%s%s%s%s
CATEGORIES:%s
SEQUENCE:1
PRIORITY:%d
STATUS:%s
END:VTODO\n"
                 (concat prefix uid)
                 (or start dts)
                 (or summary hd)
                 (if (and location (string-match "\\S-" location))
                 (concat "\nLOCATION: " location) "")
                 (if (and desc (string-match "\\S-" desc))
                 (concat "\nDESCRIPTION: " desc) "")
                 (if due (concat "\n" due) "")
                 categories
                 pri status)))))))))
</t>
<t tx="ekr.20100929212226.14524">
(defun org-export-get-categories ()
  "Get categories according to `org-icalendar-categories'."
  (let ((cs org-icalendar-categories) c rtn tmp)
    (while (setq c (pop cs))
      (cond
       ((eq c 'category) (push (org-get-category) rtn))
       ((eq c 'todo-state)
    (setq tmp (org-get-todo-state))
    (and tmp (push tmp rtn)))
       ((eq c 'local-tags)
    (setq rtn (append (nreverse (org-get-local-tags-at (point))) rtn)))
       ((eq c 'all-tags)
    (setq rtn (append (nreverse (org-get-tags-at (point))) rtn)))))
    (mapconcat 'identity (nreverse rtn) ",")))
</t>
<t tx="ekr.20100929212226.14525">
(defun org-icalendar-cleanup-string (s &amp;optional is-body maxlength)
  "Take out stuff and quote what needs to be quoted.
When IS-BODY is non-nil, assume that this is the body of an item, clean up
whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
characters."
  (if (not s)
      nil
    (if is-body
      (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
        (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
    (while (string-match re s) (setq s (replace-match "" t t s)))
    (while (string-match re2 s) (setq s (replace-match "" t t s))))
      (setq s (replace-regexp-in-string "[[:space:]]+" " " s)))
    (let ((start 0))
      (while (string-match "\\([,;]\\)" s start)
    (setq start (+ (match-beginning 0) 2)
          s (replace-match "\\\\\\1" nil nil s))))
    (setq s (org-trim s))
    (when is-body
      (while (string-match "[ \t]*\n[ \t]*" s)
    (setq s (replace-match "\\n" t t s))))
    (if is-body
    (if maxlength
        (if (and (numberp maxlength)
             (&gt; (length s) maxlength))
        (setq s (substring s 0 maxlength)))))
    s))
</t>
<t tx="ekr.20100929212226.14526">
(defun org-icalendar-cleanup-string-rfc2455 (s &amp;optional is-body maxlength)
  "Take out stuff and quote what needs to be quoted.
When IS-BODY is non-nil, assume that this is the body of an item, clean up
whitespace, newlines, drawers, and timestamps, and cut it down to MAXLENGTH
characters.
This seems to be more like RFC 2455, but it causes problems, so it is
not used right now."
  (if (not s)
      nil
    (if is-body
    (let ((re (concat "\\(" org-drawer-regexp "\\)[^\000]*?:END:.*\n?"))
          (re2 (concat "^[ \t]*" org-keyword-time-regexp ".*\n?")))
      (while (string-match re s) (setq s (replace-match "" t t s)))
      (while (string-match re2 s) (setq s (replace-match "" t t s)))
      (setq s (org-trim s))
      (while (string-match "[ \t]*\n[ \t]*" s)
        (setq s (replace-match "\\n" t t s)))
      (if maxlength
          (if (and (numberp maxlength)
               (&gt; (length s) maxlength))
          (setq s (substring s 0 maxlength)))))
      (setq s (org-trim s)))
    (while (string-match "\"" s) (setq s (replace-match "''" t t s)))
    (when (string-match "[;,:]" s) (setq s (concat "\"" s "\"")))
    s))
</t>
<t tx="ekr.20100929212226.14527">
(defun org-start-icalendar-file (name)
  "Start an iCalendar file by inserting the header."
  (let ((user user-full-name)
    (name (or name "unknown"))
    (timezone (if (&gt; (length org-icalendar-timezone) 0)
              org-icalendar-timezone
            (cadr (current-time-zone))))
    (description org-icalendar-combined-description))
    (princ
     (format "BEGIN:VCALENDAR
VERSION:2.0
X-WR-CALNAME:%s
PRODID:-//%s//Emacs with Org-mode//EN
X-WR-TIMEZONE:%s
X-WR-CALDESC:%s
CALSCALE:GREGORIAN\n" name user timezone description))))
</t>
<t tx="ekr.20100929212226.14528">
(defun org-finish-icalendar-file ()
  "Finish an iCalendar file by inserting the END statement."
  (princ "END:VCALENDAR\n"))
</t>
<t tx="ekr.20100929212226.14529">
(defun org-ical-ts-to-string (s keyword &amp;optional inc)
  "Take a time string S and convert it to iCalendar format.
KEYWORD is added in front, to make a complete line like DTSTART....
When INC is non-nil, increase the hour by two (if time string contains
a time), or the day by one (if it does not contain a time)."
  (let ((t1 (ignore-errors (org-parse-time-string s 'nodefault)))
    t2 fmt have-time time)
    (if (not t1)
    ""
      (if (and (car t1) (nth 1 t1) (nth 2 t1))
      (setq t2 t1 have-time t)
    (setq t2 (org-parse-time-string s)))
      (let ((s (car t2))   (mi (nth 1 t2)) (h (nth 2 t2))
        (d (nth 3 t2)) (m  (nth 4 t2)) (y (nth 5 t2)))
    (when inc
      (if have-time
          (if org-agenda-default-appointment-duration
          (setq mi (+ org-agenda-default-appointment-duration mi))
        (setq h (+ 2 h)))
        (setq d (1+ d))))
    (setq time (encode-time s mi h d m y)))
      (setq fmt (if have-time ":%Y%m%dT%H%M%S" ";VALUE=DATE:%Y%m%d"))
      (concat keyword (format-time-string fmt time)))))
</t>
<t tx="ekr.20100929212226.14530">@language lisp
@tabwidth -4
@others

(provide 'org-exp-blocks)

;; arch-tag: 1c365fe9-8808-4f72-bb15-0b00f36d8024
;;; org-exp-blocks.el ends here
</t>
<t tx="ekr.20100929212226.14531">;;; org-exp-blocks.el --- pre-process blocks when exporting org files

;; Copyright (C) 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Eric Schulte
;; Version: 7.01h

;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:
;;
;; This is a utility for pre-processing blocks in org files before
;; export using the `org-export-preprocess-hook'.  It can be used for
;; exporting new types of blocks from org-mode files and also for
;; changing the default export behavior of existing org-mode blocks.
;; The `org-export-blocks' and `org-export-interblocks' variables can
;; be used to control how blocks and the spaces between blocks
;; respectively are processed upon export.
;;
;; The type of a block is defined as the string following =#+begin_=,
;; so for example the following block would be of type ditaa.  Note
;; that both upper or lower case are allowed in =#+BEGIN_= and
;; =#+END_=.
;;
;; #+begin_ditaa blue.png -r -S
;; +---------+
;; | cBLU    |
;; |         |
;; |    +----+
;; |    |cPNK|
;; |    |    |
;; +----+----+
;; #+end_ditaa
;;
;;; Currently Implemented Block Types
;;
;; ditaa :: Convert ascii pictures to actual images using ditaa
;;          http://ditaa.sourceforge.net/.  To use this set
;;          `org-ditaa-jar-path' to the path to ditaa.jar on your
;;          system (should be set automatically in most cases) .
;;
;; dot :: Convert graphs defined using the dot graphing language to
;;        images using the dot utility.  For information on dot see
;;        http://www.graphviz.org/
;;
;; comment :: Wrap comments with titles and author information, in
;;            their own divs with author-specific ids allowing for css
;;            coloring of comments based on the author.
;;
;;; Adding new blocks
;;
;; When adding a new block type first define a formatting function
;; along the same lines as `org-export-blocks-format-dot' and then use
;; `org-export-blocks-add-block' to add your block type to
;; `org-export-blocks'.

;;; Code:

(eval-when-compile
  (require 'cl))
(require 'org)

(defvar htmlp)
(defvar latexp)
(defvar docbookp)
(defvar asciip)

</t>
<t tx="ekr.20100929212226.14532">(defun org-export-blocks-set (var value)
  "Set the value of `org-export-blocks' and install fontification."
  (set var value)
  (mapc (lambda (spec)
      (if (nth 2 spec)
          (setq org-protecting-blocks
            (delete (symbol-name (car spec))
                org-protecting-blocks))
        (add-to-list 'org-protecting-blocks
             (symbol-name (car spec)))))
    value))
</t>
<t tx="ekr.20100929212226.14533">
(defcustom org-export-blocks
  '((comment org-export-blocks-format-comment t)
    (ditaa org-export-blocks-format-ditaa nil)
    (dot org-export-blocks-format-dot nil))
  "Use this alist to associate block types with block exporting functions.
The type of a block is determined by the text immediately
following the '#+BEGIN_' portion of the block header.  Each block
export function should accept three arguments."
  :group 'org-export-general
  :type '(repeat
      (list
       (symbol :tag "Block name")
       (function :tag "Block formatter")
       (boolean :tag "Fontify content as Org syntax")))
  :set 'org-export-blocks-set)

(defun org-export-blocks-add-block (block-spec)
  "Add a new block type to `org-export-blocks'.
BLOCK-SPEC should be a three element list the first element of
which should indicate the name of the block, the second element
should be the formatting function called by
`org-export-blocks-preprocess' and the third element a flag
indicating whether these types of blocks should be fontified in
org-mode buffers (see `org-protecting-blocks').  For example the
BLOCK-SPEC for ditaa blocks is as follows.

  (ditaa org-export-blocks-format-ditaa nil)"
  (unless (member block-spec org-export-blocks)
    (setq org-export-blocks (cons block-spec org-export-blocks))
    (org-export-blocks-set 'org-export-blocks org-export-blocks)))
</t>
<t tx="ekr.20100929212226.14534">
(defcustom org-export-interblocks
  '()
  "Use this a-list to associate block types with block exporting functions.
The type of a block is determined by the text immediately
following the '#+BEGIN_' portion of the block header.  Each block
export function should accept three arguments."
  :group 'org-export-general
  :type 'alist)

(defcustom org-export-blocks-witheld
  '(hidden)
  "List of block types (see `org-export-blocks') which should not be exported."
  :group 'org-export-general
  :type 'list)

(defcustom org-export-blocks-postblock-hook nil
  "Run after blocks have been processed with `org-export-blocks-preprocess'."
  :group 'org-export-general
  :type 'hook)

(defun org-export-blocks-html-quote (body &amp;optional open close)
  "Protect BODY from org html export.
The optional OPEN and CLOSE tags will be inserted around BODY."

  (concat
   "\n#+BEGIN_HTML\n"
   (or open "")
   body (if (string-match "\n$" body) "" "\n")
   (or close "")
   "#+END_HTML\n"))
</t>
<t tx="ekr.20100929212226.14535">
(defun org-export-blocks-latex-quote (body &amp;optional open close)
  "Protect BODY from org latex export.
The optional OPEN and CLOSE tags will be inserted around BODY."
  (concat
   "\n#+BEGIN_LaTeX\n"
   (or open "")
   body (if (string-match "\n$" body) "" "\n")
   (or close "")
   "#+END_LaTeX\n"))
</t>
<t tx="ekr.20100929212226.14536">
(defun org-export-blocks-preprocess ()
  "Export all blocks according to the `org-export-blocks' block export alist.
Does not export block types specified in specified in BLOCKS
which defaults to the value of `org-export-blocks-witheld'."
  (interactive)
  (save-window-excursion
    (let ((case-fold-search t)
      (types '())
      indentation type func start body headers preserve-indent progress-marker)
      (flet ((interblock (start end)
             (mapcar (lambda (pair) (funcall (second pair) start end))
                 org-export-interblocks)))
    (goto-char (point-min))
    (setq start (point))
    (while (re-search-forward
        "^\\([ \t]*\\)#\\+begin_\\(\\S-+\\)[ \t]*\\(.*\\)?[\r\n]\\([^\000]*?\\)[\r\n][ \t]*#\\+end_\\S-+.*[\r\n]?" nil t)
          (setq indentation (length (match-string 1)))
      (setq type (intern (downcase (match-string 2))))
      (setq headers (save-match-data (org-split-string (match-string 3) "[ \t]+")))
      (setq body (match-string 4))
      (setq preserve-indent (or org-src-preserve-indentation (member "-i" headers)))
      (unless preserve-indent
        (setq body (save-match-data (org-remove-indentation body))))
      (unless (memq type types) (setq types (cons type types)))
      (save-match-data (interblock start (match-beginning 0)))
      (when (setq func (cadr (assoc type org-export-blocks)))
            (let ((replacement (save-match-data
                                 (if (memq type org-export-blocks-witheld) ""
                                   (apply func body headers)))))
              (when replacement
                (replace-match replacement t t)
                (unless preserve-indent
                  (indent-code-rigidly
                   (match-beginning 0) (match-end 0) indentation)))))
      (setq start (match-end 0)))
    (interblock start (point-max))
    (run-hooks 'org-export-blocks-postblock-hook)))))
</t>
<t tx="ekr.20100929212226.14537">
(add-hook 'org-export-preprocess-hook 'org-export-blocks-preprocess)

;;================================================================================
;; type specific functions

;;--------------------------------------------------------------------------------
;; ditaa: create images from ASCII art using the ditaa utility
(defvar org-ditaa-jar-path (expand-file-name
                "ditaa.jar"
                (file-name-as-directory
                 (expand-file-name
                  "scripts"
                  (file-name-as-directory
                   (expand-file-name
                "../contrib"
                (file-name-directory (or load-file-name buffer-file-name)))))))
  "Path to the ditaa jar executable.")

(defun org-export-blocks-format-ditaa (body &amp;rest headers)
  "Pass block BODY to the ditaa utility creating an image.
Specify the path at which the image should be saved as the first
element of headers, any additional elements of headers will be
passed to the ditaa utility as command line arguments."
  (message "ditaa-formatting...")
  (let* ((args (if (cdr headers) (mapconcat 'identity (cdr headers) " ")))
         (data-file (make-temp-file "org-ditaa"))
     (hash (progn
         (set-text-properties 0 (length body) nil body)
         (sha1 (prin1-to-string (list body args)))))
     (raw-out-file (if headers (car headers)))
     (out-file-parts (if (string-match "\\(.+\\)\\.\\([^\\.]+\\)$" raw-out-file)
                 (cons (match-string 1 raw-out-file)
                   (match-string 2 raw-out-file))
               (cons raw-out-file "png")))
     (out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts))))
    (unless (file-exists-p org-ditaa-jar-path)
      (error (format "Could not find ditaa.jar at %s" org-ditaa-jar-path)))
    (setq body (if (string-match "^\\([^:\\|:[^ ]\\)" body)
           body
         (mapconcat (lambda (x) (substring x (if (&gt; (length x) 1) 2 1)))
                (org-split-string body "\n")
                "\n")))
    (cond
     ((or htmlp latexp docbookp)
      (unless (file-exists-p out-file)
        (mapc ;; remove old hashed versions of this file
         (lambda (file)
           (when (and (string-match (concat (regexp-quote (car out-file-parts))
                                            "_\\([[:alnum:]]+\\)\\."
                                            (regexp-quote (cdr out-file-parts)))
                                    file)
                      (= (length (match-string 1 out-file)) 40))
             (delete-file (expand-file-name file
                                            (file-name-directory out-file)))))
         (directory-files (or (file-name-directory out-file)
                              default-directory)))
        (with-temp-file data-file (insert body))
        (message (concat "java -jar " org-ditaa-jar-path " " args " " data-file " " out-file))
        (shell-command (concat "java -jar " org-ditaa-jar-path " " args " " data-file " " out-file)))
      (format "\n[[file:%s]]\n" out-file))
     (t (concat
     "\n#+BEGIN_EXAMPLE\n"
     body (if (string-match "\n$" body) "" "\n")
     "#+END_EXAMPLE\n")))))
</t>
<t tx="ekr.20100929212226.14538">
;;--------------------------------------------------------------------------------
;; dot: create graphs using the dot graphing language
;;      (require the dot executable to be in your path)
(defun org-export-blocks-format-dot (body &amp;rest headers)
  "Pass block BODY to the dot graphing utility creating an image.
Specify the path at which the image should be saved as the first
element of headers, any additional elements of headers will be
passed to the dot utility as command line arguments.  Don't
forget to specify the output type for the dot command, so if you
are exporting to a file with a name like 'image.png' you should
include a '-Tpng' argument, and your block should look like the
following.

#+begin_dot models.png -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\" -&gt; \"data_product\"
}
#+end_dot"
  (message "dot-formatting...")
  (let* ((args (if (cdr headers) (mapconcat 'identity (cdr headers) " ")))
         (data-file (make-temp-file "org-ditaa"))
     (hash (progn
         (set-text-properties 0 (length body) nil body)
         (sha1 (prin1-to-string (list body args)))))
     (raw-out-file (if headers (car headers)))
     (out-file-parts (if (string-match "\\(.+\\)\\.\\([^\\.]+\\)$" raw-out-file)
                 (cons (match-string 1 raw-out-file)
                   (match-string 2 raw-out-file))
               (cons raw-out-file "png")))
     (out-file (concat (car out-file-parts) "_" hash "." (cdr out-file-parts))))
    (cond
     ((or htmlp latexp docbookp)
      (unless (file-exists-p out-file)
        (mapc ;; remove old hashed versions of this file
         (lambda (file)
           (when (and (string-match (concat (regexp-quote (car out-file-parts))
                                            "_\\([[:alnum:]]+\\)\\."
                                            (regexp-quote (cdr out-file-parts)))
                                    file)
                      (= (length (match-string 1 out-file)) 40))
             (delete-file (expand-file-name file
                                            (file-name-directory out-file)))))
         (directory-files (or (file-name-directory out-file)
                              default-directory)))
        (with-temp-file data-file (insert body))
        (message (concat "dot " data-file " " args " -o " out-file))
        (shell-command (concat "dot " data-file " " args " -o " out-file)))
      (format "\n[[file:%s]]\n" out-file))
     (t (concat
     "\n#+BEGIN_EXAMPLE\n"
     body (if (string-match "\n$" body) "" "\n")
     "#+END_EXAMPLE\n")))))
</t>
<t tx="ekr.20100929212226.14539">
;;--------------------------------------------------------------------------------
;; comment: export comments in author-specific css-stylable divs
(defun org-export-blocks-format-comment (body &amp;rest headers)
  "Format comment BODY by OWNER and return it formatted for export.
Currently, this only does something for HTML export, for all
other backends, it converts the comment into an EXAMPLE segment."
  (let ((owner (if headers (car headers)))
    (title (if (cdr headers) (mapconcat 'identity (cdr headers) " "))))
    (cond
     (htmlp ;; We are exporting to HTML
      (concat "#+BEGIN_HTML\n"
          "&lt;div class=\"org-comment\""
          (if owner (format " id=\"org-comment-%s\" " owner))
          "&gt;\n"
          (if owner (concat "&lt;b&gt;" owner "&lt;/b&gt; ") "")
          (if (and title (&gt; (length title) 0)) (concat " -- " title "&lt;/br&gt;\n") "&lt;/br&gt;\n")
          "&lt;p&gt;\n"
          "#+END_HTML\n"
          body
          "#+BEGIN_HTML\n"
          "&lt;/p&gt;\n"
          "&lt;/div&gt;\n"
          "#+END_HTML\n"))
     (t ;; This is not HTML, so just make it an example.
      (concat "#+BEGIN_EXAMPLE\n"
          (if title (concat "Title:" title "\n") "")
          (if owner (concat "By:" owner "\n") "")
          body
          (if (string-match "\n\\'" body) "" "\n")
          "#+END_EXAMPLE\n")))))
</t>
<t tx="ekr.20100929212226.14540">@language lisp
@tabwidth -4
@others

(provide 'org-freemind)

;; arch-tag: e7b0d776-94fd-404a-b35e-0f855fae3627

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; org-freemind.el ends here
</t>
<t tx="ekr.20100929212226.14541">;;; org-freemind.el --- Export Org files to freemind

;; Copyright (C) 2009, 2010 Free Software Foundation, Inc.

;; Author: Lennart Borgman (lennart O borgman A gmail O com)
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;; --------------------------------------------------------------------
;; Features that might be required by this library:
;;
;; `backquote', `bytecomp', `cl', `easymenu', `font-lock',
;; `noutline', `org', `org-compat', `org-faces', `org-footnote',
;; `org-list', `org-macs', `org-src', `outline', `syntax',
;; `time-date', `xml'.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:
;;
;; This file tries to implement some functions useful for
;; transformation between org-mode and FreeMind files.
;;
;; Here are the commands you can use:
;;
;;    M-x `org-freemind-from-org-mode'
;;    M-x `org-freemind-from-org-mode-node'
;;    M-x `org-freemind-from-org-sparse-tree'
;;
;;    M-x `org-freemind-to-org-mode'
;;
;;    M-x `org-freemind-show'
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Change log:
;;
;; 2009-02-15: Added check for next level=current+1
;; 2009-02-21: Fixed bug in `org-freemind-to-org-mode'.
;; 2009-10-25: Added support for `org-odd-levels-only'.
;;             Added y/n question before showing in FreeMind.
;; 2009-11-04: Added support for #+BEGIN_HTML.
;;
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; This program is free software; you can redistribute it and/or
;; modify it under the terms of the GNU General Public License as
;; published by the Free Software Foundation; either version 2, or
;; (at your option) any later version.
;;
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;; General Public License for more details.
;;
;; You should have received a copy of the GNU General Public License
;; along with this program; see the file COPYING.  If not, write to
;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth
;; Floor, Boston, MA 02110-1301, USA.
;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Code:

(require 'xml)
(require 'org)
(require 'rx)
(require 'org-exp)
(eval-when-compile (require 'cl))

;; Fix-me: I am not sure these are useful:
;;
;; (defcustom org-freemind-main-fgcolor "black"
;;   "Color of main node's text."
;;   :type 'color
;;   :group 'freemind)

;; (defcustom org-freemind-main-color "black"
;;   "Background color of main node."
;;   :type 'color
;;   :group 'freemind)

;; (defcustom org-freemind-child-fgcolor "black"
;;   "Color of child nodes' text."
;;   :type 'color
;;   :group 'freemind)

;; (defcustom org-freemind-child-color "black"
;;   "Background color of child nodes."
;;   :type 'color
;;   :group 'freemind)

(defvar org-freemind-node-style nil "Internal use.")

(defcustom org-freemind-node-styles nil
  "Styles to apply to node.
NOT READY YET."
  :type '(repeat
          (list :tag "Node styles for file"
                (regexp :tag "File name")
                (repeat
                 (list :tag "Node"
                       (regexp :tag "Node name regexp")
                       (set :tag "Node properties"
                            (list :format "%v" (const :format "" node-style)
                                  (choice :tag "Style"
                                          :value bubble
                                          (const bubble)
                                          (const fork)))
                            (list :format "%v" (const :format "" color)
                                  (color :tag "Color" :value "red"))
                            (list :format "%v" (const :format "" background-color)
                                  (color :tag "Background color" :value "yellow"))
                            (list :format "%v" (const :format "" edge-color)
                                  (color :tag "Edge color" :value "green"))
                            (list :format "%v" (const :format "" edge-style)
                                  (choice :tag "Edge style" :value bezier
                                          (const :tag "Linear" linear)
                                          (const :tag "Bezier" bezier)
                                          (const :tag "Sharp Linear" sharp-linear)
                                          (const :tag "Sharp Bezier" sharp-bezier)))
                            (list :format "%v" (const :format "" edge-width)
                                  (choice :tag "Edge width" :value thin
                                          (const :tag "Parent" parent)
                                          (const :tag "Thin" thin)
                                          (const 1)
                                          (const 2)
                                          (const 4)
                                          (const 8)))
                            (list :format "%v" (const :format "" italic)
                                  (const :tag "Italic font" t))
                            (list :format "%v" (const :format "" bold)
                                  (const :tag "Bold font" t))
                            (list :format "%v" (const :format "" font-name)
                                  (string :tag "Font name" :value "SansSerif"))
                            (list :format "%v" (const :format "" font-size)
                                  (integer :tag "Font size" :value 12)))))))
  :group 'freemind)

</t>
<t tx="ekr.20100929212226.14542">;;;###autoload
(defun org-export-as-freemind (arg &amp;optional hidden ext-plist
                   to-buffer body-only pub-dir)
  (interactive "P")
  (let* ((opt-plist (org-combine-plists (org-default-export-plist)
                    ext-plist
                    (org-infile-export-plist)))
     (region-p (org-region-active-p))
     (rbeg (and region-p (region-beginning)))
     (rend (and region-p (region-end)))
     (subtree-p
      (if (plist-get opt-plist :ignore-subtree-p)
          nil
        (when region-p
          (save-excursion
        (goto-char rbeg)
        (and (org-at-heading-p)
             (&gt;= (org-end-of-subtree t t) rend))))))
     (opt-plist (setq org-export-opt-plist
              (if subtree-p
                  (org-export-add-subtree-options opt-plist rbeg)
                opt-plist)))
     (bfname (buffer-file-name (or (buffer-base-buffer) (current-buffer))))
     (filename (concat (file-name-as-directory
                (or pub-dir
                (org-export-directory :ascii opt-plist)))
               (file-name-sans-extension
                (or (and subtree-p
                     (org-entry-get (region-beginning)
                            "EXPORT_FILE_NAME" t))
                (file-name-nondirectory bfname)))
               ".mm")))
    (when (file-exists-p filename)
      (delete-file filename))
    (cond
     (subtree-p
      (org-freemind-from-org-mode-node (line-number-at-pos rbeg)
                       filename))
     (t (org-freemind-from-org-mode bfname filename)))))
</t>
<t tx="ekr.20100929212226.14543">
;;;###autoload
(defun org-freemind-show (mm-file)
  "Show file MM-FILE in FreeMind."
  (interactive
   (list
    (save-match-data
      (let ((name (read-file-name "FreeMind file: "
                                  nil nil nil
                                  (if (buffer-file-name)
                                      (file-name-nondirectory (buffer-file-name))
                                    "")
                                  ;; Fix-me: Is this an Emacs bug?
                                  ;; This predicate function is never
                                  ;; called.
                                  (lambda (fn)
                                    (string-match "^mm$" (file-name-extension fn))))))
        (setq name (expand-file-name name))
        name))))
  (org-open-file mm-file))
</t>
<t tx="ekr.20100929212226.14544">
(defconst org-freemind-org-nfix "--org-mode: ")

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Format converters

(defun org-freemind-escape-str-from-org (org-str)
  "Do some html-escaping of ORG-STR and return the result.
The characters \"&amp;&lt;&gt; will be escaped."
  (let ((chars (append org-str nil))
        (fm-str ""))
    (dolist (cc chars)
      (setq fm-str
            (concat fm-str
                    (if (&lt; cc 256)
                        (cond
                         ((= cc ?\") "&amp;quot;")
                         ((= cc ?\&amp;) "&amp;amp;")
                         ((= cc ?\&lt;) "&amp;lt;")
                         ((= cc ?\&gt;) "&amp;gt;")
                         (t (char-to-string cc)))
                      ;; Formatting as &amp;#number; is maybe needed
                      ;; according to a bug report from kazuo
                      ;; fujimoto, but I have now instead added a xml
                      ;; processing instruction saying that the mm
                      ;; file is utf-8:
                      ;;
                      ;; (format "&amp;#x%x;" (- cc ;; ?\x800))
              (format "&amp;#x%x;" (encode-char cc 'ucs))
                      ))))
    fm-str))
</t>
<t tx="ekr.20100929212226.14545">
;;(org-freemind-unescape-str-to-org "&amp;#x6d;A&amp;#x224C;B&amp;lt;C&amp;#x3C;&amp;#x3D;")
;;(org-freemind-unescape-str-to-org "&amp;#x3C;&amp;lt;")
(defun org-freemind-unescape-str-to-org (fm-str)
 "Do some html-unescaping of FM-STR and return the result.
This is the opposite of `org-freemind-escape-str-from-org' but it
will also unescape &amp;#nn;."
 (let ((org-str fm-str))
   (setq org-str (replace-regexp-in-string "&amp;quot;" "\"" org-str))
   (setq org-str (replace-regexp-in-string "&amp;amp;" "&amp;" org-str))
   (setq org-str (replace-regexp-in-string "&amp;lt;" "&lt;" org-str))
   (setq org-str (replace-regexp-in-string "&amp;gt;" "&gt;" org-str))
   (setq org-str (replace-regexp-in-string
                  "&amp;#x\\([a-f0-9]\\{2,4\\}\\);"
                  (lambda (m)
                    (char-to-string
                     (+ (string-to-number (match-string 1 m) 16)
                        0 ;?\x800 ;; What is this for? Encoding?
                        )))
                  org-str))))
</t>
<t tx="ekr.20100929212226.14546">
;; (org-freemind-test-escape)
(defun org-freemind-test-escape ()
  (let* ((str1 "a quote: \", an amp: &amp;, lt: &lt;; over 256: ��")
         (str2 (org-freemind-escape-str-from-org str1))
         (str3 (org-freemind-unescape-str-to-org str2))
        )
    (unless (string= str1 str3)
      (error "str3=%s" str3))
    ))
</t>
<t tx="ekr.20100929212226.14547">
(defun org-freemind-convert-links-from-org (org-str)
  "Convert org links in ORG-STR to FreeMind links and return the result."
  (let ((fm-str (replace-regexp-in-string
                 (rx (not (any "[\""))
                     (submatch
                      "http"
                      (opt ?\s)
                      "://"
                      (1+
                       (any "-%.?@a-zA-Z0-9()_/:~=&amp;#"))))
                 "[[\\1][\\1]]"
                 org-str)))
    (replace-regexp-in-string (rx "[["
                                  (submatch (*? nonl))
                                  "]["
                                  (submatch (*? nonl))
                                  "]]")
                              "&lt;a href=\"\\1\"&gt;\\2&lt;/a&gt;"
                              fm-str)))
</t>
<t tx="ekr.20100929212226.14548">
;;(org-freemind-convert-links-to-org "&lt;a href=\"http://www.somewhere/\"&gt;link-text&lt;/a&gt;")
(defun org-freemind-convert-links-to-org (fm-str)
  "Convert FreeMind links in FM-STR to org links and return the result."
  (let ((org-str (replace-regexp-in-string
                  (rx "&lt;a"
                      space
                      (0+
                       (0+ (not (any "&gt;")))
                       space)
                      "href=\""
                      (submatch (0+ (not (any "\""))))
                      "\""
                      (0+ (not (any "&gt;")))
                       "&gt;"
                       (submatch (0+ (not (any "&lt;"))))
                       "&lt;/a&gt;")
                  "[[\\1][\\2]]"
                  fm-str)))
    org-str))
</t>
<t tx="ekr.20100929212226.14549">
;; Fix-me:
;;(defun org-freemind-convert-drawers-from-org (text)
;;  )

;; (org-freemind-test-links)
;; (defun org-freemind-test-links ()
;;   (let* ((str1 "[[http://www.somewhere/][link-text]")
;;          (str2 (org-freemind-convert-links-from-org str1))
;;          (str3 (org-freemind-convert-links-to-org str2))
;;         )
;;     (unless (string= str1 str3)
;;       (error "str3=%s" str3))
;;     ))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; Org =&gt; FreeMind

(defun org-freemind-convert-text-p (text)
  "Convert TEXT to html with &lt;p&gt; paragraphs."
  (setq text (org-freemind-escape-str-from-org text))
  (setq text (replace-regexp-in-string (rx "\n" (0+ blank) "\n") "&lt;/p&gt;&lt;p&gt;\n" text))
  ;;(setq text (replace-regexp-in-string (rx bol (1+ blank) eol) "" text))
  ;;(setq text (replace-regexp-in-string (rx bol (1+ blank)) "&lt;br /&gt;" text))
  (setq text (replace-regexp-in-string "\n" "&lt;br /&gt;" text))
  (concat "&lt;p&gt;"
          (org-freemind-convert-links-from-org text)
          "&lt;/p&gt;\n"))
</t>
<t tx="ekr.20100929212226.14550">
(defun org-freemind-org-text-to-freemind-subnode/note (node-name start end drawers-regexp)
  "Convert text part of org node to FreeMind subnode or note.
Convert the text part of the org node named NODE-NAME.  The text
is in the current buffer between START and END.  Drawers matching
DRAWERS-REGEXP are converted to FreeMind notes."
  ;; fix-me: doc
  (let ((text (buffer-substring-no-properties start end))
        (node-res "")
        (note-res ""))
    (save-match-data
      ;;(setq text (org-freemind-escape-str-from-org text))
      ;; First see if there is something that should be moved to the
      ;; note part:
      (let (drawers)
        (while (string-match drawers-regexp text)
          (setq drawers (cons (match-string 0 text) drawers))
          (setq text
                (concat (substring text 0 (match-beginning 0))
                        (substring text (match-end 0))))
          )
        (when drawers
          (dolist (drawer drawers)
            (let ((lines (split-string drawer "\n")))
              (dolist (line lines)
                (setq note-res (concat
                                note-res
                                org-freemind-org-nfix line "&lt;br /&gt;\n")))
              ))))

      (when (&gt; (length note-res) 0)
        (setq note-res (concat
                        "&lt;richcontent TYPE=\"NOTE\"&gt;&lt;html&gt;\n"
                        "&lt;head&gt;\n"
                        "&lt;/head&gt;\n"
                        "&lt;body&gt;\n"
                        note-res
                        "&lt;/body&gt;\n"
                        "&lt;/html&gt;\n"
                        "&lt;/richcontent&gt;\n"))
        )

      ;; There is always an LF char:
      (when (&gt; (length text) 1)
        (setq node-res (concat
                        "&lt;node style=\"bubble\" background_color=\"#eeee00\"&gt;\n"
                        "&lt;richcontent TYPE=\"NODE\"&gt;&lt;html&gt;\n"
                        "&lt;head&gt;\n"
                        "&lt;style type=\"text/css\"&gt;\n"
                        "&lt;!--\n"
                        "p { margin-top: 0 }\n"
                        "--&gt;\n"
                        "&lt;/style&gt;\n"
                        "&lt;/head&gt;\n"
                        "&lt;body&gt;\n"))
        (let ((begin-html-mark (regexp-quote "#+BEGIN_HTML"))
              (end-html-mark   (regexp-quote "#+END_HTML"))
              head
              end-pos
              end-pos-match
              )
          ;; Take care of #+BEGIN_HTML - #+END_HTML
          (while (string-match begin-html-mark text)
            (setq head (substring text 0 (match-beginning 0)))
            (setq end-pos-match (match-end 0))
            (setq node-res (concat node-res
                                   (org-freemind-convert-text-p head)))
            (setq text (substring text end-pos-match))
            (setq end-pos (string-match end-html-mark text))
            (if end-pos
                (setq end-pos-match (match-end 0))
              (message "org-freemind: Missing #+END_HTML")
              (setq end-pos (length text))
              (setq end-pos-match end-pos))
            (setq node-res (concat node-res
                                   (substring text 0 end-pos)))
            (setq text (substring text end-pos-match)))
          (setq node-res (concat node-res
                                 (org-freemind-convert-text-p text))))
        (setq node-res (concat
                        node-res
                        "&lt;/body&gt;\n"
                        "&lt;/html&gt;\n"
                        "&lt;/richcontent&gt;\n"
                        ;; Put a note that this is for the parent node
                        "&lt;richcontent TYPE=\"NOTE\"&gt;&lt;html&gt;"
                        "&lt;head&gt;"
                        "&lt;/head&gt;"
                        "&lt;body&gt;"
                        "&lt;p&gt;"
                        "-- This is more about \"" node-name "\" --"
                        "&lt;/p&gt;"
                        "&lt;/body&gt;"
                        "&lt;/html&gt;"
                        "&lt;/richcontent&gt;\n"
                        "&lt;/node&gt;\n" ;; ok
                        )))
      (list node-res note-res))))
</t>
<t tx="ekr.20100929212226.14551">
(defun org-freemind-write-node (mm-buffer drawers-regexp num-left-nodes base-level current-level next-level this-m2 this-node-end this-children-visible next-node-start next-has-some-visible-child)
  (let* (this-icons
         this-bg-color
         this-m2-escaped
         this-rich-node
         this-rich-note
         )
    (when (string-match "TODO" this-m2)
      (setq this-m2 (replace-match "" nil nil this-m2))
      (add-to-list 'this-icons "button_cancel")
      (setq this-bg-color "#ffff88")
      (when (string-match "\\[#\\(.\\)\\]" this-m2)
        (let ((prior (string-to-char (match-string 1 this-m2))))
          (setq this-m2 (replace-match "" nil nil this-m2))
          (cond
           ((= prior ?A)
            (add-to-list 'this-icons "full-1")
            (setq this-bg-color "#ff0000"))
           ((= prior ?B)
            (add-to-list 'this-icons "full-2")
            (setq this-bg-color "#ffaa00"))
           ((= prior ?C)
            (add-to-list 'this-icons "full-3")
            (setq this-bg-color "#ffdd00"))
           ((= prior ?D)
            (add-to-list 'this-icons "full-4")
            (setq this-bg-color "#ffff00"))
           ((= prior ?E)
            (add-to-list 'this-icons "full-5"))
           ((= prior ?F)
            (add-to-list 'this-icons "full-6"))
           ((= prior ?G)
            (add-to-list 'this-icons "full-7"))
           ))))
    (setq this-m2 (org-trim this-m2))
    (setq this-m2-escaped (org-freemind-escape-str-from-org this-m2))
    (let ((node-notes (org-freemind-org-text-to-freemind-subnode/note
                       this-m2-escaped
                       this-node-end
                       (1- next-node-start)
                       drawers-regexp)))
      (setq this-rich-node (nth 0 node-notes))
      (setq this-rich-note (nth 1 node-notes)))
    (with-current-buffer mm-buffer
      (insert "&lt;node text=\"" this-m2-escaped "\"")
      (org-freemind-get-node-style this-m2)
      (when (&gt; next-level current-level)
        (unless (or this-children-visible
                    next-has-some-visible-child)
          (insert " folded=\"true\"")))
      (when (and (= current-level (1+ base-level))
                 (&gt; num-left-nodes 0))
        (setq num-left-nodes (1- num-left-nodes))
        (insert " position=\"left\""))
      (when this-bg-color
        (insert " background_color=\"" this-bg-color "\""))
      (insert "&gt;\n")
      (when this-icons
        (dolist (icon this-icons)
          (insert "&lt;icon builtin=\"" icon "\"/&gt;\n")))
      )
    (with-current-buffer mm-buffer
      (when this-rich-note (insert this-rich-note))
      (when this-rich-node (insert this-rich-node))))
  num-left-nodes)
</t>
<t tx="ekr.20100929212226.14552">
(defun org-freemind-check-overwrite (file interactively)
  "Check if file FILE already exists.
If FILE does not exists return t.

If INTERACTIVELY is non-nil ask if the file should be replaced
and return t/nil if it should/should not be replaced.

Otherwise give an error say the file exists."
  (if (file-exists-p file)
      (if interactively
          (y-or-n-p (format "File %s exists, replace it? " file))
        (error "File %s already exists" file))
    t))
</t>
<t tx="ekr.20100929212226.14553">
(defvar org-freemind-node-pattern (rx bol
                         (submatch (1+ "*"))
                         (1+ space)
                         (submatch (*? nonl))
                         eol))

(defun org-freemind-look-for-visible-child (node-level)
  (save-excursion
    (save-match-data
      (let ((found-visible-child nil))
        (while (and (not found-visible-child)
                    (re-search-forward org-freemind-node-pattern nil t))
          (let* ((m1 (match-string-no-properties 1))
                 (level (length m1)))
            (if (&gt;= node-level level)
                (setq found-visible-child 'none)
              (unless (get-char-property (line-beginning-position) 'invisible)
                (setq found-visible-child 'found)))))
        (eq found-visible-child 'found)
        ))))
</t>
<t tx="ekr.20100929212226.14554">
(defun org-freemind-goto-line (line)
  "Go to line number LINE."
  (save-restriction
    (widen)
    (goto-char (point-min))
    (forward-line (1- line))))
</t>
<t tx="ekr.20100929212226.14555">
(defun org-freemind-write-mm-buffer (org-buffer mm-buffer node-at-line)
  (with-current-buffer org-buffer
    (dolist (node-style org-freemind-node-styles)
      (when (org-string-match-p (car node-style) buffer-file-name)
        (setq org-freemind-node-style (cadr node-style))))
    ;;(message "org-freemind-node-style =%s" org-freemind-node-style)
    (save-match-data
      (let* ((drawers (copy-sequence org-drawers))
             drawers-regexp
             (num-top1-nodes 0)
             (num-top2-nodes 0)
             num-left-nodes
             (unclosed-nodes 0)
         (odd-only org-odd-levels-only)
             (first-time t)
             (current-level 1)
             base-level
             prev-node-end
             rich-text
             unfinished-tag
             node-at-line-level
             node-at-line-last)
        (with-current-buffer mm-buffer
          (erase-buffer)
          (insert "&lt;?xml version=\"1.0\" encoding=\"utf-8\"?&gt;\n")
          (insert "&lt;map version=\"0.9.0\"&gt;\n")
          (insert "&lt;!-- To view this file, download free mind mapping software FreeMind from http://freemind.sourceforge.net --&gt;\n"))
        (save-excursion
          ;; Get special buffer vars:
          (goto-char (point-min))
          (while (re-search-forward (rx bol "#+DRAWERS:") nil t)
            (let ((dr-txt (buffer-substring-no-properties (match-end 0) (line-end-position))))
              (setq drawers (append drawers (split-string dr-txt) nil))))
          (setq drawers-regexp
                (concat (rx bol (0+ blank) ":")
                        (regexp-opt drawers)
                        (rx ":" (0+ blank)
                            "\n"
                            (*? anything)
                            "\n"
                            (0+ blank)
                            ":END:"
                            (0+ blank)
                            eol)
                        ))

          (if node-at-line
              ;; Get number of top nodes and last line for this node
              (progn
                (org-freemind-goto-line node-at-line)
                (unless (looking-at org-freemind-node-pattern)
                  (error "No node at line %s" node-at-line))
                (setq node-at-line-level (length (match-string-no-properties 1)))
                (forward-line)
                (setq node-at-line-last
                      (catch 'last-line
                        (while (re-search-forward org-freemind-node-pattern nil t)
                          (let* ((m1 (match-string-no-properties 1))
                                 (level (length m1)))
                            (if (&lt;= level node-at-line-level)
                                (progn
                                  (beginning-of-line)
                                  (throw 'last-line (1- (point))))
                              (if (= level (1+ node-at-line-level))
                                  (setq num-top2-nodes (1+ num-top2-nodes))))))))
                (setq current-level node-at-line-level)
                (setq num-top1-nodes 1)
                (org-freemind-goto-line node-at-line))

            ;; First get number of top nodes
            (goto-char (point-min))
            (while (re-search-forward org-freemind-node-pattern nil t)
              (let* ((m1 (match-string-no-properties 1))
                     (level (length m1)))
                (if (= level 1)
                    (setq num-top1-nodes (1+ num-top1-nodes))
                  (if (= level 2)
                      (setq num-top2-nodes (1+ num-top2-nodes))))))
            ;; If there is more than one top node we need to insert a node
            ;; to keep them together.
            (goto-char (point-min))
            (when (&gt; num-top1-nodes 1)
              (setq num-top2-nodes num-top1-nodes)
              (setq current-level 0)
              (let ((orig-name (if buffer-file-name
                                   (file-name-nondirectory (buffer-file-name))
                                 (buffer-name))))
                (with-current-buffer mm-buffer
                  (insert "&lt;node text=\"" orig-name "\" background_color=\"#00bfff\"&gt;\n"
                          ;; Put a note that this is for the parent node
                          "&lt;richcontent TYPE=\"NOTE\"&gt;&lt;html&gt;"
                          "&lt;head&gt;"
                          "&lt;/head&gt;"
                          "&lt;body&gt;"
                          "&lt;p&gt;"
                          org-freemind-org-nfix "WHOLE FILE"
                          "&lt;/p&gt;"
                          "&lt;/body&gt;"
                          "&lt;/html&gt;"
                          "&lt;/richcontent&gt;\n")))))

          (setq num-left-nodes (floor num-top2-nodes 2))
          (setq base-level current-level)
          (let (this-m2
                this-node-end
                this-children-visible
                next-m2
                next-node-start
                next-level
                next-has-some-visible-child
                next-children-visible
                )
            (while (and
                    (re-search-forward org-freemind-node-pattern nil t)
                    (if node-at-line-last (&lt;= (point) node-at-line-last) t)
                    )
              (let* ((next-m1 (match-string-no-properties 1))
                     (next-node-end (match-end 0))
                     )
                (setq next-node-start (match-beginning 0))
                (setq next-m2 (match-string-no-properties 2))
                (setq next-level (length next-m1))
                (setq next-children-visible
                      (not (eq 'outline
                               (get-char-property (line-end-position) 'invisible))))
                (setq next-has-some-visible-child
                      (if next-children-visible t
                        (org-freemind-look-for-visible-child next-level)))
                (when this-m2
                  (setq num-left-nodes (org-freemind-write-node mm-buffer drawers-regexp num-left-nodes base-level current-level next-level this-m2 this-node-end this-children-visible next-node-start next-has-some-visible-child)))
                (when (if (= num-top1-nodes 1) (&gt; current-level base-level) t)
                  (while (&gt;= current-level next-level)
                    (with-current-buffer mm-buffer
                      (insert "&lt;/node&gt;\n")
                      (setq current-level
                (- current-level (if odd-only 2 1))))))
                (setq this-node-end (1+ next-node-end))
                (setq this-m2 next-m2)
                (setq current-level next-level)
                (setq this-children-visible next-children-visible)
                (forward-char)
                ))
;;;             (unless (if node-at-line-last
;;;                         (&gt;= (point) node-at-line-last)
;;;                       nil)
              ;; Write last node:
              (setq this-m2 next-m2)
              (setq current-level next-level)
              (setq next-node-start (if node-at-line-last
                                        (1+ node-at-line-last)
                                      (point-max)))
              (setq num-left-nodes (org-freemind-write-node mm-buffer drawers-regexp num-left-nodes base-level current-level next-level this-m2 this-node-end this-children-visible next-node-start next-has-some-visible-child))
              (with-current-buffer mm-buffer (insert "&lt;/node&gt;\n"))
              ;)
            )
          (with-current-buffer mm-buffer
            (while (&gt; current-level base-level)
              (insert "&lt;/node&gt;\n")
          (setq current-level
            (- current-level (if odd-only 2 1)))
              ))
          (with-current-buffer mm-buffer
            (insert "&lt;/map&gt;")
            (delete-trailing-whitespace)
            (goto-char (point-min))
            ))))))
</t>
<t tx="ekr.20100929212226.14556">
(defun org-freemind-get-node-style (node-name)
  "NOT READY YET."
  ;;&lt;node BACKGROUND_COLOR="#eeee00" CREATED="1234668815593" MODIFIED="1234668815593" STYLE="bubble"&gt;
  ;;&lt;font BOLD="true" NAME="SansSerif" SIZE="12"/&gt;
  (let (node-styles
        node-style)
    (dolist (style-list org-freemind-node-style)
      (let ((node-regexp (car style-list)))
        (message "node-regexp=%s node-name=%s" node-regexp node-name)
        (when (org-string-match-p node-regexp node-name)
          ;;(setq node-style (org-freemind-do-apply-node-style style-list))
          (setq node-style (cadr style-list))
          (when node-style
            (message "node-style=%s" node-style)
            (setq node-styles (append node-styles node-style)))
          )))))
</t>
<t tx="ekr.20100929212226.14557">
(defun org-freemind-do-apply-node-style (style-list)
  (message "style-list=%S" style-list)
  (let ((node-style 'fork)
        (color "red")
        (background-color "yellow")
        (edge-color "green")
        (edge-style 'bezier)
        (edge-width 'thin)
        (italic t)
        (bold t)
        (font-name "SansSerif")
        (font-size 12))
    (dolist (style (cadr style-list))
      (message "    style=%s" style)
      (let ((what (car style)))
        (cond
         ((eq what 'node-style)
          (setq node-style (cadr style)))
         ((eq what 'color)
          (setq color (cadr style)))
         ((eq what 'background-color)
          (setq background-color (cadr style)))

         ((eq what 'edge-color)
          (setq edge-color (cadr style)))

         ((eq what 'edge-style)
          (setq edge-style (cadr style)))

         ((eq what 'edge-width)
          (setq edge-width (cadr style)))

         ((eq what 'italic)
          (setq italic (cadr style)))

         ((eq what 'bold)
          (setq bold (cadr style)))

         ((eq what 'font-name)
          (setq font-name (cadr style)))

         ((eq what 'font-size)
          (setq font-size (cadr style)))
         )
        (insert (format " style=\"%s\"" node-style))
        (insert (format " color=\"%s\"" color))
        (insert (format " background_color=\"%s\"" background-color))
        (insert "&gt;\n")
        (insert "&lt;edge")
        (insert (format " color=\"%s\"" edge-color))
        (insert (format " style=\"%s\"" edge-style))
        (insert (format " width=\"%s\"" edge-width))
        (insert "/&gt;\n")
        (insert "&lt;font")
        (insert (format " italic=\"%s\"" italic))
        (insert (format " bold=\"%s\"" bold))
        (insert (format " name=\"%s\"" font-name))
        (insert (format " size=\"%s\"" font-size))
        ))))
</t>
<t tx="ekr.20100929212226.14558">
;;;###autoload
(defun org-freemind-from-org-mode-node (node-line mm-file)
  "Convert node at line NODE-LINE to the FreeMind file MM-FILE."
  (interactive
   (progn
     (unless (org-back-to-heading nil)
       (error "Can't find org-mode node start"))
     (let* ((line (line-number-at-pos))
            (default-mm-file (concat (if buffer-file-name
                                         (file-name-nondirectory buffer-file-name)
                                       "nofile")
                                     "-line-" (number-to-string line)
                                     ".mm"))
            (mm-file (read-file-name "Output FreeMind file: " nil nil nil default-mm-file)))
       (list line mm-file))))
  (when (org-freemind-check-overwrite mm-file (interactive-p))
    (let ((org-buffer (current-buffer))
          (mm-buffer (find-file-noselect mm-file)))
      (org-freemind-write-mm-buffer org-buffer mm-buffer node-line)
      (with-current-buffer mm-buffer
        (basic-save-buffer)
        (when (interactive-p)
          (switch-to-buffer-other-window mm-buffer)
          (when (y-or-n-p "Show in FreeMind? ")
            (org-freemind-show buffer-file-name)))))))
</t>
<t tx="ekr.20100929212226.14559">
;;;###autoload
(defun org-freemind-from-org-mode (org-file mm-file)
  "Convert the `org-mode' file ORG-FILE to the FreeMind file MM-FILE."
  ;; Fix-me: better doc, include recommendations etc.
  (interactive
   (let* ((org-file buffer-file-name)
          (default-mm-file (concat
                            (if org-file
                                (file-name-nondirectory org-file)
                              "nofile")
                            ".mm"))
          (mm-file (read-file-name "Output FreeMind file: " nil nil nil default-mm-file)))
     (list org-file mm-file)))
  (when (org-freemind-check-overwrite mm-file (interactive-p))
    (let ((org-buffer (if org-file (find-file-noselect org-file) (current-buffer)))
          (mm-buffer (find-file-noselect mm-file)))
      (org-freemind-write-mm-buffer org-buffer mm-buffer nil)
      (with-current-buffer mm-buffer
        (basic-save-buffer)
        (when (interactive-p)
          (switch-to-buffer-other-window mm-buffer)
          (when (y-or-n-p "Show in FreeMind? ")
            (org-freemind-show buffer-file-name)))))))
</t>
<t tx="ekr.20100929212226.14560">
;;;###autoload
(defun org-freemind-from-org-sparse-tree (org-buffer mm-file)
  "Convert visible part of buffer ORG-BUFFER to FreeMind file MM-FILE."
  (interactive
   (let* ((org-file buffer-file-name)
          (default-mm-file (concat
                            (if org-file
                                (file-name-nondirectory org-file)
                              "nofile")
                            "-sparse.mm"))
          (mm-file (read-file-name "Output FreeMind file: " nil nil nil default-mm-file)))
     (list (current-buffer) mm-file)))
  (when (org-freemind-check-overwrite mm-file (interactive-p))
    (let (org-buffer
          (mm-buffer (find-file-noselect mm-file)))
      (save-window-excursion
        (org-export-visible ?\  nil)
        (setq org-buffer (current-buffer)))
      (org-freemind-write-mm-buffer org-buffer mm-buffer nil)
      (with-current-buffer mm-buffer
        (basic-save-buffer)
        (when (interactive-p)
          (switch-to-buffer-other-window mm-buffer)
          (when (y-or-n-p "Show in FreeMind? ")
            (org-freemind-show buffer-file-name)))))))
</t>
<t tx="ekr.20100929212226.14561">

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;; FreeMind =&gt; Org

;; (sort '(b a c) 'org-freemind-lt-symbols)
(defun org-freemind-lt-symbols (sym-a sym-b)
  (string&lt; (symbol-name sym-a) (symbol-name sym-b)))
</t>
<t tx="ekr.20100929212226.14562">;; (sort '((b . 1) (a . 2) (c . 3)) 'org-freemind-lt-xml-attrs)
(defun org-freemind-lt-xml-attrs (attr-a attr-b)
  (string&lt; (symbol-name (car attr-a)) (symbol-name (car attr-b))))
</t>
<t tx="ekr.20100929212226.14563">
;; xml-parse-region gives things like
;; ((p nil "\n"
;;     (a
;;      ((href . "link"))
;;      "text")
;;     "\n"
;;     (b nil "hej")
;;     "\n"))

;; '(a . nil)

;; (org-freemind-symbols= 'a (car '(A B)))
(defsubst org-freemind-symbols= (sym-a sym-b)
  "Return t if downcased names of SYM-A and SYM-B are equal.
SYM-A and SYM-B should be symbols."
  (or (eq sym-a sym-b)
      (string= (downcase (symbol-name sym-a))
               (downcase (symbol-name sym-b)))))

(defun org-freemind-get-children (parent path)
  "Find children node to PARENT from PATH.
PATH should be a list of steps, where each step has the form

  '(NODE-NAME (ATTR-NAME . ATTR-VALUE))"
  ;; Fix-me: maybe implement op? step: Name, number, attr, attr op val
  ;; Fix-me: case insensitive version for children?
  (let* ((children (if (not (listp (car parent)))
                       (cddr parent)
                     (let (cs)
                       (dolist (p parent)
                         (dolist (c (cddr p))
                           (add-to-list 'cs c)))
                       cs)
                     ))
         (step (car path))
         (step-node (if (listp step) (car step) step))
         (step-attr-list (when (listp step) (sort (cdr step) 'org-freemind-lt-xml-attrs)))
         (path-tail (cdr path))
         path-children)
    (dolist (child children)
      ;; skip xml.el formatting nodes
      (unless (stringp child)
        ;; compare node name
        (when (if (not step-node)
                  t ;; any node name
                (org-freemind-symbols= step-node (car child)))
          (if (not step-attr-list)
              ;;(throw 'path-child child) ;; no attr to care about
              (add-to-list 'path-children child)
            (let* ((child-attr-list (cadr child))
                   (step-attr-copy (copy-sequence step-attr-list)))
              (dolist (child-attr child-attr-list)
                                   ;; Compare attr names:
                (when (org-freemind-symbols= (caar step-attr-copy) (car child-attr))
                  ;; Compare values:
                  (let ((step-val (cdar step-attr-copy))
                        (child-val (cdr child-attr)))
                    (when (if (not step-val)
                              t ;; any value
                            (string= step-val child-val))
                      (setq step-attr-copy (cdr step-attr-copy))))))
              ;; Did we find all?
              (unless step-attr-copy
                ;;(throw 'path-child child)
                (add-to-list 'path-children child)
                ))))))
    (if path-tail
        (org-freemind-get-children path-children path-tail)
      path-children)))
</t>
<t tx="ekr.20100929212226.14564">
(defun org-freemind-get-richcontent-node (node)
  (let ((rc-nodes
         (org-freemind-get-children node '((richcontent (type . "NODE")) html body))))
    (when (&gt; (length rc-nodes) 1)
      (lwarn t :warning "Unexpected structure: several &lt;richcontent type=\"NODE\" ...&gt;"))
    (car rc-nodes)))
</t>
<t tx="ekr.20100929212226.14565">
(defun org-freemind-get-richcontent-note (node)
  (let ((rc-notes
         (org-freemind-get-children node '((richcontent (type . "NOTE")) html body))))
    (when (&gt; (length rc-notes) 1)
      (lwarn t :warning "Unexpected structure: several &lt;richcontent type=\"NOTE\" ...&gt;"))
    (car rc-notes)))
</t>
<t tx="ekr.20100929212226.14566">
(defun org-freemind-test-get-tree-text ()
  (let ((node '(p nil "\n"
                 (a
                  ((href . "link"))
                  "text")
                 "\n"
                 (b nil "hej")
                 "\n")))
    (org-freemind-get-tree-text node)))
</t>
<t tx="ekr.20100929212226.14567">;; (org-freemind-test-get-tree-text)

(defun org-freemind-get-tree-text (node)
  (when node
    (let ((ntxt "")
          (link nil)
          (lf-after nil))
      (dolist (n node)
        (case n
          ;;(a (setq is-link t) )
          ((h1 h2 h3 h4 h5 h6 p)
           ;;(setq ntxt (concat "\n" ntxt))
           (setq lf-after 2)
           )
          (br
           (setq lf-after 1)
           )
          (t
           (cond
            ((stringp n)
             (when (string= n "\n") (setq n ""))
             (if link
                 (setq ntxt (concat ntxt
                                    "[[" link "][" n "]]"))
               (setq ntxt (concat ntxt n))))
            ((and n (listp n))
             (if (symbolp (car n))
                 (setq ntxt (concat ntxt (org-freemind-get-tree-text n)))
               ;; This should be the attributes:
               (dolist (att-val n)
                 (let ((att (car att-val))
                       (val (cdr att-val)))
                   (when (eq att 'href)
                     (setq link val)))))
             )))))
      (if lf-after
          (setq ntxt (concat ntxt (make-string lf-after ?\n)))
        (setq ntxt (concat ntxt " ")))
      ;;(setq ntxt (concat ntxt (format "{%s}" n)))
      ntxt)))
</t>
<t tx="ekr.20100929212226.14568">
(defun org-freemind-get-richcontent-node-text (node)
  "Get the node text as from the richcontent node NODE."
  (save-match-data
    (let* ((rc (org-freemind-get-richcontent-node node))
           (txt (org-freemind-get-tree-text rc)))
      ;;(when txt (setq txt (replace-regexp-in-string (rx (1+ whitespace)) " " txt)))
      txt
      )))
</t>
<t tx="ekr.20100929212226.14569">
(defun org-freemind-get-richcontent-note-text (node)
  "Get the node text as from the richcontent note NODE."
  (save-match-data
    (let* ((rc (org-freemind-get-richcontent-note node))
           (txt (when rc (org-freemind-get-tree-text rc))))
      ;;(when txt (setq txt (replace-regexp-in-string (rx (1+ whitespace)) " " txt)))
      txt
      )))
</t>
<t tx="ekr.20100929212226.14570">
(defun org-freemind-get-icon-names (node)
  (let* ((icon-nodes (org-freemind-get-children node '((icon ))))
         names)
    (dolist (icn icon-nodes)
      (setq names (cons (cdr (assq 'builtin (cadr icn))) names)))
    ;; (icon (builtin . "full-1"))
    names))
</t>
<t tx="ekr.20100929212226.14571">
(defun org-freemind-node-to-org (node level skip-levels)
  (let ((qname (car node))
        (attributes (cadr node))
        text
        (note (org-freemind-get-richcontent-note-text node))
        (mark "-- This is more about ")
        (icons (org-freemind-get-icon-names node))
        (children (cddr node)))
    (when (&lt; 0 (- level skip-levels))
      (dolist (attrib attributes)
        (case (car attrib)
          ('TEXT (setq text (cdr attrib)))
          ('text (setq text (cdr attrib)))))
      (unless text
        ;; There should be a richcontent node holding the text:
        (setq text (org-freemind-get-richcontent-node-text node)))
      (when icons
        (when (member "full-1" icons) (setq text (concat "[#A] " text)))
        (when (member "full-2" icons) (setq text (concat "[#B] " text)))
        (when (member "full-3" icons) (setq text (concat "[#C] " text)))
        (when (member "full-4" icons) (setq text (concat "[#D] " text)))
        (when (member "full-5" icons) (setq text (concat "[#E] " text)))
        (when (member "full-6" icons) (setq text (concat "[#F] " text)))
        (when (member "full-7" icons) (setq text (concat "[#G] " text)))
        (when (member "button_cancel" icons) (setq text (concat "TODO " text)))
        )
      (if (and note
               (string= mark (substring note 0 (length mark))))
          (progn
            (setq text (replace-regexp-in-string "\n $" "" text))
            (insert text))
        (case qname
          ('node
           (insert (make-string (- level skip-levels) ?*) " " text "\n")
           ))))
    (dolist (child children)
      (unless (or (null child)
                  (stringp child))
        (org-freemind-node-to-org child (1+ level) skip-levels)))))
</t>
<t tx="ekr.20100929212226.14572">
;; Fix-me: put back special things, like drawers that are stored in
;; the notes. Should maybe all notes contents be put in drawers?
;;;###autoload
(defun org-freemind-to-org-mode (mm-file org-file)
  "Convert FreeMind file MM-FILE to `org-mode' file ORG-FILE."
  (interactive
   (save-match-data
     (let* ((mm-file (buffer-file-name))
            (default-org-file (concat (file-name-nondirectory mm-file) ".org"))
            (org-file (read-file-name "Output org-mode file: " nil nil nil default-org-file)))
       (list mm-file org-file))))
  (when (org-freemind-check-overwrite org-file (interactive-p))
    (let ((mm-buffer (find-file-noselect mm-file))
          (org-buffer (find-file-noselect org-file)))
      (with-current-buffer mm-buffer
        (let* ((xml-list (xml-parse-file mm-file))
               (top-node (cadr (cddar xml-list)))
               (note (org-freemind-get-richcontent-note-text top-node))
               (skip-levels
                (if (and note
                         (string-match (rx bol "--org-mode: WHOLE FILE" eol) note))
                    1
                  0)))
          (with-current-buffer org-buffer
            (erase-buffer)
            (org-freemind-node-to-org top-node 1 skip-levels)
            (goto-char (point-min))
            (org-set-tags t t) ;; Align all tags
            )
          (switch-to-buffer-other-window org-buffer)
          )))))
</t>
<t tx="ekr.20100929212226.14573">@language lisp
@tabwidth -4
@others

(defconst org-latex-entities
 '("\\!"
   "\\'"
   "\\+"
   "\\,"
   "\\-"
   "\\:"
   "\\;"
   "\\&lt;"
   "\\="
   "\\&gt;"
   "\\Huge"
   "\\LARGE"
   "\\Large"
   "\\Styles"
   "\\\\"
   "\\`"
   "\\addcontentsline"
   "\\address"
   "\\addtocontents"
   "\\addtocounter"
   "\\addtolength"
   "\\addvspace"
   "\\alph"
   "\\appendix"
   "\\arabic"
   "\\author"
   "\\begin{array}"
   "\\begin{center}"
   "\\begin{description}"
   "\\begin{enumerate}"
   "\\begin{eqnarray}"
   "\\begin{equation}"
   "\\begin{figure}"
   "\\begin{flushleft}"
   "\\begin{flushright}"
   "\\begin{itemize}"
   "\\begin{list}"
   "\\begin{minipage}"
   "\\begin{picture}"
   "\\begin{quotation}"
   "\\begin{quote}"
   "\\begin{tabbing}"
   "\\begin{table}"
   "\\begin{tabular}"
   "\\begin{thebibliography}"
   "\\begin{theorem}"
   "\\begin{titlepage}"
   "\\begin{verbatim}"
   "\\begin{verse}"
   "\\bf"
   "\\bf"
   "\\bibitem"
   "\\bigskip"
   "\\cdots"
   "\\centering"
   "\\circle"
   "\\cite"
   "\\cleardoublepage"
   "\\clearpage"
   "\\cline"
   "\\closing"
   "\\dashbox"
   "\\date"
   "\\ddots"
   "\\dotfill"
   "\\em"
   "\\fbox"
   "\\flushbottom"
   "\\fnsymbol"
   "\\footnote"
   "\\footnotemark"
   "\\footnotesize"
   "\\footnotetext"
   "\\frac"
   "\\frame"
   "\\framebox"
   "\\hfill"
   "\\hline"
   "\\hrulespace"
   "\\hspace"
   "\\huge"
   "\\hyphenation"
   "\\include"
   "\\includeonly"
   "\\indent"
   "\\input"
   "\\it"
   "\\kill"
   "\\label"
   "\\large"
   "\\ldots"
   "\\line"
   "\\linebreak"
   "\\linethickness"
   "\\listoffigures"
   "\\listoftables"
   "\\location"
   "\\makebox"
   "\\maketitle"
   "\\mark"
   "\\mbox"
   "\\medskip"
   "\\multicolumn"
   "\\multiput"
   "\\newcommand"
   "\\newcounter"
   "\\newenvironment"
   "\\newfont"
   "\\newlength"
   "\\newline"
   "\\newpage"
   "\\newsavebox"
   "\\newtheorem"
   "\\nocite"
   "\\nofiles"
   "\\noindent"
   "\\nolinebreak"
   "\\nopagebreak"
   "\\normalsize"
   "\\onecolumn"
   "\\opening"
   "\\oval"
   "\\overbrace"
   "\\overline"
   "\\pagebreak"
   "\\pagenumbering"
   "\\pageref"
   "\\pagestyle"
   "\\par"
   "\\parbox"
   "\\put"
   "\\raggedbottom"
   "\\raggedleft"
   "\\raggedright"
   "\\raisebox"
   "\\ref"
   "\\rm"
   "\\roman"
   "\\rule"
   "\\savebox"
   "\\sc"
   "\\scriptsize"
   "\\setcounter"
   "\\setlength"
   "\\settowidth"
   "\\sf"
   "\\shortstack"
   "\\signature"
   "\\sl"
   "\\small"
   "\\smallskip"
   "\\sqrt"
   "\\tableofcontents"
   "\\telephone"
   "\\thanks"
   "\\thispagestyle"
   "\\tiny"
   "\\title"
   "\\tt"
   "\\twocolumn"
   "\\typein"
   "\\typeout"
   "\\underbrace"
   "\\underline"
   "\\usebox"
   "\\usecounter"
   "\\value"
   "\\vdots"
   "\\vector"
   "\\verb"
   "\\vfill"
   "\\vline"
   "\\vspace")
 "A list of LaTeX commands to be protected when performing conversion.")

(defconst org-latex-entities-regexp
  (let (names rest)
    (dolist (x org-latex-entities)
      (if (string-match "[a-zA-Z]$" x)
      (push x names)
    (push x rest)))
    (concat "\\(" (regexp-opt (nreverse names)) "\\&gt;\\)"
        "\\|\\(" (regexp-opt (nreverse rest)) "\\)")))

(provide 'org-export-latex)
(provide 'org-latex)

;; arch-tag: 23c2b87d-da04-4c2d-ad2d-1eb6487bc3ad

;;; org-latex.el ends here
</t>
<t tx="ekr.20100929212226.14574">;;; org-latex.el --- LaTeX exporter for org-mode
;;
;; Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
;;
;; Emacs Lisp Archive Entry
;; Filename: org-latex.el
;; Version: 7.01h
;; Author: Bastien Guerry &lt;bzg AT altern DOT org&gt;
;; Maintainer: Carsten Dominik &lt;carsten.dominik AT gmail DOT com&gt;
;; Keywords: org, wp, tex
;; Description: Converts an org-mode buffer into LaTeX

;; This file is part of GNU Emacs.

;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.

;;; Commentary:
;;
;; This library implements a LaTeX exporter for org-mode.
;;
;; It is part of Org and will be autoloaded
;;
;; The interactive functions are similar to those of the HTML exporter:
;;
;; M-x `org-export-as-latex'
;; M-x `org-export-as-pdf'
;; M-x `org-export-as-pdf-and-open'
;; M-x `org-export-as-latex-batch'
;; M-x `org-export-as-latex-to-buffer'
;; M-x `org-export-region-as-latex'
;; M-x `org-replace-region-by-latex'
;;
;;; Code:

(eval-when-compile
  (require 'cl))

(require 'footnote)
(require 'org)
(require 'org-exp)
(require 'org-macs)
(require 'org-beamer)

;;; Variables:
(defvar org-export-latex-class nil)
(defvar org-export-latex-class-options nil)
(defvar org-export-latex-header nil)
(defvar org-export-latex-append-header nil)
(defvar org-export-latex-options-plist nil)
(defvar org-export-latex-todo-keywords-1 nil)
(defvar org-export-latex-complex-heading-re nil)
(defvar org-export-latex-not-done-keywords nil)
(defvar org-export-latex-done-keywords nil)
(defvar org-export-latex-display-custom-times nil)
(defvar org-export-latex-all-targets-re nil)
(defvar org-export-latex-add-level 0)
(defvar org-export-latex-sectioning "")
(defvar org-export-latex-sectioning-depth 0)
(defvar org-export-latex-special-keyword-regexp
  (concat "\\&lt;\\(" org-scheduled-string "\\|"
      org-deadline-string "\\|"
      org-closed-string"\\)")
  "Regexp matching special time planning keywords plus the time after it.")

(defvar latexp)    ; dynamically scoped from org.el
(defvar re-quote)  ; dynamically scoped from org.el
(defvar commentsp) ; dynamically scoped from org.el

;;; User variables:

(defgroup org-export-latex nil
  "Options for exporting Org-mode files to LaTeX."
  :tag "Org Export LaTeX"
  :group 'org-export)

(defcustom org-export-latex-default-class "article"
  "The default LaTeX class."
  :group 'org-export-latex
  :type '(string :tag "LaTeX class"))

(defcustom org-export-latex-classes
  '(("article"
     "\\documentclass[11pt]{article}"
     ("\\section{%s}" . "\\section*{%s}")
     ("\\subsection{%s}" . "\\subsection*{%s}")
     ("\\subsubsection{%s}" . "\\subsubsection*{%s}")
     ("\\paragraph{%s}" . "\\paragraph*{%s}")
     ("\\subparagraph{%s}" . "\\subparagraph*{%s}"))
    ("report"
     "\\documentclass[11pt]{report}"
     ("\\part{%s}" . "\\part*{%s}")
     ("\\chapter{%s}" . "\\chapter*{%s}")
     ("\\section{%s}" . "\\section*{%s}")
     ("\\subsection{%s}" . "\\subsection*{%s}")
     ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
    ("book"
     "\\documentclass[11pt]{book}"
     ("\\part{%s}" . "\\part*{%s}")
     ("\\chapter{%s}" . "\\chapter*{%s}")
     ("\\section{%s}" . "\\section*{%s}")
     ("\\subsection{%s}" . "\\subsection*{%s}")
     ("\\subsubsection{%s}" . "\\subsubsection*{%s}"))
    ("beamer"
     "\\documentclass{beamer}"
     org-beamer-sectioning
     ))
  "Alist of LaTeX classes and associated header and structure.
If #+LaTeX_CLASS is set in the buffer, use its value and the
associated information.  Here is the structure of each cell:

  \(class-name
    header-string
    (numbered-section . unnumbered-section\)
    ...\)

The header string
-----------------

The HEADER-STRING is the header that will be inserted into the LaTeX file.
It should contain the \\documentclass macro, and anything else that is needed
for this setup.  To this header, the following commands will be added:

- Calls to \\usepackage for all packages mentioned in the variables
  `org-export-latex-default-packages-alist' and
  `org-export-latex-packages-alist'.  Thus, your header definitions should
  avoid to also request these packages.

- Lines specified via \"#+LaTeX_HEADER:\"

If you need more control about the sequence in which the header is built
up, or if you want to exclude one of these building blocks for a particular
class, you can use the following macro-like placeholders.

 [DEFAULT-PACKAGES]      \\usepackage statements for default packages
 [NO-DEFAULT-PACKAGES]   do not include any of the default packages
 [PACKAGES]              \\usepackage statements for packages
 [NO-PACKAGES]           do not include the packages
 [EXTRA]                 the stuff from #+LaTeX_HEADER
 [NO-EXTRA]              do not include #+LaTeX_HEADER stuff
 [BEAMER-HEADER-EXTRA]   the beamer extra headers

So a header like

  \\documentclass{article}
  [NO-DEFAULT-PACKAGES]
  [EXTRA]
  \\providecommand{\\alert}[1]{\\textbf{#1}}
  [PACKAGES]

will omit the default packages, and will include the #+LaTeX_HEADER lines,
then have a call to \\providecommand, and then place \\usepackage commands
based on the content of `org-export-latex-packages-alist'.

If your header or `org-export-latex-default-packages-alist' inserts
\"\\usepackage[AUTO]{inputenc}\", AUTO will automatically be replaced with
a coding system derived from `buffer-file-coding-system'.  See also the
variable `org-export-latex-inputenc-alist' for a way to influence this
mechanism.

The sectioning structure
------------------------

The sectioning structure of the class is given by the elements following
the header string.  For each sectioning level, a number of strings is
specified.  A %s formatter is mandatory in each section string and will
be replaced by the title of the section.

Instead of a cons cell (numbered . unnumbered), you can also provide a list
of 2 or 4 elements,

  (numbered-open numbered-close)

or

  (numbered-open numbered-close unnumbered-open unnumbered-close)

providing opening and closing strings for a LaTeX environment that should
represent the document section.  The opening clause should have a %s
to represent the section title.

Instead of a list of sectioning commands, you can also specify a
function name.  That function will be called with two parameters,
the (reduced) level of the headline, and the headline text.  The function
must return a cons cell with the (possibly modified) headline text, and the
sectioning list in the cdr."
  :group 'org-export-latex
  :type '(repeat
      (list (string :tag "LaTeX class")
        (string :tag "LaTeX header")
        (repeat :tag "Levels" :inline t
            (choice
             (cons :tag "Heading"
                   (string :tag "  numbered")
                   (string :tag "unnumbered"))
             (list :tag "Environment"
                   (string :tag "Opening   (numbered)")
                   (string :tag "Closing   (numbered)")
                   (string :tag "Opening (unnumbered)")
                   (string :tag "Closing (unnumbered)"))
             (function :tag "Hook computing sectioning"))))))

(defcustom org-export-latex-inputenc-alist nil
  "Alist of inputenc coding system names, and what should really be used.
For example, adding an entry

      (\"utf8\" . \"utf8x\")

will cause \\usepackage[utf8x]{inputenc} to be used for buffers that
are written as utf8 files."
  :group 'org-export-latex
  :type '(repeat
      (cons
       (string :tag "Derived from buffer")
       (string :tag "Use this instead"))))


(defcustom org-export-latex-emphasis-alist
  '(("*" "\\textbf{%s}" nil)
    ("/" "\\emph{%s}" nil)
    ("_" "\\underline{%s}" nil)
    ("+" "\\st{%s}" nil)
    ("=" "\\verb" t)
    ("~" "\\verb" t))
  "Alist of LaTeX expressions to convert emphasis fontifiers.
Each element of the list is a list of three elements.
The first element is the character used as a marker for fontification.
The second element is a formatting string to wrap fontified text with.
If it is \"\\verb\", Org will automatically select a delimiter
character that is not in the string.
The third element decides whether to protect converted text from other
conversions."
  :group 'org-export-latex
  :type 'alist)

(defcustom org-export-latex-title-command "\\maketitle"
  "The command used to insert the title just after \\begin{document}.
If this string contains the formatting specification \"%s\" then
it will be used as a formatting string, passing the title as an
argument."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-import-inbuffer-stuff nil
  "Non-nil means define TeX macros for Org's inbuffer definitions.
For example \orgTITLE for #+TITLE."
  :group 'org-export-latex
  :type 'boolean)

(defcustom org-export-latex-date-format
  "%d %B %Y"
  "Format string for \\date{...}."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-todo-keyword-markup "\\textbf{%s}"
  "Markup for TODO keywords, as a printf format.
This can be a single format for all keywords, a cons cell with separate
formats for not-done and done states, or an association list with setup
for individual keywords.  If a keyword shows up for which there is no
markup defined, the first one in the association list will be used."
  :group 'org-export-latex
  :type '(choice
      (string :tag "Default")
      (cons :tag "Distinguish undone and done"
        (string :tag "Not-DONE states")
        (string :tag "DONE states"))
      (repeat :tag "Per keyword markup"
          (cons
           (string :tag "Keyword")
           (string :tag "Markup")))))

(defcustom org-export-latex-timestamp-markup "\\textit{%s}"
  "A printf format string to be applied to time stamps."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-timestamp-keyword-markup "\\texttt{%s}"
  "A printf format string to be applied to time stamps."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-hyperref-format "\\href{%s}{%s}"
  "A printf format string to be applied to hyperref links.
The format must contain two %s instances.  The first will be filled with
the link, the second with the link description."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-tables-verbatim nil
  "When non-nil, tables are exported verbatim."
  :group 'org-export-latex
  :type 'boolean)

(defcustom org-export-latex-tables-centered t
  "When non-nil, tables are exported in a center environment."
  :group 'org-export-latex
  :type 'boolean)

(defcustom org-export-latex-tables-column-borders nil
  "When non-nil, grouping columns can cause outer vertical lines in tables.
When nil, grouping causes only separation lines between groups."
  :group 'org-export-latex
  :type 'boolean)

(defcustom org-export-latex-low-levels 'itemize
  "How to convert sections below the current level of sectioning.
This is specified by the `org-export-headline-levels' option or the
value of \"H:\" in Org's #+OPTION line.

This can be either nil (skip the sections), `description', `itemize',
or `enumerate' (convert the sections as the corresponding list type), or
a string to be used instead of \\section{%s}.  In this latter case,
the %s stands here for the inserted headline and is mandatory.

It may also be a list of three string to define a user-defined environment
that should be used.  The first string should be the like
\"\\begin{itemize}\", the second should be like \"\\item %s %s\" with up
to two occurrences of %s for the title and a label, respectively.  The third
string should be like \"\\end{itemize\"."
  :group 'org-export-latex
  :type '(choice (const :tag "Ignore" nil)
         (const :tag "Convert as descriptive list" description)
         (const :tag "Convert as itemized list" itemize)
         (const :tag "Convert as enumerated list" enumerate)
         (list  :tag "User-defined environment"
            :value ("\\begin{itemize}" "\\end{itemize}" "\\item %s")
            (string :tag "Start")
            (string :tag "End")
            (string :tag "item"))
         (string :tag "Use a section string" :value "\\subparagraph{%s}")))

(defcustom org-export-latex-list-parameters
  '(:cbon "$\\boxtimes$" :cboff "$\\Box$")
  "Parameters for the LaTeX list exporter.
These parameters will be passed on to `org-list-to-latex', which in turn
will pass them (combined with the LaTeX default list parameters) to
`org-list-to-generic'."
  :group 'org-export-latex
  :type 'plist)

(defcustom org-export-latex-verbatim-wrap
  '("\\begin{verbatim}\n" . "\\end{verbatim}\n")
  "Environment to be wrapped around a fixed-width section in LaTeX export.
This is a cons with two strings, to be added before and after the
fixed-with text.

Defaults to \\begin{verbatim} and \\end{verbatim}."
  :group 'org-export-translation
  :group 'org-export-latex
  :type '(cons (string :tag "Open")
           (string :tag "Close")))

(defcustom org-export-latex-listings nil
  "Non-nil means export source code using the listings package.
This package will fontify source code, possibly even with color.
If you want to use this, you also need to make LaTeX use the
listings package, and if you want to have color, the color
package.  Just add these to `org-export-latex-packages-alist',
for example using customize, or with something like

  (require 'org-latex)
  (add-to-list 'org-export-latex-packages-alist '(\"\" \"listings\"))
  (add-to-list 'org-export-latex-packages-alist '(\"\" \"color\"))"
  :group 'org-export-latex
  :type 'boolean)

(defcustom org-export-latex-listings-langs
  '((emacs-lisp "Lisp") (lisp "Lisp")
    (c "C") (cc "C++")
    (fortran "fortran")
    (perl "Perl") (cperl "Perl") (python "Python") (ruby "Ruby")
    (html "HTML") (xml "XML")
    (tex "TeX") (latex "TeX")
    (shell-script "bash")
    (gnuplot "Gnuplot")
    (ocaml "Caml") (caml "Caml")
    (sql "SQL") (sqlite "sql"))
  "Alist mapping languages to their listing language counterpart.
The key is a symbol, the major mode symbol without the \"-mode\".
The value is the string that should be inserted as the language parameter
for the listings package.  If the mode name and the listings name are
the same, the language does not need an entry in this list - but it does not
hurt if it is present."
  :group 'org-export-latex
  :type '(repeat
      (list
       (symbol :tag "Major mode       ")
       (string :tag "Listings language"))))

(defcustom org-export-latex-remove-from-headlines
  '(:todo nil :priority nil :tags nil)
  "A plist of keywords to remove from headlines.  OBSOLETE.
Non-nil means remove this keyword type from the headline.

Don't remove the keys, just change their values.

Obsolete, this variable is no longer used.  Use the separate
variables `org-export-with-todo-keywords', `org-export-with-priority',
and `org-export-with-tags' instead."
  :type 'plist
  :group 'org-export-latex)

(defcustom org-export-latex-image-default-option "width=10em"
  "Default option for images."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-tabular-environment "tabular"
  "Default environment used to build tables."
  :group 'org-export-latex
  :type 'string)

(defcustom org-export-latex-inline-image-extensions
  '("pdf" "jpeg" "jpg" "png" "ps" "eps")
  "Extensions of image files that can be inlined into LaTeX.
Note that the image extension *actually* allowed depend on the way the
LaTeX file is processed.  When used with pdflatex, pdf, jpg and png images
are OK.  When processing through dvi to Postscript, only ps and eps are
allowed.  The default we use here encompasses both."
  :group 'org-export-latex
  :type '(repeat (string :tag "Extension")))

(defcustom org-export-latex-coding-system nil
  "Coding system for the exported LaTeX file."
  :group 'org-export-latex
  :type 'coding-system)

(defgroup org-export-pdf nil
  "Options for exporting Org-mode files to PDF, via LaTeX."
  :tag "Org Export PDF"
  :group 'org-export-latex
  :group 'org-export)

(defcustom org-latex-to-pdf-process
  '("pdflatex -interaction nonstopmode %s"
    "pdflatex -interaction nonstopmode %s")
  "Commands to process a LaTeX file to a PDF file.
This is a list of strings, each of them will be given to the shell
as a command.  %s in the command will be replaced by the full file name, %b
by the file base name (i.e. without extension).
The reason why this is a list is that it usually takes several runs of
pdflatex, maybe mixed with a call to bibtex.  Org does not have a clever
mechanism to detect which of these commands have to be run to get to a stable
result, and it also does not do any error checking.

Alternatively, this may be a Lisp function that does the processing, so you
could use this to apply the machinery of AUCTeX or the Emacs LaTeX mode.
This function should accept the file name as its single argument."
  :group 'org-export-pdf
  :type '(choice (repeat :tag "Shell command sequence"
          (string :tag "Shell command"))
         (function)))

(defcustom org-export-pdf-logfiles
  '("aux" "idx" "log" "out" "toc" "nav" "snm" "vrb")
  "The list of file extensions to consider as LaTeX logfiles."
  :group 'org-export-pdf
  :type '(repeat (string :tag "Extension")))

(defcustom org-export-pdf-remove-logfiles t
  "Non-nil means remove the logfiles produced by PDF production.
These are the .aux, .log, .out, and .toc files."
  :group 'org-export-pdf
  :type 'boolean)

;;; Hooks

(defvar org-export-latex-after-initial-vars-hook nil
  "Hook run before LaTeX export.
The exact moment is after the initial variables like org-export-latex-class
have been determined from the environment.")

(defvar org-export-latex-after-blockquotes-hook nil
  "Hook run during LaTeX export, after blockquote, verse, center are done.")

(defvar org-export-latex-final-hook nil
  "Hook run in the finalized LaTeX buffer.")

(defvar org-export-latex-after-save-hook nil
  "Hook run in the finalized LaTeX buffer, after it has been saved.")

</t>
<t tx="ekr.20100929212226.14575">;;; Autoload functions:

;;;###autoload
(defun org-export-as-latex-batch ()
  "Call `org-export-as-latex', may be used in batch processing.
For example:

emacs   --batch
        --load=$HOME/lib/emacs/org.el
        --eval \"(setq org-export-headline-levels 2)\"
        --visit=MyFile --funcall org-export-as-latex-batch"
  (org-export-as-latex org-export-headline-levels 'hidden))
</t>
<t tx="ekr.20100929212226.14576">
;;;###autoload
(defun org-export-as-latex-to-buffer (arg)
  "Call `org-export-as-latex` with output to a temporary buffer.
No file is created.  The prefix ARG is passed through to `org-export-as-latex'."
  (interactive "P")
  (org-export-as-latex arg nil nil "*Org LaTeX Export*")
  (when org-export-show-temporary-export-buffer
    (switch-to-buffer-other-window "*Org LaTeX Export*")))
</t>
<t tx="ekr.20100929212226.14577">
;;;###autoload
(defun org-replace-region-by-latex (beg end)
  "Replace the region from BEG to END with its LaTeX export.
It assumes the region has `org-mode' syntax, and then convert it to
LaTeX.  This can be used in any buffer.  For example, you could
write an itemized list in `org-mode' syntax in an LaTeX buffer and
then use this command to convert it."
  (interactive "r")
  (let (reg latex buf)
    (save-window-excursion
      (if (org-mode-p)
      (setq latex (org-export-region-as-latex
               beg end t 'string))
    (setq reg (buffer-substring beg end)
          buf (get-buffer-create "*Org tmp*"))
    (with-current-buffer buf
      (erase-buffer)
      (insert reg)
      (org-mode)
      (setq latex (org-export-region-as-latex
               (point-min) (point-max) t 'string)))
    (kill-buffer buf)))
    (delete-region beg end)
    (insert latex)))
</t>
<t tx="ekr.20100929212226.14578">
;;;###autoload
(defun org-export-region-as-latex (beg end &amp;optional body-only buffer)
  "Convert region from BEG to END in `org-mode' buffer to LaTeX.
If prefix arg BODY-ONLY is set, omit file header, footer, and table of
contents, and only produce the region of converted text, useful for
cut-and-paste operations.
If BUFFER is a buffer or a string, use/create that buffer as a target
of the converted LaTeX.  If BUFFER is the symbol `string', return the
produced LaTeX as a string and leave no buffer behind.  For example,
a Lisp program could call this function in the following way:

  (setq latex (org-export-region-as-latex beg end t 'string))

When called interactively, the output buffer is selected, and shown
in a window.  A non-interactive call will only return the buffer."
  (interactive "r\nP")
  (when (interactive-p)
    (setq buffer "*Org LaTeX Export*"))
  (let ((transient-mark-mode t) (zmacs-regions t)
    ext-plist rtn)
    (setq ext-plist (plist-put ext-plist :ignore-subtree-p t))
    (goto-char end)
    (set-mark (point)) ;; to activate the region
    (goto-char beg)
    (setq rtn (org-export-as-latex
           nil nil ext-plist
           buffer body-only))
    (if (fboundp 'deactivate-mark) (deactivate-mark))
    (if (and (interactive-p) (bufferp rtn))
    (switch-to-buffer-other-window rtn)
      rtn)))
</t>
<t tx="ekr.20100929212226.14579">
;;;###autoload
(defun org-export-as-latex (arg &amp;optional hidden ext-plist
                to-buffer body-only pub-dir)
  "Export current buffer to a LaTeX file.
If there is an active region, export only the region.  The prefix
ARG specifies how many levels of the outline should become
headlines.  The default is 3.  Lower levels will be exported
depending on `org-export-latex-low-levels'.  The default is to
convert them as description lists.
HIDDEN is obsolete and does nothing.
EXT-PLIST is a property list with
external parameters overriding org-mode's default settings, but
still inferior to file-local settings.  When TO-BUFFER is
non-nil, create a buffer with that name and export to that
buffer.  If TO-BUFFER is the symbol `string', don't leave any
buffer behind but just return the resulting LaTeX as a string.
When BODY-ONLY is set, don't produce the file header and footer,
simply return the content of \\begin{document}...\\end{document},
without even the \\begin{document} and \\end{document} commands.
when PUB-DIR is set, use this as the publishing directory."
  (interactive "P")
  (when (and (not body-only) arg (listp arg)) (setq body-only t))
  (run-hooks 'org-export-first-hook)

  ;; Make sure we have a file name when we need it.
  (when (and (not (or to-buffer body-only))
         (not buffer-file-name))
    (if (buffer-base-buffer)
    (org-set-local 'buffer-file-name
               (with-current-buffer (buffer-base-buffer)
             buffer-file-name))
      (error "Need a file name to be able to export")))

  (message "Exporting to LaTeX...")
  (org-unmodified
   (let ((inhibit-read-only t))
     (remove-text-properties (point-min) (point-max)
                 '(:org-license-to-kill nil))))
  (org-update-radio-target-regexp)
  (org-export-latex-set-initial-vars ext-plist arg)
  (setq org-export-opt-plist org-export-latex-options-plist)
  (org-install-letbind)
  (run-hooks 'org-export-latex-after-initial-vars-hook)
  (let* ((wcf (current-window-configuration))
     (opt-plist org-export-latex-options-plist)
     (region-p (org-region-active-p))
     (rbeg (and region-p (region-beginning)))
     (rend (and region-p (region-end)))
     (subtree-p
      (if (plist-get opt-plist :ignore-subtree-p)
          nil
        (when region-p
          (save-excursion
        (goto-char rbeg)
        (and (org-at-heading-p)
             (&gt;= (org-end-of-subtree t t) rend))))))
     (opt-plist (setq org-export-opt-plist
              (if subtree-p
                  (org-export-add-subtree-options opt-plist rbeg)
                opt-plist)))
     ;; Make sure the variable contains the updated values.
     (org-export-latex-options-plist (setq org-export-opt-plist opt-plist))
     ;; The following two are dynamically scoped into other
     ;; routines below.
     (org-current-export-dir
      (or pub-dir (org-export-directory :html opt-plist)))
     (org-current-export-file buffer-file-name)
     (title (or (and subtree-p (org-export-get-title-from-subtree))
            (plist-get opt-plist :title)
            (and (not
              (plist-get opt-plist :skip-before-1st-heading))
             (org-export-grab-title-from-buffer))
            (and buffer-file-name
             (file-name-sans-extension
              (file-name-nondirectory buffer-file-name)))
            "No Title"))
     (filename
      (and (not to-buffer)
           (concat
        (file-name-as-directory
         (or pub-dir
             (org-export-directory :LaTeX ext-plist)))
        (file-name-sans-extension
         (or (and subtree-p
              (org-entry-get rbeg "EXPORT_FILE_NAME" t))
             (file-name-nondirectory ;sans-extension
              (or buffer-file-name
              (error "Don't know which export file to use")))))
        ".tex")))
     (filename
      (and filename
           (if (equal (file-truename filename)
              (file-truename (or buffer-file-name "dummy.org")))
           (concat filename ".tex")
         filename)))
     (buffer (if to-buffer
             (cond
              ((eq to-buffer 'string) (get-buffer-create
                           "*Org LaTeX Export*"))
              (t (get-buffer-create to-buffer)))
           (find-file-noselect filename)))
     (odd org-odd-levels-only)
     (header (org-export-latex-make-header title opt-plist))
     (skip (cond (subtree-p nil)
             (region-p nil)
             (t (plist-get opt-plist :skip-before-1st-heading))))
     (text (plist-get opt-plist :text))
     (org-export-preprocess-hook
      (cons
       `(lambda () (org-set-local 'org-complex-heading-regexp
                      ,org-export-latex-complex-heading-re))
       org-export-preprocess-hook))
     (first-lines (if skip "" (org-export-latex-first-lines
                   opt-plist
                   (if subtree-p
                       (save-excursion
                     (goto-char rbeg)
                     (point-at-bol 2))
                     rbeg)
                   (if region-p rend))))
     (coding-system (and (boundp 'buffer-file-coding-system)
                 buffer-file-coding-system))
     (coding-system-for-write (or org-export-latex-coding-system
                      coding-system))
     (save-buffer-coding-system (or org-export-latex-coding-system
                    coding-system))
     (region (buffer-substring
          (if region-p (region-beginning) (point-min))
          (if region-p (region-end) (point-max))))
     (text
      (and text (string-match "\\S-" text)
           (org-export-preprocess-string
        text
        :emph-multiline t
        :for-LaTeX t
        :comments nil
        :tags (plist-get opt-plist :tags)
        :priority (plist-get opt-plist :priority)
        :footnotes (plist-get opt-plist :footnotes)
        :drawers (plist-get opt-plist :drawers)
        :timestamps (plist-get opt-plist :timestamps)
        :todo-keywords (plist-get opt-plist :todo-keywords)
        :add-text nil
        :skip-before-1st-heading skip
        :select-tags nil
        :exclude-tags nil
        :LaTeX-fragments nil)))
     (string-for-export
      (org-export-preprocess-string
       region
       :emph-multiline t
       :for-LaTeX t
       :comments nil
       :tags (plist-get opt-plist :tags)
       :priority (plist-get opt-plist :priority)
       :footnotes (plist-get opt-plist :footnotes)
       :drawers (plist-get opt-plist :drawers)
       :timestamps (plist-get opt-plist :timestamps)
       :todo-keywords (plist-get opt-plist :todo-keywords)
       :add-text (if (eq to-buffer 'string) nil text)
       :skip-before-1st-heading skip
       :select-tags (plist-get opt-plist :select-tags)
       :exclude-tags (plist-get opt-plist :exclude-tags)
       :LaTeX-fragments nil)))

    (set-buffer buffer)
    (erase-buffer)
    (org-install-letbind)

    (and (fboundp 'set-buffer-file-coding-system)
     (set-buffer-file-coding-system coding-system-for-write))

    ;; insert the header and initial document commands
    (unless (or (eq to-buffer 'string) body-only)
      (insert header))

    ;; insert text found in #+TEXT
    (when (and text (not (eq to-buffer 'string)))
      (insert (org-export-latex-content
           text '(lists tables fixed-width keywords))
           "\n\n"))

    ;; insert lines before the first headline
    (unless skip
      (insert first-lines))

    ;; export the content of headlines
    (org-export-latex-global
     (with-temp-buffer
       (insert string-for-export)
       (goto-char (point-min))
       (when (re-search-forward "^\\(\\*+\\) " nil t)
     (let* ((asters (length (match-string 1)))
        (level (if odd (- asters 2) (- asters 1))))
       (setq org-export-latex-add-level
         (if odd (1- (/ (1+ asters) 2)) (1- asters)))
       (org-export-latex-parse-global level odd)))))

    ;; finalization
    (unless body-only (insert "\n\\end{document}"))

    ;; Attach description terms to the \item macro
    (goto-char (point-min))
    (while (re-search-forward "^[ \t]*\\\\item\\([ \t]+\\)\\[" nil t)
      (delete-region (match-beginning 1) (match-end 1)))

    ;; Relocate the table of contents
    (goto-char (point-min))
    (when (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
      (goto-char (point-min))
      (while (re-search-forward "\\\\tableofcontents\\&gt;[ \t]*\n?" nil t)
    (replace-match ""))
      (goto-char (point-min))
      (and (re-search-forward "\\[TABLE-OF-CONTENTS\\]" nil t)
       (replace-match "\\tableofcontents" t t)))

    ;; Cleanup forced line ends in items where they are not needed
    (goto-char (point-min))
    (while (re-search-forward
        "^[ \t]*\\\\item\\&gt;.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*\n\\\\begin"
        nil t)
      (delete-region (match-beginning 1) (match-end 1)))
    (goto-char (point-min))
    (while (re-search-forward
        "^[ \t]*\\\\item\\&gt;.*\\(\\\\\\\\\\)[ \t]*\\(\n\\\\label.*\\)*"
        nil t)
      (if (looking-at "[\n \t]+")
      (replace-match "\n")))

    (run-hooks 'org-export-latex-final-hook)
    (if to-buffer
    (unless (eq major-mode 'latex-mode) (latex-mode))
      (save-buffer))
    (org-export-latex-fix-inputenc)
    (run-hooks 'org-export-latex-after-save-hook)
    (goto-char (point-min))
    (or (org-export-push-to-kill-ring "LaTeX")
    (message "Exporting to LaTeX...done"))
    (prog1
    (if (eq to-buffer 'string)
        (prog1 (buffer-substring (point-min) (point-max))
          (kill-buffer (current-buffer)))
      (current-buffer))
      (set-window-configuration wcf))))
</t>
<t tx="ekr.20100929212226.14580">
;;;###autoload
(defun org-export-as-pdf (arg &amp;optional hidden ext-plist
                  to-buffer body-only pub-dir)
  "Export as LaTeX, then process through to PDF."
  (interactive "P")
  (message "Exporting to PDF...")
  (let* ((wconfig (current-window-configuration))
     (lbuf (org-export-as-latex arg hidden ext-plist
                    to-buffer body-only pub-dir))
     (file (buffer-file-name lbuf))
     (base (file-name-sans-extension (buffer-file-name lbuf)))
     (pdffile (concat base ".pdf"))
     (cmds org-latex-to-pdf-process)
     (outbuf (get-buffer-create "*Org PDF LaTeX Output*"))
     (bibtex-p (with-current-buffer lbuf
             (save-excursion
               (goto-char (point-min))
               (re-search-forward "\\\\bibliography{" nil t))))
     cmd)
    (with-current-buffer outbuf (erase-buffer))
    (message "Processing LaTeX file...")
    (if (and cmds (symbolp cmds))
    (funcall cmds (shell-quote-argument file))
      (while cmds
    (setq cmd (pop cmds))
    (while (string-match "%b" cmd)
      (setq cmd (replace-match
             (save-match-data
               (shell-quote-argument base))
             t t cmd)))
    (while (string-match "%s" cmd)
      (setq cmd (replace-match
             (save-match-data
               (shell-quote-argument file))
             t t cmd)))
    (shell-command cmd outbuf outbuf)))
    (message "Processing LaTeX file...done")
    (if (not (file-exists-p pdffile))
    (error "PDF file was not produced")
      (set-window-configuration wconfig)
      (when org-export-pdf-remove-logfiles
    (dolist (ext org-export-pdf-logfiles)
      (setq file (concat base "." ext))
      (and (file-exists-p file) (delete-file file))))
      (message "Exporting to PDF...done")
      pdffile)))
</t>
<t tx="ekr.20100929212226.14581">
;;;###autoload
(defun org-export-as-pdf-and-open (arg)
  "Export as LaTeX, then process through to PDF, and open."
  (interactive "P")
  (let ((pdffile (org-export-as-pdf arg)))
    (if pdffile
    (progn
      (org-open-file pdffile)
      (when org-export-kill-product-buffer-when-displayed
        (kill-buffer (find-buffer-visiting
              (concat (file-name-sans-extension (buffer-file-name))
                  ".tex")))))
      (error "PDF file was not produced"))))
</t>
<t tx="ekr.20100929212226.14582">
;;; Parsing functions:

(defun org-export-latex-parse-global (level odd)
  "Parse the current buffer recursively, starting at LEVEL.
If ODD is non-nil, assume the buffer only contains odd sections.
Return a list reflecting the document structure."
  (save-excursion
    (goto-char (point-min))
    (let* ((cnt 0) output
       (depth org-export-latex-sectioning-depth))
      (while (org-re-search-forward-unprotected
          (concat "^\\(\\(?:\\*\\)\\{"
              (number-to-string (+ (if odd 2 1) level))
              "\\}\\) \\(.*\\)$")
          ;; make sure that there is no upper heading
          (when (&gt; level 0)
        (save-excursion
          (save-match-data
            (org-re-search-forward-unprotected
             (concat "^\\(\\(?:\\*\\)\\{"
                 (number-to-string level)
                 "\\}\\) \\(.*\\)$") nil t)))) t)
    (setq cnt (1+ cnt))
    (let* ((pos (match-beginning 0))
           (heading (match-string 2))
           (nlevel (if odd (/ (+ 3 level) 2) (1+ level))))
      (save-excursion
        (narrow-to-region
         (point)
         (save-match-data
           (if (org-re-search-forward-unprotected
            (concat "^\\(\\(?:\\*\\)\\{"
                (number-to-string (+ (if odd 2 1) level))
                "\\}\\) \\(.*\\)$") nil t)
           (match-beginning 0)
         (point-max))))
        (goto-char (point-min))
        (setq output
          (append output
              (list
               (list
                `(pos . ,pos)
                `(level . ,nlevel)
                `(occur . ,cnt)
                `(heading . ,heading)
                `(content . ,(org-export-latex-parse-content))
                `(subcontent . ,(org-export-latex-parse-subcontent
                         level odd)))))))
      (widen)))
      (list output))))
</t>
<t tx="ekr.20100929212226.14583">
(defun org-export-latex-parse-content ()
  "Extract the content of a section."
  (let ((beg (point))
    (end (if (org-re-search-forward-unprotected "^\\(\\*\\)+ .*$" nil t)
         (progn (beginning-of-line) (point))
           (point-max))))
    (buffer-substring beg end)))
</t>
<t tx="ekr.20100929212226.14584">
(defun org-export-latex-parse-subcontent (level odd)
  "Extract the subcontent of a section at LEVEL.
If ODD Is non-nil, assume subcontent only contains odd sections."
  (if (not (org-re-search-forward-unprotected
        (concat "^\\(\\(?:\\*\\)\\{"
            (number-to-string (+ (if odd 4 2) level))
            "\\}\\) \\(.*\\)$")
        nil t))
      nil ; subcontent is nil
    (org-export-latex-parse-global (+ (if odd 2 1) level) odd)))
</t>
<t tx="ekr.20100929212226.14585">
;;; Rendering functions:
(defun org-export-latex-global (content)
  "Export CONTENT to LaTeX.
CONTENT is an element of the list produced by
`org-export-latex-parse-global'."
  (if (eq (car content) 'subcontent)
      (mapc 'org-export-latex-sub (cdr content))
    (org-export-latex-sub (car content))))
</t>
<t tx="ekr.20100929212226.14586">
(defun org-export-latex-sub (subcontent)
  "Export the list SUBCONTENT to LaTeX.
SUBCONTENT is an alist containing information about the headline
and its content."
  (let ((num (plist-get org-export-latex-options-plist :section-numbers)))
    (mapc (lambda(x) (org-export-latex-subcontent x num)) subcontent)))
</t>
<t tx="ekr.20100929212226.14587">
(defun org-export-latex-subcontent (subcontent num)
  "Export each cell of SUBCONTENT to LaTeX.
If NUM, export sections as numerical sections."
  (let* ((heading (cdr (assoc 'heading subcontent)))
     (level (- (cdr (assoc 'level subcontent))
           org-export-latex-add-level))
     (occur (number-to-string (cdr (assoc 'occur subcontent))))
     (content (cdr (assoc 'content subcontent)))
     (subcontent (cadr (assoc 'subcontent subcontent)))
     (label (org-get-text-property-any 0 'target heading))
     (label-list (cons label (cdr (assoc label
                         org-export-target-aliases))))
     (sectioning org-export-latex-sectioning)
     (depth org-export-latex-sectioning-depth)
     main-heading sub-heading)
    (when (symbolp (car sectioning))
      (setq sectioning (funcall (car sectioning) level heading))
      (when sectioning
    (setq heading (car sectioning)
          sectioning (cdr sectioning)
          ;; target property migh have changed...
          label (org-get-text-property-any 0 'target heading)
          label-list (cons label (cdr (assoc label
                         org-export-target-aliases)))))
      (if sectioning (setq sectioning (make-list 10 sectioning)))
      (setq depth (if sectioning 10000 0)))
    (if (string-match "[ \t]*\\\\\\\\[ \t]*" heading)
    (setq main-heading (substring heading 0 (match-beginning 0))
          sub-heading (substring heading (match-end 0))))
    (setq heading (org-export-latex-fontify-headline heading)
      sub-heading (and sub-heading
               (org-export-latex-fontify-headline sub-heading))
      main-heading (and main-heading
                (org-export-latex-fontify-headline main-heading)))
    (cond
     ;; Normal conversion
     ((&lt;= level depth)
      (let* ((sec (nth (1- level) sectioning))
         start end)
    (if (consp (cdr sec))
        (setq start (nth (if num 0 2) sec)
          end (nth (if num 1 3) sec))
      (setq start (if num (car sec) (cdr sec))))
    (insert (format start (if main-heading main-heading heading)
            (or sub-heading "")))
    (insert "\n")
    (when label
      (insert (mapconcat (lambda (l) (format "\\label{%s}" l))
                 label-list "\n") "\n"))
    (insert (org-export-latex-content content))
    (cond ((stringp subcontent) (insert subcontent))
          ((listp subcontent)
           (while (org-looking-back "\n\n") (backward-delete-char 1))
           (org-export-latex-sub subcontent)))
    (when (and end (string-match "[^ \t]" end))
      (let ((hook (org-get-text-property-any 0 'org-insert-hook end)))
        (and (functionp hook) (funcall hook)))
      (insert end "\n"))))
     ;; At a level under the hl option: we can drop this subsection
     ((&gt; level depth)
      (cond ((eq org-export-latex-low-levels 'description)
         (if (string-match "% ends low level$"
                   (buffer-substring (point-at-bol 0) (point)))
         (delete-region (point-at-bol 0) (point))
           (insert "\\begin{description}\n"))
         (insert (format "\n\\item[%s]%s~\n"
                 heading
                 (if label (format "\\label{%s}" label) "")))
         (insert (org-export-latex-content content))
         (cond ((stringp subcontent) (insert subcontent))
           ((listp subcontent) (org-export-latex-sub subcontent)))
         (insert "\\end{description} % ends low level\n"))
        ((memq org-export-latex-low-levels '(itemize enumerate))
         (if (string-match "% ends low level$"
                   (buffer-substring (point-at-bol 0) (point)))
         (delete-region (point-at-bol 0) (point))
           (insert (format "\\begin{%s}\n"
                   (symbol-name org-export-latex-low-levels))))
         (insert (format "\n\\item %s\\\\\n%s%%"
                 heading
                 (if label (format "\\label{%s}" label) "")))
         (insert (org-export-latex-content content))
         (cond ((stringp subcontent) (insert subcontent))
           ((listp subcontent) (org-export-latex-sub subcontent)))
         (insert (format "\\end{%s} %% ends low level\n"
                 (symbol-name org-export-latex-low-levels))))

        ((listp org-export-latex-low-levels)
         (if (string-match "% ends low level$"
                   (buffer-substring (point-at-bol 0) (point)))
         (delete-region (point-at-bol 0) (point))
           (insert (car org-export-latex-low-levels) "\n"))
         (insert (format (nth 2 org-export-latex-low-levels)
                 heading
                 (if label (format "\\label{%s}" label) "")))
         (insert (org-export-latex-content content))
         (cond ((stringp subcontent) (insert subcontent))
           ((listp subcontent) (org-export-latex-sub subcontent)))
         (insert (nth 1 org-export-latex-low-levels)
             " %% ends low level\n"))

        ((stringp org-export-latex-low-levels)
         (insert (format org-export-latex-low-levels heading) "\n")
         (when label (insert (format "\\label{%s}\n" label)))
         (insert (org-export-latex-content content))
         (cond ((stringp subcontent) (insert subcontent))
           ((listp subcontent) (org-export-latex-sub subcontent)))))))))
</t>
<t tx="ekr.20100929212226.14588">
;;; Exporting internals:
(defun org-export-latex-set-initial-vars (ext-plist level)
  "Store org local variables required for LaTeX export.
EXT-PLIST is an optional additional plist.
LEVEL indicates the default depth for export."
  (setq org-export-latex-todo-keywords-1 org-todo-keywords-1
    org-export-latex-done-keywords org-done-keywords
    org-export-latex-not-done-keywords org-not-done-keywords
    org-export-latex-complex-heading-re org-complex-heading-regexp
    org-export-latex-display-custom-times org-display-custom-times
    org-export-latex-all-targets-re
    (org-make-target-link-regexp (org-all-targets))
    org-export-latex-options-plist
    (org-combine-plists (org-default-export-plist) ext-plist
                (org-infile-export-plist))
    org-export-latex-class
    (or (and (org-region-active-p)
         (save-excursion
           (goto-char (region-beginning))
           (and (looking-at org-complex-heading-regexp)
            (org-entry-get nil "LaTeX_CLASS" 'selective))))
        (save-excursion
          (save-restriction
        (widen)
        (goto-char (point-min))
        (and (re-search-forward "^#\\+LaTeX_CLASS:[ \t]*\\(-[a-zA-Z]+\\)" nil t)
             (match-string 1))))
        (plist-get org-export-latex-options-plist :latex-class)
        org-export-latex-default-class)
    org-export-latex-class-options
    (or (and (org-region-active-p)
         (save-excursion
           (goto-char (region-beginning))
           (and (looking-at org-complex-heading-regexp)
            (org-entry-get nil "LaTeX_CLASS_OPTIONS" 'selective))))
        (save-excursion
          (save-restriction
        (widen)
        (goto-char (point-min))
        (and (re-search-forward "^#\\+LaTeX_CLASS_OPTIONS:[ \t]*\\(.*?\\)[ \t]*$" nil t)
             (match-string 1))))
        (plist-get org-export-latex-options-plist :latex-class-options))
    org-export-latex-class
    (or (car (assoc org-export-latex-class org-export-latex-classes))
        (error "No definition for class `%s' in `org-export-latex-classes'"
           org-export-latex-class))
    org-export-latex-header
    (cadr (assoc org-export-latex-class org-export-latex-classes))
    org-export-latex-sectioning
    (cddr (assoc org-export-latex-class org-export-latex-classes))
    org-export-latex-sectioning-depth
    (or level
        (let ((hl-levels
           (plist-get org-export-latex-options-plist :headline-levels))
          (sec-depth (length org-export-latex-sectioning)))
          (if (&gt; hl-levels sec-depth) sec-depth hl-levels))))
  (when (and org-export-latex-class-options
         (string-match "\\S-" org-export-latex-class-options)
         (string-match "^[ \t]*\\(\\\\documentclass\\)\\(\\[.*?\\]\\)?"
               org-export-latex-header))
    (setq org-export-latex-header
      (concat (substring org-export-latex-header 0 (match-end 1))
          org-export-latex-class-options
          (substring org-export-latex-header (match-end 0))))))
</t>
<t tx="ekr.20100929212226.14589">
(defvar org-export-latex-format-toc-function
  'org-export-latex-format-toc-default
  "The function formatting returning the string to create the table of contents.
The function mus take one parameter, the depth of the table of contents.")

(defun org-export-latex-make-header (title opt-plist)
  "Make the LaTeX header and return it as a string.
TITLE is the current title from the buffer or region.
OPT-PLIST is the options plist for current buffer."
  (let ((toc (plist-get opt-plist :table-of-contents))
    (author (org-export-apply-macros-in-string
         (plist-get opt-plist :author))))
    (concat
     (if (plist-get opt-plist :time-stamp-file)
     (format-time-string "%% Created %Y-%m-%d %a %H:%M\n"))
     ;; insert LaTeX custom header and packages from the list
     (org-splice-latex-header
      (org-export-apply-macros-in-string org-export-latex-header)
      org-export-latex-default-packages-alist
      org-export-latex-packages-alist nil
      (org-export-apply-macros-in-string
       (plist-get opt-plist :latex-header-extra)))
     ;; append another special variable
     (org-export-apply-macros-in-string org-export-latex-append-header)
     ;; define align if not yet defined
     "\n\\providecommand{\\alert}[1]{\\textbf{#1}}"
     ;; insert the title
     (format
      "\n\n\\title{%s}\n"
      ;; convert the title
      (org-export-latex-content
       title '(lists tables fixed-width keywords)))
     ;; insert author info
     (if (plist-get opt-plist :author-info)
     (format "\\author{%s}\n"
         (org-export-latex-fontify-headline (or author user-full-name)))
       (format "%%\\author{%s}\n"
           (org-export-latex-fontify-headline (or author user-full-name))))
     ;; insert the date
     (format "\\date{%s}\n"
         (format-time-string
          (or (plist-get opt-plist :date)
          org-export-latex-date-format)))
     ;; beginning of the document
     "\n\\begin{document}\n\n"
     ;; insert the title command
     (when (string-match "\\S-" title)
       (if (string-match "%s" org-export-latex-title-command)
       (format org-export-latex-title-command title)
     org-export-latex-title-command))
     "\n\n"
     ;; table of contents
     (when (and org-export-with-toc
        (plist-get opt-plist :section-numbers))
       (funcall org-export-latex-format-toc-function
        (cond ((numberp toc)
               (min toc (plist-get opt-plist :headline-levels)))
              (toc  (plist-get opt-plist :headline-levels))))))))
</t>
<t tx="ekr.20100929212226.14590">
(defun org-export-latex-format-toc-default (depth)
  (when depth
    (format "\\setcounter{tocdepth}{%s}\n\\tableofcontents\n\\vspace*{1cm}\n"
        depth)))
</t>
<t tx="ekr.20100929212226.14591">
(defun org-export-latex-first-lines (opt-plist &amp;optional beg end)
  "Export the first lines before first headline.
If BEG is non-nil, it is the beginning of the region.
If END is non-nil, it is the end of the region."
  (save-excursion
    (goto-char (or beg (point-min)))
    (let* ((pt (point))
       (end (if (re-search-forward "^\\*+ " end t)
            (goto-char (match-beginning 0))
          (goto-char (or end (point-max))))))
      (prog1
      (org-export-latex-content
       (org-export-preprocess-string
        (buffer-substring pt end)
        :for-LaTeX t
        :emph-multiline t
        :add-text nil
        :comments nil
        :skip-before-1st-heading nil
        :LaTeX-fragments nil
        :timestamps (plist-get opt-plist :timestamps)
        :footnotes (plist-get opt-plist :footnotes)))
    (org-unmodified
     (let ((inhibit-read-only t)
           (limit (max pt (1- end))))
       (add-text-properties pt limit
                '(:org-license-to-kill t))
       (save-excursion
         (goto-char pt)
         (while (re-search-forward "^[ \t]*#+.*\n?" limit t)
           (remove-text-properties (match-beginning 0) (match-end 0)
                '(:org-license-to-kill t))))))))))
</t>
<t tx="ekr.20100929212226.14592">

\\-11(defvar org-export-latex-header-defs nil
\\-9"The header definitions that might be used in the LaTeX body.")
\\-11(defvar org-export-latex-header-defs-re nil
\\-9"The header definitions that might be used in the LaTeX body.")

(defun org-export-latex-content (content &amp;optional exclude-list)
  "Convert CONTENT string to LaTeX.
Don't perform conversions that are in EXCLUDE-LIST.  Recognized
conversion types are: quotation-marks, emphasis, sub-superscript,
links, keywords, lists, tables, fixed-width"
  (with-temp-buffer
   (insert content)
   (unless (memq 'timestamps exclude-list)
     (org-export-latex-time-stamps))
   (unless (memq 'quotation-marks exclude-list)
     (org-export-latex-quotation-marks))
   (unless (memq 'emphasis exclude-list)
     (when (plist-get org-export-latex-options-plist :emphasize)
       (org-export-latex-fontify)))
   (unless (memq 'sub-superscript exclude-list)
     (org-export-latex-special-chars
      (plist-get org-export-latex-options-plist :sub-superscript)))
   (unless (memq 'links exclude-list)
     (org-export-latex-links))
   (unless (memq 'keywords exclude-list)
     (org-export-latex-keywords))
   (unless (memq 'lists exclude-list)
     (org-export-latex-lists))
   (unless (memq 'tables exclude-list)
     (org-export-latex-tables
      (plist-get org-export-latex-options-plist :tables)))
   (unless (memq 'fixed-width exclude-list)
     (org-export-latex-fixed-width
      (plist-get org-export-latex-options-plist :fixed-width)))
   ;; return string
   (buffer-substring (point-min) (point-max))))
</t>
<t tx="ekr.20100929212226.14593">
(defun org-export-latex-protect-string (s)
  "Add the org-protected property to string S."
  (add-text-properties 0 (length s) '(org-protected t) s) s)
</t>
<t tx="ekr.20100929212226.14594">
(defun org-export-latex-protect-char-in-string (char-list string)
  "Add org-protected text-property to char from CHAR-LIST in STRING."
  (with-temp-buffer
    (save-match-data
      (insert string)
      (goto-char (point-min))
      (while (re-search-forward (regexp-opt char-list) nil t)
    (add-text-properties (match-beginning 0)
                 (match-end 0) '(org-protected t)))
      (buffer-string))))
</t>
<t tx="ekr.20100929212226.14595">
(defun org-export-latex-keywords-maybe (&amp;optional remove-list)
  "Maybe remove keywords depending on rules in REMOVE-LIST."
  (goto-char (point-min))
  (let ((re-todo (mapconcat 'identity org-export-latex-todo-keywords-1 "\\|"))
    (case-fold-search nil)
    (todo-markup org-export-latex-todo-keyword-markup)
    fmt)
    ;; convert TODO keywords
    (when (re-search-forward (concat "^\\(" re-todo "\\)") nil t)
      (if (plist-get remove-list :todo)
      (replace-match "")
    (setq fmt (cond
           ((stringp todo-markup) todo-markup)
           ((and (consp todo-markup) (stringp (car todo-markup)))
            (if (member (match-string 1) org-export-latex-done-keywords)
            (cdr todo-markup) (car todo-markup)))
           (t (cdr (or (assoc (match-string 1) todo-markup)
                   (car todo-markup))))))
    (replace-match (org-export-latex-protect-string
            (format fmt (match-string 1))) t t)))
    ;; convert priority string
    (when (re-search-forward "\\[\\\\#.\\]" nil t)
      (if (plist-get remove-list :priority)
      (replace-match "")
    (replace-match (format "\\textbf{%s}" (match-string 0)) t t)))
    ;; convert tags
    (when (re-search-forward "\\(:[a-zA-Z0-9_@]+\\)+:" nil t)
      (if (or (not org-export-with-tags)
          (plist-get remove-list :tags))
      (replace-match "")
    (replace-match
     (org-export-latex-protect-string
      (format "\\textbf{%s}"
          (save-match-data
            (replace-regexp-in-string
             "_" "\\\\_" (match-string 0)))))
     t t)))))
</t>
<t tx="ekr.20100929212226.14596">
(defun org-export-latex-fontify-headline (string)
  "Fontify special words in STRING."
  (with-temp-buffer
    ;; FIXME: org-inside-LaTeX-fragment-p doesn't work when the $...$ is at
    ;; the beginning of the buffer - inserting "\n" is safe here though.
    (insert "\n" string)
    (goto-char (point-min))
    (let ((re (concat "\\\\\\([a-zA-Z]+\\)"
              "\\(?:&lt;[^&lt;&gt;\n]*&gt;\\)*"
              "\\(?:\\[[^][\n]*?\\]\\)*"
              "\\(?:&lt;[^&lt;&gt;\n]*&gt;\\)*"
              "\\("
              (org-create-multibrace-regexp "{" "}" 3)
              "\\)\\{1,3\\}")))
      (while (re-search-forward re nil t)
    (unless (or
         ;; check for comment line
         (save-excursion (goto-char (match-beginning 0))
                 (org-in-indented-comment-line))
         ;; Check if this is a defined entity, so that is may need conversion
         (org-entity-get (match-string 1)))
      (add-text-properties (match-beginning 0) (match-end 0)
                   '(org-protected t)))))
    (when (plist-get org-export-latex-options-plist :emphasize)
      (org-export-latex-fontify))
    (org-export-latex-keywords-maybe)
    (org-export-latex-special-chars
     (plist-get org-export-latex-options-plist :sub-superscript))
    (org-export-latex-links)
    (org-trim (buffer-string))))
</t>
<t tx="ekr.20100929212226.14597">
(defun org-export-latex-time-stamps ()
  "Format time stamps."
  (goto-char (point-min))
  (let ((org-display-custom-times org-export-latex-display-custom-times))
    (while (re-search-forward org-ts-regexp-both nil t)
      (org-if-unprotected-at (1- (point))
       (replace-match
    (org-export-latex-protect-string
     (format org-export-latex-timestamp-markup
         (substring (org-translate-time (match-string 0)) 1 -1)))
    t t)))))
</t>
<t tx="ekr.20100929212226.14598">
(defun org-export-latex-quotation-marks ()
  "Export quotation marks depending on language conventions."
  (let* ((lang (plist-get org-export-latex-options-plist :language))
     (quote-rpl (if (equal lang "fr")
            '(("\\(\\s-\\)\"" "«~")
              ("\\(\\S-\\)\"" "~»")
              ("\\(\\s-\\)'" "`"))
              '(("\\(\\s-\\|[[(]\\)\"" "``")
            ("\\(\\S-\\)\"" "''")
            ("\\(\\s-\\|(\\)'" "`")))))
    (mapc (lambda(l) (goto-char (point-min))
        (while (re-search-forward (car l) nil t)
          (let ((rpl (concat (match-string 1)
                 (org-export-latex-protect-string
                  (copy-sequence (cadr l))))))
        (org-if-unprotected-1
         (replace-match rpl t t))))) quote-rpl)))
</t>
<t tx="ekr.20100929212226.14599">
(defun org-export-latex-special-chars (sub-superscript)
  "Export special characters to LaTeX.
If SUB-SUPERSCRIPT is non-nil, convert \\ and ^.
See the `org-export-latex.el' code for a complete conversion table."
  (goto-char (point-min))
  (mapc (lambda(c)
      (goto-char (point-min))
      (while (re-search-forward c nil t)
        ;; Put the point where to check for org-protected
        (unless (get-text-property (match-beginning 2) 'org-protected)
          (cond ((member (match-string 2) '("\\$" "$"))
             (if (equal (match-string 2) "\\$")
             nil
               (replace-match "\\$" t t)))
            ((member (match-string 2) '("&amp;" "%" "#"))
             (if (equal (match-string 1) "\\")
             (replace-match (match-string 2) t t)
               (replace-match (concat (match-string 1) "\\"
                          (match-string 2)) t t)
               (backward-char 1)))
            ((equal (match-string 2) "...")
             (replace-match
              (concat (match-string 1)
                  (org-export-latex-protect-string "\\ldots{}")) t t))
            ((equal (match-string 2) "~")
             (cond ((equal (match-string 1) "\\") nil)
               ((eq 'org-link (get-text-property 0 'face (match-string 2)))
                (replace-match (concat (match-string 1) "\\~") t t))
               (t (replace-match
                   (org-export-latex-protect-string
                (concat (match-string 1) "\\~{}")) t t))))
            ((member (match-string 2) '("{" "}"))
             (unless (save-match-data (org-inside-latex-math-p))
               (if (equal (match-string 1) "\\")
               (replace-match (match-string 2) t t)
             (replace-match (concat (match-string 1) "\\"
                        (match-string 2)) t t)))))
          (unless (save-match-data (org-inside-latex-math-p))
        (cond ((equal (match-string 2) "\\")
               (replace-match (or (save-match-data
                        (org-export-latex-treat-backslash-char
                         (match-string 1)
                         (or (match-string 3) "")))
                      "") t t)
               (when (and (get-text-property (1- (point)) 'org-entity)
                  (looking-at "{}"))
             ;; OK, this was an entity replacement, and the user
             ;; had terminated the entity with {}.  Make sure
             ;; {} is protected as well, and remove the extra {}
             ;; inserted by the conversion.
             (put-text-property (point) (+ 2 (point)) 'org-protected t)
             (if (save-excursion (goto-char (max (- (point) 2) (point-min)))
                         (looking-at "{}"))
                 (replace-match ""))
             (forward-char 2))
               (backward-char 1))
              ((member (match-string 2) '("_" "^"))
               (replace-match (or (save-match-data
                        (org-export-latex-treat-sub-super-char
                         sub-superscript
                         (match-string 2)
                         (match-string 1)
                         (match-string 3))) "") t t)
               (backward-char 1)))))))
    '(;"^\\([^\n$]*?\\|^\\)\\(\\\\?\\$\\)\\([^\n$]*\\)$"
      "\\(\\(\\\\?\\$\\)\\)"
      "\\([a-zA-Z0-9()]+\\|[ \t\n]\\|\\b\\|\\\\\\)\\(_\\|\\^\\)\\({[^{}]+}\\|[a-zA-Z0-9]+\\|[ \t\n]\\|[:punct:]\\|)\\|{[a-zA-Z0-9]+}\\|([a-zA-Z0-9]+)\\)"
      "\\(.\\|^\\)\\(\\\\\\)\\([ \t\n]\\|\\([&amp;#%{}\"]\\|[a-zA-Z][a-zA-Z0-9]*\\)\\)"
      "\\(.\\|^\\)\\(&amp;\\)"
      "\\(.\\|^\\)\\(#\\)"
      "\\(.\\|^\\)\\(%\\)"
      "\\(.\\|^\\)\\({\\)"
      "\\(.\\|^\\)\\(}\\)"
      "\\(.\\|^\\)\\(~\\)"
      "\\(.\\|^\\)\\(\\.\\.\\.\\)"
      ;; (?\&lt; . "\\textless{}")
      ;; (?\&gt; . "\\textgreater{}")
      )))
</t>
<t tx="ekr.20100929212226.14600">
(defun org-inside-latex-math-p ()
  (get-text-property (point) 'org-latex-math))
</t>
<t tx="ekr.20100929212226.14601">
(defun org-export-latex-treat-sub-super-char
  (subsup char string-before string-after)
  "Convert the \"_\" and \"^\" characters to LaTeX.
SUBSUP corresponds to the ^: option in the #+OPTIONS line.
Convert CHAR depending on STRING-BEFORE and STRING-AFTER."
  (cond ((equal string-before "\\")
     (concat string-before char string-after))
    ((and (string-match "\\S-+" string-after))
     ;; this is part of a math formula
     (cond ((eq 'org-link (get-text-property 0 'face char))
        (concat string-before "\\" char string-after))
           ((save-match-data (org-inside-latex-math-p))
        (if subsup
            (cond ((eq 1 (length string-after))
               (concat string-before char string-after))
              ((string-match "[({]?\\([^)}]+\\)[)}]?" string-after)
               (format "%s%s{%s}" string-before char
                   (match-string 1 string-after))))))
           ((and (&gt; (length string-after) 1)
             (or (eq subsup t)
             (and (equal subsup '{}) (eq (string-to-char string-after) ?\{)))
             (or (string-match "[{]?\\([^}]+\\)[}]?" string-after)
             (string-match "[(]?\\([^)]+\\)[)]?" string-after)))

        (org-export-latex-protect-string
         (format "%s$%s{%s}$" string-before char
             (if (and (&gt; (match-end 1) (1+ (match-beginning 1)))
                  (not (equal (substring string-after 0 2) "{\\")))
                 (concat "\\mathrm{" (match-string 1 string-after) "}")
               (match-string 1 string-after)))))
           ((eq subsup t) (concat string-before "$" char string-after "$"))
           (t (org-export-latex-protect-string
           (concat string-before "\\" char "{}" string-after)))))
    (t (org-export-latex-protect-string
        (concat string-before "\\" char "{}" string-after)))))
</t>
<t tx="ekr.20100929212226.14602">
(defun org-export-latex-treat-backslash-char (string-before string-after)
  "Convert the \"$\" special character to LaTeX.
The conversion is made depending of STRING-BEFORE and STRING-AFTER."
  (let  ((ass (org-entity-get string-after)))
    (cond
     (ass (org-add-props
          (if (nth 2 ass)
          (concat string-before
              (org-export-latex-protect-string
               (concat "$" (nth 1 ass) "$")))
        (concat string-before (org-export-latex-protect-string
                       (nth 1 ass))))
          nil 'org-entity t))
     ((and (not (string-match "^[ \n\t]" string-after))
       (not (string-match "[ \t]\\'\\|^" string-before)))
      ;; backslash is inside a word
      (concat string-before
          (org-export-latex-protect-string
           (concat "\\textbackslash{}" string-after))))
     ((not (or (equal string-after "")
           (string-match "^[ \t\n]" string-after)))
      ;; backslash might escape a character (like \#) or a user TeX
      ;; macro (like \setcounter)
      (concat string-before
          (org-export-latex-protect-string (concat "\\" string-after))))
     ((and (string-match "^[ \t\n]" string-after)
       (string-match "[ \t\n]\\'" string-before))
      ;; backslash is alone, convert it to $\backslash$
      (org-export-latex-protect-string
       (concat string-before "\\textbackslash{}" string-after)))
     (t (org-export-latex-protect-string
     (concat string-before "\\textbackslash{}" string-after))))))
</t>
<t tx="ekr.20100929212226.14603">
(defun org-export-latex-keywords ()
  "Convert special keywords to LaTeX."
  (goto-char (point-min))
  (while (re-search-forward org-export-latex-special-keyword-regexp nil t)
    (replace-match (format org-export-latex-timestamp-keyword-markup
               (match-string 0)) t t)
    (save-excursion
      (beginning-of-line 1)
      (unless (looking-at ".*\n[ \t]*\n")
    (end-of-line 1)
    (insert "\n")))))
</t>
<t tx="ekr.20100929212226.14604">
(defun org-export-latex-fixed-width (opt)
  "When OPT is non-nil convert fixed-width sections to LaTeX."
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*:\\([ \t]\\|$\\)" nil t)
    (unless (get-text-property (point) 'org-example)
     (if opt
     (progn (goto-char (match-beginning 0))
        (insert "\\begin{verbatim}\n")
        (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
          (replace-match (concat (match-string 1)
                     (match-string 2)) t t)
          (forward-line))
        (insert "\\end{verbatim}\n\n"))
       (progn (goto-char (match-beginning 0))
          (while (looking-at "^\\([ \t]*\\):\\(\\([ \t]\\|$\\).*\\)$")
        (replace-match (concat "%" (match-string 1)
                       (match-string 2)) t t)
        (forward-line)))))))
</t>
<t tx="ekr.20100929212226.14605">
(defvar org-table-last-alignment) ; defined in org-table.el
(defvar org-table-last-column-widths) ; defined in org-table.el
(declare-function orgtbl-to-latex "org-table" (table params) t)
(defun org-export-latex-tables (insert)
  "Convert tables to LaTeX and INSERT it."
  ;; First, get the table.el tables
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*\\(\\+-[-+]*\\+\\)[ \t]*\n[ \t]*|" nil t)
    (org-if-unprotected
     (require 'table)
     (org-export-latex-convert-table.el-table)))

  ;; And now the Org-mode tables
  (goto-char (point-min))
  (while (re-search-forward "^\\([ \t]*\\)|" nil t)
    (org-if-unprotected-at (1- (point))
      (org-table-align)
      (let* ((beg (org-table-begin))
             (end (org-table-end))
             (raw-table (buffer-substring beg end))
             (org-table-last-alignment (copy-sequence org-table-last-alignment))
             (org-table-last-column-widths (copy-sequence
                                            org-table-last-column-widths))
             fnum fields line lines olines gr colgropen line-fmt align
             caption shortn label attr floatp longtblp)
        (if org-export-latex-tables-verbatim
            (let* ((tbl (concat "\\begin{verbatim}\n" raw-table
                                "\\end{verbatim}\n")))
              (apply 'delete-region (list beg end))
              (insert (org-export-latex-protect-string tbl)))
          (progn
            (setq caption (org-find-text-property-in-string
                           'org-caption raw-table)
          shortn (org-find-text-property-in-string
              'org-caption-shortn raw-table)
                  attr (org-find-text-property-in-string
                        'org-attributes raw-table)
                  label (org-find-text-property-in-string
                         'org-label raw-table)
                  longtblp (and attr (stringp attr)
                                (string-match "\\&lt;longtable\\&gt;" attr))
                  align (and attr (stringp attr)
                             (string-match "\\&lt;align=\\([^ \t\n\r]+\\)" attr)
                             (match-string 1 attr))
                  floatp (or caption label))
        (setq caption (and caption (org-export-latex-fontify-headline caption)))
            (setq lines (org-split-string raw-table "\n"))
            (apply 'delete-region (list beg end))
            (when org-export-table-remove-special-lines
              (setq lines (org-table-clean-before-export lines 'maybe-quoted)))
            (when org-table-clean-did-remove-column
          (pop org-table-last-alignment)
          (pop org-table-last-column-widths))
            ;; make a formatting string to reflect alignment
            (setq olines lines)
            (while (and (not line-fmt) (setq line (pop olines)))
              (unless (string-match "^[ \t]*|-" line)
                (setq fields (org-split-string line "[ \t]*|[ \t]*"))
                (setq fnum (make-vector (length fields) 0))
                (setq line-fmt
                      (mapconcat
                       (lambda (x)
                         (setq gr (pop org-table-colgroup-info))
                         (format "%s%%s%s"
                                 (cond ((eq gr :start)
                                        (prog1 (if colgropen "|" "|")
                                          (setq colgropen t)))
                                       ((eq gr :startend)
                                        (prog1 (if colgropen "|" "|")
                                          (setq colgropen nil)))
                                       (t ""))
                                 (if (memq gr '(:end :startend))
                                     (progn (setq colgropen nil) "|")
                                   "")))
                       fnum ""))))
            ;; fix double || in line-fmt
            (setq line-fmt (replace-regexp-in-string "||" "|" line-fmt))
            ;; maybe remove the first and last "|"
            (when (and (not org-export-latex-tables-column-borders)
                       (string-match "^\\(|\\)?\\(.+\\)|$" line-fmt))
              (setq line-fmt (match-string 2 line-fmt)))
            ;; format alignment
            (unless align
              (setq align (apply 'format
                                 (cons line-fmt
                                       (mapcar (lambda (x) (if x "r" "l"))
                                               org-table-last-alignment)))))
            ;; prepare the table to send to orgtbl-to-latex
            (setq lines
                  (mapcar
                   (lambda(elem)
                     (or (and (string-match "[ \t]*|-+" elem) 'hline)
                         (org-split-string (org-trim elem) "|")))
                   lines))
            (when insert
              (insert (org-export-latex-protect-string
                       (concat
                        (if longtblp
                            (concat "\\begin{longtable}{" align "}\n")
                          (if floatp "\\begin{table}[htb]\n"))
                        (if floatp
                            (format
                             "\\caption%s{%s}"
                             (if shortn (concat "[" shortn "]") "")
                             (or caption "")))
                        (if (and longtblp caption) "\\\\\n" "\n")
                        (if (and org-export-latex-tables-centered (not longtblp))
                            "\\begin{center}\n")
                        (if (not longtblp)
                (format "\\begin{%s}{%s}\n"
                    org-export-latex-tabular-environment align))
                        (orgtbl-to-latex
                         lines
                         `(:tstart nil :tend nil
                                   :hlend ,(if longtblp
                                               (format "\\\\
\\hline
\\endhead
\\hline\\multicolumn{%d}{r}{Continued on next page}\\
\\endfoot
\\endlastfoot" (length org-table-last-alignment))
                                             nil)))
                        (if (not longtblp)
                (format "\n\\end{%s}"
                    org-export-latex-tabular-environment))
                        (if longtblp "\n" (if org-export-latex-tables-centered
                                              "\n\\end{center}\n" "\n"))
                        (if longtblp
                            "\\end{longtable}"
                          (if floatp "\\end{table}"))))
                      "\n\n"))))))))
</t>
<t tx="ekr.20100929212226.14606">
(defun org-export-latex-convert-table.el-table ()
  "Replace table.el table at point with LaTeX code."
  (let (tbl caption shortn label line floatp attr align rmlines)
    (setq line (buffer-substring (point-at-bol) (point-at-eol))
      label (org-get-text-property-any 0 'org-label line)
      caption (org-get-text-property-any 0 'org-caption line)
      shortn (org-get-text-property-any 0 'org-caption-shortn line)
      attr (org-get-text-property-any 0 'org-attributes line)
      align (and attr (stringp attr)
             (string-match "\\&lt;align=\\([^ \t\n\r,]+\\)" attr)
             (match-string 1 attr))
      rmlines (and attr (stringp attr)
               (string-match "\\&lt;rmlines\\&gt;" attr))
      floatp (or label caption))
    (and (get-buffer "*org-export-table*")
     (kill-buffer (get-buffer "*org-export-table*")))
    (table-generate-source 'latex "*org-export-table*" "caption")
    (setq tbl (with-current-buffer "*org-export-table*"
        (buffer-string)))
    (while (string-match "^%.*\n" tbl)
      (setq tbl (replace-match "" t t tbl)))
    ;; fix the hlines
    (when rmlines
      (let ((n 0) lines)
    (setq lines (mapcar (lambda (x)
                  (if (string-match "^\\\\hline$" x)
                  (progn
                    (setq n (1+ n))
                    (if (= n 2) x nil))
                x))
                (org-split-string tbl "\n")))
    (setq tbl (mapconcat 'identity (delq nil lines) "\n"))))
    (when (and align (string-match "\\\\begin{tabular}{.*}" tbl))
      (setq tbl (replace-match (concat "\\begin{tabular}{" align "}")
                   t t tbl)))
    (and (get-buffer "*org-export-table*")
     (kill-buffer (get-buffer "*org-export-table*")))
    (beginning-of-line 0)
    (while (looking-at "[ \t]*\\(|\\|\\+-\\)")
      (delete-region (point) (1+ (point-at-eol))))
    (when org-export-latex-tables-centered
      (setq tbl (concat "\\begin{center}\n" tbl "\\end{center}")))
    (when floatp
      (setq tbl (concat "\\begin{table}\n"
            (format "\\caption%s{%s%s}\n"
                (if shortn (format "[%s]" shortn) "")
                (if label (format "\\label{%s}" label) "")
                (or caption ""))
            tbl
            "\n\\end{table}\n")))
    (insert (org-export-latex-protect-string tbl))))
</t>
<t tx="ekr.20100929212226.14607">
(defun org-export-latex-fontify ()
  "Convert fontification to LaTeX."
  (goto-char (point-min))
  (while (re-search-forward org-emph-re nil t)
    ;; The match goes one char after the *string*, except at the end of a line
    (let ((emph (assoc (match-string 3)
               org-export-latex-emphasis-alist))
      (beg (match-beginning 0))
      (end (match-end 0))
      rpl s)
      (unless emph
    (message "`org-export-latex-emphasis-alist' has no entry for formatting triggered by \"%s\""
         (match-string 3)))
      (unless (or (and (get-text-property (- (point) 2) 'org-protected)
               (not (get-text-property
                 (- (point) 2) 'org-verbatim-emph)))
          (equal (char-after (match-beginning 3))
             (char-after (1+ (match-beginning 3))))
          (save-excursion
            (goto-char (match-beginning 1))
            (save-match-data
              (and (org-at-table-p)
               (string-match
                "[|\n]" (buffer-substring beg end)))))
          (and (equal (match-string 3) "+")
               (save-match-data
             (string-match "\\`-+\\'" (match-string 4)))))
    (setq s (match-string 4))
    (setq rpl (concat (match-string 1)
              (org-export-latex-emph-format (cadr emph)
                            (match-string 4))
              (match-string 5)))
    (if (caddr emph)
        (setq rpl (org-export-latex-protect-string rpl))
      (save-match-data
        (if (string-match "\\`.?\\(\\\\[a-z]+{\\)\\(.*\\)\\(}\\).?\\'" rpl)
        (progn
          (add-text-properties (match-beginning 1) (match-end 1)
                       '(org-protected t) rpl)
          (add-text-properties (match-beginning 3) (match-end 3)
                       '(org-protected t) rpl)))))
    (replace-match rpl t t)))
    (backward-char)))
</t>
<t tx="ekr.20100929212226.14608">
(defvar org-export-latex-use-verb nil)
(defun org-export-latex-emph-format (format string)
  "Format an emphasis string and handle the \\verb special case."
  (when (equal format "\\verb")
    (save-match-data
      (if org-export-latex-use-verb
      (let ((ll "~,./?;':\"|!@#%^&amp;-_=+abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ&lt;&gt;()[]{}"))
        (catch 'exit
          (loop for i from 0 to (1- (length ll)) do
            (if (not (string-match (regexp-quote (substring ll i (1+ i)))
                       string))
            (progn
              (setq format (concat "\\verb" (substring ll i (1+ i))
                           "%s" (substring ll i (1+ i))))
              (throw 'exit nil))))))
    (let ((start 0)
          (trans '(("\\" . "\\textbackslash{}")
               ("~" . "\\textasciitilde{}")
               ("^" . "\\textasciicircum{}")))
          (rtn "") char)
      (while (string-match "[\\{}$%&amp;_#~^]" string)
        (setq char (match-string 0 string))
        (if (&gt; (match-beginning 0) 0)
        (setq rtn (concat rtn (substring string
                         0 (match-beginning 0)))))
        (setq string (substring string (1+ (match-beginning 0))))
        (setq char (or (cdr (assoc char trans)) (concat "\\" char))
          rtn (concat rtn char)))
      (setq string (concat rtn string) format "\\texttt{%s}")))))
  (format format string))
</t>
<t tx="ekr.20100929212226.14609">
(defun org-export-latex-links ()
  ;; Make sure to use the LaTeX hyperref and graphicx package
  ;; or send some warnings.
  "Convert links to LaTeX."
  (goto-char (point-min))
  (while (re-search-forward org-bracket-link-analytic-regexp++ nil t)
    (org-if-unprotected-1
     (goto-char (match-beginning 0))
     (let* ((re-radio org-export-latex-all-targets-re)
        (remove (list (match-beginning 0) (match-end 0)))
        (raw-path (org-extract-attributes (match-string 3)))
        (full-raw-path (concat (match-string 1) raw-path))
        (desc (match-string 5))
        (type (or (match-string 2)
              (if (or (file-name-absolute-p raw-path)
                  (string-match "^\\.\\.?/" raw-path))
              "file")))
        (coderefp (equal type "coderef"))
        (caption (org-find-text-property-in-string 'org-caption raw-path))
        (shortn (org-find-text-property-in-string 'org-caption-shortn raw-path))
        (attr (or (org-find-text-property-in-string 'org-attributes raw-path)
              (plist-get org-export-latex-options-plist :latex-image-options)))
        (label (org-find-text-property-in-string 'org-label raw-path))
        imgp radiop fnc
        ;; define the path of the link
        (path (cond
           ((member type '("coderef"))
            raw-path)
           ((member type '("http" "https" "ftp"))
            (concat type ":" raw-path))
           ((and re-radio (string-match re-radio raw-path))
            (setq radiop t))
           ((equal type "mailto")
            (concat type ":" raw-path))
           ((equal type "file")
            (if (and (org-file-image-p
                  (expand-file-name
                   raw-path)
                  org-export-latex-inline-image-extensions)
                 (or (get-text-property 0 'org-no-description
                            raw-path)
                 (equal desc full-raw-path)))
            (setq imgp t)
              (progn (when (string-match "\\(.+\\)::.+" raw-path)
                   (setq raw-path (match-string 1 raw-path)))
                 (if (file-exists-p raw-path)
                 (concat type "://" (expand-file-name raw-path))
                   (concat type "://" (org-export-directory
                           :LaTeX org-export-latex-options-plist)
                       raw-path))))))))
       ;; process with link inserting
       (apply 'delete-region remove)
       (setq caption (and caption (org-export-latex-fontify-headline caption)))
       (cond ((and imgp
           (plist-get org-export-latex-options-plist :inline-images))
          ;; OK, we need to inline an image
          (insert
           (org-export-latex-format-image raw-path caption label attr shortn)))
         (coderefp
          (insert (format
               (org-export-get-coderef-format path desc)
               (cdr (assoc path org-export-code-refs)))))
         (radiop (insert (format "\\hyperref[%s]{%s}"
                     (org-solidify-link-text raw-path) desc)))
         ((not type)
          (insert (format "\\hyperref[%s]{%s}"
                  (org-remove-initial-hash
                   (org-solidify-link-text raw-path))
                  desc)))
         (path
          (when (org-at-table-p)
        ;; There is a strange problem when we have a link in a table,
        ;; ampersands then cause a problem.  I think this must be
        ;; a LaTeX issue, but we here implement a work-around anyway.
        (setq path (org-export-latex-protect-amp path)
              desc (org-export-latex-protect-amp desc)))
          (insert (format org-export-latex-hyperref-format path desc)))

         ((functionp (setq fnc (nth 2 (assoc type org-link-protocols))))
          ;; The link protocol has a function for formatting the link
          (insert
           (save-match-data
         (funcall fnc (org-link-unescape raw-path) desc 'latex))))

         (t (insert "\\texttt{" desc "}")))))))
</t>
<t tx="ekr.20100929212226.14610">

(defun org-export-latex-format-image (path caption label attr &amp;optional shortn)
  "Format the image element, depending on user settings."
  (let (ind floatp wrapp multicolumnp placement figenv)
    (setq floatp (or caption label))
    (setq ind (org-get-text-property-any 0 'original-indentation path))
    (when (and attr (stringp attr))
      (if (string-match "[ \t]*\\&lt;wrap\\&gt;" attr)
      (setq wrapp t floatp nil attr (replace-match "" t t attr)))
      (if (string-match "[ \t]*\\&lt;float\\&gt;" attr)
      (setq wrapp nil floatp t attr (replace-match "" t t attr)))
      (if (string-match "[ \t]*\\&lt;multicolumn\\&gt;" attr)
      (setq multicolumnp t attr (replace-match "" t t attr))))

    (setq placement
      (cond
       (wrapp "{l}{0.5\\textwidth}")
       (floatp "[htb]")
       (t "")))

    (when (and attr (stringp attr)
           (string-match "[ \t]*\\&lt;placement=\\(\\S-+\\)" attr))
      (setq placement (match-string 1 attr)
        attr (replace-match "" t t attr)))
    (setq attr (and attr (org-trim attr)))
    (when (or (not attr) (= (length attr) 0))
      (setq attr (cond (floatp "width=0.7\\textwidth")
               (wrapp "width=0.48\\textwidth")
               (t attr))))
    (setq figenv
      (cond
       (wrapp "\\begin{wrapfigure}%placement
\\centering
\\includegraphics[%attr]{%path}
\\caption%shortn{%labelcmd%caption}
\\end{wrapfigure}")
       (multicolumnp "\\begin{figure*}%placement
\\centering
\\includegraphics[%attr]{%path}
\\caption{%labelcmd%caption}
\\end{figure*}")
       (floatp "\\begin{figure}%placement
\\centering
\\includegraphics[%attr]{%path}
\\caption{%labelcmd%caption}
\\end{figure}")
       (t "\\includegraphics[%attr]{%path}")))


    (setq figenv (mapconcat 'identity (split-string figenv "\n")
                (save-excursion (beginning-of-line 1)
                        (looking-at "[ \t]*")
                        (concat "\n" (match-string 0)))))

    (if (and (not label) (not caption)
         (string-match "^\\\\caption{.*\n" figenv))
    (setq figenv (replace-match "" t t figenv)))
    (org-add-props
    (org-fill-template
     figenv
     (list (cons "path"
             (if (file-name-absolute-p path)
             (expand-file-name path)
               path))
           (cons "attr" attr)
           (cons "shortn" (if shortn (format "[%s]" shortn) ""))
           (cons "labelcmd" (if label (format "\\label{%s}"
                          label)""))
           (cons "caption" (or caption ""))
           (cons "placement" (or placement ""))))
    nil 'original-indentation ind)))
</t>
<t tx="ekr.20100929212226.14611">
(defun org-export-latex-protect-amp (s)
  (while (string-match "\\([^\\\\]\\)\\(&amp;\\)" s)
    (setq s (replace-match (concat (match-string 1 s) "\\" (match-string 2 s))
               t t s)))
  s)
</t>
<t tx="ekr.20100929212226.14612">
(defun org-remove-initial-hash (s)
  (if (string-match "\\`#" s)
      (substring s 1)
    s))
</t>
<t tx="ekr.20100929212226.14613">(defvar org-latex-entities)   ; defined below
(defvar org-latex-entities-regexp)   ; defined below

(defun org-export-latex-preprocess (parameters)
  "Clean stuff in the LaTeX export."
  ;; Preserve line breaks
  (goto-char (point-min))
  (while (re-search-forward "\\\\\\\\" nil t)
    (add-text-properties (match-beginning 0) (match-end 0)
             '(org-protected t)))

  ;; Preserve latex environments
  (goto-char (point-min))
  (while (re-search-forward "^[ \t]*\\\\begin{\\([a-zA-Z]+\\*?\\)}" nil t)
    (org-if-unprotected
     (let* ((start (progn (beginning-of-line) (point)))
       (end (and (re-search-forward
              (concat "^[ \t]*\\\\end{"
                  (regexp-quote (match-string 1))
                  "}") nil t)
             (point-at-eol))))
      (if end
      (add-text-properties start end '(org-protected t))
    (goto-char (point-at-eol))))))

  ;; Preserve math snippets

  (let* ((matchers (plist-get org-format-latex-options :matchers))
     (re-list org-latex-regexps)
     beg end re e m n block off)
    ;; Check the different regular expressions
    (while (setq e (pop re-list))
      (setq m (car e) re (nth 1 e) n (nth 2 e)
        block (if (nth 3 e) "\n\n" ""))
      (setq off (if (member m '("$" "$1")) 1 0))
      (when (and (member m matchers) (not (equal m "begin")))
    (goto-char (point-min))
    (while (re-search-forward re nil t)
      (setq beg (+ (match-beginning 0) off) end (- (match-end 0) 0))
      (add-text-properties beg end '(org-protected t org-latex-math t))))))

  ;; Convert LaTeX to \LaTeX{} and TeX to \TeX{}
  (goto-char (point-min))
  (let ((case-fold-search nil))
    (while (re-search-forward "\\&lt;\\(\\(La\\)?TeX\\)\\&gt;" nil t)
      (unless (eq (char-before (match-beginning 1)) ?\\)
    (org-if-unprotected-1
     (replace-match (org-export-latex-protect-string
             (concat "\\" (match-string 1)
                 "{}")) t t)))))

  ;; Convert blockquotes
  (goto-char (point-min))
  (while (search-forward "ORG-BLOCKQUOTE-START" nil t)
    (org-replace-match-keep-properties "\\begin{quote}" t t))
  (goto-char (point-min))
  (while (search-forward "ORG-BLOCKQUOTE-END" nil t)
    (org-replace-match-keep-properties "\\end{quote}" t t))

  ;; Convert verse
  (goto-char (point-min))
  (while (search-forward "ORG-VERSE-START" nil t)
    (org-replace-match-keep-properties "\\begin{verse}" t t)
    (beginning-of-line 2)
    (while (and (not (looking-at "[ \t]*ORG-VERSE-END.*")) (not (eobp)))
      (when (looking-at "\\([ \t]+\\)\\([^ \t\n]\\)")
    (goto-char (match-end 1))
    (org-replace-match-keep-properties
     (org-export-latex-protect-string
      (concat "\\hspace*{1cm}" (match-string 2))) t t)
    (beginning-of-line 1))
      (if (looking-at "[ \t]*$")
      (insert (org-export-latex-protect-string "\\vspace*{1em}"))
    (unless (looking-at ".*?[^ \t\n].*?\\\\\\\\[ \t]*$")
      (end-of-line 1)
      (insert "\\\\")))
      (beginning-of-line 2))
    (and (looking-at "[ \t]*ORG-VERSE-END.*")
     (org-replace-match-keep-properties "\\end{verse}" t t)))

  ;; Convert center
  (goto-char (point-min))
  (while (search-forward "ORG-CENTER-START" nil t)
    (org-replace-match-keep-properties "\\begin{center}" t t))
  (goto-char (point-min))
  (while (search-forward "ORG-CENTER-END" nil t)
    (org-replace-match-keep-properties "\\end{center}" t t))

  (run-hooks 'org-export-latex-after-blockquotes-hook)

  ;; Convert horizontal rules
  (goto-char (point-min))
  (while (re-search-forward "^----+.$" nil t)
    (org-if-unprotected
     (replace-match (org-export-latex-protect-string "\\hrule") t t)))

  ;; Protect LaTeX commands like \command[...]{...} or \command{...}
  (goto-char (point-min))
  (let ((re (concat
         "\\\\\\([a-zA-Z]+\\)"
         "\\(?:&lt;[^&lt;&gt;\n]*&gt;\\)*"
         "\\(?:\\[[^][\n]*?\\]\\)*"
         "\\(?:&lt;[^&lt;&gt;\n]*&gt;\\)*"
         "\\(" (org-create-multibrace-regexp "{" "}" 3) "\\)\\{1,3\\}")))
    (while (re-search-forward re nil t)
      (unless (or
           ;; check for comment line
           (save-excursion (goto-char (match-beginning 0))
                   (org-in-indented-comment-line))
           ;; Check if this is a defined entity, so that is may need conversion
           (org-entity-get (match-string 1))
           )
    (add-text-properties (match-beginning 0) (match-end 0)
                 '(org-protected t)))))

  ;; Special case for \nbsp
  (goto-char (point-min))
  (while (re-search-forward "\\\\nbsp\\({}\\|\\&gt;\\)" nil t)
    (org-if-unprotected
     (replace-match (org-export-latex-protect-string "~"))))

  ;; Protect LaTeX entities
  (goto-char (point-min))
  (while (re-search-forward org-latex-entities-regexp nil t)
    (org-if-unprotected
     (add-text-properties (match-beginning 0) (match-end 0)
              '(org-protected t))))

  ;; Replace radio links
  (goto-char (point-min))
  (while (re-search-forward
      (concat "&lt;&lt;&lt;?" org-export-latex-all-targets-re
          "&gt;&gt;&gt;?\\((INVISIBLE)\\)?") nil t)
    (org-if-unprotected-at (+ (match-beginning 0) 2)
     (replace-match
      (concat
       (org-export-latex-protect-string
    (format "\\label{%s}" (save-match-data (org-solidify-link-text
                        (match-string 1)))))
       (if (match-string 2) "" (match-string 1)))
      t t)))

  ;; Delete @&lt;...&gt; constructs
  ;; Thanks to Daniel Clemente for this regexp
  (goto-char (point-min))
  (while (re-search-forward "@&lt;\\(?:[^\"\n]\\|\".*\"\\)*?&gt;" nil t)
    (org-if-unprotected
     (replace-match "")))

  ;; When converting to LaTeX, replace footnotes
  ;; FIXME: don't protect footnotes from conversion
  (when (plist-get org-export-latex-options-plist :footnotes)
    (goto-char (point-min))
    (while (re-search-forward "\\[\\([0-9]+\\)\\]" nil t)
      (org-if-unprotected
       (when (and (save-match-data
            (save-excursion (beginning-of-line)
                    (looking-at "[^:|#]")))
          (not (org-in-verbatim-emphasis)))
     (let ((foot-beg (match-beginning 0))
           (foot-end (match-end 0))
           (foot-prefix (match-string 0))
           footnote footnote-rpl)
       (save-excursion
         (if (not (re-search-forward (concat "^" (regexp-quote foot-prefix))
                     nil t))
         (replace-match (org-export-latex-protect-string
                 (concat "$^{" (match-string 1) "}$")))
           (replace-match "")
           (let ((end (save-excursion
                (if (re-search-forward "^$\\|^#.*$\\|\\[[0-9]+\\]" nil t)
                (match-beginning 0) (point-max)))))
         (setq footnote (concat (org-trim (buffer-substring (point) end))
                    " ")) ; prevent last } being part of a link
         (delete-region (point) end))
           (goto-char foot-beg)
           (delete-region foot-beg foot-end)
           (unless (null footnote)
         (setq footnote-rpl (format "\\footnote{%s}" footnote))
         (add-text-properties 0 10 '(org-protected t) footnote-rpl)
         (add-text-properties (1- (length footnote-rpl))
                      (length footnote-rpl)
                      '(org-protected t) footnote-rpl)
         (if (org-on-heading-p)
                     (setq footnote-rpl
                           (concat (org-export-latex-protect-string "\\protect")
                                   footnote-rpl)))
         (insert footnote-rpl)))
         )))))

    ;; Remove footnote section tag for LaTeX
    (goto-char (point-min))
    (while (re-search-forward
        (concat "^" footnote-section-tag-regexp) nil t)
      (org-if-unprotected
       (replace-match "")))))
</t>
<t tx="ekr.20100929212226.14614">
(defun org-export-latex-fix-inputenc ()
  "Set the coding system in inputenc to what the buffer is."
  (let* ((cs buffer-file-coding-system)
     (opt (or (ignore-errors (latexenc-coding-system-to-inputenc cs))
          "utf8")))
    (when opt
      ;; Translate if that is requested
      (setq opt (or (cdr (assoc opt org-export-latex-inputenc-alist)) opt))
      ;; find the \usepackage statement and replace the option
      (goto-char (point-min))
      (while (re-search-forward "\\\\usepackage\\[\\(AUTO\\)\\]{inputenc}"
                nil t)
    (goto-char (match-beginning 1))
    (delete-region (match-beginning 1) (match-end 1))
    (insert opt))
      (and buffer-file-name
       (save-buffer)))))
</t>
<t tx="ekr.20100929212226.14615">
;;; List handling:

(defun org-export-latex-lists ()
  "Convert plain text lists in current buffer into LaTeX lists."
  (let (res)
    (goto-char (point-min))
    (while (org-re-search-forward-unprotected org-list-beginning-re nil t)
      (beginning-of-line)
      (setq res (org-list-to-latex (org-list-parse-list t)
                   org-export-latex-list-parameters))
      (while (string-match "^\\(\\\\item[ \t]+\\)\\[@start:\\([0-9]+\\)\\]"
               res)
    (setq res (replace-match
           (concat (format "\\setcounter{enumi}{%d}"
                   (1- (string-to-number
                    (match-string 2 res))))
               "\n"
               (match-string 1 res))
           t t res)))
      (insert res "\n"))))
</t>
<t tx="ekr.20100929212226.14616">@language lisp
@tabwidth -4
@others

(provide 'org-agenda)

;; arch-tag: 77f7565d-7c4b-44af-a2df-9f6f7070cff1

;;; org-agenda.el ends here
</t>
<t tx="ekr.20100929212226.14617">;;; org-agenda.el --- Dynamic task and appointment lists for Org

;; Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010
;;   Free Software Foundation, Inc.

;; Author: Carsten Dominik &lt;carsten at orgmode dot org&gt;
;; Keywords: outlines, hypermedia, calendar, wp
;; Homepage: http://orgmode.org
;; Version: 7.01h
;;
;; This file is part of GNU Emacs.
;;
;; GNU Emacs is free software: you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.

;; GNU Emacs is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;; GNU General Public License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs.  If not, see &lt;http://www.gnu.org/licenses/&gt;.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;; Commentary:

;; This file contains the code for creating and using the Agenda for Org-mode.

;;; Code:

(require 'org)
(eval-when-compile
  (require 'cl))

(declare-function diary-add-to-list "diary-lib"
                  (date string specifier &amp;optional marker globcolor literal))
(declare-function calendar-absolute-from-iso    "cal-iso"    (date))
(declare-function calendar-astro-date-string    "cal-julian" (&amp;optional date))
(declare-function calendar-bahai-date-string    "cal-bahai"  (&amp;optional date))
(declare-function calendar-chinese-date-string  "cal-china"  (&amp;optional date))
(declare-function calendar-coptic-date-string   "cal-coptic" (&amp;optional date))
(declare-function calendar-ethiopic-date-string "cal-coptic" (&amp;optional date))
(declare-function calendar-french-date-string   "cal-french" (&amp;optional date))
(declare-function calendar-goto-date            "cal-move"   (date))
(declare-function calendar-hebrew-date-string   "cal-hebrew" (&amp;optional date))
(declare-function calendar-islamic-date-string  "cal-islam"  (&amp;optional date))
(declare-function calendar-iso-date-string      "cal-iso"    (&amp;optional date))
(declare-function calendar-iso-from-absolute    "cal-iso"    (date))
(declare-function calendar-julian-date-string   "cal-julian" (&amp;optional date))
(declare-function calendar-mayan-date-string    "cal-mayan"  (&amp;optional date))
(declare-function calendar-persian-date-string  "cal-persia" (&amp;optional date))
(declare-function org-datetree-find-date-create "org-datetree"
          (date &amp;optional keep-restriction))
(declare-function org-columns-quit              "org-colview" ())
(declare-function diary-date-display-form       "diary-lib"  (&amp;optional type))
(declare-function org-mobile-write-agenda-for-mobile "org-mobile" (file))
(declare-function org-habit-insert-consistency-graphs
          "org-habit" (&amp;optional line))
(declare-function org-is-habit-p "org-habit" (&amp;optional pom))
(declare-function org-habit-parse-todo "org-habit" (&amp;optional pom))
(declare-function org-habit-get-priority "org-habit" (habit &amp;optional moment))
(defvar calendar-mode-map)
(defvar org-mobile-force-id-on-agenda-items) ; defined in org-mobile.el
(defvar org-habit-show-habits)
(defvar org-habit-show-habits-only-for-today)

;; Defined somewhere in this file, but used before definition.
(defvar org-agenda-buffer-name)
(defvar org-agenda-overriding-header)
(defvar org-agenda-title-append nil)
(defvar entry)
(defvar date)
(defvar org-agenda-undo-list)
(defvar org-agenda-pending-undo-list)
(defvar original-date) ; dynamically scoped, calendar.el does scope this

(defcustom org-agenda-confirm-kill 1
  "When set, remote killing from the agenda buffer needs confirmation.
When t, a confirmation is always needed.  When a number N, confirmation is
only needed when the text to be killed contains more than N non-white lines."
  :group 'org-agenda
  :type '(choice
      (const :tag "Never" nil)
      (const :tag "Always" t)
      (integer :tag "When more than N lines")))

(defcustom org-agenda-compact-blocks nil
  "Non-nil means make the block agenda more compact.
This is done by leaving out unnecessary lines."
  :group 'org-agenda
  :type 'boolean)

(defcustom org-agenda-block-separator ?=
  "The separator between blocks in the agenda.
If this is a string, it will be used as the separator, with a newline added.
If it is a character, it will be repeated to fill the window width."
  :group 'org-agenda
  :type '(choice
      (character)
      (string)))

(defgroup org-agenda-export nil
 "Options concerning exporting agenda views in Org-mode."
 :tag "Org Agenda Export"
 :group 'org-agenda)

(defcustom org-agenda-with-colors t
  "Non-nil means use colors in agenda views."
  :group 'org-agenda-export
  :type 'boolean)

(defcustom org-agenda-exporter-settings nil
  "Alist of variable/value pairs that should be active during agenda export.
This is a good place to set options for ps-print and for htmlize.
Note that the way this is implemented, the values will be evaluated
before assigned to the variables.  So make sure to quote values you do
*not* want evaluated, for example

   (setq org-agenda-exporter-settings
         '((ps-print-color-p 'black-white)))"
  :group 'org-agenda-export
  :type '(repeat
      (list
       (variable)
       (sexp :tag "Value"))))

(defcustom org-agenda-before-write-hook '(org-agenda-add-entry-text)
  "Hook run in temporary buffer before writing it to an export file.
A useful function is `org-agenda-add-entry-text'."
  :group 'org-agenda-export
  :type 'hook
  :options '(org-agenda-add-entry-text))

(defcustom org-agenda-add-entry-text-maxlines 0
  "Maximum number of entry text lines to be added to agenda.
This is only relevant when `org-agenda-add-entry-text' is part of
`org-agenda-before-write-hook', which it is by default.
When this is 0, nothing will happen.  When it is greater than 0, it
specifies the maximum number of lines that will be added for each entry
that is listed in the agenda view.

Note that this variable is not used during display, only when exporting
the agenda.  For agenda display, see the variables `org-agenda-entry-text-mode'
and `org-agenda-entry-text-maxlines'."
  :group 'org-agenda
  :type 'integer)

(defcustom org-agenda-add-entry-text-descriptive-links t
  "Non-nil means export org-links as descriptive links in agenda added text.
This variable applies to the text added to the agenda when
`org-agenda-add-entry-text-maxlines' is larger than 0.
When this variable nil, the URL will (also) be shown."
  :group 'org-agenda
  :type 'boolean)

(defcustom org-agenda-export-html-style ""
  "The style specification for exported HTML Agenda files.
If this variable contains a string, it will replace the default &lt;style&gt;
section as produced by `htmlize'.
Since there are different ways of setting style information, this variable
needs to contain the full HTML structure to provide a style, including the
surrounding HTML tags.  The style specifications should include definitions
the fonts used by the agenda, here is an example:

   &lt;style type=\"text/css\"&gt;
       p { font-weight: normal; color: gray; }
       .org-agenda-structure {
          font-size: 110%;
          color: #003399;
          font-weight: 600;
       }
       .org-todo {
          color: #cc6666;
          font-weight: bold;
       }
       .org-agenda-done {
          color: #339933;
       }
       .org-done {
          color: #339933;
       }
       .title { text-align: center; }
       .todo, .deadline { color: red; }
       .done { color: green; }
    &lt;/style&gt;

or, if you want to keep the style in a file,

   &lt;link rel=\"stylesheet\" type=\"text/css\" href=\"mystyles.css\"&gt;

As the value of this option simply gets inserted into the HTML &lt;head&gt; header,
you can \"misuse\" it to also add other text to the header.  However,
&lt;style&gt;...&lt;/style&gt; is required, if not present the variable will be ignored."
  :group 'org-agenda-export
  :group 'org-export-html
  :type 'string)

(defcustom org-agenda-persistent-filter nil
  "When set, keep filters from one agenda view to the next."
  :group 'org-agenda
  :type 'boolean)

(defgroup org-agenda-custom-commands nil
 "Options concerning agenda views in Org-mode."
 :tag "Org Agenda Custom Commands"
 :group 'org-agenda)

(defconst org-sorting-choice
  '(choice
    (const time-up) (const time-down)
    (const category-keep) (const category-up) (const category-down)
    (const tag-down) (const tag-up)
    (const priority-up) (const priority-down)
    (const todo-state-up) (const todo-state-down)
    (const effort-up) (const effort-down)
    (const habit-up) (const habit-down)
    (const alpha-up) (const alpha-down)
    (const user-defined-up) (const user-defined-down))
  "Sorting choices.")

(defconst org-agenda-custom-commands-local-options
  `(repeat :tag "Local settings for this command. Remember to quote values"
       (choice :tag "Setting"
        (list :tag "Heading for this block"
          (const org-agenda-overriding-header)
          (string :tag "Headline"))
        (list :tag "Files to be searched"
          (const org-agenda-files)
          (list
           (const :format "" quote)
           (repeat (file))))
        (list :tag "Sorting strategy"
          (const org-agenda-sorting-strategy)
          (list
           (const :format "" quote)
           (repeat
            ,org-sorting-choice)))
        (list :tag "Prefix format"
          (const org-agenda-prefix-format :value "  %-12:c%?-12t% s")
          (string))
        (list :tag "Number of days in agenda"
          (const org-agenda-ndays)
          (integer :value 1))
        (list :tag "Fixed starting date"
          (const org-agenda-start-day)
          (string :value "2007-11-01"))
        (list :tag "Start on day of week"
          (const org-agenda-start-on-weekday)
          (choice :value 1
              (const :tag "Today" nil)
              (integer :tag "Weekday No.")))
        (list :tag "Include data from diary"
          (const org-agenda-include-diary)
          (boolean))
        (list :tag "Deadline Warning days"
          (const org-deadline-warning-days)
          (integer :value 1))
        (list :tag "Tags filter preset"
          (const org-agenda-filter-preset)
          (list
           (const :format "" quote)
           (repeat
            (string :tag "+tag or -tag"))))
        (list :tag "Set daily/weekly entry types"
          (const org-agenda-entry-types)
          (set :greedy t :value (:deadline :scheduled :timestamp :sexp)
               (const :deadline)
               (const :scheduled)
               (const :timestamp)
               (const :sexp)))
        (list :tag "Standard skipping condition"
          :value (org-agenda-skip-function '(org-agenda-skip-entry-if))
          (const org-agenda-skip-function)
          (list
           (const :format "" quote)
           (list
            (choice
             :tag "Skipping range"
             (const :tag "Skip entry" org-agenda-skip-entry-if)
             (const :tag "Skip subtree" org-agenda-skip-subtree-if))
            (repeat :inline t :tag "Conditions for skipping"
                (choice
                 :tag "Condition type"
                 (list :tag "Regexp matches" :inline t (const :format "" 'regexp) (regexp))
                 (list :tag "Regexp does not match" :inline t (const :format "" 'notregexp) (regexp))
                 (list :tag "TODO state is" :inline t
                   (const 'todo)
                   (choice
                    (const :tag "any not-done state" 'todo)
                    (const :tag "any done state" 'done)
                    (const :tag "any state" 'any)
                    (list :tag "Keyword list"
                      (const :format "" quote)
                      (repeat (string :tag "Keyword")))))
                 (list :tag "TODO state is not" :inline t
                   (const 'nottodo)
                   (choice
                    (const :tag "any not-done state" 'todo)
                    (const :tag "any done state" 'done)
                    (const :tag "any state" 'any)
                    (list :tag "Keyword list"
                      (const :format "" quote)
                      (repeat (string :tag "Keyword")))))
                 (const :tag "scheduled" 'scheduled)
                 (const :tag "not scheduled" 'notscheduled)
                 (const :tag "deadline" 'deadline)
                 (const :tag "no deadline" 'notdeadline)
                 (const :tag "timestamp" 'timestamp)
                 (const :tag "no timestamp" 'nottimestamp))))))
        (list :tag "Non-standard skipping condition"
          :value (org-agenda-skip-function)
          (const org-agenda-skip-function)
          (sexp :tag "Function or form (quoted!)"))
        (list :tag "Any variable"
          (variable :tag "Variable")
          (sexp :tag "Value (sexp)"))))
  "Selection of examples for agenda command settings.
This will be spliced into the custom type of
`org-agenda-custom-commands'.")


(defcustom org-agenda-custom-commands nil
  "Custom commands for the agenda.
These commands will be offered on the splash screen displayed by the
agenda dispatcher \\[org-agenda].  Each entry is a list like this:

   (key desc type match settings files)

key      The key (one or more characters as a string) to be associated
         with the command.
desc     A description of the command, when omitted or nil, a default
         description is built using MATCH.
type     The command type, any of the following symbols:
          agenda      The daily/weekly agenda.
          todo        Entries with a specific TODO keyword, in all agenda files.
          search      Entries containing search words entry or headline.
          tags        Tags/Property/TODO match in all agenda files.
          tags-todo   Tags/P/T match in all agenda files, TODO entries only.
          todo-tree   Sparse tree of specific TODO keyword in *current* file.
          tags-tree   Sparse tree with all tags matches in *current* file.
          occur-tree  Occur sparse tree for *current* file.
          ...         A user-defined function.
match    What to search for:
          - a single keyword for TODO keyword searches
          - a tags match expression for tags searches
          - a word search expression for text searches.
          - a regular expression for occur searches
          For all other commands, this should be the empty string.
settings  A list of option settings, similar to that in a let form, so like
          this: ((opt1 val1) (opt2 val2) ...).   The values will be
          evaluated at the moment of execution, so quote them when needed.
files     A list of files file to write the produced agenda buffer to
          with the command `org-store-agenda-views'.
          If a file name ends in \".html\", an HTML version of the buffer
          is written out.  If it ends in \".ps\", a postscript version is
          produced.  Otherwise, only the plain text is written to the file.

You can also define a set of commands, to create a composite agenda buffer.
In this case, an entry looks like this:

  (key desc (cmd1 cmd2 ...) general-settings-for-whole-set files)

where

desc   A description string to be displayed in the dispatcher menu.
cmd    An agenda command, similar to the above.  However, tree commands
       are no allowed, but instead you can get agenda and global todo list.
       So valid commands for a set are:
       (agenda \"\" settings)
       (alltodo \"\" settings)
       (stuck \"\" settings)
       (todo \"match\" settings files)
       (search \"match\" settings files)
       (tags \"match\" settings files)
       (tags-todo \"match\" settings files)

Each command can carry a list of options, and another set of options can be
given for the whole set of commands.  Individual command options take
precedence over the general options.

When using several characters as key to a command, the first characters
are prefix commands.  For the dispatcher to display useful information, you
should provide a description for the prefix, like

 (setq org-agenda-custom-commands
   '((\"h\" . \"HOME + Name tag searches\") ; describe prefix \"h\"
     (\"hl\" tags \"+HOME+Lisa\")
     (\"hp\" tags \"+HOME+Peter\")
     (\"hk\" tags \"+HOME+Kim\")))"
  :group 'org-agenda-custom-commands
  :type `(repeat
      (choice :value ("x" "Describe command here" tags "" nil)
       (list :tag "Single command"
         (string :tag "Access Key(s) ")
         (option (string :tag "Description"))
         (choice
          (const :tag "Agenda" agenda)
          (const :tag "TODO list" alltodo)
          (const :tag "Search words" search)
          (const :tag "Stuck projects" stuck)
          (const :tag "Tags/Property match (all agenda files)" tags)
          (const :tag "Tags/Property match of TODO entries (all agenda files)" tags-todo)
          (const :tag "TODO keyword search (all agenda files)" todo)
          (const :tag "Tags sparse tree (current buffer)" tags-tree)
          (const :tag "TODO keyword tree (current buffer)" todo-tree)
          (const :tag "Occur tree (current buffer)" occur-tree)
          (sexp :tag "Other, user-defined function"))
         (string :tag "Match (only for some commands)")
         ,org-agenda-custom-commands-local-options
         (option (repeat :tag "Export" (file :tag "Export to"))))
       (list :tag "Command series, all agenda files"
         (string :tag "Access Key(s)")
         (string :tag "Description  ")
         (repeat :tag "Component"
          (choice
           (list :tag "Agenda"
             (const :format "" agenda)
             (const :tag "" :format "" "")
             ,org-agenda-custom-commands-local-options)
           (list :tag "TODO list (all keywords)"
             (const :format "" alltodo)
             (const :tag "" :format "" "")
             ,org-agenda-custom-commands-local-options)
           (list :tag "Search words"
             (const :format "" search)
             (string :tag "Match")
             ,org-agenda-custom-commands-local-options)
           (list :tag "Stuck projects"
             (const :format "" stuck)
             (const :tag "" :format "" "")
             ,org-agenda-custom-commands-local-options)
           (list :tag "Tags search"
             (const :format "" tags)
             (string :tag "Match")
             ,org-agenda-custom-commands-local-options)
           (list :tag "Tags search, TODO entries only"
             (const :format "" tags-todo)
             (string :tag "Match")
             ,org-agenda-custom-commands-local-options)
           (list :tag "TODO keyword search"
             (const :format "" todo)
             (string :tag "Match")
             ,org-agenda-custom-commands-local-options)
           (list :tag "Other, user-defined function"
             (symbol :tag "function")
             (string :tag "Match")
             ,org-agenda-custom-commands-local-options)))

         (repeat :tag "Settings for entire command set"
             (list (variable :tag "Any variable")
                   (sexp :tag "Value")))
         (option (repeat :tag "Export" (file :tag "Export to"))))
       (cons :tag "Prefix key documentation"
         (string :tag "Access Key(s)")
         (string :tag "Description  ")))))

(defcustom org-agenda-query-register ?o
  "The register holding the current query string.
The purpose of this is that if you construct a query string interactively,
you can then use it to define a custom command."
  :group 'org-agenda-custom-commands
  :type 'character)

(defcustom org-stuck-projects
  '("+LEVEL=2/-DONE" ("TODO" "NEXT" "NEXTACTION") nil "")
  "How to identify stuck projects.
This is a list of four items:
1. A tags/todo/property matcher string that is used to identify a project.
   See the manual for a description of tag and property searches.
   The entire tree below a headline matched by this is considered one project.
2. A list of TODO keywords identifying non-stuck projects.
   If the project subtree contains any headline with one of these todo
   keywords, the project is considered to be not stuck.  If you specify
   \"*\" as a keyword, any TODO keyword will mark the project unstuck.
3. A list of tags identifying non-stuck projects.
   If the project subtree contains any headline with one of these tags,
   the project is considered to be not stuck.  If you specify \"*\" as
   a tag, any tag will mark the project unstuck.  Note that this is about
   the explicit presence of a tag somewhere in the subtree, inherited
   tags to not count here.  If inherited tags make a project not stuck,
   use \"-TAG\" in the tags part of the matcher under (1.) above.
4. An arbitrary regular expression matching non-stuck projects.

If the project turns out to be not stuck, search continues also in the
subtree to see if any of the subtasks have project status.

See also the variable `org-tags-match-list-sublevels' which applies
to projects matched by this search as well.

After defining this variable, you may use \\[org-agenda-list-stuck-projects]
or `C-c a #' to produce the list."
  :group 'org-agenda-custom-commands
  :type '(list
      (string :tag "Tags/TODO match to identify a project")
      (repeat :tag "Projects are *not* stuck if they have an entry with TODO keyword any of" (string))
      (repeat :tag "Projects are *not* stuck if they have an entry with TAG being any of" (string))
      (regexp :tag "Projects are *not* stuck if this regexp matches inside the subtree")))

(defcustom org-agenda-filter-effort-default-operator "&lt;"
  "The default operator for effort estimate filtering.
If you select an effort estimate limit without first pressing an operator,
this one will be used."
  :group 'org-agenda-custom-commands
  :type '(choice (const :tag "less or equal" "&lt;")
         (const :tag "greater or equal""&gt;")
         (const :tag "equal" "=")))

(defgroup org-agenda-skip nil
 "Options concerning skipping parts of agenda files."
 :tag "Org Agenda Skip"
 :group 'org-agenda)
(defgroup org-agenda-daily/weekly nil
  "Options concerning the daily/weekly agenda."
  :tag "Org Agenda Daily/Weekly"
  :group 'org-agenda)
(defgroup org-agenda-todo-list nil
  "Options concerning the global todo list agenda view."
  :tag "Org Agenda Todo List"
  :group 'org-agenda)
(defgroup org-agenda-match-view nil
  "Options concerning the general tags/property/todo match agenda view."
  :tag "Org Agenda Match View"
  :group 'org-agenda)
(defgroup org-agenda-search-view nil
  "Options concerning the general tags/property/todo match agenda view."
  :tag "Org Agenda Match View"
  :group 'org-agenda)

(defvar org-agenda-archives-mode nil
  "Non-nil means the agenda will include archived items.
If this is the symbol `trees', trees in the selected agenda scope
that are marked with the ARCHIVE tag will be included anyway.  When this is
t, also all archive files associated with the current selection of agenda
files will be included.")

(defcustom org-agenda-skip-comment-trees t
  "Non-nil means skip trees that start with the COMMENT keyword.
When nil, these trees are also scanned by agenda commands."
  :group 'org-agenda-skip
  :type 'boolean)

(defcustom org-agenda-todo-list-sublevels t
  "Non-nil means check also the sublevels of a TODO entry for TODO entries.
When nil, the sublevels of a TODO entry are not checked, resulting in
potentially much shorter TODO lists."
  :group 'org-agenda-skip
  :group 'org-agenda-todo-list
  :type 'boolean)

(defcustom org-agenda-todo-ignore-with-date nil
  "Non-nil means don't show entries with a date in the global todo list.
You can use this if you prefer to mark mere appointments with a TODO keyword,
but don't want them to show up in the TODO list.
When this is set, it also covers deadlines and scheduled items, the settings
of `org-agenda-todo-ignore-scheduled' and `org-agenda-todo-ignore-deadlines'
will be ignored.
See also the variable `org-agenda-tags-todo-honor-ignore-options'."
  :group 'org-agenda-skip
  :group 'org-agenda-todo-list
  :type 'boolean)

(defcustom org-agenda-todo-ignore-scheduled nil
  "Non-nil means, ignore some scheduled TODO items when making TODO list.
This applies when creating the global todo list.
Valid values are:

past     Don't show entries scheduled today or in the past.

future   Don't show entries scheduled in the future.
         The idea behind this is that by scheduling it, you don't want to
         think about it until the scheduled date.

all      Don't show any scheduled entries in the global todo list.
         The idea behind this is that by scheduling it, you have already
         \"taken care\" of this item.

t        Same as `all', for backward compatibility.

See also `org-agenda-todo-ignore-with-date'.
See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
to make his option also apply to the tags-todo list."
  :group 'org-agenda-skip
  :group 'org-agenda-todo-list
  :type '(choice
      (const :tag "Ignore future-scheduled todos" future)
      (const :tag "Ignore past- or present-scheduled todos" past)
      (const :tag "Ignore all scheduled todos" all)
      (const :tag "Ignore all scheduled todos (compatibility)" t)
      (const :tag "Show scheduled todos" nil)))

(defcustom org-agenda-todo-ignore-deadlines nil
  "Non-nil means ignore some deadlined TODO items when making TODO list.
There are different motivations for using different values, please think
carefully when configuring this variable.

This applies when creating the global todo list.
Valid values are:

near    Don't show near deadline entries.  A deadline is near when it is
        closer than `org-deadline-warning-days' days.  The idea behind this
        is that such items will appear in the agenda anyway.

far     Don't show TODO entries where a deadline has been defined, but
        the deadline is not near.  This is useful if you don't want to
        use the todo list to figure out what to do now.

past    Don't show entries with a deadline timestamp for today or in the past.

future  Don't show entries with a deadline timestamp in the future, not even
        when they become `near' ones.  Use it with caution.

all     Ignore all TODO entries that do have a deadline.

t       Same as `near', for backward compatibility.

See also `org-agenda-todo-ignore-with-date'.
See also the variable `org-agenda-tags-todo-honor-ignore-options' if you want
to make his option also apply to the tags-todo list."
  :group 'org-agenda-skip
  :group 'org-agenda-todo-list
  :type '(choice
      (const :tag "Ignore near deadlines" near)
      (const :tag "Ignore near deadlines (compatibility)" t)
      (const :tag "Ignore far deadlines" far)
      (const :tag "Ignore all TODOs with a deadlines" all)
      (const :tag "Show all TODOs, even if they have a deadline" nil)))

(defcustom org-agenda-tags-todo-honor-ignore-options nil
  "Non-nil means honor todo-list ...ignore options also in tags-todo search.
The variables
   `org-agenda-todo-ignore-with-date',
   `org-agenda-todo-ignore-scheduled'
   `org-agenda-todo-ignore-deadlines'
make the global TODO list skip entries that have time stamps of certain
kinds.  If this option is set, the same options will also apply for the
tags-todo search, which is the general tags/property matcher
restricted to unfinished TODO entries only."
  :group 'org-agenda-skip
  :group 'org-agenda-todo-list
  :group 'org-agenda-match-view
  :type 'boolean)

(defcustom org-agenda-skip-scheduled-if-done nil
  "Non-nil means don't show scheduled items in agenda when they are done.
This is relevant for the daily/weekly agenda, not for the TODO list.  And
it applies only to the actual date of the scheduling.  Warnings about
an item with a past scheduling dates are always turned off when the item
is DONE."
  :group 'org-agenda-skip
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-skip-scheduled-if-deadline-is-shown nil
  "Non-nil means skip scheduling line if same entry shows because of deadline.
In the agenda of today, an entry can show up multiple times because
it is both scheduled and has a nearby deadline, and maybe a plain time
stamp as well.
When this variable is t, then only the deadline is shown and the fact that
the entry is scheduled today or was scheduled previously is not shown.
When this variable is nil, the entry will be shown several times.  When
the variable is the symbol `not-today', then skip scheduled previously,
but not scheduled today."
  :group 'org-agenda-skip
  :group 'org-agenda-daily/weekly
  :type '(choice
      (const :tag "Never" nil)
      (const :tag "Always" t)
      (const :tag "Not when scheduled today" not-today)))

(defcustom org-agenda-skip-deadline-if-done nil
  "Non-nil means don't show deadlines when the corresponding item is done.
When nil, the deadline is still shown and should give you a happy feeling.
This is relevant for the daily/weekly agenda.  And it applied only to the
actually date of the deadline.  Warnings about approaching and past-due
deadlines are always turned off when the item is DONE."
  :group 'org-agenda-skip
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-skip-deadline-prewarning-if-scheduled nil
  "Non-nil means skip deadline prewarning when entry is also scheduled.
This will apply on all days where a prewarning for the deadline would
be shown, but not at the day when the entry is actually due.  On that day,
the deadline will be shown anyway.
This variable may be set to nil, t, or a number which will then give
the number of days before the actual deadline when the prewarnings
should resume.
This can be used in a workflow where the first showing of the deadline will
trigger you to schedule it, and then you don't want to be reminded of it
because you will take care of it on the day when scheduled."
  :group 'org-agenda-skip
  :group 'org-agenda-daily/weekly
  :type '(choice
      (const :tag "Alwas show prewarning" nil)
      (const :tag "Remove prewarning if entry is scheduled" t)
      (integer :tag "Restart prewarning N days before deadline")))

(defcustom org-agenda-skip-additional-timestamps-same-entry t
  "When nil, multiple same-day timestamps in entry make multiple agenda lines.
When non-nil, after the search for timestamps has matched once in an
entry, the rest of the entry will not be searched."
  :group 'org-agenda-skip
  :type 'boolean)

(defcustom org-agenda-skip-timestamp-if-done nil
  "Non-nil means don't select item by timestamp or -range if it is DONE."
  :group 'org-agenda-skip
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-dim-blocked-tasks t
  "Non-nil means dim blocked tasks in the agenda display.
This causes some overhead during agenda construction, but if you
have turned on `org-enforce-todo-dependencies',
`org-enforce-todo-checkbox-dependencies', or any other blocking
mechanism, this will create useful feedback in the agenda.

Instead of t, this variable can also have the value `invisible'.
Then blocked tasks will be invisible and only become visible when
they become unblocked.  An exemption to this behavior is when a task is
blocked because of unchecked checkboxes below it.  Since checkboxes do
not show up in the agenda views, making this task invisible you remove any
trace from agenda views that there is something to do.  Therefore, a task
that is blocked because of checkboxes will never be made invisible, it
will only be dimmed."
  :group 'org-agenda-daily/weekly
  :group 'org-agenda-todo-list
  :type '(choice
      (const :tag "Do not dim" nil)
      (const :tag "Dim to a grey face" t)
      (const :tag "Make invisible" invisible)))

(defcustom org-timeline-show-empty-dates 3
  "Non-nil means `org-timeline' also shows dates without an entry.
When nil, only the days which actually have entries are shown.
When t, all days between the first and the last date are shown.
When an integer, show also empty dates, but if there is a gap of more than
N days, just insert a special line indicating the size of the gap."
  :group 'org-agenda-skip
  :type '(choice
      (const :tag "None" nil)
      (const :tag "All" t)
      (integer :tag "at most")))

(defgroup org-agenda-startup nil
  "Options concerning initial settings in the Agenda in Org Mode."
  :tag "Org Agenda Startup"
  :group 'org-agenda)

(defcustom org-finalize-agenda-hook nil
  "Hook run just before displaying an agenda buffer."
  :group 'org-agenda-startup
  :type 'hook)

(defcustom org-agenda-mouse-1-follows-link nil
  "Non-nil means mouse-1 on a link will follow the link in the agenda.
A longer mouse click will still set point.  Does not work on XEmacs.
Needs to be set before org.el is loaded."
  :group 'org-agenda-startup
  :type 'boolean)

(defcustom org-agenda-start-with-follow-mode nil
  "The initial value of follow mode in a newly created agenda window."
  :group 'org-agenda-startup
  :type 'boolean)

(defcustom org-agenda-show-outline-path t
  "Non-nil means show outline path in echo area after line motion."
  :group 'org-agenda-startup
  :type 'boolean)

(defcustom org-agenda-start-with-entry-text-mode nil
  "The initial value of entry-text-mode in a newly created agenda window."
  :group 'org-agenda-startup
  :type 'boolean)

(defcustom org-agenda-entry-text-maxlines 5
  "Number of text lines to be added when `E' is pressed in the agenda.

Note that this variable only used during agenda display.  Add add entry text
when exporting the agenda, configure the variable
`org-agenda-add-entry-ext-maxlines'."
  :group 'org-agenda
  :type 'integer)

(defcustom org-agenda-entry-text-exclude-regexps nil
  "List of regular expressions to clean up entry text.
The complete matches of all regular expressions in this list will be
removed from entry text before it is shown in the agenda."
  :group 'org-agenda
  :type '(repeat (regexp)))

(defvar org-agenda-entry-text-cleanup-hook nil
  "Hook that is run after basic cleanup of entry text to be shown in agenda.
This cleanup is done in a temporary buffer, so the function may inspect and
change the entire buffer.
Some default stuff like drawers and scheduling/deadline dates will already
have been removed when this is called, as will any matches for regular
expressions listed in `org-agenda-entry-text-exclude-regexps'.")

(defvar org-agenda-include-inactive-timestamps nil
  "Non-nil means include inactive time stamps in agenda and timeline.")

(defgroup org-agenda-windows nil
  "Options concerning the windows used by the Agenda in Org Mode."
  :tag "Org Agenda Windows"
  :group 'org-agenda)

(defcustom org-agenda-window-setup 'reorganize-frame
  "How the agenda buffer should be displayed.
Possible values for this option are:

current-window    Show agenda in the current window, keeping all other windows.
other-window      Use `switch-to-buffer-other-window' to display agenda.
reorganize-frame  Show only two windows on the current frame, the current
                  window and the agenda.
other-frame       Use `switch-to-buffer-other-frame' to display agenda.
                  Also, when exiting the agenda, kill that frame.
See also the variable `org-agenda-restore-windows-after-quit'."
  :group 'org-agenda-windows
  :type '(choice
      (const current-window)
      (const other-frame)
      (const other-window)
      (const reorganize-frame)))

(defcustom org-agenda-window-frame-fractions '(0.5 . 0.75)
  "The min and max height of the agenda window as a fraction of frame height.
The value of the variable is a cons cell with two numbers between 0 and 1.
It only matters if `org-agenda-window-setup' is `reorganize-frame'."
  :group 'org-agenda-windows
  :type '(cons (number :tag "Minimum") (number :tag "Maximum")))

(defcustom org-agenda-restore-windows-after-quit nil
  "Non-nil means restore window configuration open exiting agenda.
Before the window configuration is changed for displaying the agenda,
the current status is recorded.  When the agenda is exited with
`q' or `x' and this option is set, the old state is restored.  If
`org-agenda-window-setup' is `other-frame', the value of this
option will be ignored."
  :group 'org-agenda-windows
  :type 'boolean)

(defcustom org-agenda-ndays 7
  "Number of days to include in overview display.
Should be 1 or 7.
Custom commands can set this variable in the options section."
  :group 'org-agenda-daily/weekly
  :type 'integer)

(defcustom org-agenda-start-on-weekday 1
  "Non-nil means start the overview always on the specified weekday.
0 denotes Sunday, 1 denotes Monday etc.
When nil, always start on the current day.
Custom commands can set this variable in the options section."
  :group 'org-agenda-daily/weekly
  :type '(choice (const :tag "Today" nil)
         (integer :tag "Weekday No.")))

(defcustom org-agenda-show-all-dates t
  "Non-nil means `org-agenda' shows every day in the selected range.
When nil, only the days which actually have entries are shown."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-format-date 'org-agenda-format-date-aligned
  "Format string for displaying dates in the agenda.
Used by the daily/weekly agenda and by the timeline.  This should be
a format string understood by `format-time-string', or a function returning
the formatted date as a string.  The function must take a single argument,
a calendar-style date list like (month day year)."
  :group 'org-agenda-daily/weekly
  :type '(choice
      (string :tag "Format string")
      (function :tag "Function")))

</t>
<t tx="ekr.20100929212226.14618">(defun org-agenda-format-date-aligned (date)
  "Format a date string for display in the daily/weekly agenda, or timeline.
This function makes sure that dates are aligned for easy reading."
  (require 'cal-iso)
  (let* ((dayname (calendar-day-name date))
     (day (cadr date))
     (day-of-week (calendar-day-of-week date))
     (month (car date))
     (monthname (calendar-month-name month))
     (year (nth 2 date))
     (iso-week (org-days-to-iso-week
            (calendar-absolute-from-gregorian date)))
     (weekyear (cond ((and (= month 1) (&gt;= iso-week 52))
              (1- year))
             ((and (= month 12) (&lt;= iso-week 1))
              (1+ year))
             (t year)))
     (weekstring (if (= day-of-week 1)
             (format " W%02d" iso-week)
               "")))
    (format "%-10s %2d %s %4d%s"
        dayname day monthname year weekstring)))
</t>
<t tx="ekr.20100929212226.14619">
(defcustom org-agenda-time-leading-zero nil
  "Non-nil means use leading zero for military times in agenda.
For example, 9:30am would become 09:30 rather than  9:30."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-weekend-days '(6 0)
  "Which days are weekend?
These days get the special face `org-agenda-date-weekend' in the agenda
and timeline buffers."
  :group 'org-agenda-daily/weekly
  :type '(set :greedy t
          (const :tag "Monday" 1)
          (const :tag "Tuesday" 2)
          (const :tag "Wednesday" 3)
          (const :tag "Thursday" 4)
          (const :tag "Friday" 5)
          (const :tag "Saturday" 6)
          (const :tag "Sunday" 0)))

(defcustom org-agenda-include-diary nil
  "If non-nil, include in the agenda entries from the Emacs Calendar's diary.
Custom commands can set this variable in the options section."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-include-deadlines t
  "If non-nil, include entries within their deadline warning period.
Custom commands can set this variable in the options section."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-include-all-todo nil
  "Set  means weekly/daily agenda will always contain all TODO entries.
The TODO entries will be listed at the top of the agenda, before
the entries for specific days.
This option is deprecated, it is better to define a block agenda instead."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-repeating-timestamp-show-all t
  "Non-nil means show all occurrences of a repeating stamp in the agenda.
When nil, only one occurrence is shown, either today or the
nearest into the future."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-scheduled-past-days 10000
  "No. of days to continue listing scheduled items that are not marked DONE.
When an item is scheduled on a date, it shows up in the agenda on this
day and will be listed until it is marked done for the number of days
given here."
  :group 'org-agenda-daily/weekly
  :type 'integer)

(defcustom org-agenda-log-mode-items '(closed clock)
  "List of items that should be shown in agenda log mode.
This list may contain the following symbols:

  closed    Show entries that have been closed on that day.
  clock     Show entries that have received clocked time on that day.
  state     Show all logged state changes.
Note that instead of changing this variable, you can also press `C-u l' in
the agenda to display all available LOG items temporarily."
  :group 'org-agenda-daily/weekly
  :type '(set :greedy t (const closed) (const clock) (const state)))

(defcustom org-agenda-log-mode-add-notes t
  "Non-nil means add first line of notes to log entries in agenda views.
If a log item like a state change or a clock entry is associated with
notes, the first line of these notes will be added to the entry in the
agenda display."
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-start-with-log-mode nil
  "The initial value of log-mode in a newly created agenda window."
  :group 'org-agenda-startup
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-start-with-clockreport-mode nil
  "The initial value of clockreport-mode in a newly created agenda window."
  :group 'org-agenda-startup
  :group 'org-agenda-daily/weekly
  :type 'boolean)

(defcustom org-agenda-clockreport-parameter-plist '(:link t :maxlevel 2)
  "Property list with parameters for the clocktable in clockreport mode.
This is the display mode that shows a clock table in the daily/weekly
agenda, the properties for this dynamic block can be set here.
The usual clocktable parameters are allowed here, but you cannot set
the properties :name, :tstart, :tend, :block, and :scope - these will
be overwritten to make sure the content accurately reflects the
current display in the agenda."
  :group 'org-agenda-daily/weekly
  :type 'plist)

(defcustom org-agenda-search-view-always-boolean nil
  "Non-nil means the search string is interpreted as individual parts.

The search string for search view can either be interpreted as a phrase,
or as a list of snippets that define a boolean search for a number of
strings.

When this is non-nil, the string will be split on whitespace, and each
snippet will be searched individually, and all must match in order to
select an entry.  A snippet is then a single string of non-white
characters, or a string in double quotes, or a regexp in {} braces.
If a snippet is preceded by \"-\", the snippet must *not* match.
\"+\" is syntactic sugar for positive selection.  Each snippet may
be found as a full word or a partial word, but see the variable
`org-agenda-search-view-force-full-words'.

When this is nil, search will look for the entire search phrase as one,
with each space character matching any amount of whitespace, including
line breaks.

Even when this is nil, you can still switch to Boolean search dynamically
by preceding the first snippet with \"+\" or \"-\".  If the first snippet
is a regexp marked with braces like \"{abc}\", this will also switch to
boolean search."
  :group 'org-agenda-search-view
  :type 'boolean)

(if (fboundp 'defvaralias)
    (defvaralias 'org-agenda-search-view-search-words-only
      'org-agenda-search-view-always-boolean))

(defcustom org-agenda-search-view-force-full-words nil
  "Non-nil means, search words must be matches as complete words.
When nil, they may also match part of a word."
  :group 'org-agenda-search-view
  :type 'boolean)

(defgroup org-agenda-time-grid nil
  "Options concerning the time grid in the Org-mode Agenda."
  :tag "Org Agenda Time Grid"
  :group 'org-agenda)

(defcustom org-agenda-search-headline-for-time t
  "Non-nil means search headline for a time-of-day.
If the headline contains a time-of-day in one format or another, it will
be used to sort the entry into the time sequence of items for a day.
Some people have time stamps in the headline that refer to the creation
time or so, and then this produces an unwanted side effect.  If this is
the case for your, use this variable to turn off searching the headline
for a time."
  :group 'org-agenda-time-grid
  :type 'boolean)

(defcustom org-agenda-use-time-grid t
  "Non-nil means show a time grid in the agenda schedule.
A time grid is a set of lines for specific times (like every two hours between
8:00 and 20:00).  The items scheduled for a day at specific times are
sorted in between these lines.
For details about when the grid will be shown, and what it will look like, see
the variable `org-agenda-time-grid'."
  :group 'org-agenda-time-grid
  :type 'boolean)

(defcustom org-agenda-time-grid
  '((daily today require-timed)
    "----------------"
    (800 1000 1200 1400 1600 1800 2000))

  "The settings for time grid for agenda display.
This is a list of three items.  The first item is again a list.  It contains
symbols specifying conditions when the grid should be displayed:

 daily         if the agenda shows a single day
 weekly        if the agenda shows an entire week
 today         show grid on current date, independent of daily/weekly display
 require-timed show grid only if at least one item has a time specification

The second item is a string which will be placed behind the grid time.

The third item is a list of integers, indicating the times that should have
a grid line."
  :group 'org-agenda-time-grid
  :type
  '(list
    (set :greedy t :tag "Grid Display Options"
     (const :tag "Show grid in single day agenda display" daily)
     (const :tag "Show grid in weekly agenda display" weekly)
     (const :tag "Always show grid for today" today)
     (const :tag "Show grid only if any timed entries are present"
        require-timed)
     (const :tag "Skip grid times already present in an entry"
        remove-match))
    (string :tag "Grid String")
    (repeat :tag "Grid Times" (integer :tag "Time"))))

(defgroup org-agenda-sorting nil
  "Options concerning sorting in the Org-mode Agenda."
  :tag "Org Agenda Sorting"
  :group 'org-agenda)

(defcustom org-agenda-sorting-strategy
  '((agenda habit-down time-up priority-down category-keep)
    (todo   priority-down category-keep)
    (tags   priority-down category-keep)
    (search category-keep))
  "Sorting structure for the agenda items of a single day.
This is a list of symbols which will be used in sequence to determine
if an entry should be listed before another entry.  The following
symbols are recognized:

time-up            Put entries with time-of-day indications first, early first
time-down          Put entries with time-of-day indications first, late first
category-keep      Keep the default order of categories, corresponding to the
           sequence in `org-agenda-files'.
category-up        Sort alphabetically by category, A-Z.
category-down      Sort alphabetically by category, Z-A.
tag-up             Sort alphabetically by last tag, A-Z.
tag-down           Sort alphabetically by last tag, Z-A.
priority-up        Sort numerically by priority, high priority last.
priority-down      Sort numerically by priority, high priority first.
todo-state-up      Sort by todo state, tasks that are done last.
todo-state-down    Sort by todo state, tasks that are done first.
effort-up          Sort numerically by estimated effort, high effort last.
effort-down        Sort numerically by estimated effort, high effort first.
user-defined-up    Sort according to `org-agenda-cmp-user-defined', high last.
user-defined-down  Sort according to `org-agenda-cmp-user-defined', high first.
habit-up           Put entries that are habits first
habit-down         Put entries that are habits last
alpha-up           Sort headlines alphabetically
alpha-down         Sort headlines alphabetically, reversed

The different possibilities will be tried in sequence, and testing stops
if one comparison returns a \"not-equal\".  For example, the default
    '(time-up category-keep priority-down)
means: Pull out all entries having a specified time of day and sort them,
in order to make a time schedule for the current day the first thing in the
agenda listing for the day.  Of the entries without a time indication, keep
the grouped in categories, don't sort the categories, but keep them in
the sequence given in `org-agenda-files'.  Within each category sort by
priority.

Leaving out `category-keep' would mean that items will be sorted across
categories by priority.

Instead of a single list, this can also be a set of list for specific
contents, with a context symbol in the car of the list, any of
`agenda', `todo', `tags', `search' for the corresponding agenda views.

Custom commands can bind this variable in the options section."
  :group 'org-agenda-sorting
  :type `(choice
      (repeat :tag "General" ,org-sorting-choice)
      (list :tag "Individually"
        (cons (const :tag "Strategy for Weekly/Daily agenda" agenda)
              (repeat ,org-sorting-choice))
        (cons (const :tag "Strategy for TODO lists" todo)
              (repeat ,org-sorting-choice))
        (cons (const :tag "Strategy for Tags matches" tags)
              (repeat ,org-sorting-choice))
        (cons (const :tag "Strategy for search matches" search)
              (repeat ,org-sorting-choice)))))

(defcustom org-agenda-cmp-user-defined nil
  "A function to define the comparison `user-defined'.
This function must receive two arguments, agenda entry a and b.
If a&gt;b, return +1.  If a&lt;b, return -1.  If they are equal as seen by
the user comparison, return nil.
When this is defined, you can make `user-defined-up' and `user-defined-down'
part of an agenda sorting strategy."
  :group 'org-agenda-sorting
  :type 'symbol)

(defcustom org-sort-agenda-notime-is-late t
  "Non-nil means items without time are considered late.
This is only relevant for sorting.  When t, items which have no explicit
time like 15:30 will be considered as 99:01, i.e. later than any items which
do have a time.  When nil, the default time is before 0:00.  You can use this
option to decide if the schedule for today should come before or after timeless
agenda entries."
  :group 'org-agenda-sorting
  :type 'boolean)

(defcustom org-sort-agenda-noeffort-is-high t
  "Non-nil means items without effort estimate are sorted as high effort.
This also applies when filtering an agenda view with respect to the
&lt; or &gt; effort operator.  Then, tasks with no effort defined will be treated
as tasks with high effort.
When nil, such items are sorted as 0 minutes effort."
  :group 'org-agenda-sorting
  :type 'boolean)

(defgroup org-agenda-line-format nil
  "Options concerning the entry prefix in the Org-mode agenda display."
  :tag "Org Agenda Line Format"
  :group 'org-agenda)

(defcustom org-agenda-prefix-format
  '((agenda  . "  %-12:c%?-12t% s")
    (timeline  . "  % s")
    (todo  . "  %-12:c")
    (tags  . "  %-12:c")
    (search . "  %-12:c"))
  "Format specifications for the prefix of items in the agenda views.
An alist with four entries, for the different agenda types.  The keys to the
sublists are `agenda', `timeline', `todo', and `tags'.  The values
are format strings.
This format works similar to a printf format, with the following meaning:

  %c   the category of the item, \"Diary\" for entries from the diary, or
       as given by the CATEGORY keyword or derived from the file name.
  %T   the *last* tag of the item.  Last because inherited tags come
       first in the list.
  %t   the time-of-day specification if one applies to the entry, in the
       format HH:MM
  %s   Scheduling/Deadline information, a short string

All specifiers work basically like the standard `%s' of printf, but may
contain two additional characters:  A question mark just after the `%' and
a whitespace/punctuation character just before the final letter.

If the first character after `%' is a question mark, the entire field
will only be included if the corresponding value applies to the
current entry.  This is useful for fields which should have fixed
width when present, but zero width when absent.  For example,
\"%?-12t\" will result in a 12 character time field if a time of the
day is specified, but will completely disappear in entries which do
not contain a time.

If there is punctuation or whitespace character just before the final
format letter, this character will be appended to the field value if
the value is not empty.  For example, the format \"%-12:c\" leads to
\"Diary: \" if the category is \"Diary\".  If the category were be
empty, no additional colon would be inserted.

The default value of this option is \"  %-12:c%?-12t% s\", meaning:
- Indent the line with two space characters
- Give the category in a 12 chars wide field, padded with whitespace on
  the right (because of `-').  Append a colon if there is a category
  (because of `:').
- If there is a time-of-day, put it into a 12 chars wide field.  If no
  time, don't put in an empty field, just skip it (because of '?').
- Finally, put the scheduling information and append a whitespace.

As another example, if you don't want the time-of-day of entries in
the prefix, you could use:

  (setq org-agenda-prefix-format \"  %-11:c% s\")

See also the variables `org-agenda-remove-times-when-in-prefix' and
`org-agenda-remove-tags'.

Custom commands can set this variable in the options section."
  :type '(choice
      (string :tag "General format")
      (list :greedy t :tag "View dependent"
        (cons  (const agenda) (string :tag "Format"))
        (cons  (const timeline) (string :tag "Format"))
        (cons  (const todo) (string :tag "Format"))
        (cons  (const tags) (string :tag "Format"))
        (cons  (const search) (string :tag "Format"))))
  :group 'org-agenda-line-format)

(defvar org-prefix-format-compiled nil
  "The compiled version of the most recently used prefix format.
See the variable `org-agenda-prefix-format'.")

(defcustom org-agenda-todo-keyword-format "%-1s"
  "Format for the TODO keyword in agenda lines.
Set this to something like \"%-12s\" if you want all TODO keywords
to occupy a fixed space in the agenda display."
  :group 'org-agenda-line-format
  :type 'string)

(defcustom org-agenda-timerange-leaders '("" "(%d/%d): ")
  "Text preceding timerange entries in the agenda view.
This is a list with two strings.  The first applies when the range
is entirely on one day.  The second applies if the range spans several days.
The strings may have two \"%d\" format specifiers which will be filled
with the sequence number of the days, and the total number of days in the
range, respectively."
  :group 'org-agenda-line-format
  :type '(list
      (string :tag "Deadline today   ")
      (choice :tag "Deadline relative"
          (string :tag "Format string")
          (function))))

(defcustom org-agenda-scheduled-leaders '("Scheduled: " "Sched.%2dx: ")
  "Text preceding scheduled items in the agenda view.
This is a list with two strings.  The first applies when the item is
scheduled on the current day.  The second applies when it has been scheduled
previously, it may contain a %d indicating that this is the nth time that
this item is scheduled, due to automatic rescheduling of unfinished items
for the following day.  So this number is one larger than the number of days
that passed since this item was scheduled first."
  :group 'org-agenda-line-format
  :type '(list
      (string :tag "Scheduled today     ")
      (string :tag "Scheduled previously")))

(defcustom org-agenda-inactive-leader "["
  "Text preceding item pulled into the agenda by inactive time stamps.
These entries are added to the agenda when pressing \"[\"."
  :group 'org-agenda-line-format
  :type '(list
      (string :tag "Scheduled today     ")
      (string :tag "Scheduled previously")))

(defcustom org-agenda-deadline-leaders '("Deadline:  " "In %3d d.: ")
  "Text preceding deadline items in the agenda view.
This is a list with two strings.  The first applies when the item has its
deadline on the current day.  The second applies when it is in the past or
in the future, it may contain %d to capture how many days away the deadline
is (was)."
  :group 'org-agenda-line-format
  :type '(list
      (string :tag "Deadline today   ")
      (choice :tag "Deadline relative"
          (string :tag "Format string")
          (function))))

(defcustom org-agenda-remove-times-when-in-prefix t
  "Non-nil means remove duplicate time specifications in agenda items.
When the format `org-agenda-prefix-format' contains a `%t' specifier, a
time-of-day specification in a headline or diary entry is extracted and
placed into the prefix.  If this option is non-nil, the original specification
\(a timestamp or -range, or just a plain time(range) specification like
11:30-4pm) will be removed for agenda display.  This makes the agenda less
cluttered.
The option can be t or nil.  It may also be the symbol `beg', indicating
that the time should only be removed when it is located at the beginning of
the headline/diary entry."
  :group 'org-agenda-line-format
  :type '(choice
      (const :tag "Always" t)
      (const :tag "Never" nil)
      (const :tag "When at beginning of entry" beg)))

(defcustom org-agenda-remove-timeranges-from-blocks nil
  "Non-nil means remove time ranges specifications in agenda
items that span on several days."
  :group 'org-agenda-line-format
  :type 'boolean)

(defcustom org-agenda-default-appointment-duration nil
  "Default duration for appointments that only have a starting time.
When nil, no duration is specified in such cases.
When non-nil, this must be the number of minutes, e.g. 60 for one hour."
  :group 'org-agenda-line-format
  :type '(choice
      (integer :tag "Minutes")
      (const :tag "No default duration")))

(defcustom org-agenda-show-inherited-tags t
  "Non-nil means show inherited tags in each agenda line."
  :group 'org-agenda-line-format
  :type 'boolean)

(defcustom org-agenda-hide-tags-regexp nil
  "Regular expression used to filter away specific tags in agenda views.
This means that these tags will be present, but not be shown in the agenda
line.  Secondary filtering will still work on the hidden tags.
Nil means don't hide any tags."
  :group 'org-agenda-line-format
  :type '(choice
      (const  :tag "Hide none" nil)
      (string :tag "Regexp   ")))

(defcustom org-agenda-remove-tags nil
  "Non-nil means remove the tags from the headline copy in the agenda.
When this is the symbol `prefix', only remove tags when
`org-agenda-prefix-format' contains a `%T' specifier."
  :group 'org-agenda-line-format
  :type '(choice
      (const :tag "Always" t)
      (const :tag "Never" nil)
      (const :tag "When prefix format contains %T" prefix)))

(if (fboundp 'defvaralias)
    (defvaralias 'org-agenda-remove-tags-when-in-prefix
      'org-agenda-remove-tags))

(defcustom org-agenda-tags-column (if (featurep 'xemacs) -79 -80)
  "Shift tags in agenda items to this column.
If this number is positive, it specifies the column.  If it is negative,
it means that the tags should be flushright to that column.  For example,
-80 works well for a normal 80 character screen."
  :group 'org-agenda-line-format
  :type 'integer)

(if (fboundp 'defvaralias)
    (defvaralias 'org-agenda-align-tags-to-column 'org-agenda-tags-column))

(defcustom org-agenda-fontify-priorities 'cookies
  "Non-nil means highlight low and high priorities in agenda.
When t, the highest priority entries are bold, lowest priority italic.
However, settings in `org-priority-faces' will overrule these faces.
When this variable is the symbol `cookies', only fontify the
cookies, not the entire task.
This may also be an association list of priority faces, whose
keys are the character values of `org-highest-priority',
`org-default-priority', and `org-lowest-priority' (the default values
are ?A, ?B, and ?C, respectively).  The face may be a named face, a
color as a string, or a list like `(:background \"Red\")'.
If it is a color, the variable `org-faces-easy-properties'
determines if it is a foreground or a background color."
  :group 'org-agenda-line-format
  :type '(choice
      (const :tag "Never" nil)
      (const :tag "Defaults" t)
      (const :tag "Cookies only" cookies)
      (repeat :tag "Specify"
          (list (character :tag "Priority" :value ?A)
            (choice    :tag "Face    "
                   (string :tag "Color")
                   (sexp :tag "Face"))))))

(defgroup org-agenda-column-view nil
  "Options concerning column view in the agenda."
  :tag "Org Agenda Column View"
  :group 'org-agenda)

(defcustom org-agenda-columns-show-summaries t
  "Non-nil means show summaries for columns displayed in the agenda view."
  :group 'org-agenda-column-view
  :type 'boolean)

(defcustom org-agenda-columns-remove-prefix-from-item t
  "Non-nil means remove the prefix from a headline for agenda column view.
The special ITEM field in the columns format contains the current line, with
all information shown in other columns (like the TODO state or a tag).
When this variable is non-nil, also the agenda prefix will be removed from
the content of the ITEM field, to make sure as much as possible of the
headline can be shown in the limited width of the field."
  :group 'org-agenda
  :type 'boolean)

(defcustom org-agenda-columns-compute-summary-properties t
  "Non-nil means recompute all summary properties before column view.
When column view in the agenda is listing properties that have a summary
operator, it can go to all relevant buffers and recompute the summaries
there.  This can mean overhead for the agenda column view, but is necessary
to have thing up to date.
As a special case, a CLOCKSUM property also makes sure that the clock
computations are current."
  :group 'org-agenda-column-view
  :type 'boolean)

(defcustom org-agenda-columns-add-appointments-to-effort-sum nil
  "Non-nil means the duration of an appointment will add to day effort.
The property to which appointment durations will be added is the one given
in the option `org-effort-property'.  If an appointment does not have
an end time, `org-agenda-default-appointment-duration' will be used.  If that
is not set, an appointment without end time will not contribute to the time
estimate."
  :group 'org-agenda-column-view
  :type 'boolean)

(defcustom org-agenda-auto-exclude-function nil
  "A function called with a tag to decide if it is filtered on '/ RET'.
The sole argument to the function, which is called once for each
possible tag, is a string giving the name of the tag.  The
function should return either nil if the tag should be included
as normal, or \"-&lt;TAG&gt;\" to exclude the tag.
Note that for the purpose of tag filtering, only the lower-case version of
all tags will be considered, so that this function will only ever see
the lower-case version of all tags."
  :group 'org-agenda
  :type 'function)

(eval-when-compile
  (require 'cl))
(require 'org)

(defun org-add-agenda-custom-command (entry)
  "Replace or add a command in `org-agenda-custom-commands'.
This is mostly for hacking and trying a new command - once the command
works you probably want to add it to `org-agenda-custom-commands' for good."
  (let ((ass (assoc (car entry) org-agenda-custom-commands)))
    (if ass
    (setcdr ass (cdr entry))
      (push entry org-agenda-custom-commands))))
</t>
<t tx="ekr.20100929212226.14620">
;;; Define the Org-agenda-mode

(defvar org-agenda-mode-map (make-sparse-keymap)
  "Keymap for `org-agenda-mode'.")
(if (fboundp 'defvaralias)
    (defvaralias 'org-agenda-keymap 'org-agenda-mode-map))

(defvar org-agenda-menu) ; defined later in this file.
(defvar org-agenda-restrict) ; defined later in this file.
(defvar org-agenda-follow-mode nil)
(defvar org-agenda-entry-text-mode nil)
(defvar org-agenda-clockreport-mode nil)
(defvar org-agenda-show-log nil)
(defvar org-agenda-redo-command nil)
(defvar org-agenda-query-string nil)
(defvar org-agenda-mode-hook nil
  "Hook for `org-agenda-mode', run after the mode is turned on.")
(defvar org-agenda-type nil)
(defvar org-agenda-force-single-file nil)
(defvar org-agenda-bulk-marked-entries) ;; Defined further down in this file

(defun org-agenda-mode ()
  "Mode for time-sorted view on action items in Org-mode files.

The following commands are available:

\\{org-agenda-mode-map}"
  (interactive)
  (kill-all-local-variables)
  (setq org-agenda-undo-list nil
    org-agenda-pending-undo-list nil
    org-agenda-bulk-marked-entries nil)
  (setq major-mode 'org-agenda-mode)
  ;; Keep global-font-lock-mode from turning on font-lock-mode
  (org-set-local 'font-lock-global-modes (list 'not major-mode))
  (setq mode-name "Org-Agenda")
  (use-local-map org-agenda-mode-map)
  (easy-menu-add org-agenda-menu)
  (if org-startup-truncated (setq truncate-lines t))
  (org-set-local 'line-move-visual nil)
  (org-add-hook 'post-command-hook 'org-agenda-post-command-hook nil 'local)
  (org-add-hook 'pre-command-hook 'org-unhighlight nil 'local)
  ;; Make sure properties are removed when copying text
  (when (boundp 'buffer-substring-filters)
    (org-set-local 'buffer-substring-filters
           (cons (lambda (x)
                           (set-text-properties 0 (length x) nil x) x)
             buffer-substring-filters)))
  (unless org-agenda-keep-modes
    (setq org-agenda-follow-mode org-agenda-start-with-follow-mode
      org-agenda-entry-text-mode org-agenda-start-with-entry-text-mode
      org-agenda-clockreport-mode org-agenda-start-with-clockreport-mode
      org-agenda-show-log org-agenda-start-with-log-mode))

  (easy-menu-change
   '("Agenda") "Agenda Files"
   (append
    (list
     (vector
      (if (get 'org-agenda-files 'org-restrict)
      "Restricted to single file"
    "Edit File List")
      '(org-edit-agenda-file-list)
      (not (get 'org-agenda-files 'org-restrict)))
     "--")
    (mapcar 'org-file-menu-entry (org-agenda-files))))
  (org-agenda-set-mode-name)
  (apply
   (if (fboundp 'run-mode-hooks) 'run-mode-hooks 'run-hooks)
   (list 'org-agenda-mode-hook)))
</t>
<t tx="ekr.20100929212226.14621">
(substitute-key-definition 'undo 'org-agenda-undo
               org-agenda-mode-map global-map)
(org-defkey org-agenda-mode-map "\C-i"     'org-agenda-goto)
(org-defkey org-agenda-mode-map [(tab)]    'org-agenda-goto)
(org-defkey org-agenda-mode-map "\C-m"     'org-agenda-switch-to)
(org-defkey org-agenda-mode-map "\C-k"     'org-agenda-kill)
(org-defkey org-agenda-mode-map "\C-c\C-w" 'org-agenda-refile)
(org-defkey org-agenda-mode-map "m"        'org-agenda-bulk-mark)
(org-defkey org-agenda-mode-map "u"        'org-agenda-bulk-unmark)
(org-defkey org-agenda-mode-map "U"        'org-agenda-bulk-remove-all-marks)
(org-defkey org-agenda-mode-map "B"        'org-agenda-bulk-action)
(org-defkey org-agenda-mode-map "\C-c\C-x!" 'org-reload)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-a" 'org-agenda-archive-default)
(org-defkey org-agenda-mode-map "\C-c\C-xa"    'org-agenda-toggle-archive-tag)
(org-defkey org-agenda-mode-map "\C-c\C-xA"    'org-agenda-archive-to-archive-sibling)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-s" 'org-agenda-archive)
(org-defkey org-agenda-mode-map "\C-c$"        'org-agenda-archive)
(org-defkey org-agenda-mode-map "$"        'org-agenda-archive)
(org-defkey org-agenda-mode-map "\C-c\C-o" 'org-agenda-open-link)
(org-defkey org-agenda-mode-map " "        'org-agenda-show-and-scroll-up)
(org-defkey org-agenda-mode-map [backspace] 'org-agenda-show-scroll-down)
(org-defkey org-agenda-mode-map "\d" 'org-agenda-show-scroll-down)
(org-defkey org-agenda-mode-map [(control shift right)] 'org-agenda-todo-nextset)
(org-defkey org-agenda-mode-map [(control shift left)]  'org-agenda-todo-previousset)
(org-defkey org-agenda-mode-map "\C-c\C-xb" 'org-agenda-tree-to-indirect-buffer)
(org-defkey org-agenda-mode-map "o"        'delete-other-windows)
(org-defkey org-agenda-mode-map "L"        'org-agenda-recenter)
(org-defkey org-agenda-mode-map "\C-c\C-t" 'org-agenda-todo)
(org-defkey org-agenda-mode-map "t"        'org-agenda-todo)
(org-defkey org-agenda-mode-map "a"        'org-agenda-archive-default-with-confirmation)
(org-defkey org-agenda-mode-map ":"        'org-agenda-set-tags)
(org-defkey org-agenda-mode-map "\C-c\C-q" 'org-agenda-set-tags)
(org-defkey org-agenda-mode-map "."        'org-agenda-goto-today)
(org-defkey org-agenda-mode-map "j"        'org-agenda-goto-date)
(org-defkey org-agenda-mode-map "d"        'org-agenda-day-view)
(org-defkey org-agenda-mode-map "w"        'org-agenda-week-view)
(org-defkey org-agenda-mode-map "y"        'org-agenda-year-view)
(org-defkey org-agenda-mode-map "\C-c\C-z" 'org-agenda-add-note)
(org-defkey org-agenda-mode-map "z"        'org-agenda-add-note)
(org-defkey org-agenda-mode-map "k"        'org-agenda-action)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-k" 'org-agenda-action)
(org-defkey org-agenda-mode-map [(shift right)] 'org-agenda-do-date-later)
(org-defkey org-agenda-mode-map [(shift left)] 'org-agenda-do-date-earlier)
(org-defkey org-agenda-mode-map [?\C-c ?\C-x (right)] 'org-agenda-do-date-later)
(org-defkey org-agenda-mode-map [?\C-c ?\C-x (left)] 'org-agenda-do-date-earlier)

(org-defkey org-agenda-mode-map "&gt;" 'org-agenda-date-prompt)
(org-defkey org-agenda-mode-map "\C-c\C-s" 'org-agenda-schedule)
(org-defkey org-agenda-mode-map "\C-c\C-d" 'org-agenda-deadline)
(let ((l '(1 2 3 4 5 6 7 8 9 0)))
  (while l (org-defkey org-agenda-mode-map
         (int-to-string (pop l)) 'digit-argument)))

(org-defkey org-agenda-mode-map "F" 'org-agenda-follow-mode)
(org-defkey org-agenda-mode-map "R" 'org-agenda-clockreport-mode)
(org-defkey org-agenda-mode-map "E" 'org-agenda-entry-text-mode)
(org-defkey org-agenda-mode-map "l" 'org-agenda-log-mode)
(org-defkey org-agenda-mode-map "v" 'org-agenda-view-mode-dispatch)
(org-defkey org-agenda-mode-map "D" 'org-agenda-toggle-diary)
(org-defkey org-agenda-mode-map "!" 'org-agenda-toggle-deadlines)
(org-defkey org-agenda-mode-map "G" 'org-agenda-toggle-time-grid)
(org-defkey org-agenda-mode-map "r" 'org-agenda-redo)
(org-defkey org-agenda-mode-map "g" 'org-agenda-redo)
(org-defkey org-agenda-mode-map "e" 'org-agenda-set-effort)
(org-defkey org-agenda-mode-map "\C-c\C-xe" 'org-agenda-set-effort)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-e"
        'org-clock-modify-effort-estimate)
(org-defkey org-agenda-mode-map "\C-c\C-xp" 'org-agenda-set-property)
(org-defkey org-agenda-mode-map "q" 'org-agenda-quit)
(org-defkey org-agenda-mode-map "x" 'org-agenda-exit)
(org-defkey org-agenda-mode-map "\C-x\C-w" 'org-write-agenda)
(org-defkey org-agenda-mode-map "\C-x\C-s" 'org-save-all-org-buffers)
(org-defkey org-agenda-mode-map "s" 'org-save-all-org-buffers)
(org-defkey org-agenda-mode-map "P" 'org-agenda-show-priority)
(org-defkey org-agenda-mode-map "T" 'org-agenda-show-tags)
(org-defkey org-agenda-mode-map "n" 'org-agenda-next-line)
(org-defkey org-agenda-mode-map "p" 'org-agenda-previous-line)
(substitute-key-definition 'next-line 'org-agenda-next-line
               org-agenda-mode-map global-map)
(substitute-key-definition 'previous-line 'org-agenda-previous-line
               org-agenda-mode-map global-map)
(org-defkey org-agenda-mode-map "\C-c\C-a" 'org-attach)
(org-defkey org-agenda-mode-map "\C-c\C-n" 'org-agenda-next-date-line)
(org-defkey org-agenda-mode-map "\C-c\C-p" 'org-agenda-previous-date-line)
(org-defkey org-agenda-mode-map "," 'org-agenda-priority)
(org-defkey org-agenda-mode-map "\C-c," 'org-agenda-priority)
(org-defkey org-agenda-mode-map "i" 'org-agenda-diary-entry)
(org-defkey org-agenda-mode-map "c" 'org-agenda-goto-calendar)
(org-defkey org-agenda-mode-map "C" 'org-agenda-convert-date)
(org-defkey org-agenda-mode-map "M" 'org-agenda-phases-of-moon)
(org-defkey org-agenda-mode-map "S" 'org-agenda-sunrise-sunset)
(org-defkey org-agenda-mode-map "h" 'org-agenda-holidays)
(org-defkey org-agenda-mode-map "H" 'org-agenda-holidays)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-i" 'org-agenda-clock-in)
(org-defkey org-agenda-mode-map "I" 'org-agenda-clock-in)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-o" 'org-agenda-clock-out)
(org-defkey org-agenda-mode-map "O" 'org-agenda-clock-out)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-x" 'org-agenda-clock-cancel)
(org-defkey org-agenda-mode-map "X" 'org-agenda-clock-cancel)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-j" 'org-clock-goto)
(org-defkey org-agenda-mode-map "J" 'org-clock-goto)
(org-defkey org-agenda-mode-map "+" 'org-agenda-priority-up)
(org-defkey org-agenda-mode-map "-" 'org-agenda-priority-down)
(org-defkey org-agenda-mode-map [(shift up)] 'org-agenda-priority-up)
(org-defkey org-agenda-mode-map [(shift down)] 'org-agenda-priority-down)
(org-defkey org-agenda-mode-map [?\C-c ?\C-x (up)] 'org-agenda-priority-up)
(org-defkey org-agenda-mode-map [?\C-c ?\C-x (down)] 'org-agenda-priority-down)
(org-defkey org-agenda-mode-map "f" 'org-agenda-later)
(org-defkey org-agenda-mode-map "b" 'org-agenda-earlier)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-c" 'org-agenda-columns)
(org-defkey org-agenda-mode-map "\C-c\C-x&gt;" 'org-agenda-remove-restriction-lock)

(org-defkey org-agenda-mode-map "[" 'org-agenda-manipulate-query-add)
(org-defkey org-agenda-mode-map "]" 'org-agenda-manipulate-query-subtract)
(org-defkey org-agenda-mode-map "{" 'org-agenda-manipulate-query-add-re)
(org-defkey org-agenda-mode-map "}" 'org-agenda-manipulate-query-subtract-re)
(org-defkey org-agenda-mode-map "/" 'org-agenda-filter-by-tag)
(org-defkey org-agenda-mode-map "\\" 'org-agenda-filter-by-tag-refine)
(org-defkey org-agenda-mode-map ";" 'org-timer-set-timer)
(define-key org-agenda-mode-map "?" 'org-agenda-show-the-flagging-note)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-mg"    'org-mobile-pull)
(org-defkey org-agenda-mode-map "\C-c\C-x\C-mp"    'org-mobile-push)

(org-defkey org-agenda-mode-map [mouse-2] 'org-agenda-goto-mouse)
(org-defkey org-agenda-mode-map [mouse-3] 'org-agenda-show-mouse)
(when org-agenda-mouse-1-follows-link
  (org-defkey org-agenda-mode-map [follow-link] 'mouse-face))
(easy-menu-define org-agenda-menu org-agenda-mode-map "Agenda menu"
  '("Agenda"
    ("Agenda Files")
    "--"
    ("Agenda Dates"
     ["Goto Today" org-agenda-goto-today (org-agenda-check-type nil 'agenda 'timeline)]
     ["Next Dates" org-agenda-later (org-agenda-check-type nil 'agenda)]
     ["Previous Dates" org-agenda-earlier (org-agenda-check-type nil 'agenda)]
     ["Jump to date" org-agenda-goto-date (org-agenda-check-type nil 'agenda)])
    "--"
    ("View"
     ["Day View" org-agenda-day-view
      :active (org-agenda-check-type nil 'agenda)
      :style radio :selected (equal org-agenda-ndays 1)
      :keys "v d  (or just d)"]
     ["Week View" org-agenda-week-view
      :active (org-agenda-check-type nil 'agenda)
      :style radio :selected (equal org-agenda-ndays 7)
      :keys "v w  (or just w)"]
     ["Month View" org-agenda-month-view
      :active (org-agenda-check-type nil 'agenda)
      :style radio :selected (member org-agenda-ndays '(28 29 30 31))
      :keys "v m"]
     ["Year View" org-agenda-year-view
      :active (org-agenda-check-type nil 'agenda)
      :style radio :selected (member org-agenda-ndays '(365 366))
      :keys "v y"]
     "--"
     ["Include Diary" org-agenda-toggle-diary
      :style toggle :selected org-agenda-include-diary
      :active (org-agenda-check-type nil 'agenda)]
     ["Include Deadlines" org-agenda-toggle-deadlines
      :style toggle :selected org-agenda-include-deadlines
      :active (org-agenda-check-type nil 'agenda)]
     ["Use Time Grid" org-agenda-toggle-time-grid
      :style toggle :selected org-agenda-use-time-grid
      :active (org-agenda-check-type nil 'agenda)]
     "--"
     ["Show clock report" org-agenda-clockreport-mode
      :style toggle :selected org-agenda-clockreport-mode
      :active (org-agenda-check-type nil 'agenda)]
     ["Show some entry text" org-agenda-entry-text-mode
      :style toggle :selected org-agenda-entry-text-mode
      :active t]
    "--"
     ["Show Logbook entries" org-agenda-log-mode
      :style toggle :selected org-agenda-show-log
      :active (org-agenda-check-type nil 'agenda 'timeline)
      :keys "v l (or just l)"]
     ["Include archived trees" org-agenda-archives-mode
      :style toggle :selected org-agenda-archives-mode :active t
      :keys "v a"]
     ["Include archive files" (org-agenda-archives-mode t)
      :style toggle :selected (eq org-agenda-archives-mode t) :active t
      :keys "v A"]
     "--"
     ["Remove Restriction" org-agenda-remove-restriction-lock org-agenda-restrict])
    ["Write view to file" org-write-agenda t]
    ["Rebuild buffer" org-agenda-redo t]
    ["Save all Org-mode Buffers" org-save-all-org-buffers t]
    "--"
    ["Show original entry" org-agenda-show t]
    ["Go To (other window)" org-agenda-goto t]
    ["Go To (this window)" org-agenda-switch-to t]
    ["Follow Mode" org-agenda-follow-mode
     :style toggle :selected org-agenda-follow-mode :active t]
;    ["Tree to indirect frame" org-agenda-tree-to-indirect-buffer t]
    "--"
    ("TODO"
     ["Cycle TODO" org-agenda-todo t]
     ["Next TODO set" org-agenda-todo-nextset t]
     ["Previous TODO set" org-agenda-todo-previousset t]
     ["Add note" org-agenda-add-note t])
    ("Archive/Refile/Delete"
     ["Archive default" org-agenda-archive-default t]
     ["Archive default" org-agenda-archive-default-with-confirmation t]
     ["Toggle ARCHIVE tag" org-agenda-toggle-archive-tag t]
     ["Move to archive sibling" org-agenda-archive-to-archive-sibling t]
     ["Archive subtree" org-agenda-archive t]
     "--"
     ["Refile" org-agenda-refile t]
     "--"
     ["Delete subtree" org-agenda-kill t])
    ("Bulk action"
     ["Mark entry" org-agenda-bulk-mark t]
     ["Unmark entry" org-agenda-bulk-unmark t]
     ["Act on all marked" org-agenda-bulk-action t]
     ["Unmark all entries" org-agenda-bulk-remove-all-marks :active t :keys "C-u s"])
    "--"
    ("Tags and Properties"
     ["Show all Tags" org-agenda-show-tags t]
     ["Set Tags current line" org-agenda-set-tags (not (org-region-active-p))]
     ["Change tag in region" org-agenda-set-tags (org-region-active-p)]
     "--"
     ["Column View" org-columns t])
    ("Deadline/Schedule"
     ["Schedule" org-agenda-schedule t]
     ["Set Deadline" org-agenda-deadline t]
     "--"
     ["Mark item" org-agenda-action :active t :keys "k m"]
     ["Show mark item" org-agenda-action :active t :keys "k v"]
     ["Schedule marked item" org-agenda-action :active t :keys "k s"]
     ["Set Deadline for marked item" org-agenda-action :active t :keys "k d"]
     "--"
     ["Change Date +1 day" org-agenda-date-later (org-agenda-check-type nil 'agenda 'timeline)]
     ["Change Date -1 day" org-agenda-date-earlier (org-agenda-check-type nil 'agenda 'timeline)]
     ["Change Time +1 hour" org-agenda-do-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-right"]
     ["Change Time -1 hour" org-agenda-do-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u S-left"]
     ["Change Time +  min" org-agenda-date-later :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-right"]
     ["Change Time -  min" org-agenda-date-earlier :active (org-agenda-check-type nil 'agenda 'timeline) :keys "C-u C-u S-left"]
     ["Change Date to ..." org-agenda-date-prompt (org-agenda-check-type nil 'agenda 'timeline)])
    ("Clock and Effort"
     ["Clock in" org-agenda-clock-in t]
     ["Clock out" org-agenda-clock-out t]
     ["Clock cancel" org-agenda-clock-cancel t]
     ["Goto running clock" org-clock-goto t]
     "--"
     ["Set Effort" org-agenda-set-effort t]
     ["Change clocked effort" org-clock-modify-effort-estimate
      (org-clock-is-active)])
    ("Priority"
     ["Set Priority" org-agenda-priority t]
     ["Increase Priority" org-agenda-priority-up t]
     ["Decrease Priority" org-agenda-priority-down t]
     ["Show Priority" org-agenda-show-priority t])
    ("Calendar/Diary"
     ["New Diary Entry" org-agenda-diary-entry (org-agenda-check-type nil 'agenda 'timeline)]
     ["Goto Calendar" org-agenda-goto-calendar (org-agenda-check-type nil 'agenda 'timeline)]
     ["Phases of the Moon" org-agenda-phases-of-moon (org-agenda-check-type nil 'agenda 'timeline)]
     ["Sunrise/Sunset" org-agenda-sunrise-sunset (org-agenda-check-type nil 'agenda 'timeline)]
     ["Holidays" org-agenda-holidays (org-agenda-check-type nil 'agenda 'timeline)]
     ["Convert" org-agenda-convert-date (org-agenda-check-type nil 'agenda 'timeline)]
     "--"
     ["Create iCalendar File" org-export-icalendar-combine-agenda-files t])
    "--"
    ["Undo Remote Editing" org-agenda-undo org-agenda-undo-list]
    "--"
    ("MobileOrg"
     ["Push Files and Views" org-mobile-push t]
     ["Get Captured and Flagged" org-mobile-pull t]
     ["Find FLAGGED Tasks" (org-agenda nil "?") :active t :keys "C-c a ?"]
     ["Show note / unflag" org-agenda-show-the-flagging-note t]
     "--"
     ["Setup" (progn (require 'org-mobile) (customize-group 'org-mobile)) t])
    "--"
    ["Quit" org-agenda-quit t]
    ["Exit and Release Buffers" org-agenda-exit t]
    ))

;;; Agenda undo

(defvar org-agenda-allow-remote-undo t
  "Non-nil means allow remote undo from the agenda buffer.")
(defvar org-agenda-undo-list nil
  "List of undoable operations in the agenda since last refresh.")
(defvar org-agenda-undo-has-started-in nil
  "Buffers that have already seen `undo-start' in the current undo sequence.")
(defvar org-agenda-pending-undo-list nil
  "In a series of undo commands, this is the list of remaining undo items.")


(defun org-agenda-undo ()
  "Undo a remote editing step in the agenda.
This undoes changes both in the agenda buffer and in the remote buffer
that have been changed along."
  (interactive)
  (or org-agenda-allow-remote-undo
      (error "Check the variable `org-agenda-allow-remote-undo' to activate remote undo"))
  (if (not (eq this-command last-command))
      (setq org-agenda-undo-has-started-in nil
        org-agenda-pending-undo-list org-agenda-undo-list))
  (if (not org-agenda-pending-undo-list)
      (error "No further undo information"))
  (let* ((entry (pop org-agenda-pending-undo-list))
     buf line cmd rembuf)
    (setq cmd (pop entry) line (pop entry))
    (setq rembuf (nth 2 entry))
    (org-with-remote-undo rembuf
      (while (bufferp (setq buf (pop entry)))
    (if (pop entry)
        (with-current-buffer buf
          (let ((last-undo-buffer buf)
                    (inhibit-read-only t))
        (unless (memq buf org-agenda-undo-has-started-in)
          (push buf org-agenda-undo-has-started-in)
          (make-local-variable 'pending-undo-list)
          (undo-start))
        (while (and pending-undo-list
                (listp pending-undo-list)
                (not (car pending-undo-list)))
          (pop pending-undo-list))
        (undo-more 1))))))
    (org-goto-line line)
    (message "`%s' undone (buffer %s)" cmd (buffer-name rembuf))))
</t>
<t tx="ekr.20100929212226.14622">
(defun org-verify-change-for-undo (l1 l2)
  "Verify that a real change occurred between the undo lists L1 and L2."
  (while (and l1 (listp l1) (null (car l1))) (pop l1))
  (while (and l2 (listp l2) (null (car l2))) (pop l2))
  (not (eq l1 l2)))
</t>
<t tx="ekr.20100929212226.14623">
;;; Agenda dispatch

(defvar org-agenda-restrict nil)
(defvar org-agenda-restrict-begin (make-marker))
(defvar org-agenda-restrict-end (make-marker))
(defvar org-agenda-last-dispatch-buffer nil)
(defvar org-agenda-overriding-restriction nil)

;;;###autoload
(defun org-agenda (&amp;optional arg keys restriction)
  "Dispatch agenda commands to collect entries to the agenda buffer.
Prompts for a command to execute.  Any prefix arg will be passed
on to the selected command.  The default selections are:

a     Call `org-agenda-list' to display the agenda for current day or week.
t     Call `org-todo-list' to display the global todo list.
T     Call `org-todo-list' to display the global todo list, select only
      entries with a specific TODO keyword (the user gets a prompt).
m     Call `org-tags-view' to display headlines with tags matching
      a condition  (the user is prompted for the condition).
M     Like `m', but select only TODO entries, no ordinary headlines.
L     Create a timeline for the current buffer.
e     Export views to associated files.
s     Search entries for keywords.
/     Multi occur across all agenda files and also files listed
      in `org-agenda-text-search-extra-files'.
&lt;     Restrict agenda commands to buffer, subtree, or region.
      Press several times to get the desired effect.
&gt;     Remove a previous restriction.
#     List \"stuck\" projects.
!     Configure what \"stuck\" means.
C     Configure custom agenda commands.

More commands can be added by configuring the variable
`org-agenda-custom-commands'.  In particular, specific tags and TODO keyword
searches can be pre-defined in this way.

If the current buffer is in Org-mode and visiting a file, you can also
first press `&lt;' once to indicate that the agenda should be temporarily
\(until the next use of \\[org-agenda]) restricted to the current file.
Pressing `&lt;' twice means to restrict to the current subtree or region
\(if active)."
  (interactive "P")
  (catch 'exit
    (let* ((prefix-descriptions nil)
       (org-agenda-window-setup (if (equal (buffer-name)
                           org-agenda-buffer-name)
                    'current-window
                      org-agenda-window-setup))
       (org-agenda-custom-commands-orig org-agenda-custom-commands)
       (org-agenda-custom-commands
        ;; normalize different versions
        (delq nil
          (mapcar
           (lambda (x)
             (cond ((stringp (cdr x))
                (push x prefix-descriptions)
                nil)
               ((stringp (nth 1 x)) x)
               ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
               (t (cons (car x) (cons "" (cdr x))))))
           org-agenda-custom-commands)))
       (buf (current-buffer))
       (bfn (buffer-file-name (buffer-base-buffer)))
       entry key type match lprops ans)
      ;; Turn off restriction unless there is an overriding one,
      (unless org-agenda-overriding-restriction
    (unless (org-bound-and-true-p org-agenda-keep-restricted-file-list)
      ;; There is a request to keep the file list in place
      (put 'org-agenda-files 'org-restrict nil))
    (setq org-agenda-restrict nil)
    (move-marker org-agenda-restrict-begin nil)
    (move-marker org-agenda-restrict-end nil))
      ;; Delete old local properties
      (put 'org-agenda-redo-command 'org-lprops nil)
      ;; Remember where this call originated
      (setq org-agenda-last-dispatch-buffer (current-buffer))
      (unless keys
    (setq ans (org-agenda-get-restriction-and-command prefix-descriptions)
          keys (car ans)
          restriction (cdr ans)))
      ;; Establish the restriction, if any
      (when (and (not org-agenda-overriding-restriction) restriction)
    (put 'org-agenda-files 'org-restrict (list bfn))
    (cond
     ((eq restriction 'region)
      (setq org-agenda-restrict t)
      (move-marker org-agenda-restrict-begin (region-beginning))
      (move-marker org-agenda-restrict-end (region-end)))
     ((eq restriction 'subtree)
      (save-excursion
        (setq org-agenda-restrict t)
        (org-back-to-heading t)
        (move-marker org-agenda-restrict-begin (point))
        (move-marker org-agenda-restrict-end
             (progn (org-end-of-subtree t)))))))

      ;; For example the todo list should not need it (but does...)
      (cond
       ((setq entry (assoc keys org-agenda-custom-commands))
    (if (or (symbolp (nth 2 entry)) (functionp (nth 2 entry)))
        (progn
          (setq type (nth 2 entry) match (eval (nth 3 entry))
            lprops (nth 4 entry))
          (put 'org-agenda-redo-command 'org-lprops lprops)
          (cond
           ((eq type 'agenda)
        (org-let lprops '(org-agenda-list current-prefix-arg)))
           ((eq type 'alltodo)
        (org-let lprops '(org-todo-list current-prefix-arg)))
           ((eq type 'search)
        (org-let lprops '(org-search-view current-prefix-arg match nil)))
           ((eq type 'stuck)
        (org-let lprops '(org-agenda-list-stuck-projects
                  current-prefix-arg)))
           ((eq type 'tags)
        (org-let lprops '(org-tags-view current-prefix-arg match)))
           ((eq type 'tags-todo)
        (org-let lprops '(org-tags-view '(4) match)))
           ((eq type 'todo)
        (org-let lprops '(org-todo-list match)))
           ((eq type 'tags-tree)
        (org-check-for-org-mode)
        (org-let lprops '(org-match-sparse-tree current-prefix-arg match)))
           ((eq type 'todo-tree)
        (org-check-for-org-mode)
        (org-let lprops
          '(org-occur (concat "^" outline-regexp "[ \t]*"
                      (regexp-quote match) "\\&gt;"))))
           ((eq type 'occur-tree)
        (org-check-for-org-mode)
        (org-let lprops '(org-occur match)))
           ((functionp type)
        (org-let lprops '(funcall type match)))
           ((fboundp type)
        (org-let lprops '(funcall type match)))
           (t (error "Invalid custom agenda command type %s" type))))
      (org-run-agenda-series (nth 1 entry) (cddr entry))))
       ((equal keys "C")
    (setq org-agenda-custom-commands org-agenda-custom-commands-orig)
    (customize-variable 'org-agenda-custom-commands))
       ((equal keys "a") (call-interactively 'org-agenda-list))
       ((equal keys "s") (call-interactively 'org-search-view))
       ((equal keys "t") (call-interactively 'org-todo-list))
       ((equal keys "T") (org-call-with-arg 'org-todo-list (or arg '(4))))
       ((equal keys "m") (call-interactively 'org-tags-view))
       ((equal keys "M") (org-call-with-arg 'org-tags-view (or arg '(4))))
       ((equal keys "e") (call-interactively 'org-store-agenda-views))
       ((equal keys "?") (org-tags-view nil "+FLAGGED")
    (org-add-hook
     'post-command-hook
     (lambda ()
       (unless (current-message)
         (let* ((m (org-agenda-get-any-marker))
            (note (and m (org-entry-get m "THEFLAGGINGNOTE"))))
           (when note
         (message (concat
               "FLAGGING-NOTE ([?] for more info): "
               (org-add-props
                   (replace-regexp-in-string
                "\\\\n" "//"
                (copy-sequence note))
                   nil 'face 'org-warning)))))))
     t t))
       ((equal keys "L")
    (unless (org-mode-p)
      (error "This is not an Org-mode file"))
    (unless restriction
      (put 'org-agenda-files 'org-restrict (list bfn))
      (org-call-with-arg 'org-timeline arg)))
       ((equal keys "#") (call-interactively 'org-agenda-list-stuck-projects))
       ((equal keys "/") (call-interactively 'org-occur-in-agenda-files))
       ((equal keys "!") (customize-variable 'org-stuck-projects))
       (t (error "Invalid agenda key"))))))
</t>
<t tx="ekr.20100929212226.14624">
(defun org-agenda-normalize-custom-commands (cmds)
  (delq nil
    (mapcar
     (lambda (x)
       (cond ((stringp (cdr x)) nil)
         ((stringp (nth 1 x)) x)
         ((not (nth 1 x)) (cons (car x) (cons "" (cddr x))))
         (t (cons (car x) (cons "" (cdr x))))))
     cmds)))
</t>
<t tx="ekr.20100929212226.14625">
(defun org-agenda-get-restriction-and-command (prefix-descriptions)
  "The user interface for selecting an agenda command."
  (catch 'exit
    (let* ((bfn (buffer-file-name (buffer-base-buffer)))
       (restrict-ok (and bfn (org-mode-p)))
       (region-p (org-region-active-p))
       (custom org-agenda-custom-commands)
       (selstring "")
       restriction second-time
       c entry key type match prefixes rmheader header-end custom1 desc)
      (save-window-excursion
    (delete-other-windows)
    (org-switch-to-buffer-other-window " *Agenda Commands*")
    (erase-buffer)
    (