Friday, September 3, 2010

Gnus group line pretty printing with UNREAD indicators

The following code assigns a unique read/unread face to the pertinent parts of the gnus group lines in the *Group* buffer. use %ug in your gnus-group-line-format and %s in your gnus-summary-line-format.

Here is an example screenshot

(setq rgr/server-name-maps
'(("RI" . "Private")
("SH" . "Work")
("FR" . "Friends")
("KL" . "Sports")
("HA" . "Fun")
("GM" . "Gmane")
("GN" . "Gnu")
("" . "Unknown")

(copy-face 'default 'my-subject-face)
(copy-face 'default 'my-group-face)
(copy-face 'default 'my-group-face-unread)
(copy-face 'default 'my-inbox-face)
(copy-face 'default 'my-inbox-face-unread)
(copy-face 'default 'my-group-server-face)
(copy-face 'default 'my-group-server-face-unread)
(copy-face 'default 'my-unread-count-face)
(copy-face 'default 'my-unread-count-face-unread)

(copy-face 'default 'my-topic-empty-face)
(copy-face 'default 'my-topic-face)

(setq gnus-topic-line-format "%i[ %u&topic-line; ] %v\n")

(defun rgr/unread-face (f)
(intern (if (> (string-to-number gnus-tmp-number-of-unread) 0) (concat f "-unread") f)))

;; this corresponds to a topic line format of "%n %A"
(defun gnus-user-format-function-topic-line (dummy)
(let ((topic-face (if (zerop total-number-of-articles)
(format "%s %d" name total-number-of-articles)
'face topic-face)))

(defun gnus-user-format-function-s (header)
(propertize (mail-header-subject header) 'face 'my-subject-face 'gnus-face t))

(defun gnus-user-format-function-g (headers) ;; gnus-group-line-format use %ug to call this func! e.g "%M%S%p%P%(%-40,40ug%)%-5uy %ud\n"
;; split full group protocol-server:group into three parts.
(string-match "\\(^.*\\)\\+\\(.*\\):\\(.*\\)" gnus-tmp-group)
;; map the first two letters of the server name to a more friendly and cuddly display name
(let* ((match-ok (match-string 2 gnus-tmp-group))
(server-key (if (null match-ok) nil (upcase(substring match-ok 0 2)))))
(if (zerop (length server-key))
;; construct new group format line with a small envelope taking the place of any INBOX
(format "%-8s" (cdr (assoc server-key rgr/server-name-maps)))
'face (rgr/unread-face "my-group-server-face") 'gnus-face t)
" - "
(if (string-match "INBOX" (match-string 3 gnus-tmp-group) )
(propertize "\x2709" 'face (rgr/unread-face "my-inbox-face") 'gnus-face t)
(propertize (match-string 3 gnus-tmp-group) 'face (rgr/unread-face "my-group-face") 'gnus-face t) )))))

(defun gnus-user-format-function-j (headers)
;; prefix each post depending on whether to, cc or Bcc to
(let ((to (gnus-extra-header 'To headers)))
(if (string-match rgr-mails to)
(if (string-match "," to) "~" "»")
(if (or (string-match rgr-mails
(gnus-extra-header 'Cc headers))
(string-match rgr-mails
(gnus-extra-header 'BCc headers)))
" "))))

(setq gnus-user-date-format-alist
;; Format the date so we can see today/tomorrow quickly.
;; See for the original.
((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

(defun gnus-user-format-function-y (headers)
(if (string-match "^nnfolder" gnus-tmp-group)
(propertize (concat "" gnus-tmp-number-of-unread "") 'face '(rgr/unread-face "my-unread-count-face") 'gnus-face t)))

No comments:

Post a Comment