# More Stupid Gnus Hacks

## 1 More Stupid Gnus Hacks

Elsewhere on the site I’ve published some hacks to help make Gmail work a little more smoothly with Gnus. Here I’ll list a few things that I do to make Gnus work the way I wish.

Gnus, like Emacs itself, is highly flexible. It has never happened that I’ve asked myself, “Can I do x-y-z in Gnus?” and found the answer to be in the negative. I doubt there is any other mail or news reader as customizable as Gnus.

That comes at a price. Gnus is filled with obscure commands initiated by obscure keystroke sequences. Gnus is something of an adventure, an exploration, rather than something profoundly simple and intuitive.

Gnus out of the box needed tweaking to do things my way. If you’re an Emacs user and a Gnus user, you’re into tweaking, you practically live for it. So here goes. This is a work in progress and I expect to modify and expand upon it over time.

## 2 Mailing From Web Pages.

If you want Gnus to be invoked on a ’mailto’ link in a web page (in w3m or eww; we’re talking about within Emacs here), I do this.

(setq browse-url-mailto-function 'rjn-browse-url-mailto)

(defvar rjn-mail-subject)
"Fix for url-browse and w3m mailto to work with gnus styles"
;; This still isn't quite right because it assumes the subject is
;; right after the mailto address.
(progn
(setq rjn-mail-subject (replace-regexp-in-string "?subject=" "" rjn-mail-subject))
)
;;; No subject.
(setq rjn-mail-subject nil)
)
;;; Delete supposedly anything after the mailto address.
)


This works for me more or less as you would expect, setting up an email that looks right.

## 3 Using Message Mode

I want to always use message mode. I do not want to use mail mode sometimes and message mode other times. The following code takes care of that.

;;; We're okay with being in message mode rather than mail mode.
(setq compose-mail-user-agent-warnings nil)

;;; Make 'mail' shortcut use gnus-group-mail. May not be necessary
;;; with the 'defalias' above?
(define-key global-map "\C-xm" 'gnus-msg-mail)


## 4 Forwarding Mail

Forwarding email in Gnus is a little odd. There is a key sequence, C-c C-f, which invokes gnus-summary-mail-forward, but it only works in the summary buffer. If you’re within an email (in Gnus terms everything is an ’article’), you can give the command M-x message-forward. (Don’t try that in a summary buffer, though! You’ll end up mailing the summary buffer, not the email in question.) But that’s inconsistent.

Actually, gnus-summary-mail-forward also works in the article buffer! It just isn’t tied to a nice keystroke by default. So why not use \C-c\C-f also?

Now, gnus-summary-mail-forward by default includes just about every last mail header and defaults to multipart. In general I didn’t want this. I want to forward a message in-line, with \C-c\C-f, with only a few select headers.

The code below does this, but creates its own problem. If you have a mulitpart message (with attachments) the attachments won’t be forwarded. You’ll have to use the M-2 prefix, that is M-2\C-c\C-f, which makes the whole message multipart (not just the attachments). I have to yet to figure out how to put the message inline and make the attachments a MIME part. Suggestions welcome.

;;; There is no forward key in the article buffer, so make one.
;;; Oddly gnus-summary-mail-forward seems to work correctly.
(define-key gnus-article-mode-map "\C-c\C-f" 'gnus-summary-mail-forward)

;;; Make summary forwarding behave a little better. This also makes
;;; message forwarding and summary forwarding consistent. But note that
;;; if you wish to forward an attachment you must use M-2\C-c\C-f.
(setq message-forward-as-mime nil)
(setq message-forward-show-mml nil)


The mime and mml options may not suit you, and you may want a different selection of headers, but all of that is easy to modify.

## 5 Wrapping Up Gnus on Emacs Exit

If we close Emacs without first closing Gnus, we may not get a server update if we’re using IMAP to fetch mail directly into Gnus. Here’s a possible fix; it works for me.

;; Add an exit hook. Is this a good idea? Mostly it is, as we
;; want to close gnus and update stuff every time, but once in a
;; while it causes a hang, when gnus itself is hosed.

(defun exit-gnus-on-exit ()
(if (and (fboundp 'gnus-group-exit)
(gnus-alive-p))
(with-current-buffer (get-buffer "*Group*")
; (let (gnus-interactive-exit)
(setq gnus-interactive-exit 'quiet)
(gnus-group-exit))))


And I like to do this to avoid prompting.

(setq gnus-expert-user t)


## 6 Catching Up in All Groups

I like to keep “caught up” on unread mail, and there’s often a lot of stuff I don’t read. In the group buffer you can easily mark each group as individually caught up with ’c’. But how about catching up all groups at once? This is how I do that.

(defun gnus-catchup-irrelevant ()
"Catchup displayed groups."
(interactive)
;; Seems to work in group or topic mode.
;; Setting gnus-expert-user to t recommended.
;; If you have more than 100 groups displayed, rethink your
;; approach, or change the number below.
(with-current-buffer "*Group*"
(message "Clearing groups...")
(goto-char (point-min))
(gnus-group-catchup-current 100)
(message "...done.")))

(define-key gnus-group-mode-map "K" 'gnus-catchup-irrelevant)


Now, in the group buffer, ’K’ for ’katchup’ does a global catchup. (’C’ is already in use. Finding a free key in Gnus? Not so easy.)

Email: bobnewell@bobnewell.net

Created: 2018-03-07 Wed 14:02

Validate