Go back to Greybird for GTK3
[~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 '(counsel
21 creamsody-theme
22 crux
23 ;; mu4e has to be installed manually,
24 ;; and make sure it's in load-path
25 (mu4e :location site)
26 smtpmail
27 writeroom-mode
28 znc)
29 "The list of Lisp packages required by the aminb layer.")
30
31 (defun aminb/post-init-counsel ()
32 (use-package counsel
33 :defer t
34 :config
35 (progn
36 (spacemacs/set-leader-keys-for-major-mode 'eshell-mode
37 "," 'counsel-esh-history)
38 (add-hook 'eshell-mode-hook
39 '(lambda () (define-key eshell-mode-map
40 (kbd "M-l") 'counsel-esh-history)))
41 )))
42
43 (defun aminb/init-creamsody-theme ())
44
45 (defun aminb/init-crux ()
46 (use-package crux
47 :defer t
48 :bind (("C-c d" . crux-duplicate-current-line-or-region)
49 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region)
50 )))
51
52 (defun aminb/init-writeroom-mode ()
53 (use-package writeroom-mode ; Distraction-free editing
54 :defer t
55 :config (setq writeroom-width 82)
56 :bind (("C-c W" . writeroom-mode)
57 ("s-?" . writeroom-toggle-mode-line))))
58
59 (defun aminb/init-znc ()
60 (use-package znc
61 :defer t
62 :init
63 (spacemacs/set-leader-keys
64 "aiz" 'znc-erc)
65 :config
66 (progn
67 ;; Set the erc nick completion postfix to ", "
68 (setq erc-pcomplete-nick-postfix ", ")
69
70 ;; Restore channel buffers from logs
71 (setq erc-log-insert-log-on-open t)
72
73 ;;; (BEGIN) work around log restoration bug
74 ;; taken from https://www.emacswiki.org/emacs/ErcLogging
75
76 ;; ;;; Original version in the Emacs sources:
77 ;; (defun erc-log-all-but-server-buffers (buffer)
78 ;; "Returns t if logging should be enabled in BUFFER.
79 ;; Returns nil if `erc-server-buffer-p' returns t."
80 ;; (save-excursion
81 ;; (save-window-excursion
82 ;; (set-buffer buffer)
83 ;; (not (erc-server-buffer-p)))))
84
85 ;; My version:
86 (defun erc-log-all-but-server-buffers (buffer)
87 (with-current-buffer buffer
88 (not (erc-server-buffer-p))))
89 ;;
90 ;; ;;; Anyway, a more direct modification also works fine:
91 ;; (defun erc-log-all-but-server-buffers (buffer)
92 ;; (set-buffer buffer)
93 ;; (not (erc-server-buffer-p)))
94 ;;; (END)
95
96 (require 'notifications)
97 (defun erc-global-notify (match-type nick message)
98 "Notify when a message is recieved."
99 (notifications-notify
100 :title nick
101 :body message
102 ;; :app-icon (concat spacemacs-assets-directory "spacemacs.svg")
103 :urgency 'normal))
104
105 (defun vbe:znc-add-server (server port user networks)
106 "Add a server to the list of ZNC servers.
107 We use SSL inconditionaly. Moreover, we don't store the password
108 but put nil instead. At least, we tweak the username to contain
109 the network name later, this will be separated again."
110 (add-to-list 'znc-servers
111 (list server
112 port
113 t ; SSL enabled
114 (mapcar (function (lambda (slug) (list slug
115 (format "%s/%s" user slug)
116 nil)))
117 networks))))
118
119 (defun vbe:znc-erc-ssl-connector (&rest R)
120 "Connect to ERC using SSL and retrieve password with `auth-source-search'.
121 Moreover, handle multiple networks by sending the password with
122 the appropriate network slug that we extract from the nick."
123 (let* ((user (nth 0 (split-string (plist-get R :nick) "/")))
124 (slug (nth 1 (split-string (plist-get R :nick) "/")))
125 (found (nth 0 (auth-source-search :host (plist-get R :server)
126 :user user
127 :require '(:user :secret)
128 :max 1))))
129 (if found
130 (let ((password (let ((secret (plist-get found :secret)))
131 (if (functionp secret)
132 (funcall secret)
133 secret))))
134 (plist-put R :password (format "%s/%s:%s" user slug password))
135 (plist-put R :nick user)
136 (apply 'erc-tls R)))))
137 (setq znc-erc-ssl-connector 'vbe:znc-erc-ssl-connector)
138
139 ;; Define networks
140 (vbe:znc-add-server "nix.aminb.org" 6669 "amin"
141 '(freenode mozilla))
142
143 ;; https://www.emacswiki.org/emacs/ErcBar
144 ;; Display a bar before unread messages
145 (eval-after-load 'erc-track
146 '(progn
147 (defun erc-bar-move-back (n)
148 "Moves back n message lines. Ignores wrapping, and server messages."
149 (interactive "nHow many lines ? ")
150 (re-search-backward "^.*<.*>" nil t n))
151
152 (defun erc-bar-update-overlay ()
153 "Update the overlay for current buffer, based on the content of
154 erc-modified-channels-alist. Should be executed on window change."
155 (interactive)
156 (let* ((info (assq (current-buffer) erc-modified-channels-alist))
157 (count (cadr info)))
158 (if (and info (> count erc-bar-threshold))
159 (save-excursion
160 (end-of-buffer)
161 (when (erc-bar-move-back count)
162 (let ((inhibit-field-text-motion t))
163 (move-overlay erc-bar-overlay
164 (line-beginning-position)
165 (line-end-position)
166 (current-buffer)))))
167 (delete-overlay erc-bar-overlay))))
168
169 (defvar erc-bar-threshold 1
170 "Display bar when there are more than erc-bar-threshold unread messages.")
171 (defvar erc-bar-overlay nil
172 "Overlay used to set bar")
173 (setq erc-bar-overlay (make-overlay 0 0))
174 (overlay-put erc-bar-overlay 'face '(:underline "purple"))
175 ;;put the hook before erc-modified-channels-update
176 (defadvice erc-track-mode (after erc-bar-setup-hook
177 (&rest args) activate)
178 ;;remove and add, so we know it's in the first place
179 (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay)
180 (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay))
181 (add-hook 'erc-send-completed-hook (lambda (str)
182 (erc-bar-update-overlay)))))
183
184 )))
185
186 (defun aminb/post-init-mu4e ()
187 (setq maildir "~/mail")
188 (use-package mu4e
189 :defer t
190 :config
191 (progn
192 (setq mu4e-maildir maildir
193 mu4e-get-mail-command "true"
194 mu4e-update-interval 300
195 mu4e-view-show-addresses t
196 mu4e-headers-include-related t
197 mu4e-enable-notifications t
198 mu4e-enable-mode-line t
199 mu4e-compose-signature-auto-include t
200 mu4e-compose-signature
201 (concat
202 "Amin Bandali\n"
203 "<aminb.org>\n")
204 message-kill-buffer-on-exit t ; don't keep message buffers around
205 mu4e-attachment-dir "~/dls"
206 mu4e-sent-folder "/amin/Sent"
207 mu4e-drafts-folder "/amin/Drafts"
208 mu4e-trash-folder "/amin/Trash"
209 user-full-name "Amin Bandali"
210 user-mail-address "amin@aminb.org"
211 mu4e-view-html-plaintext-ratio-heuristic most-positive-fixnum
212 mu4e-context-policy 'pick-first
213 mu4e-contexts
214 (list (make-mu4e-context
215 :name "Personal"
216 :enter-func (lambda () (mu4e-message "Switch to the Personal context"))
217 :match-func (lambda (msg)
218 (when msg
219 (s-prefix? "/amin/" (mu4e-message-field msg :maildir))))
220 :vars '((user-mail-address . "amin@aminb.org")
221 (mu4e-sent-folder . "/amin/Sent")
222 (mu4e-drafts-folder . "/amin/Drafts")
223 (mu4e-trash-folder . "/amin/Trash")
224 (mu4e-sent-messages-behavior . sent)
225 (smtpmail-default-smtp-server . "nix.aminb.org")
226 (smtpmail-smtp-server . "nix.aminb.org")
227 (smtpmail-stream-type . starttls)
228 (smtpmail-smtp-service . 587)))
229 (make-mu4e-context
230 :name "BB"
231 :enter-func (lambda () (mu4e-message "Switch to the BB context"))
232 :match-func (lambda (msg)
233 (when msg
234 (s-prefix? "/gmail/" (mu4e-message-field msg :maildir))))
235 :vars '((user-mail-address . "amin.bandali@gmail.com")
236 (mu4e-sent-folder . "/gmail/Sent")
237 (mu4e-drafts-folder . "/gmail/Drafts")
238 (mu4e-trash-folder . "/gmail/Trash")
239 (mu4e-sent-messages-behavior . delete)
240 (mu4e-compose-signature . nil)
241 (smtpmail-default-smtp-server . "smtp.gmail.com")
242 (smtpmail-smtp-server . "smtp.gmail.com")
243 (smtpmail-stream-type . starttls)
244 (smtpmail-smtp-service . 587)))
245 (make-mu4e-context
246 :name "GNU"
247 :enter-func (lambda () (mu4e-message "Switch to the GNU context"))
248 :match-func (lambda (msg)
249 (when msg
250 (s-prefix? "/gnu/" (mu4e-message-field msg :maildir))))
251 :vars '((user-mail-address . "aminb@gnu.org")
252 (mu4e-sent-folder . "/gnu/Sent")
253 (mu4e-drafts-folder . "/gnu/Drafts")
254 (mu4e-trash-folder . "/gnu/Trash")
255 (mu4e-sent-messages-behavior . sent)
256 (smtpmail-default-smtp-server . "fencepost.gnu.org")
257 (smtpmail-smtp-server . "fencepost.gnu.org")
258 (smtpmail-stream-type . starttls)
259 (smtpmail-smtp-service . 587)))))
260 (with-eval-after-load 'mu4e-alert
261 ;; Enable Desktop notifications
262 (mu4e-alert-set-default-style 'notifications))))
263
264 (use-package gnus-dired
265 ;; A special version of the gnus-dired-mail-buffers function
266 ;; that understands mu4e buffers as well.
267 ;; Usage: mark the file(s) in dired and press C-c RET C-a,
268 ;; then will be asked whether to attach them to an existing
269 ;; message, or create a new one.
270 :defer t
271 :config
272 (progn
273 ;; make the `gnus-dired-mail-buffers' function also work on
274 ;; message-mode derived modes, such as mu4e-compose-mode
275 (defun gnus-dired-mail-buffers ()
276 "Return a list of active message buffers."
277 (let (buffers)
278 (save-current-buffer
279 (dolist (buffer (buffer-list t))
280 (set-buffer buffer)
281 (when (and (derived-mode-p 'message-mode)
282 (null message-sent-message-via))
283 (push (buffer-name buffer) buffers))))
284 (nreverse buffers)))
285 (setq gnus-dired-mail-mode 'mu4e-user-agent)
286 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode))
287 )
288
289 ;; Exclude the files in maildir from recents
290 (use-package recentf
291 :defer t
292 :config
293 (add-to-list 'recentf-exclude (expand-file-name maildir)))
294
295 (spacemacs/set-leader-keys
296 "am" 'mu4e)
297 )
298
299 (defun aminb/init-smtpmail ()
300 (use-package smtpmail
301 :defer t
302 :config
303 (setq smtpmail-default-smtp-server "nix.aminb.org"
304 smtpmail-local-domain "aminb.org"
305 smtpmail-smtp-server "nix.aminb.org"
306 smtpmail-stream-type 'starttls
307 smtpmail-smtp-service 587
308 send-mail-function 'smtpmail-send-it)))
309
310 ;;; packages.el ends here