Already in some previous entry I sang the praises about org-mode, the
emacs-mode that is such a nice, flexible way to organize your life. There is
so much in org-mode
that it's quite hard to fit in here, but thankfully
org-mode is documented very well; there's not only the reference manual, there
is also a lot of user-provided documentation about how they use org-mode
. A
nice recent example of that is Bernt Hansen's Org Mode - Organize Your Life In Plain Text!.
I use org-mode
for time-management too - I'm using it in a rather simple
fashion compared to Bernt Hansen, but find it very useful. I also useorg-mode
for writing webpages and blogs (like this one), and that is what
I'd like to discuss here.
Actually the first time I heard about this org-mode
-thing people were raving
about, it was for taking notes. Curious as I am, the next time I needed to
take notes, I uttered M-x org-mode
to try it out, and found how easy and
natural it is to write structured, semi-rich-text with org-mode
. Some
examples:
Markup
I can write headings by starting lines with some stars, the number of stars
determining the heading level:
* level 1 heading
some text
** level 2 heading
some more text
*** level 3 heading
even more
org-mode
helpfully gives them some different colors; by pressing TAB
when
I am on a heading, I can hide/show the lower levels and the contents. Nice!
It's also easy to get all the basic markup by decorating your words a bit:
This is *bold* /italics/ _underline_ [[http:/emacs-fu.blogspot.com][Emacs-Fu]]
In org-mode
it looks like:
This is *bold* /italics/ _underline_ Emacs-Fu
There are many more things; for example, there's the table editor; I simply type|country|capital|<Enter>|-<Tab>
and I get:
| country | capital |
|---------+---------|
| | |
Now, I fill in the names in the colums, ending each line with <Alt><Enter>
(or M-RET
), and org-mode
takes care of making everything fit, so we get:
| country | capital |
|-------------+-----------|
| finland | helsinki |
| netherlands | amsterdam |
You can even insert formulae in the cells, turning this into a simple kind of
spreadsheet. Haven't used that yet though.
Blogging
Now, one of the things I use org-mode
for is blogging; for that, I need to
convert the org
-text into HTML; this is simple org-export-as-html
(or C-c C-e
). I can then copy the HTML into blogger.com
or whatever (that might be
automatable). You can also export to plain-text, LaTex and other formats.
I found that it makes me a much more productive blogger if can use org-mode
;
it's so much more convenient to write the mark-up than to write raw HTML. Now,
sometimes I might want still want to write some raw HTML, but that can be
easily done:
<button onclick="alert('you are!');">I feel lucky!</button>
in the export HTML this will become:
How cool is that?!
However, I only found out about the nicest trick very recently from theorg
-mailing list.
In this blog, I often use blurbs of code; I'd like to show those blurbs with
the syntax-highlighting that emacs gives me. For that, I use thehtmlize
-package. For example, when showing some Emacs-Lisp code, I would
copy that to an Emacs-Lisp buffer, then run htmlize-region
on the code, and
finally copy the result back in a raw-html block (like the one for the <button>).
I wondered - could I not do that automatically? I could mark code inorg-mode
as being 'Emacs-Lisp'-code (or Perl, or Python, or …), and when
I'd export the html, org-mode
would go through the trouble of callinghtmlize-region
on it and use that in its output. Sounded like a nice idea, I
asked for some advise on how to do it.
Five minutes after asking, I got a reply – 'just use#+BEGIN_SRC/#+END_SRC
'. Wow – it was already there in org-mode
, it's
even documented, but somehow I missed that. So, now I can write:
#+BEGIN_SRC perl
for (my $i = 0; $i != 10; ++i) {
print "hello, world!\n";
}
#+END_SRC
#+BEGIN_SRC c++
for (int i = 0; i != 10; ++i)
std::cout << "hello, world!" << std::endl;
#+END_SRC
and in the export HTML, this will look like:
for (my $i = 0; $i != 10; ++i) {
print "hello, world!\n";
}
for (int i = 0; i != 10; ++i)
std::cout << "hello, world!" << std::endl;
I am impressed.
These were just some of the things I've discovered in the last few months of
using org-mode
, and I am only scratching the surface. Feel free to share
your org-mode
-writing tips in the comments :-)
No comments:
Post a Comment