Sams Teach Yourself Emacs in 24 Hours
Hour 21: Advanced Gnus
Are you ready to see why I constantly hail Gnus as being the most powerful mail and news reader? In this hour you will see some of the really cool things one can do with Gnus. These include
Scoring--This is a mechanism with which you can tell Gnus about authors you think say interesting things, and about subjects that you very much dislike, and that you think messages longer than 100 lines are way out.
This hour also helps you customize some of the minor things that can be annoying if they don't work the way you want them to. Hey, this is Emacs--almost everything can be customized!
Start with the Group buffer. In this section you will see how you can organize your mail groups into topics, how you can customize the group line to show only the information you are interested in, and how you may make Gnus sort your incoming mail into a set of groups.
After you learn how to subscribe to groups and you find out how easy it is to make Gnus find the messages in a group that are of special interest to you, you will suddenly find that you are subscribed to 20 different newsgroups, and perhaps as many mailing lists.
The problem then is to find the group you want to read messages from. Fortunately, there's a solution in Gnus to this problem-- topic. Topic is like a directory structure where each topic can contain a number of groups and subtopics. Furthermore you can fold topics so their content is hidden. This can be seen in Figure 21.1. (Note that this is from my personal setup, and I've changed the group lines; you will shortly learn how to do that.)
All the topic commands are available from the Topics menu item, but before you can do anything with topics, you need to enable topics, which you do by pressing t.
Now you can add new topics by pressing T n. Gnus queries you in the minibuffer for the name of the topic, and inserts it as the last element under the topic, which point currently is within. If this is not the correct location for the topic, you can move it to another location by killing it with C-k and pasting it in at another location with C-y. If you paste a topic at the end of another topic, it will be located at the same level as the other topic. If your intention was that it should have been a subtopic of this other topic, simply press the Tab key, which pushes the topic one level down. This can be seen in Figures 21.2 and 21.3.
There are a few different ways to move groups around, but the easiest way is simply to kill them with C-k and then paste them in again at another location using C-y. You can kill several groups after each other. The order in which they are pasted in is in the reverse order they have been killed--that is, the last one killed is the first one pasted in.
You can collapse and expand topics by pressing the Enter key when point is on top of them, or by pressing the second mouse button upon them.
Once you have set up topics, you always want to have them enabled, right? You can achieve this by inserting the following into your .Gnus file:
(add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
Gnus has a few additional servers, called doc-server and virtual-server. There is no need for you to think about these features as servers in general, but you will see them listed as servers in different places in Gnus, so it is convenient for you to know.
The doc-server is used to tell Gnus to read a file as a group. This is convenient if you have an old mailbox that you just want to peek into. To create a doc-group, type G-f. Gnus now asks you for the name of the file and creates a group from this file.
If you want to copy any of the messages from this file to any of your existing groups, then you can press B c. Gnus then asks you for the group to copy this message to. You can also mark a number of messages by pressing # and copy them all in one go.
If, on the other hand, you want the messages handled as if they have just arrived, press B r. This might be of interest if you have set Gnus up to sort your incoming mail into several different groups (this is discussed in the section "Sorting Incoming Mail Using Gnus").
When you are finished with the group, kill it using C-k.
Sometimes different newsgroups exist that more or less cover the same topic, or it might at least seem so from your point of view. Examples of this include
comp.emacs and gnu.emacs.help
alt.fan.depeche-mode and alt.music.depeche-mode
The existence of two groups might have the following disadvantages to you:
You have to read and manage two groups. This is, however, not a big issue, because you could expect twice as many messages if there were one common group.
If someone posts a question to both groups, it can be answered separately in each of the groups. This means that you have to go to both groups to see an answer. This is worse than it sounds! For each thread of answers, you have to get into context before you can read the answers. Getting into context means that you have to understand the question. With answers located in both groups, you have to get into context twice, which can give you a substantial amount of overhead.
The solution to this problem is to merge the two groups into one group. This is done using a virtual group.
This task shows you how to create a virtual group with the messages from comp.emacs and gnu.emacs.help. Follow these steps:
1. Subscribe to the two groups as usual.
2. Create a virtual group by pressing G V. Gnus now asks for the name of the group. Call it Emacs. Now a virtual group exists, but it does not contain any messages, because no groups are attached to it.
3. Move point to each of the two Emacs groups, and for each of them press G v. Gnus now asks you which virtual group the current group should be attached to. Type the name you gave it previously.
4. Now a virtual group exists. It contains all the messages from both groups, and you will never see that it is not one group, but in fact two. The two original groups are, however, also still visible. To remove them, you must unsubscribe them, but not kill them. That is press u when point is on the original groups.
The same method may also be used to join your outgoing and incoming
mail groups together to one, where you can see both the letters you sent and
the letters which you received.
There is one caveat with virtual groups, which is that when you want to post a new message to one of the groups that the virtual group contains, you have to go to the original groups and post the message from there. This, however, doesn't apply to followups to the messages in the groups.
The group lines (those showing a group in the Group buffer), the topic lines, and the summary lines (those showing the messages in the Summary buffer) can all be configured. This way you can make Gnus include just the information you care about. If you, for example, do not want to see the select method (for example, nnfolder:), you can configure the group line not to show this. Likewise you might want to know how many messages a given group contains--that is, not only the number of unread messages (which is the default), but the total number of messages.
The group line is configured using the variable gnus-group-line-format. This variable must have a string assigned to it that shows the information you want. In this string you can include placeholders, each of which are expanded to show information about the group in question. The placeholders are specified with a percent character ( %), and a character specifying which placeholder it is. The default value of the group line can be seen in Figure 21.4.
All the specifics available for this variable can be seen in the description of the variable. That is, press C-h v. (describe-variable) and type gnus-group-line-format. If you do not want to see the select method, but only the name of the group, you can insert the following into your .Gnus file:
(setq Gnus-group-line-format "%M%S%p%P%5y: %(%G%)%l\n")
Whenever Gnus finds new mail, it moves it to a location that is private for Gnus. During this mail transferring, Gnus can also sort the mail into several different groups. This is useful if you are subscribed to a number of mailing lists and do not care to use the time to set up an external program to sort mail for you (such as procmail).
The configuration of mail sorting is done with the variable nnmail-split-methods. The following is a configuration where mail is split in three different groups:
(setq nnmail-split-methods '( ("debian-devel" "^To:.*firstname.lastname@example.org") ("postcard" "^Subject:.*Postcard:") ("Miscellaneous" "") ))
The previous code is a Lisp expression, but you should be able to figure out how to use it without knowing anything about Lisp. The three lines in the middle are the ones that say which mail should go where. Each line must start and end with a parenthesis. Between the parentheses, two strings limited by quotation marks are listed. The first string names the mail folder that mail should be put in if the regular expression, given as the second string, matches.
The regular expression of the last line should always be the empty string to ensure that there always is at least one regular expression that matches. The letter is always placed in the group associated with the first regular expression that matches the letter. Thus each letter is always located in only one group!
Gnus can in fact do more powerful mail sorting than the previous example indicates, but in case you need more power, I suggest that you use a tool, such as procmail, developed specifically for this task.
Note - If you want to use procmail, it might be a good idea to use The Dotfile Generator to configure the .procmailrc file. This file specifies how procmail should sort the mail. Information about The Dotfile Generator is available from its home page, located at http://www.imada.ou.dk/~blackie/dotfile/.
Sams Teach Yourself Emacs in 24 Hours
Hour 21: Advanced Gnus
© Copyright Macmillan USA. All rights reserved.