Add missing user-full-name, and set send-mail-function
[~bandali/configs] / spacemacs / .emacs.d / private / aminb / packages.el
1 ;;; packages.el --- aminb layer packages file for Spacemacs.
2 ;;
3 ;; Copyright (c) 2016 Amin Bandali
4 ;;
5 ;; Author: Amin Bandali <amin@aminb.org>
6 ;; URL: https://github.com/aminb/dotfiles
7 ;;
8 ;; This file is not part of GNU Emacs.
9 ;;
10 ;;; License: GPLv3
11
12 ;;; Commentary:
13
14 ;; This file is a collection of my settings and customizations on top of
15 ;; spacemacs.
16
17 ;;; Code:
18
19 (defconst aminb-packages
20 '(creamsody-theme
21 crux
22 ;; mu4e has to be installed manually,
23 ;; and make sure it's in load-path
24 (mu4e :location site)
25 (mu4e-contrib :location site)
26 smtpmail
27 writeroom-mode
28 znc)
29 "The list of Lisp packages required by the aminb layer.")
30
31 (defun aminb/init-creamsody-theme ())
32
33 (defun aminb/init-crux ()
34 (use-package crux
35 :defer t
36 :bind (("C-c d" . crux-duplicate-current-line-or-region)
37 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region)
38 )))
39
40 (defun aminb/init-writeroom-mode ()
41 (use-package writeroom-mode ; Distraction-free editing
42 :defer t
43 :config (setq writeroom-width 82)
44 :bind (("C-c W" . writeroom-mode)
45 ("s-?" . writeroom-toggle-mode-line))))
46
47 (defun aminb/init-znc ()
48 (use-package znc
49 :defer t
50 :init
51 (spacemacs/set-leader-keys
52 "aiz" 'znc-erc)
53 :config
54 (progn
55 ;; Set the erc nick completion postfix to ", "
56 (setq erc-pcomplete-nick-postfix ", ")
57
58 ;; Restore channel buffers from logs
59 (setq erc-log-insert-log-on-open t)
60
61 (defun vbe:znc-add-server (server port user networks)
62 "Add a server to the list of ZNC servers.
63 We use SSL inconditionaly. Moreover, we don't store the password
64 but put nil instead. At least, we tweak the username to contain
65 the network name later, this will be separated again."
66 (add-to-list 'znc-servers
67 (list server
68 port
69 t ; SSL enabled
70 (mapcar (function (lambda (slug) (list slug
71 (format "%s/%s" user slug)
72 nil)))
73 networks))))
74
75 (defun vbe:znc-erc-ssl-connector (&rest R)
76 "Connect to ERC using SSL and retrieve password with `auth-source-search'.
77 Moreover, handle multiple networks by sending the password with
78 the appropriate network slug that we extract from the nick."
79 (let* ((user (nth 0 (split-string (plist-get R :nick) "/")))
80 (slug (nth 1 (split-string (plist-get R :nick) "/")))
81 (found (nth 0 (auth-source-search :host (plist-get R :server)
82 :user user
83 :require '(:user :secret)
84 :max 1))))
85 (if found
86 (let ((password (let ((secret (plist-get found :secret)))
87 (if (functionp secret)
88 (funcall secret)
89 secret))))
90 (plist-put R :password (format "%s/%s:%s" user slug password))
91 (plist-put R :nick user)
92 (apply 'erc-tls R)))))
93 (setq znc-erc-ssl-connector 'vbe:znc-erc-ssl-connector)
94
95 ;; Define networks
96 (vbe:znc-add-server "nix.aminb.org" 6669 "amin"
97 '(freenode mozilla))
98
99 ;; https://www.emacswiki.org/emacs/ErcBar
100 ;; Display a bar before unread messages
101 (eval-after-load 'erc-track
102 '(progn
103 (defun erc-bar-move-back (n)
104 "Moves back n message lines. Ignores wrapping, and server messages."
105 (interactive "nHow many lines ? ")
106 (re-search-backward "^.*<.*>" nil t n))
107
108 (defun erc-bar-update-overlay ()
109 "Update the overlay for current buffer, based on the content of
110 erc-modified-channels-alist. Should be executed on window change."
111 (interactive)
112 (let* ((info (assq (current-buffer) erc-modified-channels-alist))
113 (count (cadr info)))
114 (if (and info (> count erc-bar-threshold))
115 (save-excursion
116 (end-of-buffer)
117 (when (erc-bar-move-back count)
118 (let ((inhibit-field-text-motion t))
119 (move-overlay erc-bar-overlay
120 (line-beginning-position)
121 (line-end-position)
122 (current-buffer)))))
123 (delete-overlay erc-bar-overlay))))
124
125 (defvar erc-bar-threshold 1
126 "Display bar when there are more than erc-bar-threshold unread messages.")
127 (defvar erc-bar-overlay nil
128 "Overlay used to set bar")
129 (setq erc-bar-overlay (make-overlay 0 0))
130 (overlay-put erc-bar-overlay 'face '(:underline "purple"))
131 ;;put the hook before erc-modified-channels-update
132 (defadvice erc-track-mode (after erc-bar-setup-hook
133 (&rest args) activate)
134 ;;remove and add, so we know it's in the first place
135 (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay)
136 (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay))
137 (add-hook 'erc-send-completed-hook (lambda (str)
138 (erc-bar-update-overlay)))))
139
140 )))
141
142 (defun aminb/post-init-mu4e ()
143 (use-package mu4e
144 :defer t
145 :config
146 (progn
147 (setq mu4e-maildir "~/mail"
148 mu4e-get-mail-command "mbsync -a" ;; or fetchmail, or ...
149 mu4e-update-interval 300 ;; update every 5 minutes
150 mu4e-view-show-addresses t
151 mu4e-headers-include-related t
152 mu4e-enable-notifications t
153 mu4e-enable-mode-line t
154 mu4e-compose-signature-auto-include t
155 mu4e-compose-signature
156 (concat
157 "Amin Bandali\n"
158 "<aminb.org>\n")
159 ;; don't keep message buffers around
160 message-kill-buffer-on-exit t
161 mu4e-attachment-dir "~/dls"
162 mu4e-sent-folder "/amin/Sent"
163 mu4e-drafts-folder "/amin/Drafts"
164 mu4e-trash-folder "/amin/Trash"
165 user-full-name "Amin Bandali"
166 user-mail-address "amin@aminb.org"
167 mu4e-context-policy 'pick-first
168 mu4e-contexts
169 (list (make-mu4e-context
170 :name "amin"
171 :enter-func (lambda () (mu4e-message "Switch to the amin context"))
172 :match-func (lambda (msg)
173 (when msg
174 (s-prefix? "/amin/" (mu4e-message-field msg :maildir))))
175 :vars '((user-mail-address . "amin@aminb.org")
176 (mu4e-sent-folder . "/amin/Sent")
177 (mu4e-drafts-folder . "/amin/Drafts")
178 (mu4e-trash-folder . "/amin/Trash")
179 (mu4e-sent-messages-behavior . sent)
180 (smtpmail-default-smtp-server . "nix.aminb.org")
181 (smtpmail-smtp-server . "nix.aminb.org")
182 (smtpmail-stream-type . starttls)
183 (smtpmail-smtp-service . 587)))
184 (make-mu4e-context
185 :name "gmail"
186 :enter-func (lambda () (mu4e-message "Switch to the gmail context"))
187 :match-func (lambda (msg)
188 (when msg
189 (s-prefix? "/gmail/" (mu4e-message-field msg :maildir))))
190 :vars '((user-mail-address . "amin.bandali@gmail.com")
191 (mu4e-sent-folder . "/gmail/Sent")
192 (mu4e-drafts-folder . "/gmail/Drafts")
193 (mu4e-trash-folder . "/gmail/Trash")
194 (mu4e-sent-messages-behavior . delete)
195 (smtpmail-default-smtp-server . "smtp.gmail.com")
196 (smtpmail-smtp-server . "smtp.gmail.com")
197 (smtpmail-stream-type . starttls)
198 (smtpmail-smtp-service . 587)))))
199 (with-eval-after-load 'mu4e-alert
200 ;; Enable Desktop notifications
201 (mu4e-alert-set-default-style 'notifications))))
202
203 (use-package gnus-dired
204 ;; A special version of the gnus-dired-mail-buffers function
205 ;; that understands mu4e buffers as well
206 :defer t
207 :config
208 (progn
209 ;; make the `gnus-dired-mail-buffers' function also work on
210 ;; message-mode derived modes, such as mu4e-compose-mode
211 (defun gnus-dired-mail-buffers ()
212 "Return a list of active message buffers."
213 (let (buffers)
214 (save-current-buffer
215 (dolist (buffer (buffer-list t))
216 (set-buffer buffer)
217 (when (and (derived-mode-p 'message-mode)
218 (null message-sent-message-via))
219 (push (buffer-name buffer) buffers))))
220 (nreverse buffers)))
221 (setq gnus-dired-mail-mode 'mu4e-user-agent)
222 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode))
223 )
224
225 (spacemacs/set-leader-keys
226 "am" 'mu4e)
227 )
228
229 (defun aminb/init-mu4e-contrib ()
230 (use-package mu4e-contrib
231 :defer t
232 :config
233 (setq mu4e-html2text-command 'mu4e-shr2text
234 mu4e-view-html-plaintext-ratio-heuristic 10
235 mu4e-view-prefer-html t)))
236
237 (defun aminb/init-smtpmail ()
238 (use-package smtpmail
239 :defer t
240 :config
241 (setq smtpmail-default-smtp-server "nix.aminb.org"
242 smtpmail-local-domain "aminb.org"
243 smtpmail-smtp-server "nix.aminb.org"
244 smtpmail-stream-type 'starttls
245 smtpmail-smtp-service 587
246 send-mail-function 'smtpmail-send-it)))
247
248 ;;; packages.el ends here