Two Gnus tricks

I’ve added a couple of tweaks to my Gnus config lately. Nothing earth-shattering, but in both cases i was writing my own elisp for something that was already in there. So, i’ve thought i’d share them and, maybe, save you the trouble.

The first one is a quickie, and you probably know about it; but for some reason it took me ages to discover the correct configuration knob. When you reply a mail, emacs will use the value of user-mail-address to compose the From: header. One can also tweak gnus-posting-styles to change the address on a per group basis. But what i really wanted was to use the address in the mail i was replying to. I was writing a hook to that effect when i found the variable to set to accomplish it: message-alternative-mails. Here’s how i set it up:

    (setq message-alternative-emails
        (regexp-opt '("" "" "")))

Worked like a charm. Now for the second one.

As i’ve mentioned in some post before, Gnus let’s you customise the summary line to your heart’s content by tweaking the variable gnus-summary-line-format. I normally use emacs in a maximized urxvt terminal, so i’ve got plenty of room in my summary lines. One thing i wanted to add is the message’s date in a) my time zone and b) human readable form (you know, something like ‘Today, 22:33’ or ‘Yesterday, 02:44’). I only knew two format directives showing a date (%d and %D), but neither fulfilled my wishes. So i started coding my own, but halfway discovered that Gnus already comes with a custom one, called user-date. You use it by inserting %&user-date; in the line format string. It works in conjunction with a configuration stored in gnus-user-date-format-alist, which contains a lists of pairs. The first member of the pair is the age of the message, the second a time format string for displaying the date of messages that old. You’ll understand it better with an example, taken from my current configuration:

    (setq gnus-user-date-format-alist
          '(((gnus-seconds-today) . "Today, %H:%M")
            ((+ 86400 (gnus-seconds-today)) . "Yesterday, %H:%M")
            (604800 . "%A %H:%M") ;;that's one week
            ((gnus-seconds-month) . "%A %d")
            ((gnus-seconds-year) . "%B %d")
            (t . "%B %d '%y"))) ;;this one is used when no other does match

    (setq gnus-summary-line-format
      (concat "%U%R %~(pad-right 2)t%* %uj %B%~(max-right 30)~(pad-right 30)n  "
              "%~(max-right 90)~(pad-right 90)s %-135=%&user-date;\n"))

I’ve copied my whole line format so that you can see, in addition, how i manage to keep things aligned in a frame around 180 columns wide. For details on the %uj directive, see this previous post.

Posted in Gnus. 2 Comments »

Numbered links in emacs-w3m

I’ve been trying conkeror as my secondary browser for a while, and i really like it. It has a much smaller memory footprint than Firefox, and it doesn’t take ages to start up. It’s also nicely hackable and extensible (using javascript), and it comes with some interesting functionality, available out of the box. For instance, external editor support or link numbering: pressing ‘f’ numbers all links in the page and you enter a link number to follow it.

As it happens, recent (as in CVS 1.4.4) versions of emacs-w3m offer a similar functionality in the w3m-lnum package. M-x w3m-link-numbering-mode toggles a minor mode showing link numbers on an overlay, and M-n M-x w3m-move-numbered-anchor, where n is the link number, moves the pointer to the desired link. Providing conkeror’s
more handy functionality is then a matter of a few elisp lines:

  (require 'w3m-lnum)
  (defun jao-w3m-go-to-linknum ()
    "Turn on link numbers and ask for one to go to."
    (let ((active w3m-link-numbering-mode))
      (when (not active) (w3m-link-numbering-mode))
          (w3m-move-numbered-anchor (read-number "Anchor number: "))
        (when (not active) (w3m-link-numbering-mode)))))

  (define-key w3m-mode-map "f" 'jao-w3m-go-to-linknum)

Happy browsing!