about summary refs log tree commit diff stats
path: root/gnus.el
blob: d17993763d62867f22a7412ca509f8d922b9b79c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
;;; gnus.el -*- lexical-binding: t; coding: utf-8-unix -*-

;; Author: Case Duckworth <acdw@acdw.net>
;; Created: Sometime during Covid-19, 2020
;; Keywords: configuration
;; URL: https://tildegit.org/acdw/emacs

;; This file is NOT part of GNU Emacs.

;;; License:
;; Everyone is permitted to do whatever with this software, without
;; limitation.  This software comes without any warranty whatsoever,
;; but with two pieces of advice:
;; - Don't hurt yourself.
;; - Make good choices.

;;; Code:

;;; Private files
(require 'acdw-private)

;;; Select Methods
(setq gnus-select-method '(nnnil ""))

(add-hook 'gnus-startup-hook
          (defun gnus-startup@feed-setup ()
            (cond ((fboundp #'gnus/init-feed-list)
                   (gnus/init-feed-list))
                  ((and (fboundp #'gnus/import-feed-list)
                        (file-exists-p (expand-file-name
                                        "feeds.txt" user-emacs-directory)))
                   (gnus/import-feed-list (expand-file-name
                                           "feeds.txt" user-emacs-directory)))
                  (t (message "Oops, no feeds :/")))))

;;; Gnus cloud
(setq gnus-cloud-storage-method nil ; Don't always have GPG or gzip
      gnus-cloud-covered-servers '("nntp:news.tilde.club"
                                   "nntp:news.gwene.org"
                                   "nntp:news.gmane.io"))
(add-hook 'gnus-started-hook #'gnus-cloud-download-all-data)
(add-hook 'gnus-exit-gnus-hook #'gnus-cloud-upload-all-data)

;;; Gnus behavior options
(setq gnus-gcc-mark-as-read t
      message-signature (or (file-exists-p message-signature-file)
                            "~ acdw")
      gnus-startup-file (expand-file-name "newsrc" gnus-home-directory)
      gnus-save-newsrc-file nil
      gnus-read-newsrc-file nil
      gnus-read-active-file 'some
      gnus-always-read-dribble-file t
      gnus-interactive-exit nil
      gnus-use-cache t)

;; Keybindings
(define-key gnus-group-mode-map (kbd "q")
  (defun gnus-cloud-upload-and-bury-buffer ()
    (interactive)
    (gnus-cloud-upload-all-data)
    (bury-buffer)))
(define-key gnus-group-mode-map (kbd "Q") #'gnus-group-exit)
(define-key gnus-group-mode-map (kbd "C-q") #'gnus-group-quit)

;;; Other parameters
(setq gnus-parameters
      '(("fastmail.com:.*"
         (display . 200)
         (expiry-wait . immediate)
         (expiry-target . "nnimap+fastmail.com:Archive"))))

;;; Gnus UI options
(setq gnus-thread-sort-functions '(gnus-thread-sort-by-most-recent-date
                                   (not gnus-thread-sort-by-number))
      gnus-use-cache t
      gnus-summary-thread-gathering-function #'gnus-gather-threads-by-subject
      gnus-thread-hide-subtree t
      gnus-thread-ignore-subject t
      gnus-html-frame-width fill-column)

(when window-system
  (setq gnus-sum-thread-tree-indent "  ")
  (setq gnus-sum-thread-tree-root "● ")
  (setq gnus-sum-thread-tree-false-root "○ ")
  (setq gnus-sum-thread-tree-single-indent "◎ ")
  (setq gnus-sum-thread-tree-vertical        "│")
  (setq gnus-sum-thread-tree-leaf-with-other "├─ ")
  (setq gnus-sum-thread-tree-single-leaf     "╰─ "))

(setq gnus-summary-line-format
      (concat
       "%0{%U%R%z%}"
       "%3{│%}" "%1{%d%}" "%3{│%}"      ; date
       "  "
       "%4{%-20,20f%}"                  ; name
       "  "
       "%3{│%}"
       " "
       "%1{%B%}"
       "%s\n"))

(setq gnus-summary-display-arrow t)

(add-hook 'gnus-group-mode-hook #'hl-line-mode)
(add-hook 'gnus-article-mode-hook #'acdw/reading-mode)

;;; MIME types
(setq mm-discouraged-alternatives '("text/html"
                                    "text/richtext"))

(with-eval-after-load 'mailcap
  (cond ((eq system-type 'darwin))
        ((eq system-type 'windows-nt))
        (t (mailcap-parse-mailcaps))))

;;; Composing mail
(add-hook 'message-mode-hook
          (defun message-mode@setup ()
            (flyspell-mode +1)
            (local-set-key (kbd "TAB") #'bbdb-complete-mail)))

;;; Packages

;; searching (?)
(require 'nnir)

;; contacts
(setup (:straight bbdb)
  (require 'bbdb)
  (bbdb-initialize 'message 'gnus 'mail)
  (bbdb-insinuate-message)
  (add-hook 'gnus-startup-hook 'bbdb-insinuate-gnus)
  (:option bbdb/gnus-summary-prefer-real-names t
           bbdb/mail-auto-create-p t
           bbdb/news-auto-create-p t
           bbdb-use-pop-up t
           bbdb-offer-save 1
           bbdb-update-records-p t))

;;; Functions
;; see https://wpc.io/blog/posts/bulk-import-rss-feeds-to-gnus-via-gwene.html
(defun gnus/slurp (file)
  "Read FILE into a string."
  (with-temp-buffer
    (insert-file-contents file)
    (buffer-substring-no-properties
     (point-min)
     (point-max))))

(defun gnus/import-feed-list (path)
  "Import list of NNTP feeds from file at PATH."
  (interactive "F")
  (let ((feeds (split-string (gnus/slurp path) "\n" t)))
    (cl-loop for feed in feeds
             do (with-message (format "Subscribing to %s" feed)
                  (gnus-subscribe-group feed)))))