I’ve been using Gnus running inside GNU Emacs for my main email and news reader for a few weeks now. It has been a rather pleasing ride so far, and I am only now beginning to appreciate the infinite configurability and customizability that a Lisp based mailer offers.
One of the first things I wanted to tweak was the default keys for expiring and editing articles. A little background information may be useful before we go into the details of how the default keys can be tweaked.
Gnus uses a very newsreaderly method of handling your email messages too. This means that, by default, no email messages will ever be deleted from your local email folders. This is an important detail, so it’s worth repeating: Gnus will never delete email messages. Unless you ask Gnus to delete them forever. The method of asking Gnus to delete a message forever is to “expire” the relevant message/article. An article can be expired in the summary buffer of a mail or news group by hitting “
Some message groups support article editing too. The “nnml” type of message groups does, and it’s a very handy feature too. I often have to edit email headers in email messages that use the wrong charset, for example. The default key for editing an article in Gnus is “
After a few weeks of using Gnus for my email, I realized that I type “
E” to expire articles far more often than I type “
e” to edit articles. When I say “far more often”, I mean really far more often, as in several hundred of times per day vs. maybe once or twice. This prompted me to look into the manual of Gnus for a simple way to swap the behavior of these two keys. Having to hold down “
Shift-E” instead of merely pressing “
e” tends to get a bit old after the first few thousands of times you have reached for the shift modifier key.
The solution was, as is very commonly the case with the excellent manual of Gnus, already there. It was just waiting for me to discover it, in section 3.7.5 (Generic Marking Commands):
3.7.5 Generic Marking Commands
Some people would like the command that ticks an article (“
!“) go to the next article. Others would like it to go to the next unread article. Yet others would like it to stay on the current article. And even though I haven’t heard of anybody wanting it to go to the previous (unread) article, I’m sure there are people that want that as well.
Multiply these five behaviors with five different marking commands, and you get a potentially complex set of variable to control what each command should do.
To sidestep that mess, Gnus provides commands that do all these different things. They can be found on the “
M M” map in the summary buffer. Type “
M M C-h” to see them all—there are too many of them to list in this manual.
While you can use these commands directly, most users would prefer altering the summary mode keymap. For instance, if you would like the “
!” command to go to the next article instead of the next unread article, you could say something like:(add-hook 'gnus-summary-mode-hook 'my-alter-summary-map) (defun my-alter-summary-map () (local-set-key "!" 'gnus-summary-put-mark-as-ticked-next))
or(defun my-alter-summary-map () (local-set-key "!" "MM!n"))
That’s it. The sample gnus-summary-mode-hook was all I needed to see. Then I added in my own personal
~/.gnus startup file my own hook:
;; Swap the default behavior of the 'e' and 'E' keys in the group summary ;; buffers. Using a shifted key to expire articles is somewhat painful. ;; I expire articles far too often, but I only very occasionally edit the ;; contents of email articles. So it should be easier to expire them. (add-hook 'gnus-summary-mode-hook 'keramida-alter-summary-map) (add-hook 'gnus-article-prepare-hook 'keramida-alter-summary-map) (defun keramida-alter-summary-map () (local-set-key "e" "MMen") (local-set-key "E" 'gnus-summary-edit-article))
To apply the changes I didn’t even have to restart Emacs or Gnus. I evaluated the expressions right there, inside my
~/.gnus buffer, by typing “
C-x C-e“, and that’s all. They were instantly part of my running Emacs and Gnus session.
Now I can expire articles by simply hitting “
e“, and for the rare occasion that I have to manually edit an article’s headers or body, “
E” is always there too :-)
Yay for the astonishing configurability of Gnus!
Update (06:38am): I didn’t really like the mapping of “
e” to “
MMen” very much, because it means the behavior of the “
e” depends on whatever happens to be mapped to that key combination. After reading the source of Gnus a bit, I rewrote the hook function to look like this:
(defun keramida-alter-summary-map () (local-set-key "e" (lambda (n) (interactive "p") (with-current-buffer gnus-summary-buffer (gnus-summary-put-mark-as-expirable-next n)))) (local-set-key "E" 'gnus-summary-edit-article))
This works equally well in gnus-summary-mode and gnus-article-mode. I am a bit unsure about the (interactive) property of an anonymous lambda function, so I’ve posted a question to the gnu.emacs.gnus newsgroup, asking if this is considered bad style. Let’s see what other, more experienced Gnusers have to say…