## 2009-03-31

Emacs-users like to stay in their own little world, even when interacting with the Others - and they are right of course. Why leave the comforts of your well-configured emacs for the inconveniences of yet another app? For example, when using twitter, I prefer to do that from within emacs. There are different ways and packages to do so.

My favorite so far is twitter.el. Installation is easy: put twitter.el in your load-path (see installing packages if needed). After that, put something like

(autoload 'twitter-get-friends-timeline "twitter" nil t)
(add-hook 'twitter-status-edit-mode-hook 'longlines-mode)
and maybe make an easy keybinding (Shift-F1):
(global-set-key (kbd "<S-f1>")  'twitter-get-friends-timeline)
in your .emacs. Assuming that you already have a Twitter-account (which you'll need to get through its web-interface...), you can then get your friends' 'tweets' with M-x twitter-get-friends-timeline, and update your status with twitter-status-edit (when done, press C-c C-c). Can't be much easier, can it?

One small problem I faced with twitter.el is that it's default color are not very well-suited for my dark color theme. Therefore, I've added the following to my theme:

(twitter-user-name-face ((t (:bold t :foreground "white"  :background "blue"))))
(twitter-time-stamp-face ((t (:bold nil :foreground "white" :background "blue"))))
Et voilà! The screen shot shows one weakness in twitter.el: it does not understand HTML.

The great Socrates once taught us that the unexamined life is not worth living. Thankfully, these days we have twitter now, so we can spend all day examining each others lives... and now without leaving emacs.

(btw, on twitter you can find me as djcb).

## 2009-03-18

### 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 :)

## 2009-03-08

### windows and daemons

Update: Scott has updated instructions -- please see this Reddit page for all the details. Thanks Scott!
[Today, a nice trick from guest blogger Scott Turner (thanks Scott!), on how to improve emacsclient behavior on Windows (see emacs --daemon for a discussion of a daemonized emacs on Unix/Linux). As Scott mentions, there is a nice Emacs-for-Windows package called EmacsW32; the people behind that did a very nice job. It makes the Windows editing experience so much nicer, even when sometimes Emacs' non-Windows origins shine through.

If you'd also like to contribute to Emacs-Fu, please contact me by e-mail (rot13 "qwpo@qwpofbsgjner.ay") or IM (rot13 "qwpo@wnoore.bet").]

First, I recommend using the W32 package. W32 has hacked the emacsclient in several useful ways. It will start Emacs if it isn't already running, it will call "raise-frame" on the Emacs window when started, and it permits starting emacsclient without a filename.

Second, put the following in your .emacs file:

(defun my-done ()
(interactive)
(server-edit)
(make-frame-invisible nil t))
(global-set-key (kbd "C-x C-c") 'my-done)
Now when you "exit" Emacs with the familiar key sequence, what actually happens is that the server buffers (from emacsclientw) are saved and deleted and then the frame (Emacs window) is made invisible. You can check the task manager to see that Emacs is indeed still running.

When you next invoke Emacs through emacsclient, the Emacs window is "raised", making it visible,and switched to the emacsclient buffer.

The end result is a single reusable Emacs which is hidden off-screen when not in use.

(If you're used to using C-x # to exit from an emacsclient session, you might want to bind the my-done function to that key combination. That's harder than you might expect, though. If you try to do that in your .emacs file, the key binding will be overwritten when Emacs starts server-mode. One option is to force the loading of server.el before you change the keybinding. Another is to hang the keybinding on server-visit-hook.)

You can probably achieve much the same effect in a vanilla Emacs 23 package, but you'll have to use the alternate editor argument to emacsclient to start up an Emacs if one isn't running and enter server-mode, and the eval argument to execute raise-frame and make the Emacs window visible again.

## 2009-03-04

### color theming

There are people who think it's a waste of time to spend time customizing the colors in emacs. They are probably right; I haven't seen evidence that the some color scheme makes you more productive (which is the purpose of life, of course). Red on orange may not be the best though. Nevertheless, I like to customize emacs' colors. I like darkness with shades of blue - please do your own psycho-analysis.

Anyway, to change the colors that emacs uses, you can do something like (yuk!)

(set-face-foreground 'default "blue")
(set-face-background 'default "green")

This sets the foreground color of the text recognized as default to blue, and the background to green; some other properties (such as 'underline') are available as well. Emacs 'knows' what text is supposed to be a 'warning', a 'variable' or a 'comment', and applies the color configured for it. Now, if you see some text that has some unexpected color, and you wonder why that is, move the cursor there, and call M-x describe-face. With that information, you can then configure the looks (note: if you don't see any colors you might be either (color-)blind, have a monochrome monitor, or forgot to specify (global-font-lock-mode t) in your .emacs)

You can also use set-face-foreground et al interactively; it lets you scroll to a long list of named colors, and alternatively you can use an HTML-style "#RRGGBB" hexadecimal red-green-blue color description. For example, "#000000" is black, "#ffffff" is white, and all colors of the form "#XYXYXY" (the RGB components are equal) give you various shades of gray: "#151515" is a rather dark gray, while "#e5e5e5" is rather light. For the full rainbow, a program like The Gimp can give you the hex-representation.

Using this knowledge, we can define all the colors, make comments gray, warnings red and so on. However, some people have already done much of the work for you, and prepared a wide range of color themes -- get the color-theme-el package. After installing, you can select interesting color-themes like M-x color-theme-subtle-hacker or M-x color-theme-blippblopp. Meanwhile, color-theme-select gives you an overview of all available color theme.

Of course, we're not happy with any of those, and prefer our very own theme. See below for an example of how to create your own color theme. When you're totally happy with the theme, you could even submit it to the color-theme people, and it might end up in a future version of the package.

(require 'color-theme)
(defun color-theme-djcb-dark ()
"dark color theme created by djcb, Jan. 2009."
(interactive)
(color-theme-install
'(color-theme-djcb-dark
(background-color . "black")
(background-mode . dark))
(bold ((t (:bold t))))
(bold-italic ((t (:italic t :bold t))))
(default ((t (nil))))

(font-lock-builtin-face ((t (:italic t :foreground "#a96da0"))))
(font-lock-comment-face ((t (:italic t :foreground "#bbbbbb"))))
(font-lock-comment-delimiter-face ((t (:foreground "#666666"))))
(font-lock-constant-face ((t (:bold t :foreground "#197b6e"))))
(font-lock-doc-string-face ((t (:foreground "#3041c4"))))
(font-lock-doc-face ((t (:foreground "gray"))))
(font-lock-reference-face ((t (:foreground "white"))))
(font-lock-function-name-face ((t (:foreground "#356da0"))))
(font-lock-keyword-face ((t (:bold t :foreground "#bcf0f1"))))
(font-lock-preprocessor-face ((t (:foreground "#e3ea94"))))
(font-lock-string-face ((t (:foreground "#ffffff"))))
(font-lock-type-face ((t (:bold t :foreground "#364498"))))
(font-lock-variable-name-face ((t (:foreground "#7685de"))))
(font-lock-warning-face ((t (:bold t :italic nil :underline nil
:foreground "yellow"))))
(hl-line ((t (:background "#112233"))))
(mode-line ((t (:foreground "#ffffff" :background "#333333"))))
(region ((t (:foreground nil :background "#555555"))))
(show-paren-match-face ((t (:bold t :foreground "#ffffff"
:background "#050505")))))))
To activate this theme, simply do M-x color-theme-djcb-dark. One nice side-effect of the color-theme package is the fact that colors work properly when you open new frames (windows).

## 2009-03-01

### math formulae in webpages

[Note, I published this before elsewhere; now, a new version is available] Sometimes, I like to use mathematical notation in webpages, either to impress people or simply for decoration. One way to do that is MathML, which is an XML-based markup language for mathematical notation. However, many browsers do not support MathML at all, or require you to download plugins and/or special fonts. Another problem with MathML is that XML is a really inconvenient format to edit by hand. Practically, you'll need some kind of formula editor.

### tex vs mathml

As an old-schooler, I prefer to use the math-notation invented for TeX instead - it is short and sweet and powerful. Donald Knuth invented the whole TeX language because he was unhappy with the quality of typesetting of mathematic, and it is widely used in both computer science and mathematics. Anyway, I'm sure many people remember the 'abc-formula' to calculate the roots of a quadratic function :
In the TeX-sublanguage for math, one can specify the formula as follows:
 -b \pm \sqrt{b^2 - 4ac} \over 2a
The corresponding MathML is no fewer than 20 lines; see the example in Wikipedia. Clearly, MathML is not designed for hand-editing. There are are some editors available, but hand-editing TeX is much faster (at least for me); and, as mentioned, even if you have the MathML, many browser will not show it correctly.

So what I'd like is a way to use (i) TeX-notation and (ii) have it display correctly in any (graphical) browser. One way to that is to use LaTeX to process and render the formulae, and convert that to a PNG-image. In 2004, I wrote a little tool called WebTeX to create small images from TeX-formulae. It was nothing too fancy; you enter a <img ...>-element with some decription of some formula, and the little tool would turn it into an image, using LaTeX and ImageMagick. I don't maintain that old tool anymore - it was time for something new. Therefore...

### texdrive

This weekend, I wrote a new maths-in-webpages tool using emacs-lisp. The emacs-integration makes adding formulae to html-pages really easy. For example, if I want to include the famous Bayes' Theorem, I simply type:
  M-x texdrive-insert-formula
Formula: $P(A|B) = \frac{P(B|A)P(A)}{P(B|A)P(A) + P(B|\overline{A})P(\overline{A})}$
Title: bayes-theorem
Et voilà; the following is inserted:
  <img src="bayes-theorem.png" title="bayes-theorem"
class="texdrive-formula" name="$P(A|B) = \frac{P(B|A)P(A)}{P(B|A)P(A) + P(B|\overline{A})P(\overline{A})}$"
border="0">
Now, all we need to do is texdrive-generate-images-from-html, and the corresponding image will be generated:

So, for immediate download: texdrive.el. It works pretty well for me; please let me know if you have any problems or are missing something. In some cases, the formulae are not as sharp as they could be; I hope I'll be able to improve it with some tweaking. Anyway, it's nice to see how one can solve problems by glueing together some existing open-source tools. Standing on the shoulders of giants...

Note that some wiki-software, notably Wikipedia's MediaWiki, use a similar approach.