Sunday, February 22, 2009

Viper-mode and accented chars

Viper-mode obviously has to define it's own keymaps. It does this reasonably well. Problem is, those keys it doesn't map, it leaves alone. In practice, accented characters like ö, ü, ó and the like are inserted even in viper mode. A quick fix for this, into your .emacs:

;; Unbind accented chars
(let ((accents "öüóőúéáűí")) ; The list of characters to unbind
     (dotimes (num (length accents))
             (define-key viper-vi-basic-map (string (aref accents num)) 'viper-nil)))

A note: htmlize.el seems to have some problems with Emacs 23. The version at EmacsWiki is patched for this issue.

Thursday, February 19, 2009

Mutt, Emacs, Postfix and Gmail

Update 20/02/2009: this article at The Lumber Loom is what this was supposed to be. You don't even need postfix, it seems. The 'Composing mail' part is still worth a look.

This is the current setup I use. Procmail could also be added in, but Gmail IMAP and filters are enough for me at the moment. The following setup assumes that you're using a single mail account, and are generally a simple user - not an e-mail provider or something.

Receiving mail

If you want to use IMAP to access your e-mail instead of fetching it and reading from your own computer, mutt is quite simple to configure. Here's the relevant part of my .muttrc:

set imap_login = 'abesto0'
set folder="imaps://abesto0@imap.gmail.com/INBOX"
set record="=Sent"
set postponed="=Drafts"
set ssl_starttls=yes
set ssl_force_tls=yes
set imap_passive = no
set mail_check=60
set timeout=10
set header_cache=~/.hcache
set imap_user = 'abesto0@gmail.com'

Composing mail

Mutt uses an external editor for writing mail. Using Emacs for that is simple enough. Add this to your .muttrc:
set editor = 'emacsclient %s'
And this to your .emacs, if you want to edit in mail-mode:
(add-to-list 'auto-mode-alist '("mutt-HOSTNAME" . mail-mode))
Aaaand that's it.

Sending mail

This one's a bit more complicated. Mutt itself won't send mails. It will, however, happily use another application to do it for you. This program is sendmail by default, but postfix provides a sendmail compatibility interface, so it's a drop-in replacement.

After searching the 'net all afternoon, a comment on a blog solved my problems with routing mail through the Gmail SMTP server. I've lost that blog some time in the last four hours - sorry. Most other tutorials make you create certificates, but it's apparently not necessary. Adding the following to /etc/postfix/main.cf seems to be enough:

relayhost= [smtp.gmail.com]:587

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous

You'll have to tell postfix what username and password to use. This is done by writing /etc/postfix/sasl_passwd with the following format:

[smtp.gmail.com]:587    user.name@gmail.com:password

Then, in /etc/postfix run the following command, to create a hash db: postmap sasl_passwd
This creates sasl_passwd.db, containing what you just entered in a hash database. You can delete sasl_passwd now, if you want (not sasl_passwd.db).

You can reload the postfix configuration without restarting the daemon with postfix reload. After that, you should be ready to use your mutt-emacs-postfix-gmail setup. Have fun :)

Monday, February 9, 2009

Vimperator, ClawsMail and Emacs

Update 23/02/2009: A more elegant solution in Emacs 23 is using emacs --daemon. There's a post explaining that at emacs-fu.

Just a quick note about using Emacs as an external editor with Claws Mail and Vimperator. Yeah, Vimperator + Emacs, because they both do exactly what and as I need them to. There's a twist: I need a mode (mail-mode and blog-init, respectively) started when I start Emacs for editing.

Claws Mail

This one's easy. Just set Configuration->Preferences->Message View->External Programs to emacs '%s' --execute '(mail-mode)' and you're done. In case you're wondering, %s is where the name of the temp file gets substituted, and --execute '(mail-mode)' turns mail-mode on after the file is loaded.

Vimperator

This one isn't so easy. Well, actually, that depends. If Fundamental mode is OK for you, then simply add the following line to your .vimperatorrc:

set editor=emacs

But if - like me - you want something done every time you fire up Emacs from Vimperator, then you have a problem (this might apply to Conkeror and the It's All Text! plugin, I'm not sure). Thing is, you can't put the --execute argument after the filename - the filename goes to the very end. This causes your mode to be loaded before the file is opened, which is useless. A simple script to work around this:

~/vimperator-emacs.sh
#!/bin/sh
emacs $1 --execute '(blog-init)'

This solves the problem above. For some strange reason, Vimperator doesn't seem able to run it's editor from an absolute path (so ~/vimperator-emacs.sh as the editor doesn't work). Ugly workaround: just symlink it to /usr/bin. After that, set your editor to vimperator-emacs.sh and you're done.

Update 19/02/2009: Another solution for Vimperator is the following in your .emacs:

(add-to-list 'auto-mode-alist '("vimperator*" . your-function))

You can then even use emacsclient as the editor, as this doesn't depend on a command-line argument for executing your command.

Tuesday, February 3, 2009

Getting organized in plain text

Intro to Hungarian education

It's been February for three days already, which means only three or four months left until the school-leaving exams (depending on how you count it). That means very little time for blogging - or anything, really. But it also means I have to prepare for the oral exams, preparing lots of notes.

In case the Hungarian education system is foreign to you (he-he, that was a pun, laugh up already), here's what it comes down to. We get a bunch of titles 4-5 months before the exams (about twenty in one subject). Then at the exam we get one of the titles at random and have to talk about that one. That's it - if it was the only title you knew, good for you. If it was the only one you didn't know - well, that sucks.

If you prepare the topic and learn it word for word, it should be perfect (if you prepared it right of course). So that means lots of typing (or hand-writing, but that's naturally out of the question). I did the first ten or so topics with LaTeX - it looked nice, but I lost the source due to a hard-drive crash. And anyway, LaTeX for notes? WTH.

Org-mode to the rescue

Org-mode, supposedly distributed with Emacs (but still see orgmode.org) is written for just this - taking notes and writing lists. Of course it's much more than that. Here are some of the features that come to mind. The org-mode manual details them.

While reading below, keep this in mind: all this is stored in plain old text. No fancy markup. All the functionality comes from structures that likely appear in hand-written notes and some major elisp wizardry.

So an appetizer: org-mode gives you unordered lists and ordered lists. It gives you unlimited depth headings with folding. It gives you tables with - hold tight - spreadsheet-like features according to the manual. I say that should be proper spreadsheets. As a matter of fact, you can use elisp code when computing results - so you could run an Emacs in a cell ;)

You get TODOs with two states by default (TODO and DONE), which can be customized to as many as you like, globally or per file. TODOs can also be prioritized, with three levels be default. Deadlines and scheduled start dates for the TODO tasks. Why set these? 'Cause org-modes integrates with the Emacs calendar. Automatically display how many / what percent of the TODOs under a heading are done. BTW, 'done' means "is in a state that's considered to mean done" - the state itself can be anything from LEARNED to KILLED to CHEESE-BURGER-WITH-SPINACH-SALAD. Also checkboxes as light-weight TODO items. Don't you love ASCII checkboxes?

You can store your stuff in as many files as you want, then place hyperlinks to the files in the appropriate places. Of course you can make links to anything Emacs can open - that means reference PDFs, images, archives, whatever you need. Oh, and websites, of course.
All the files can then be processed together to get an 'agenda', with the TODOs scheduled or deadline'd on the given day/week.

Org-mode also exports org files to HTML, LaTeX (and therefore Postscript and PDF), and iCalendar for timestamped entries. I could be writing this in org-mode and exporting to HTML. I'm not, but I could be - and you'd never know :)

Finally, some links

If you wanna jump right in: a list of tutorials
Org-mode homepage: orgmode.org
Org-mode manual

Have fun!