July 20, 2006

Emacs BBDB magic: Greeting people with nicknames

July 20, 2006 - Categories: emacs

I use Gnus to read my mail within the Emacs text editor. One of the advantages of using a mail client that's infinitely programmable is that you can add all sorts of little tweaks to it. Gnus can be integrated with Emacs' Big Brother Database (BBDB), a semi-structured text database in which I store all sorts of weird notes. This little hack takes the nick field of the database and automatically inserts a greeting. If someone signs himself as Mikong, I should call him that instead of Joseph Michael. Similarly, I sign my messages as Sacha, not Sandra Jean. This little tidbit makes it easier to remember to call people by their nicknames.

(defun sacha/gnus-add-nick-to-message ()
  "Inserts \"Hello, NICK!\" in messages based on the recipient's nick field."
    (let ((bbdb-get-addresses-headers (list (assoc 'recipients bbdb-get-addresses-headers)))
      (setq nicks
            (delq nil
                  (mapcar (lambda (rec) (bbdb-record-getprop rec 'nick))
                           (bbdb-get-addresses nil gnus-ignored-from-addresses 'gnus-fetch-field)
      (goto-char (point-min))
      (when (and nicks
                 (re-search-forward "--text follows this line--" nil t))
        (forward-line 1)
        (insert "Hello, "
                (mapconcat 'identity nicks ", ")

(defadvice gnus-post-news (after sacha activate)

On Technorati: , , ,

Random Japanese sentence: 虎を大きな猫というなら、同じように猫を小さな虎といってもよい。 You may as well call a cat a small tiger as call a tiger a big cat.

Pimp My Emacs

July 20, 2006 - Categories: emacs, pimpmyemacs

Along the lines of TV shows like Pimp My Ride, I'm thinking of regularly blogging something along the lines of Pimp My Emacs. For those readers who haven't had to listen to me bubble for hours on end about this text editor / way of life, Emacs is ostensibly a program that you use to edit text files. Right. But because it's insanely programmable, there are all sorts of interesting things for it, like more than five ways to read one's e-mail.

Watch for it on Technorati with tags emacs or pimpmyemacs, or subscribe to http://feeds.feedburner.com/pimpmyemacs . =)

On Technorati: ,