1 ;;; eh-gnus-common.el --- Tumashu's gnus configuation file -*- lexical-binding: t; -*-
4 ;; Copyright (c) 2008-2009, Andy Stewart
7 ;; Author: Andy Stewartf <lazycat.manatee@gmail.com>
8 ;; Feng Shu <tumashu@163.com>
9 ;; URL: https://github.com/tumashu/emacs-helper
12 ;; This file is not part of GNU Emacs.
16 ;; This program is free software; you can redistribute it and/or
17 ;; modify it under the terms of the GNU General Public License
18 ;; as published by the Free Software Foundation; either version 3
19 ;; of the License, or (at your option) any later version.
21 ;; This program is distributed in the hope that it will be useful,
22 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ;; GNU General Public License for more details.
26 ;; You should have received a copy of the GNU General Public License
27 ;; along with GNU Emacs; see the file COPYING. If not, write to the
28 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
29 ;; Boston, MA 02110-1301, USA.
34 ;; 这个文件是tumashu个人专用的emacs配置文件,emacs中文用户可以参考。
41 (setq gnus-init-file
"~/gnus/eh-gnus-personal.el")
42 (setq gnus-home-directory
"~/gnus/")
43 (setq gnus-default-directory
"~/gnus/")
44 (setq gnus-directory
"~/gnus/")
45 (setq gnus-article-save-directory
"~/gnus/Saved/")
46 (setq message-directory
"~/gnus/Mail/")
47 (setq mm-default-directory
"~/gnus/")
54 (require 'gnus-search
)
64 (require 'ebdb-i18n-chn
)
66 (make-directory "~/gnus/ebdb/" t
)
67 (setq ebdb-sources
(list "~/gnus/ebdb/default"))
68 (setq ebdb-search-transform-functions
69 (list #'pyim-cregexp-build
))
72 (ebdb-complete-enable)
76 (setq ebdb-gnus-window-size
0.25)
77 (setq ebdb-gnus-auto-update-p
80 (substitute-command-keys
81 (concat "EBDB: `\\[ebdb-mua-update-records]': 更新联系人,"
82 "`\\[ebdb-mua-snarf-article]': Snarf 联系人。"
83 "`\\[ebdb-mua-edit-sender-notes]': 备注联系人。")))
86 (defun eh-ebdb-insinuate-gnus ()
87 (define-key gnus-summary-mode-map
(kbd ";") nil
)
88 (define-key gnus-article-mode-map
(kbd ";") nil
)
89 (define-key gnus-summary-mode-map
(kbd "<f5>") #'ebdb-mua-update-records
)
90 (define-key gnus-article-mode-map
(kbd "<f5>") #'ebdb-mua-update-records
)
91 (define-key gnus-summary-mode-map
(kbd "<f6>") #'ebdb-mua-snarf-article
)
92 (define-key gnus-article-mode-map
(kbd "<f6>") #'ebdb-mua-snarf-article
)
93 (define-key gnus-summary-mode-map
(kbd "<f7>") #'ebdb-mua-edit-sender-notes
)
94 (define-key gnus-article-mode-map
(kbd "<f7>") #'ebdb-mua-edit-sender-notes
))
96 (advice-add 'ebdb-insinuate-gnus
:after
#'eh-ebdb-insinuate-gnus
)
99 (require 'ebdb-message
)
100 (setq ebdb-message-window-size
0.25)
101 (setq ebdb-message-auto-update-p ebdb-gnus-auto-update-p
)
105 ;; Notmuch 使用 Xapian 创建 index, Xapian (version < 1.5) 需要设置下面
108 ;; export XAPIAN_CJK_NGRAM=1
110 ;; Xapian (version >= 1.5) 可以自动识别 CJK, 但要求编译的时候启用
115 ;; notmuch reindex "*"
117 (setq gnus-search-notmuch-program
"notmuch")
118 (setq gnus-search-default-engines
119 '((nnimap . gnus-search-imap
)
120 (nnml . gnus-search-notmuch
)))
122 ;; 如果命令 'notmuch search --format=text --output=files hello' 得到的
123 ;; 一个结果是: '/home/feng/gnus/Mail/mail/misc/9407', 而当前搜索的组名
124 ;; 称是 mail.misc, 那么下面的变量应该设置为
125 ;; "/home/feng/gnus/Mail/". 注意,这个变量设置不对,不显示搜到邮件。
126 (setq gnus-search-notmuch-remove-prefix
127 (expand-file-name message-directory
))
130 (setq nnmail-treat-duplicates
'delete
131 nnmail-split-fancy-match-partial-words t
132 nnmail-mail-splitting-decodes t
133 nnmail-mail-splitting-charset
'utf-8
134 ;; 使用 nnimap 时,不用默认的分类方法。
135 nnimap-split-methods nil
)
137 (setq gnus-keep-backlog
1000) ;启用 backlog 功能,163 和 QQ imap 速度太慢了。
139 ;; 设置一个组的最大 article 数,这个设置对 nnimap 163邮箱很有用,因为
140 ;; 如果没有这个设置,进入 163 INBOX 会卡死 emacs.
141 (setq gnus-newsgroup-maximum-articles
100000)
144 (setq gnus-extract-address-components
145 'mail-extract-address-components
)
148 (setq gnus-message-archive-group nil
)
150 ;; 设置 message-mode 发信的方式,这里默认使用 /usr/sbin/sendmail.
151 ;; 在 `gnus-posting-styles' 中设置 "X-Message-SMTP-Method" 邮件头可以实现
153 (setq message-send-mail-function
'message-smtpmail-send-it
)
155 ;; Message 自动设置 "X-Message-SMTP-Method" 功能。
156 (defun eh-message-server-alist-function ()
157 (let* ((from (cadr (mail-extract-address-components
160 (message-narrow-to-headers-or-head)
161 (message-fetch-field "From")))))
162 (str (replace-regexp-in-string "^.*@" "" from
)))
163 (when (> (length str
) 0)
164 (format "smtp smtp.%s 465 %s" str from
))))
166 (setq message-server-alist
'((eh-message-server-alist-function)))
168 ;; 设置gnus默认编码: 如果常与国外联系,可以设置为utf-8
169 ;; 如果只在本国使用,可以设置为本地编码,比如: gbk
170 (setq gnus-default-charset
'gbk
)
173 (setq gnus-group-name-charset-method-alist
174 '(((nntp "news.newsfan.net") . gbk
)
175 ((nntp "news.cn99.com") . gbk
)))
177 ;; 根据组名称来确定组名称解析使用的编码
178 (setq gnus-group-name-charset-group-alist
182 (setq gnus-group-charset-alist
186 (setq gnus-summary-show-article-charset-alist
192 ;; 邮件MIME类型设置不正确时,gnus的处理方式。
193 (setq gnus-newsgroup-ignored-charsets
194 '(unknown-8bit x-unknown x-gbk
))
196 ;; 设置邮件附件文件名的编码方式以及邮件subject的编码方式
197 (defalias 'mail-header-encode-parameter
'rfc2047-encode-parameter
)
198 (add-to-list 'rfc2047-charset-encoding-alist
'(gbk . B
))
199 (add-to-list 'rfc2047-charset-encoding-alist
'(gb18030 . B
))
202 (setq gnus-agent t
) ; 开启agent
203 (setq read-mail-command
'gnus
) ; 使用gnus阅读邮件
204 (setq mail-user-agent
'gnus-user-agent
) ; 使用gnus发送邮件
205 (setq gnus-inhibit-startup-message t
) ; 关闭启动时的画面
206 (setq gnus-novice-user nil
) ; 关闭新手设置, 不进行确认
207 (setq gnus-expert-user t
) ; 不询问用户
208 (setq gnus-show-threads t
) ; 显示邮件threads
209 (setq gnus-interactive-exit t
) ; 退出时进行交互式询问
210 (setq gnus-use-dribble-file t
) ; 创建恢复文件
211 (setq gnus-always-read-dribble-file t
) ; 读取恢复文件
212 (setq gnus-asynchronous t
) ; 异步操作
213 (setq gnus-large-newsgroup
2000) ; 设置大容量的新闻组默认显示的大小
214 (setq gnus-large-ephemeral-newsgroup nil
) ; 设置临时新闻组默认显示的大小
215 (setq gnus-read-active-file
'some
)
216 (setq gnus-nov-is-evil nil
)
217 (setq gnus-summary-ignore-duplicates t
) ; 忽略具有相同ID的消息
218 (setq gnus-treat-fill-long-lines t
) ; 自动折行
219 (setq message-confirm-send t
) ; 发邮件前需要确认(防止误发)
220 (setq message-kill-buffer-on-exit t
) ; 发送邮件后删除buffer
221 (setq message-syntax-checks
'((sender . disabled
))) ; 语法检查
222 (setq nnmail-expiry-wait
7) ; 邮件自动删除的期限 (单位: 天)
223 (setq nnmairix-allowfast-default t
) ; 加快进入搜索结果的组
224 (setq gnus-use-correct-string-widths t
) ; 使用正确的字符宽度
225 (setq gc-cons-threshold
3500000) ; 加快 gnus 的速度
226 (setq gnus-use-cross-reference t
) ; 开启交叉索引
227 (setq gnus-summary-display-while-building
50) ; 生成 summary 时,每50封显示一下
229 ;; 进入 summer 模式时,禁止自动选择第一个article,
230 ;; 这样设置主要是因为有些 article 下载速度极慢,
232 (setq gnus-auto-select-first nil
)
233 (setq gnus-auto-select-next nil
)
235 ;; 设置 gnus 启动时,组级别大于3的不自动更新。
236 ;; 当你添加了许多速度慢的组时,比如 rss,imap 等,启动速度会相当慢。这时你
237 ;; 可以把它们的组级别设置为大于3的值,这样启动时就不自动更新了。
238 ;; 当你需要更新这些组的时候,使用 "4-g" "5-g" 等快捷键
239 (setq gnus-activate-level
3)
242 (gnus-add-configuration
249 (setq mm-inline-large-images t
)
250 (add-to-list 'mm-attachment-override-types
"image/*")
253 (setq gnus-extra-headers
'(To From
))
254 (setq nnmail-extra-headers gnus-extra-headers
)
255 (setq gnus-summary-gather-subject-limit
'fuzzy
)
256 (setq gnus-summary-make-false-root
'adopt
)
257 (setq gnus-summary-line-format
"%U%R%z %&user-date; %-16,16a %5k%I%B%s\n")
260 (setq gnus-thread-indent-level
0)
261 (setq gnus-summary-same-subject
"")
262 (setq gnus-sum-thread-tree-indent
" ")
263 (setq gnus-sum-thread-tree-single-indent
" ")
264 (setq gnus-sum-thread-tree-root
" ")
265 (setq gnus-sum-thread-tree-false-root
" ")
266 (setq gnus-sum-thread-tree-vertical
" |")
267 (setq gnus-sum-thread-tree-leaf-with-other
" |-> ")
268 (setq gnus-sum-thread-tree-single-leaf
" `-> ")
270 ;; 设置 `gnus-summary-line-format' 中的 %&user-date;
271 (setq gnus-user-date-format-alist
272 '(((gnus-seconds-today) .
" %H:%M")
273 ((gnus-seconds-month) .
" %d日")
274 ((gnus-seconds-year) .
" %m-%d")
278 (add-hook 'gnus-article-prepare-hook
#'gnus-article-date-local
)
281 (add-hook 'gnus-select-group-hook
#'gnus-group-set-timestamp
)
283 (defun eh-gnus-summary-setup ()
285 ;; summary buffer 行距设置
286 (setq line-spacing
5)
292 (local-set-key (kbd "SPC")
295 (gnus-summary-next-page)
296 (move-beginning-of-line 1)))
297 (local-set-key (kbd "C-p")
300 (delete-other-windows)
302 (local-set-key (kbd "C-n")
305 (delete-other-windows)
307 (local-set-key (kbd "<up>")
310 (delete-other-windows)
312 (local-set-key (kbd "<down>")
315 (delete-other-windows)
318 (add-hook 'gnus-summary-mode-hook
#'eh-gnus-summary-setup
)
321 (setq gnus-treat-emphasize t
322 gnus-treat-buttonize t
323 gnus-treat-buttonize-head
'head
324 gnus-treat-unsplit-urls
'last
325 gnus-treat-leading-whitespace
'head
326 gnus-treat-highlight-citation t
327 gnus-treat-highlight-signature t
328 gnus-treat-date-lapsed
'head
329 gnus-treat-strip-trailing-blank-lines t
330 gnus-treat-strip-cr t
331 gnus-treat-overstrike nil
332 gnus-treat-display-x-face t
333 gnus-treat-display-face t
334 gnus-treat-display-smileys nil
335 gnus-treat-x-pgp-sig
'head
)
338 (setq gnus-visible-headers
339 (mapconcat 'regexp-quote
340 '("From:" "Newsgroups:" "Subject:" "Date:"
341 "Organization:" "To:" "Cc:" "Followup-To" "Gnus-Warnings:"
342 "X-Sent:" "X-URL:" "User-Agent:" "X-Newsreader:"
343 "X-Mailer:" "Reply-To:" "X-Spam:" "X-Spam-Status:" "X-Now-Playing"
344 "X-Attachments" "X-Diagnostic" "X-RSS-URL")
347 ;; 设置邮件日期显示格式,使用两行日期,一行具体日期时间,
348 ;; 另一行显示article, 距现在多长时间
349 (setq gnus-article-date-headers
'(user-defined))
350 (setq gnus-article-time-format
353 (format-time-string "%Y年%m月%d日 星期%u %R" time
)
356 (article-lapsed-string time
))))
358 ;; 用 Supercite 显示多种多样的引文形式
359 (setq sc-attrib-selection-list nil
360 sc-auto-fill-region-p nil
361 sc-blank-lines-after-headers
1
362 sc-citation-delimiter-regexp
"[>]+\\|\\(: \\)+"
363 sc-cite-blank-lines-p nil
364 sc-confirm-always-p nil
365 sc-electric-references-p nil
366 sc-fixup-whitespace-p t
367 sc-nested-citation-p nil
368 sc-preferred-header-style
4
369 sc-use-only-preference-p nil
)
371 ;; 构建 threads 时抓取旧文章标题,
372 ;; 注意: 网速不快时不要使用这个选项。
373 (setq gnus-fetch-old-headers nil
)
376 (setq gnus-summary-thread-gathering-function
377 'gnus-gather-threads-by-subject
)
380 (setq gnus-thread-sort-functions
381 '(gnus-thread-sort-by-most-recent-number
382 gnus-thread-sort-by-most-recent-date
))
385 (setq gnus-subthread-sort-functions
386 '(gnus-thread-sort-by-number
387 gnus-thread-sort-by-date
))
390 (add-hook 'gnus-switch-on-after-hook
391 #'gnus-group-first-unread-group
)
393 (add-hook 'gnus-summary-exit-hook
394 #'gnus-group-first-unread-group
)
398 (provide 'eh-gnus-common
)
401 ;; coding: utf-8-unix
404 ;;; eh-gnus-common.el ends here