chiark / gitweb /
dot/gnus.el: Don't skip around wildly in the `Group' buffer.
[profile] / dot / gnus.el
1 ;;; -*- mode: emacs-lisp; coding: utf-8 -*-
2 ;;;
3 ;;; GNUS configuration
4 ;;;
5 ;;; (c) 2009 Mark Wooding
6 ;;;
7
8 ;;;----- Licensing notice ---------------------------------------------------
9 ;;;
10 ;;; This program is free software; you can redistribute it and/or modify
11 ;;; it under the terms of the GNU General Public License as published by
12 ;;; the Free Software Foundation; either version 2 of the License, or
13 ;;; (at your option) any later version.
14 ;;;
15 ;;; This program is distributed in the hope that it will be useful,
16 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 ;;; GNU General Public License for more details.
19 ;;;
20 ;;; You should have received a copy of the GNU General Public License
21 ;;; along with this program; if not, write to the Free Software
22 ;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
23
24 ;;;--------------------------------------------------------------------------
25 ;;; General Gnus preferences.
26
27 ;; Divide the main groups list by topics.
28 (add-hook 'gnus-group-mode-hook 'gnus-topic-mode)
29 (setq gnus-subscribe-newsgroup-method 'gnus-subscribe-topics)
30
31 ;; Use hacky movemail program to move mail.
32 (setq mail-source-movemail-program "~/bin/movemail-hack")
33
34 ;; Don't force use of a full window.
35 (setq gnus-use-full-window nil)
36
37 ;; Display a slrn-like tree view in the summary window.
38 (setq gnus-use-trees nil)
39 (setq gnus-summary-make-false-root 'dummy)
40 (setq gnus-summary-line-format "%U%R%z%4L %(%[%-16,16f%]%): %B %s\n"
41       gnus-summary-dummy-line-format "        %(%[----------------%]%): * %S\n")
42 (setq gnus-sum-thread-tree-root ">"
43       gnus-sum-thread-tree-false-root ">"
44       gnus-sum-thread-tree-single-indent "="
45       gnus-sum-thread-tree-indent "  ")
46 (if (memq (coding-system-get (terminal-coding-system) 'mime-charset)
47           '(nil utf-8))
48     (setq gnus-sum-thread-tree-leaf-with-other "├─>"
49           gnus-sum-thread-tree-vertical        "│ "
50           gnus-sum-thread-tree-single-leaf     "╰─>")
51   (setq gnus-sum-thread-tree-leaf-with-other   "|->"
52         gnus-sum-thread-tree-vertical          "| "
53         gnus-sum-thread-tree-single-leaf       "`->"))
54
55 ;; Sort threads in a useful way.
56 (setq gnus-thread-sort-functions
57       '(gnus-thread-sort-by-number
58         gnus-thread-sort-by-subject
59         gnus-thread-sort-by-total-score))
60
61 ;; Configure the crypto.
62 (setq mm-verify-option 'known
63       mm-sign-option 'guided
64       mm-decrypt-option 'never)
65
66 ;; Tracking available groups.  These should work for sane servers, but maybe
67 ;; they'll need hacking in the local file.
68 (setq gnus-save-killed-list nil
69       gnus-check-bogus-newsgroups nil
70       gnus-read-active-file 'ask-server)
71
72 ;; Don't skip unread groups.
73 (setq gnus-group-goto-unread nil
74       gnus-summary-next-group-on-exit nil)
75
76 ;; Use one article buffer per group.
77 (setq gnus-single-article-buffer nil)
78
79 ;; Don't expand threads on initial opening.
80 (setq gnus-thread-hide-subtree t)
81
82 ;; Don't use strange icons instead of traditional smileys.
83 (setq gnus-treat-display-smileys nil)
84
85 ;; Fairly large numbers of articles are OK; don't bother warning me.
86 (setq gnus-large-newsgroup 500)
87
88 ;; When splitting articles, crossposting is a reasonable thing to do.
89 (setq nnimap-split-crosspost t)
90
91 ;; We may have the misfortune to talk to an Exchange server.
92 (setq imap-enable-exchange-bug-workaround t)
93
94 ;; Save articles in mbox format by default, of course, and save an entire
95 ;; batch with the same name.
96 (setq gnus-prompt-before-saving t
97       gnus-default-article-saver 'gnus-summary-save-in-mail)
98
99 ;; Clean up properly when closing the summary.
100 (defadvice gnus-summary-exit (before mdw-kill-debris compile activate)
101   (gnus-summary-expand-window))
102
103 ;; Configure article display a bit.
104 (defun mdw-gnus-article-setup ()
105   (setq truncate-lines nil
106         truncate-partial-width-windows nil
107         word-wrap t
108         wrap-prefix (concat (propertize "..." 'face 'mdw-ellipsis-face)
109                             " ")))
110 (add-hook 'gnus-article-mode-hook #'mdw-gnus-article-setup)
111
112 ;; Don't expire articles on selection if they're alread read.  This provides
113 ;; a handy way to prevent expiry, and actually forcing expiry isn't
114 ;; significantly harder.
115 (remove-hook 'gnus-mark-article-hook
116              'gnus-summary-mark-read-and-unread-as-read)
117 (add-hook 'gnus-mark-article-hook 'gnus-summary-mark-unread-as-read)
118
119 ;; Leave an oubliette level 7 for broken things which look like mailboxes.
120 ;; Otherwise Gnus keeps on resurrecting them and later realising that they're
121 ;; bogus.
122 (setq gnus-level-unsubscribed 6)
123
124 ;; Reconfigure the `nnmail-split-fancy' syntax table to be less mad.
125 (setq nnmail-split-fancy-syntax-table
126       (let ((table (make-syntax-table)))
127
128         ;; This is from upstream.  I don't know what it's for.
129         (modify-syntax-entry ?% "." table)
130
131         ;; Email addresses are often wrapped in `<...>', so don't consider
132         ;; those to be part of the address.
133         (modify-syntax-entry ?< "(>" table)
134         (modify-syntax-entry ?> ")<" table)
135
136         ;; Email addresses definitely contain `.'.
137         (modify-syntax-entry ?. "_" table)
138
139         ;; Done.
140         table))
141
142 ;;;--------------------------------------------------------------------------
143 ;;; Magic for sending mail the correct way.
144
145 (defvar mdw-send-mail-alist nil
146   "An alist containing ways of sending email.
147 The keys are symbols naming mail-sending methods.  The values are
148 alists mapping Lisp variable names to values which will be bound
149 around a call to the underlying `send-mail-function'.  See
150 `mdw-message-send-it'.")
151
152 (defvar mdw-guess-send-mail-alist nil
153   "An alist for guessing the right way to send mail from a `From' address.
154 The keys are (Emacs-style) regular expressions.  The values are
155 strings naming mail-sending methods, to be used if there is no
156 `mdw-send-mail-header-name' mail header.")
157
158 (defvar mdw-send-mail-header-name "X-mdw-Send-Mail"
159   "Mail header used to override the mail-sending method.
160 If a header with this name exists, then `mdw-message-send-it'
161 will look its value up in `mdw-send-mail-alist' to find out how
162 to send the message.  The idea is that you can set this header
163 from `gnus-posting-styles'.  The header will be stripped on
164 sending.")
165
166 (defvar mdw-default-send-mail-method nil
167   "The name of the default mail-sending method.")
168
169 (defun mdw-message-send-it ()
170   "Send mail using the appropriate mail sending method.
171 Firstly, a mail-sending method name is determined.  If
172 `mdw-send-mail-header-name' has a non-nil value, and a header
173 with this name exists in the message being sent, then its value
174 is used as the name.  Otherwise, the email address from the
175 `From' header is matched against the named of the association in
176 `mdw-guess-send-mail-alist', and if any of them match then the
177 corresponding value is used as the name.  Otherwise, the value of
178 `mdw-default-send-mail-method' is used.
179
180 The name is then looked up in `mdw-send-mail-alist' to find an
181 alist of temporary variable bindings; an error is reported if no
182 matching entry is found.  The variables are temporarily bound to
183 their corresponding values, and the (possibly freshly rebound)
184 `send-mail-function' is invoked with no parameters.
185
186 If the method name is `nil', then `send-mail-function' is simply
187 invoked without doing anything else very special.  This can
188 therefore be left as a useful default, if it's generally the
189 right thing."
190
191   (let* ((method-name
192           (or
193
194            ;; Firstly, if there's an explicit header in the message, then
195            ;; we'd better use that.
196            (let ((method (message-fetch-field mdw-send-mail-header-name)))
197              (and method (intern method)))
198
199            ;; Look up the sender's address in the guess list.
200            (let* ((sender (some #'message-fetch-field
201                                 '("resent-sender" "resent-from"
202                                   "sender" "from")))
203                   (addr (cadr (mail-extract-address-components sender)))
204                   (alist mdw-guess-send-mail-alist)
205                   assoc)
206              (catch 'found
207                (while alist
208                  (setq assoc (pop alist))
209                  (when (string-match (car assoc) addr)
210                    (throw 'found (cdr assoc))))
211                nil))
212
213            ;; Otherwise use the default.
214            mdw-default-send-mail-method))
215
216          (method (and method-name
217                       (let ((assoc (assq method-name mdw-send-mail-alist)))
218                         (if assoc (cdr assoc)
219                           (error "Unknown send-mail method `%s'."
220                                  method-name))))))
221
222     ;; Bind the appropriate variables.
223     (progv
224         (mapcar #'car method)
225         (mapcar #'cdr method)
226
227       ;; Make a copy of the buffer and strip out our magic header.  (If the
228       ;; message send fails, it would be annoying to have lost the magic
229       ;; token which tells us how to retry properly.)
230       (let ((buf (current-buffer)))
231         (with-temp-buffer
232           (insert-buffer buf)
233           (message-remove-header mdw-send-mail-header-name)
234           (funcall send-mail-function))))))
235
236 (setq message-send-mail-function 'mdw-message-send-it)
237
238 ;;;--------------------------------------------------------------------------
239 ;;; Local configuration.
240
241 ;; Fetching news from the local news server seems sensible.
242 (setq gnus-select-method
243       (let ((server (mdw-config 'nntp-server)))
244         (if server
245             `(nntp ,server)
246           '(nnnil ""))))
247
248 ;; Now load a local configuration file.
249 (load "~/.gnus-local.el")
250
251 ;;;----- That's all, folks --------------------------------------------------