Org-Mode: Emacs' Swiss Army Knife
Well, this page is available in something like English only.
Table of Contents
1 About my usage of Org-mode
On this page I would like to present some insights in how I use Org-mode for task management, drafting, publishing HTML. Hopefully it will grow. Comments, suggestions are welcome.
2 Code snippets
In this section I present several code snippets I found on the net and which I use for several purposes.
2.1 "Tangling" org-mode code blocks with org-babel
This code does not work with the actual master
branch of the git
repository. The last commit I have tested with is
deef19a7864b99ec2520ef1cdacaef21ce3809cc
. I'll check the diffs and why it is broken.
I am doing experiments on the usage of org-babel
for research
work. The idea is to follow the paradigm of literate programming and
use an org-mode file for the documentation and programming. An
application for this approach could be the usage of reproducible
research done with R.1
Therefore I use several parts of org-babel
:
- I use the source code blocks to do the computation, analysis and producing of graphics.
- I use the publishing capabilities of
org-mode
for producing a HTML file which show the analysis in more detail. - I use the
tangle
part of org-mode to produce the resulting LaTeX documens like a working paper (or report) and slides for a presentation.
In doing this I was wondering whether it is possible to tangle
an
org-mode
file out of org-mode
:
#+begin_src org :tangle foo.org
,#+TITLE: Org-Mode document
,* My first heading
,* My second heading
,** TODO Part to be done
,** DONE Part already done
In a first step this did not work because org-mode
is not a
out-of-the box language of org-babel
. After consulting the mailing
list Eric Schulte came up with a short and well working solution:
;;;; tangle org-mode source code blocks ;;;; ;;;; Code by Eric Schulte <schulte.eric@gmail.com> ;;;; via gmane.emacs.orgmode ;;;; Newsgroups: gmane.emacs.orgmode ;;;; Subject: Re: Re: [org-babel] How to tangle "org-mode" files? ;;;; Date: Mon, 26 Apr 2010 08:52:21 -0600 ;;;; Message-ID: <87ljca6zbu.fsf@gmail.com> ;;;; (add-to-list 'org-babel-tangle-langs '("org" "org" nil t)) (org-babel-add-interpreter "org") (defun org-babel-expand-body:org (body params &optional processed-params) (with-temp-buffer (insert body) (goto-char (point-min)) (while (re-search-forward "^," nil t) (replace-match "")) (buffer-string)))
This only works in those versions that have the "expand-body" facility
for the org-babel
languages. I am not sure when this came into the
distributed tar ball because I normally use the development version
via the git repository.
2.2 Idle timer: Showing the agenda after x minutes of idle time
From John Wiegley's mailing list post (March 18, 2010), same text can be found at Worg.
I have the following snippet in my .emacs file, which I find very useful. Basically what it does is that if I don't touch my Emacs for 5 minutes, it displays the current agenda. This keeps my tasks "always in mind" whenever I come back to Emacs after doing something else, whereas before I had a tendency to forget that it was there.
John Wiegley: Displaying your Org agenda after idle time
(defun jump-to-org-agenda () (interactive) (let ((buf (get-buffer "*Org Agenda*")) wind) (if buf (if (setq wind (get-buffer-window buf)) (select-window wind) (if (called-interactively-p) (progn (select-window (display-buffer buf t t)) (org-fit-window-to-buffer) ;; (org-agenda-redo) ) (with-selected-window (display-buffer buf) (org-fit-window-to-buffer) ;; (org-agenda-redo) ))) (call-interactively 'org-agenda-list))) ;;(let ((buf (get-buffer "*Calendar*"))) ;; (unless (get-buffer-window buf) ;; (org-agenda-goto-calendar))) ) (run-with-idle-timer 300 t 'jump-to-org-agenda)
2.3 Generating an atom feed
This code does not work with the actual master
branch of the git
repository. The last commit I have tested with is
deef19a7864b99ec2520ef1cdacaef21ce3809cc
. I'll check the diffs and why it is broken.
David Maus wrote an interesting tool to produce an atom feed for an org-mode file. I use this for my blog's atom feed.
3 Solutions with publishing HTML
After reading the tutorial on Publishing Org-mode files to HTML I had two open questions concerning my home page project:
- If you generate a sitemap it won't have the CSS settings from the rest of your site. How can I fix that?
- How can I get a navigation bar like Dave on his home page?
And here are my solutions:
3.1 How to produce a sitemap with the web site's layout
The idea is to produce the sitemap by Org-mode and then read it into another org file which has the right options and style sheet links:
Here is my org-publish-project-alist
:
(setq org-publish-project-alist ;; .... '("dbrunner-org" :base-directory dbrunner-base-dir :base-extension "org" :publishing-directory my-pub-dir :recursive t :publishing-function 'org-publish-org-to-html :headline-levels 4 ;; just default :auto-preamble t :auto-index t :index-filename "sitemap0.org" :exclude "sitemap0.org" :index-title "Übersicht" :index-style 'tree) ;; .... )
As you noted I use the file sitemap0.org
as the output for the
automatic index generation. In the publishing process the sitemap is
written to sitemap0.org
and consists for example of the following
content:
#+TITLE: Übersicht + Arbeit + Daniels Weblog + Über mich... + Dossiers + I would call it English + Forschung + Freizeit + Heimseite von Daniel Brunner + it + Computer + Org-Mode: Emacs' Swiss Army Knife + Kontakt/Impressum + Huch, diese Seite gibt es nicht (mehr) + Übersicht + Themen, die mich beschäftigen
As you can see: Without links to the style sheet or including of any
other option files. But this file is not transfered to the
publication directory because I have put it in the :exclude
section. Instead I use a seperate file sitemap.org
which has the following
content:
#+TITLE: Übersicht #+SETUPFILE: ../templates/level-0.org #+INCLUDE: ../templates/level-0.org #+INCLUDE: sitemap0.org
In the publishing process this file will include the sitemap0.org
content and present with the right style sheet, inclusion of other
option files etc.
3.2 How to integrate a navigation bar
I wanted to have a navigation bar at the top of each page. For this
purpose I created a file templates/level-0.org
:
#+BEGIN_HTML <div class="menu"> { <a href="index.html">Home</a> | <a href="cv.html">Über mich</a> | <a href="blog.html">Blog</a> | <a href="forschung.html">Forschung</a> | <a href="themen.html">Themen</a> | <a href="dossiers.html">Texte/Dossiers</a> | <a href="sitemap.html">Index</a> | <a href="kontakt.html">Kontakt/Impressum</a> } </div> #+END_HTML
And then each file at the top level (level-0) (for example
org/cv.org
) starts with
#+TITLE: Über mich... # ... other options ... #+SETUPFILE: ../templates/level-0.org #+INCLUDE: ../templates/level-0.org
Now every file includes the level-0.org
file and produces a div
section with the navigation bar. If you are going to use more than one
level (like this web site) you should as mentioned in the tutorial
different files for the levels. I made a
templates/level-1-themen.org
file which adds another submenu
container to the navigation bar:
#+BEGIN_HTML <div class="menu"> { <a href="index.html">Home</a> | <a href="cv.html">Über mich</a> | <a href="blog.html">Blog</a> | <a href="forschung.html">Forschung</a> | <a href="themen.html">Themen</a> | <a href="dossiers.html">Texte/Dossiers</a> | <a href="sitemap.html">Index</a> | <a href="kontakt.html">Kontakt/Impressum</a> } </div> <div class="submenu"> { <a href="../arbeit.html">Arbeit</a> | <a href="index.html">Computer</a> | <a href="../freizeit.html">Freizeit</a> } </div> #+END_HTML
Footnotes:
1 See for an example on how to do this http://orgmode.org/worg/org-contrib/babel/examples/research-project.php