Showing posts with label org-mode. Show all posts
Showing posts with label org-mode. Show all posts

euro 2012 games in your org-mode agenda






Things have been rather quiet at emacs-fu - reason for this is that most of my
emacs hacking time has been spent on mu4e, the emacs e-mail client I
wrote. It's been shaping up pretty nicely, I should probably write some
emacs-fu posts about it :)



Another interesting pastime (esp. in Europe) is football/soccer, in particular
the Euro2012 games; long-time readers will remember the schedule for world cup games; I made a new one for Euro2012: https://github.com/djcb/org-euro2012.



In order to have the games show up in your agenda, make sure the file is in
your org-agenda-files. If needed, you could add it with something like this in
your org-mode settings (change the directory path to wherever you have put
euro2012.org):





(add-to-list 'org-agenda-files "~/org/euro2012.org")




One small issue with the schedule is that it uses the central-european summer
time (UTC+2), and there is no automatic way to adjust times for the local time
zone. As a work-around, Juan Pechiar provided the following function which makes
it easy to update all org-timestamps in a file:





(defun update-org-hours (n)
"Change all org-mode timestamps in the current buffer by N hours."
(interactive "nAdd hours: ")
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[[<]" nil t)
(when (org-at-timestamp-p t)
(org-timestamp-change n 'hour)))))




Evaluate this function. After that, you can go to the file with the schedule,
and give an M-x update-org-hours, provide the offset for your timezone, compared to
UTC+2.



Let the games begin!


sauron: keeping an eye on what's going on






I'm a fairly busy person, and need to keep track of a lot of things. That
includes following a bunch of internal IRC channels, attending meetings, meeting
deadlines and so on. But I don't want to stare at my org-mode calendar, or
flip through ERC buffers all the time.



Instead, I'd like to have one little emacs frame (window) that gathers these
('events'), and transfers me to wherever the event came from when I click it - some
IRC-channel in ERC, my org-calendar etc. and other inputs. Note, using
Bitlbee, you can include Facebook-contacts, GoogleTalk-buddies and
Twitter-tweets, … in ERC - so, you can track just about anything.



In addition, with so many inputs, I'd also like the possibility to filter out unwanted
events, and generate various light/sound effects and fireworks, proportional
to the priority of the event.



For all this, I wrote a little emacs-tool called Sauron that does just
that. M-x sauron-start pops up a frame that receives events, and M-x sauron-stop hides it and stops listening. It works with ERC, org, and
listens for D-Bus messages; so it's pretty easy to get events from all over
the place.



It's a bit of a balancing act to get all the important information while not
being swamped in noise, but Sauron allows you to fine-tune it to whatever
works the best for you. I've tried to have sane defaults though, so things
should mostly work without too much configuration - but if you need the power,
it's there. I also added some convenience functions to make it easy to get
sounds and other special effects.






So - it's brand new, it is of seems-to-work-for-me-quality, and I'd like to
invite others to try it out, hack it, give feedback, add new back-ends and so
on – what better Christmas present to ask for!



There's documentation, examples etc. to be found in Sauron's github repository.




quick note-taking with deft and org-mode






Emacs must be gathering a lot of enthusiasts lately; there's hardly a week
where I don't discover some new gem. Recently, I discovered deft. And
apparently, I wasn't the only one.



So what is it deft good for? Well, often I want to jot down some quick thing
during a meeting or a telephone-call. Of course, I don't want to think about
file names or anything else distracting me from my task, just get me that note
already! In addition, at some later time, I want to be able to quickly search
through the notes I made.



For MacOS, there's a program called Notational Velocity which does this. But
really - it sounds like a typical task for emacs - wouldn't it be nice to have
an emacs package that does roughly the same?



And that is what deft does - enable you to quickly write notes, and
retrieving them later. The author has an excellent introduction on his
website, so my job is very easy :) deft is not part of org-mode, but they
can work together seamlessly. Here's my set-up:





;; http://jblevins.org/projects/deft/
(when (require 'deft nil 'noerror)
(setq
deft-extension "org"
deft-directory "~/Org/deft/"
deft-text-mode 'org-mode)
(global-set-key (kbd "<f9>") 'deft))




This blob goes in my .emacs. Note, the first line ensures that emacs starts
without errors, even when I run on a system without deft. Apart from that, I
make deft use org files for note taking, which makes it all very familiar.



All notes are saved ~/Org/deft - you can set it to something else of
course. A Dropbox-folder seems to be a popular choice for synchronizing
between machines.



Finally, the last line binds F9 to deft-mode. So, when I need a quick
note, I can type F9 C-c C-n and start writing.


nice-looking pdfs with org-mode and xetex






I've discussed the wonderful org-mode here a number of times already. It has
become a pretty important part of my overall workflow. One thing I am using
org-mode for, is to produce all kinds of PDF-documents that I can share with
other people.






org-mode & LaTeX






In the past, I often used straight LaTeX for such things; I wrote my thesis
with it, but also many other documents. There are many things I like about
LaTeX, one of them being that I can use emacs for writing. Still, there are
also a few things I do not particularly like. First, I think LaTeX is quite
heavy with formatting directives, which hinder my writing flow (e.g., when I
want to include an image, a table or a source code snippet). Another thing is
that I find the default LaTeX styles a bit boring. Nothing wrong with it,
but there just too many documents with the exact same lay-out.



Now, back to org-mode. One way to use org-mode is as a friendly way to
generate LaTeX (and, consequently, PDFs). This is a big improvement! Much
more than LaTeX itself, org-mode allows to focus on the contents of the
document, rather than instructing LaTeX what to do. This comes at the price
of small bit of flexibility, but, if needed org-mode allows you include
straight LaTeX when needed – so while keeping easy things easy, hard things
are still possible. The latter does require a bit of experience with LaTeX a
though.







setting up XeTeX






Now, for the second issue, the way documents look, there are other
solutions, and they live on the LaTeX side of things. I'm sure many have seen
The Beauty of LaTeX. Using the XeTeX implementation of LaTeX and the
fontspec package, you can create LaTeX documents with a bit 'refreshed'
look.



So, the steps to get this working with org-mode:



  • install the texlive-xetex packages on Ubuntu and Debian (this installs a
    huge set of packages)

  • install the SIL fonts (I'm using ttf-sil-gentium and ttf-sil-charis, but
    there are more)

  • I'm also using DejaVu Mono (ttf-dejavu)









teaching org-mode about the new XeTeX stuff






We now need to define some LaTeX document class for org-mode that uses
XeTeX and some of these new fonts. Let's call the document class
djcb-org-article (as I often use the djcb- prefix for my own stuff), it
could be something like the following (add to your org-setup – e.g., in
your .emacs, make sure there is a (require 'org) before this:





;; 'djcb-org-article' for export org documents to the LaTex 'article', using
;; XeTeX and some fancy fonts; requires XeTeX (see org-latex-to-pdf-process)
(add-to-list 'org-export-latex-classes
'("djcb-org-article"
"\\documentclass[11pt,a4paper]{article}
\\usepackage[T1]{fontenc}
\\usepackage{fontspec}
\\usepackage{graphicx}
\\defaultfontfeatures{Mapping=tex-text}
\\setromanfont{Gentium}
\\setromanfont [BoldFont={Gentium Basic Bold},
ItalicFont={Gentium Basic Italic}]{Gentium Basic}
\\setsansfont{Charis SIL}
\\setmonofont[Scale=0.8]{DejaVu Sans Mono}
\\usepackage{geometry}
\\geometry{a4paper, textwidth=6.5in, textheight=10in,
marginparsep=7pt, marginparwidth=.6in}
\\pagestyle{empty}
\\title{}
[NO-DEFAULT-PACKAGES]
[NO-PACKAGES]"

("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))






Of course, this can be customized to your own preference; e.g.,
North-Americans may not be using A4-paper.



org-mode takes care of the export from its own format to LaTeX, but we need
to tell it to use xelatex to process the LaTeX to PDF:





(setq org-latex-to-pdf-process 
'("xelatex -interaction nonstopmode %f"
"xelatex -interaction nonstopmode %f")) ;; for multiple passes





That's all that's needed on the setup-side.







creating a document






Now, let's create a little test document, test.org, to show how it works:





#+LaTeX_CLASS: djcb-org-article
#+TITLE: My little document

* Introduction

This is my document. There are many like it, but this is mine. It's easy to
write without *too* _many_ /distractions/.

** Normal distribution

Probability density of the normal distribution, using familiar TeX notation
for formulae:

$$\frac{1}{\sqrt{2\pi\sigma^2}}e^{ -\frac{(x-\mu)^2}{2\sigma^2} }$$

** Some table

| *Greek God* | *Roman God* | *Element* |
|-------------+-------------+----------------|
| Zeus | Jupiter | Sky and clouds |
| Hera | Juno | Family |
| Poseidon | Neptune | Sea |
| Hades | Pluto | Underworld |





We can export this to a PDF using C-c C-e p (or C-c C-e d to
automatically open the PDF in a PDF-viewer). This should all work nicely; if
it doesn't, note that when exporting, say, test.org, org-mode will create
a file called test.tex, and visit in a buffer. There's also a buffer with
the output from various commands, but sometimes it can be useful to run LaTeX
(xelatex in this case) on the file by hand, to find any problems. The
wonderful org-documentation about exporting to LaTeX has more information.









I think the result is pretty nice – it stays true to the class LaTeX article
class, but freshens it up a bit with some news font. If you can make
something better – which is not unlikely – you are of course invited to
contribute your own!







Concluding






org-mode is a pretty convenient way to write nice-looking PDFs. Combined
with xelatex, they don't have to look too plain :). However, I'm aware of
my limitations when it comes to the coolness/aesthetic aspects, but I hope
others can show the way here.



Maybe org-mode could ship with a number of ready-made templates to make
it easy to make nice-looking documents, resumes, reference cards, reports,
meeting notes and so on.



executable source code blocks with org-babel






org-babel is the mechanism that org-mode offers for evaluating (executing)
blocks of source code embedded in your org-mode-documents. This is useful
for so-called reproducible research, i.e., where you allow your readers to go
through the steps that led to your results.



Here, I'm just scratching the surface with some simple examples.






source code blocks






Let's first look at how it all began: source code blocks. I guess most
org-mode-users will be familiar with those: the ability to include
syntax-highlighted ('font-locked') snippets of source code in
org-documents. We discussed source blocks before, they look like this:





#+begin_src perl
sub my_func {
print "Hello, world!\n";
}
#+end_src





And note that code blocks can be edited in their 'native mode' using C-c'= (or, =org-edit-src-code).



When code block like this are exported to, say, HTML, they'll look like the
following fully highlighted snippet (assuming you're reading Emacs-fu in
it's full-color version):





sub my_func {
print "Hello, world!\n";
}









evaluating source code






org-babel takes this a few steps further: instead of just looking at
source code, we can actually evaluate (execute) it, using the
org-mode-based system called org-babel.



If you have a recent version of org-mode (7.x or later), add the
following to your .emacs (or equivalent):





(org-babel-do-load-languages
'org-babel-load-languages
'( (perl . t)
(ruby . t)
(sh . t)
(python . t)
(emacs-lisp . t)
))





This enables org-babel for the mentioned languages; there are many
other languages available as well.



Now, suppose we have a snippet of python in an org-mode-buffer:





#+begin_src python
def hello(str):
return "Hello, " + str + "!"
return hello ("dude")
#+end_src





You can move the cursor (point) inside the src-block and press C-c C-c (or,
org-confirm-babel-evaluate). This causes the block of code to be evaluated
(executed), after asking you for confirmation. The result will inserted below
the block, like:





#+results:
: Hello, dude!





Note, in the hello example, the result of the block is the value of the
evaluation - that is, the value of the last expression evaluated. This is
the also the default, so we don't need to (but could) write:





#+begin_src python :results value





The alternative is to use the (standard) output of the function, which is
activated with :results output, e.g.:





#+begin_src sh :results output
echo "Hello $USER! Today is `date`"
#+end_src





Moving to this block and pressing C-c C=c would get you something like
the following – probably with a different username and time:





˜#+results:
: Hello djcb! Today is Sun Feb 27 13:51:50 EET 2011









almost like functions






org-babel also allows you to refer to the code blocks from elsewhere in
your document, by labeling your code-blocks with srcname. Let's say we
have some Ruby code to revert a string:





#+begin_src ruby
def revert(s)
if s == "" then
return ""
else
return s[-1].chr + revert(s.slice(0, s.length()-1))
end
end
revert(str)
#+end_src





We can now 'call' this block; note that we get the result of evaluating the block. So if you want to use the result of a function in the block, you also
need to add the call to that function (see the last line).



Now, we can use:





#+call: revert(str="VeryCoolStuff")





And we get:





: ffutSlooCyreV





Note, due to some limitation/bug in my version of org-babel, the strings
should not contain spaces or other special characters, so the following
will give result in an error note:





˜#+call: revert(str="Very Cool Stuff")





Whenever you try to evaluate a code block, emacs will ask for confirmation --
this is important, because of the obvious security implications of executing
unknown code. Anyway, if you do trust the code, you can use the following
to skip the confirmation:





(setq org-confirm-babel-evaluate nil)





These simple examples do not really capture the power that org-babel
brings, but it's a start. There is quite a bit of documentation for
org-babel to help you further. Finally, if you are already using
org-babel, feel free to share your experiences in the comments!



conkeror: web browsing the emacs way





Web browsing is one of the few computer-based activities for which I usually
do not use emacs. Of course, there are of emacs-based browsers like w3m,
which is pretty good. But for the 21st-century web, a text-mode browser is a
bit limited. There are some efforts underway to integrate a graphical web
browser experience in emacs (e.g., using Xembed), but it will take a while
before that is ready.


The next best thing to web browsing with emacs, is a browser that is
inspired by emacs. Such a browser exists: it's called conkeror (not to be
confused with KDE's Konqueror). conkeror is a Mozilla-based browser that
brings an emacs-like experience to web browsing. I've been using it for more
than a year now as my primary browser, and I am quite happy with it.


Conkeror is a user-interface for the normal Mozilla/Firefox engine
(xulrunner); this means that all those websites that work with Firefox, work
just as well in conkeror, including things like ad-blockers, Java, Flash
etc. and many plug-ins. This is a very important point for me.


If you like emacs, you'll probably also like conkeror. For starters, it uses
many of the same key bindings – C-x C-f will open a url in a new buffer
(tab), C-x 5 2 will open a new window (frame), I can inspect a key-binding
with C-h k… and so on. Some of the single-key shortcuts are the same as
those in w3m, like g to go to a webpage, or B to go back. Conkeror
is fully keyboard-driven; it allows you do almost anything on the web without
using the mouse – it can overlay numbers on items in a webpage so you can
interact with them by their number. Of course, you can still use a mouse if
you want, too.


The conkeror wiki gives many more examples. It also discusses installation in
quite some detail, which makes life a bit easier for me :) Instead, I will
just list a couple of the customizations I have made and encourage you to try
for yourself.




configuration



Like emacs, conkeror is very configurable. The big difference is that
conkeror uses Javascript instead of Elisp for the configuration; however,
the concepts and naming should be familiar for emacs-users. Conkeror's
equivalent of ~/.emacs is ~/.conkerorrc. Below are some snippets from my
setup, that can hopefully help you to create your Perfect Browser ™; all
examples below are based on the latest development version of Conkeror, as
per end of November 2010.


First, some basics:


//allow for 'contrib' stuff
load_paths.unshift("chrome://conkeror-contrib/content/");

// teach me something whenever I start my browser
homepage = "http://en.wikipedia.org/wiki/Special:Random";

// give me new tabs; open buffers (tabs) in the background
require("new-tabs.js");
require("clicks-in-new-buffer.js");
clicks_in_new_buffer_target = OPEN_NEW_BUFFER_BACKGROUND;
clicks_in_new_buffer_button = 1; // midclick links in new buffers with

// auto completion in the minibuffer
minibuffer_auto_complete_default = true;
url_completion_use_history = true; // should work since bf05c87405
url_completion_use_bookmarks = true;





modeline customization



As in emacs, you can customize the modeline. Also in good emacs tradition,
this is far from intuitive…


require("mode-line.js");
// funky icons in the modeline
require("mode-line-buttons.js");
mode_line_add_buttons(standard_mode_line_buttons, true);

// we'd like to see the # of buffers being loaded
add_hook("mode_line_hook", mode_line_adder(loading_count_widget), true);
// we don't need a clock
remove_hook("mode_line_hook", mode_line_adder(clock_widget));






bookmarks



Plain-old bookmarks are easy to add with define_webjump – and you can just
bind them to a short string. You can then 'jump' to the corresponding website by
pressing g and then this short string. For example, to go to Emacs-Fu, you
could type g efu RET. No mousing around needed.


// some bookmarks
define_webjump("conk", "http://conkeror.org");
define_webjump("efu", "http://emacs-fu.blogspot.com");
define_webjump("lkml", "http://lkml.org");
define_webjump("ew", "http://emacswiki.org");
// ...






smart links



Smartlinks are just like normal bookmarks, which the one difference that
they contain an %s-parameter which will be replaced by whatever you type
after the name of the bookmark. Thus, g imdb grande bouffe RET would
take you to the IMDB-page about the movie La Grande Bouffe.


Some examples:


define_webjump("so",    "http://stackoverflow.com/search?q=%s");
define_webjump("yts", "http://www.youtube.com/results?search_query=%s&aq=f");
define_webjump("imbd", "http://www.imdb.com/find?s=all&q=%s");
// ...






integration with emacs



Another useful feature in conkeror is the ability to interact with Emacs
(or any other text editor), so you can use emacs for writing text in web
pages; for example, when you're using emacs-daemon (you should), you could
can add the below, and C-i will then take you to emacs whenever you are in
a text field in a web page.


editor_shell_command = "emacsclient -c";






adding your own functions



It's fairly easy to add your own functions; admittedly, I'm still at the
beginning stages with that, but it's not too hard to combine the internal
function, and assign them to key bindings. Some examples:


// copy url with C-c u
interactive("copy-url",
"Copy the current buffer's URL to the clipboard",
function(I) {
var text = I.window.buffers.current.document.location.href;
writeToClipboard(text);
I.window.minibuffer.message("copied: " + text);
}
);
define_key(default_global_keymap, "C-c u", "copy-url");


// reload conkerorrc with C-c r
interactive("reload-config", "reload conkerorrc",
function(I) {
load_rc();
I.window.minibuffer.message("config reloaded");
}
);
define_key(default_global_keymap, "C-c r", "reload-config");

It's not necessarily so easy to find the exact functions / objects you need
to accomplish what you want. There's a certain learning curve – just like
when using emacs.





integration with org-mode



The integration with emacs can go further than merely editing text fields
though; it's possible to integrate conkeror with org-mode in emacs; I
have the following in my .conkerorrc (this requires emacs-daemon), based
on the code in WOrg:


// org-protocol stuff
function org_capture (url, title, selection, window) {
var cmd_str =
'emacsclient \"org-protocol:/capture:/w/'+url+'/'+title+'/'+selection+'\"';
if (window != null) {
window.minibuffer.message('Issuing ' + cmd_str);
}
shell_command_blind(cmd_str);
}

interactive("org-capture", "Clip url, title, and selection to capture via org-protocol",
function (I) {
org_capture(encodeURIComponent(I.buffer.display_uri_string),
encodeURIComponent(I.buffer.document.title),
encodeURIComponent(I.buffer.top_frame.getSelection()),
I.window);
});
// capture with C-c c
define_key(content_buffer_normal_keymap, "C-c c", "org-capture");

Then, on the emacs-side (in your .emacs), you should have a capture
template for this; for example:


;; ;; the 'w' corresponds with the 'w' used before as in:
;; emacsclient \"org-protocol:/capture:/w/ [...]
(setq org-capture-templates
'(
("w" "" entry ;; 'w' for 'org-protocol'
(file+headline "www.org" "Notes")
"* %^{Title}\n\n Source: %u, %c\n\n %i")
;; other templates
))

Now, when in conkeror, you can select some text, push C-c c ('capture');
emacs will offer you to save this text, including a link to the source, the
date and so on, and saves it for later retrieval. I really love this
feature!






so…



These were just a couple of the many things you can do with conkeror;
there's so much potential here. I haven't discussed many of the other
powerful features, such as the page-specific modes, that give special
features to specific websites, be it GMail or Wikipedia.


I've been using this fine browser for a year or so now, and I really like
it. There are a few rough edges here and there, but it's quite amazing what
the small development team has accomplished. I heartily recommend it – for
web-browsing the emacs-way, there's simple no better alternative.


Finally, if you're using conkeror already, and have some clever tricks
you'd like to share, feel free to do so in the comments.


worldcup games in your org-mode agenda





A significant part of the world population will be watching the Football World
Cup in South-Africa this month. For people who use org-mode to organize
their lives, find the schedule of all the games in this message I sent to the
org-mode mailing list.



In order to have the games show up in your agenda, make sure the file is in
your org-agenda-files. If needed, you could add it with something like in
your org-mode settings:





(add-to-list 'org-agenda-files "~/org/fifa-worldcup-2010.org")






One small issue with the schedule is that it use the South-African times, and
there is no automatic way to adjust times for the local time zone. As a
work-around, Juan Pechiar provided the following function which makes it easy
to update all org-timestamps in a file:





(defun uphours (n)
"update all timestamps n hours"
(interactive "nAdd hours: ")
(save-excursion
(goto-char (point-min))
(while (re-search-forward "[[<]" nil t)
(when (org-at-timestamp-p t)
(org-timestamp-change n 'hour)
))))






Evaluate this function (in emacs, put your cursor after the last ")"), then
press C-x C-e. After that, you can go to the file with the world cup
schedule, and give an M-x uphours, provide the offset for your timezone,
compare to South-African time (positive or negative).


zenburn for org-mode-generated html






If you read this blog directly, instead of through some aggregator or feed-reader, you can
now see the code blocks rendered in the nice zenburn color theme that I discussed before. I'm
really enjoying it, so I added some style sheet definitions, so org-mode #+BEGIN_SRC /
#+END_SRC blocks look as such in the web page (and just like they look on my screen), for
instance:





(defun fibo (n) 
"calculate the Nth (N>=0) fibonacci number in a simple yet
inefficient way"

(cond
((= n 0) 0)
((= n 1) 1)
(t (+ (fibo (- n 1)) (fibo (- n 2))))))

;; now, gimme a list of fibo numbers 0..20
(mapcar 'fibo (number-sequence 0 20))






Note, I discussed the use of such code blocks earlier; it's one of many nice features of
org-mode. Only quite recently I found that I can press C-c ' in such a code block to edit
them in a mode-specific little buffer… something new and obvious to learn every day.



Anyhow, to get the nice zenburn-output in the generated HTML, you can use the
following CSS (note, so far I have only done the code blocks):





/* zenburnesque code blocks in for html-exported org mode */

pre.src {
background: #3f3f3f; color: #dcdccc;
}

.org-preprocessor {
color: #8cd0d3;
}

.org-preprocessor {
color: #8cd0d3;
}

.org-variable-name {
color: #f0dfaf;
}

.org-string {
color: #cc9393;
}

.org-type {
color: #dfdfbf;
font-weight: bold;
}

.org-function-name {
color: #8cd0d3;
font-weight: bold;
}

.org-keyword {
color: #f0dfaf;
font-weight: bold;
}

.org-comment {
color: #7f9f7f;
}

.org-doc {
color: #afd8af;
}

.org-comment-delimiter {
color: #708070;
}

.org-constant {
color: #dca3ac;
font-weight:bold;
}

.org-builtin {
color: #7f9f7f;
}





You can save the above CSS-blob in a file (say, zenburn-code.css), and set
the style sheet for the org-html export by putting a #+STYLE:-line in your
org files:




#+STYLE: <link rel="stylesheet" type="text/css" href="zenburn-code.css" />




showing pop-ups






Updated: yes, it's %s, not %d Sometimes, it's nice when emacs can warn you when something is happening or
should happen. For example, when a new e-mail has arrived, or when there's a
meeting in 15 minutes you should attend.



As always, there are different way to do this, but here's what I've been using
for while. Various versions of this have been circulating around mailing
lists, so I don't know whom to credit with the original idea – anyway, this
is the (modified) version that I'm using.





(defun djcb-popup (title msg &optional icon sound)
"Show a popup if we're on X, or echo it otherwise; TITLE is the title
of the message, MSG is the context. Optionally, you can provide an ICON and
a sound to be played"


(interactive)
(when sound (shell-command
(concat "mplayer -really-quiet " sound " 2> /dev/null")))
(if (eq window-system 'x)
(shell-command (concat "notify-send "

(if icon (concat "-i " icon) "")
" '" title "' '" msg "'"))
;; text only version

(message (concat title ": " msg))))






A couple of notes:




  • I'm using notify-send for sending notifications; this assumes you are
    using that system (it's part of the libnotify-bin package in
    Debian/Ubuntu). You can of course replace it with whatever is available on
    your system. Alternatives are zenity or kdialog or xmessage (for
    old-timers) and their equivalents (?) on Windows, MacOS.



  • I'm now using mplayer for playing sounds. This is a bit heavy, but at
    least plays all kinds of audio files. If you only care about .wav-files,
    you could replace it with e.g. aplay;


  • as always, please ignore my ego-centric function names :-)




Now, we can use this function by evaluation e.g.




(djcb-popup "Warning" "The end is near"
"/usr/share/icons/test.png" "/usr/share/sounds/beep.ogg")








showing pop-ups from org-mode appointments






The above popup function is most useful when it's does its work based on some
event. To be notified of appointments and the like, there is the emacs appt facility. Here, we set up this appt, and then hook it up with org-mode, so

appt can warn us when there's something happening soon…





;; the appointment notification facility
(setq
appt-message-warning-time 15 ;; warn 15 min in advance

appt-display-mode-line t ;; show in the modeline
appt-display-format 'window) ;; use our func
(appt-activate 1) ;; active appt (appointment notification)
(display-time) ;; time display is required for this...

;; update appt each time agenda opened

(add-hook 'org-finalize-agenda-hook 'org-agenda-to-appt)

;; our little façade-function for djcb-popup
(defun djcb-appt-display (min-to-app new-time msg)
(djcb-popup (format "Appointment in %s minute(s)" min-to-app) msg
"/usr/share/icons/gnome/32x32/status/appointment-soon.png"

"/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg"))
(setq appt-disp-window-function (function djcb-appt-display))






Of course, you can freely choose a icon / sound to your liking.







showing pop-ups for new mail






Another event you might want to be warned about is new mail. There is
something to be set for not letting yourself be disturbed for new mail, but
if you sufficiently filter your mails before they enter your inbox, it can be
a good way to periodically bring you back from your deep sl ^H^H thinking. For
Wanderlust, I use something like this:





(add-hook 'wl-biff-notify-hook
(lambda()
(djcb-popup "Wanderlust" "You have new mail!"
"/usr/share/icons/gnome/32x32/status/mail-unread.png"
"/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg")))






Exercise for the reader: adapt this for your chosen mail client.




writing presentations with org-mode and beamer





[Updated:fixed an error in the template]
Things have been a bit quiet at Emacs-Fu lately; this is mostly because I
have been very busy with work, traveling, traveling for work
etc. Emacs-wise, this has been a very intensive time, and I have been able
to move more and more task to emacs – both professionally and
privately. This is mostly because thing become easier when I can do all my
things in one place.



Anyhow, one of the tricks I picked up recently is to write presentations
with the combination of org-mode and a LaTeX-package called beamer. The
most common tool for doing presentations is Microsoft's Powerpoint
program. It gets a lot of criticism, most famously from prof. Tufte in his
Powerpoint is Evil essay. Of course, the problem is in misuse of the tool,
not so much the tool itself.



Still, I didn't want to use Powerpoint (or Powerpoint-wannabees, like
OpenOffice's Impress). For the technically-inclined, the knee-jerk
reaction to this kind of problem is to shout 'LaTeX!'. Indeed - the LaTeX
text-processing system offers a package called Beamer, which allows you to
write presentations with LaTeX. It is quite powerful, and even allows for
all kinds of fancy graphical bling (fade-in, fade out etc.); even better, it
generates PDF-files, which can be viewed just about anywhere. The various
themes and color settings it offers are quite nice, even though they tend to
fill only a small corner of the design-universe…







beamer and org-mode






Now, while I am no stranger to LaTeX, especially for writing a quick
presentation, it can be a painful to remember the various directives and
options. I am not really a daily LaTeX-user, so I tend to forget these
things. I am a daily org-mode user though, and org-mode can export to
LaTeX (which then, in turn, are translated into PDFs). So why not use
org-mode to generate presentations?




It turns out that that is quite easy.



First, we need to define some of the LaTeX-boilerplate, and tell org-mode
about it, so we never need to think about it again. Put the following in
your .emacs:





;; allow for export=>beamer by placing

;; #+LaTeX_CLASS: beamer in org files
(unless (boundp 'org-export-latex-classes)
(setq org-export-latex-classes nil))
(add-to-list 'org-export-latex-classes
;; beamer class, for presentations
'("beamer"
"\\documentclass[11pt]{beamer}\n
\\mode<{{{beamermode}}}>\n
\\usetheme{{{{beamertheme}}}}\n
\\usecolortheme{{{{beamercolortheme}}}}\n
\\beamertemplateballitem\n
\\setbeameroption{show notes}
\\usepackage[utf8]{inputenc}\n
\\usepackage[T1]{fontenc}\n
\\usepackage{hyperref}\n
\\usepackage{color}
\\usepackage{listings}
\\lstset{numbers=none,language=[ISO]C++,tabsize=4,
frame=single,
basicstyle=\\small,
showspaces=false,showstringspaces=false,
showtabs=false,
keywordstyle=\\color{blue}\\bfseries,
commentstyle=\\color{red},
}\n
\\usepackage{verbatim}\n
\\institute{{{{beamerinstitute}}}}\n
\\subject{{{{beamersubject}}}}\n"


("\\section{%s}" . "\\section*{%s}")

("\\begin{frame}[fragile]\\frametitle{%s}"
"\\end{frame}"
"\\begin{frame}[fragile]\\frametitle{%s}"
"\\end{frame}")))

;; letter class, for formal letters

(add-to-list 'org-export-latex-classes

'("letter"
"\\documentclass[11pt]{letter}\n
\\usepackage[utf8]{inputenc}\n
\\usepackage[T1]{fontenc}\n
\\usepackage{color}"


("\\section{%s}" . "\\section*{%s}")
("\\subsection{%s}" . "\\subsection*{%s}")
("\\subsubsection{%s}" . "\\subsubsection*{%s}")
("\\paragraph{%s}" . "\\paragraph*{%s}")
("\\subparagraph{%s}" . "\\subparagraph*{%s}")))







This is based on the template by Thomas S. Dye on the org-mode mailing
list. You can of course add other packages to it with \usepackage. In my
version, I have add the Listings-package for including syntax-highlighted
snippets of source code in my presentations. Importantly, I added the

[fragile] options to the frame-settings, otherwise you cannot include
such source code fragments without LaTeX complaining in various unhelpful
ways.



Note, you can customize the way the Listings package works by changing the
template above; or by setting the options in the org-file; this involves
some 'raw LaTeX' though. It might make sense to define some macros for
that.



Now, we can easily make a presentation in org-mode; simply start the file
with something like:




#+LaTeX_CLASS: beamer
#+MACRO: BEAMERMODE presentation
#+MACRO: BEAMERTHEME Antibes
#+MACRO: BEAMERCOLORTHEME lily
#+MACRO: BEAMERSUBJECT RMRF
#+MACRO: BEAMERINSTITUTE Miskatonic University, Astrology Dept.
#+TITLE: Presentation with Org-Mode and Beamer
#+AUTHOR: Someone







Of course, you can change these parameters; for example, you might want to
change the BEAMERTHEME into Madrid or Warsaw, or … – see the Beamer User Guide (PDF).



After having set up these things, you can write presentations in the familiar
org-mode mark-up.







including source code






As mentioned before, you can use the listings-package to include source
code snippets in your presentation. You'd write this something like:





#+BEGIN_LaTeX
\begin{lstlisting}[language=c]
for (int i = 1; i != 10; ++i)
std::cout << i << ": hello, world!"
<< std::endl;
\end{lstlisting}


#+END_LaTeX







In other words, we include some 'raw' LaTeX to do this. Now, the
org-mode-way of doing this, would be to use something like





#+BEGIN_SRC c
/* code */
#+END_SRC






as discussed before. This works well when exporting to HTML, but at this
moment this will simply translate into a verbatim environment in LaTeX - so
we use lstlisting to get some syntax-highlighting.







including pictures






Of course, the full arsenal of org-mode tools is available as well, for
example Ditaa, as discussed before. Ditaa is now shipped as part of

org-mode, and you can use it to create picture which are then included in
your presentation. Very nice.



For including existing images (PNGs, JPGs etc.), it's probably easiest to
put use some raw LaTeX for that, e.g., something like





#+LaTeX:\includegraphics{/some/path/emacs.png}










putting it together






Now, let's put it all together. Below is an example presentation. Assuming
you have everything installed (ie., LaTeX with the listings package, a
fairly recent org-mode, ditaa), you create your presentation.org and
then press C-c C-e d and your presentation (presentation.pdf) is
generated and automatically shown in your PDF-viewer. Easy!



The intermediate files (such as presentation.tex) are there as well, so
you can check them if something went wrong.



I have uploaded the resulting PDF to Slideshare, so you can see what it
looks like. However, the Slideshare-converted version is extremely
blurry, unlike the crisp PDF I actually created. I'd be happy to upload
the file somewhere else if someone can point me to a good place, thanks!




So hopefully this shows that you can quite easily make presentations with
org-mode, with some help from Beamer, LaTeX etc. Beamer actually provides
a lot more, such as funky slide-transitions and other tricks – but the
things here should give you a good starting point.





#+LaTeX_CLASS: beamer
#+MACRO: BEAMERMODE presentation
#+MACRO: BEAMERTHEME Antibes

#+MACRO: BEAMERCOLORTHEME lily
#+MACRO: BEAMERSUBJECT RMRF
#+MACRO: BEAMERINSTITUTE Miskatonic University, Astrology Dept.
#+TITLE: Presentation with Org-Mode and Beamer
#+AUTHOR: Someone

* My presentation

** Overview

1. Introduction

2. Main part

3. Questions


** Some interesting stuff

*** an important point

- subpoint a

- subpoint b

** Graphics

*** a picture

#+begin_ditaa blue.png -r -S
+---------+
| cBLU |
| +----+
| |cPNK|
+----+----+

#+end_ditaa


*** another picture
#+LaTeX:\includegraphics{emacs.png}

** More interesting stuff

*** some C++ code
#+begin_LaTeX
\begin{lstlisting}[language=c]
for (int i = 1; i != 10; ++i)
std::cout << i << ": hello, world!"
<< std::endl;
\end{lstlisting}

#+end_LaTeX


*** and some Python...

#+begin_LaTeX
\begin{lstlisting}[language=python]
for i in range(1,10):
print i, "hello, world!"
\end{lstlisting}

#+end_LaTeX






writing and blogging with org-mode

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 use
org-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:





#+BEGIN_HTML
<button onclick="alert('you are!');">I feel lucky!</button>
#+END_HTML






in the export HTML this will become:

How cool is that?!



However, I only found out about the nicest trick very recently from the
org-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 the
htmlize-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 in
org-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 calling
htmlize-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 :-)


remember



remember






[ UPDATE: I have cleaned up the code; it should work better now if you don't
have an open emacsclient. I also removed the comments relating to that, as
to not confuse people…]




The human brain is quite good at forgetting things. Often, this is a good
thing. However, sometimes you might actually not want to forget. Things you
need to do – 'Buy milk', 'Register for Helsinki City Run', or simply
things that might be of interest, such as books, funny quotations, articles to
check out, and so on.



Such thoughts should me jotted down immediately, without thinking too
much. It's an essential part of productivity methods like GTD ('Getting Things Done'). The idea is that you capture ideas, thoughts, plans,
etc. at the very moment they enter your mind.



Periodically, you go through all the things you gathered, and decide what to
do with them. Maybe you need to take some action, maybe you only need to store
it somewhere. Or maybe you can simply throw it away. The main point is that
whenever something is in your mind that might be interesting later, make sure
it's not lost.



You can of course carry a simple notebook around and that's not a bad idea at
all. However, a large part of the information inflow is digitized,
computerized, and it's not very convenient to copy interesting tidbits by hand
from your notebook. Clearly, our almighty emacs should be able to help with
this, or?



Indeed. The Emacs-way to capture dispersed information is called
remember-mode. It allows you to quickly write down your thoughts, press C-c C-c and be done with it. The important thing is that is should be a mindless
little exercise to save these things, and get on with your work, life.



I'll describe my use of remember-mode in combination with org-mode. There
are many other things you can do with remember-mode; just read the manual or
the cookbook; also see the great tutorial, and the remember-mode section in
the org-mode-manual.



To integrate remember-mode with org-mode, add to your .emacs:





(org-remember-insinuate)





Now, the important thing is to have 'remember' available anywhere on your
desktop, not just when using emacs – after all, valuable ideas might come up
even when not using emacs, for example when browsing the web. Jack Moffit showed how to get little pop-up windows for remember on MacOS; inspired by
that, here is my solution for Linux/X (this is an updated version):






;; you might also want to set:
;; (setq org-agenda-skip-unavailable-files t)
;; so these warnings won't annoy the little remember-frame
;; also: I have noted infrequent problems when using ElScreen
;; (the wrong frame might be chosen for Remember in about 10% of the cases)

(defun djcb-remember-frame ()
"turn the current frame into a small popup frame for remember mode;
this is meant to be called with
emacsclient -c -e '(djcb-remember-frame)'"

(modify-frame-parameters nil
'( (name . "*Remember*") ;; must be same as in mode-hook below
(width . 80)
(height . 10)
(vertical-scroll-bars . nil)
(menu-bar-lines . nil)
(tool-bar-lines . nil)))
(org-remember)
(when (fboundp 'x-focus-frame) (x-focus-frame nil)) ;; X only....

(delete-other-windows))

;; when we're in such a remember-frame, close it when done.
(add-hook 'org-remember-mode-hook
(lambda()
(define-key org-remember-mode-map (kbd "C-c C-c")
'(lambda()(interactive)
(let ((remember-frame-p
(string= (frame-parameter nil 'name) "*Remember*")))
(when remember-frame-p (make-frame-invisible)) ;; hide quickly

(org-remember-finalize)
(when remember-frame-p (delete-frame)))))))






The next step is to have some easy way to run this. I am using emacsclient and
xbindkeys for that. In my ~/.xbindkeysrc I have:





# pop-up a remember window
"emacsclient -c -e '(make-remember-frame)'"
control+shift+r






After this (and assuming a running emacs daemon), you can run remember-mode

by pressing Control-Shift-r. Make it part of your routine; whenever an idea
comes up, press Control-Shift-r, quickly jot down the thing on your mind,
and press C-c C-c to save it for eternity. Review your notes periodically.



Finally, as mentioned, remember-mode can do quite a bit more than described
here - especially when used in combination with org-mode. One interesting
extension are templates, which are a way to create your notes in a structured
way. For example, I have the following:






(setq org-remember-templates
'(("Clipboard" ?c "* %T %^{Description}\n %x"
"~/remember.org" "Interesting")
("ToDo" ?t "* TODO %T %^{Summary}"
"~/remember.org" "Todo")))






Please refer to the manual for the exact syntax. Basically, this defines two
templates; the first one will ask you for a description, and then add then
insert the contents of the (X) clipboard under the 'Interesting'-header; the
second insert a simple 'TODO'-entry under the 'Todo'-header.



Exempli gratia – suppose I have selected some text in my web-browser. Now, I
push the key-binding we set up before: C-R (Control-Shift r). A small window
pops up, asking me if I want to make a 'Clipboard' or a 'Todo' entry. I
press c for a clipboard entry. I asks me for a description, which I provide;
it dumps the contents of the clipboard in the entry. I then push C-c C-c to
save and close the pop-up window.



All of the notes will be saved to a file ~/remember.org; you can customize
this of course, and you can also move different kinds of today items to
different files. Anyway, after a while, ~/remember.org might look somewhat
like this:






* Interesting
** <2009-04-05 Sun 18:06> what is emacs?

Emacs is a powerful, customizable, self-documenting, modeless text
editor. Emacs contains special code editing features, a scripting language
(elisp), and the capability to read mail, news, and more without leaving the
editor.
** <2009-04-05 Sun 19:39> socrates
The hour of departure has arrived, and we go our ways - I to die, and you to
live. Which is better God only knows.
* Todo
** TODO <2009-04-05 Sun 18:12> buy milk & cookies






As you see, remember.org is just another org-mode-file, so all its bells
and whistles are available. Periodically, you should go through this file and
take necessary actions.



You could go further and develop complicated templates for capturing specific
information, tagging it and so on. The various manuals give some examples. All
I wanted to do here is to give a small taste of the power of remember-mode in
combination with org-mode. The rest is up to your imagination…


in praise of org-mode

The bread-and-butter of emacs is text-editing, of course. But starting from that, emacs has gone beyond that -- far beyond, with things like e-mail clients and games. For me, one of the most useful things to with emacs is to use it as a planner/agenda - and for that I use org-mode.Now, org-mode is quite popular already - but I am sure there are many people who haven't heard about it - and if this blog entry helps only one of them, it has served its purpose.

I won't go through the basics of Org-mode here -- this has been documented very well already. I can recommend reading the reference manual; the web is full of useful tips, and the org-mode mailing list is very nice - and org-mode author Carsten Dominik is amazingly responsive.

Traditionally, I've found it hard to keep track of the things I need to do, paying bills and sending in forms on time, and so on. I solved that using some techniques like GTD ('Getting Things Done', or 'To-do lists on steroids') -- I am using it in a dilluted form that works well for me. Spending so much time with computers, it's only natural that I want some computerized to help me with that (and keep a Moleskine notebook as a low-tech satellite system). There is some dedicated software and some webapps to do this, but they never really appealed to me - they are quite rigid, and I am very picky when it comes to quick navigation, not requiring mouse operation, and so on. Of course, you wouldn't expect different from an emacs user.

So, how does org-mode solve this? In org-mode I just keep all my notes (to-do items, appointments, meeting notes etc.) in plain-text files. Within these text files, I can organize items hierarchically, ie.


* item i
* item ii
** item ii.a
*** item ii.a.1

and so on. Org-mode gives them some funny colors, allows you to show/hide part of the hierarchy, and so on. This is excellent for notes, and that makes org-mode already quite useful, even if you don't use anything else.

Still, you might. So, you can add dates to items, say:


* TODO: fix my bike SCHEDULED: <2009-03-18 Wed> :home:

Org-mode will recognize this as a TODO item, and recognize that you'd like to do it on a certain day. The :home: is a tag, which means that this is something to do when I'm at home; alternatives could be car or work, but tags can be anything; we'll see how tags come in handy.


The 'magic' now is that you can generate an agenda (week, month, year, filtered) or todo-list, which takes the items from all your org-files, and shows what to do today, this week, ..., and you can filter by tag. Thus, you can have a specific TODO-list for the office. It works really nicely.

Org-mode also allows you to export your todo-lists and agenda's to webpages. You can mark your TODO items as 'DONE', and move them to an archive file. You can have recurrent items. You could add, say, 'MAYBE:' and 'CANCELLED' to complement TODO/DONE. Just about anything is configurable.

And of course, it's all plain-text. This makes it easy to script, and it will work well with a revision control system, such as subversion or git -- and through that, you can easily use org-mode from different computers, home, office, anywhere.

So, with this entry I hope to encourage everybody who likes to manage their time with emacs to try org-mode -- and I only scratched the surface. You can start using it as an alternative to simple text files for writing notes, and then slowly define your very own 'best way' to handle all the other things.

Let's end with some interesting links:


So, let's get organized :)

Followers

Popular Posts