Commit | Line | Data |
---|---|---|
f138f1d7 AB |
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 | |
34ff6667 AB |
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) | |
f138f1d7 AB |
29 | "The list of Lisp packages required by the aminb layer.") |
30 | ||
34ff6667 AB |
31 | (defun aminb/init-creamsody-theme ()) |
32 | ||
f138f1d7 AB |
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 | ||
ab386d24 AB |
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 | |
8568bfb0 AB |
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 | ||
ab386d24 AB |
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)) | |
8568bfb0 AB |
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 | ||
ab386d24 | 140 | ))) |
f138f1d7 | 141 | |
818a4af5 AB |
142 | (defun aminb/post-init-mu4e () |
143 | (use-package mu4e | |
144 | :defer t | |
145 | :config | |
146 | (progn | |
147 | (setq mu4e-maildir "~/mail" | |
f6b1eaf9 | 148 | mu4e-get-mail-command "mbsync -a" ;; or fetchmail, or ... |
818a4af5 AB |
149 | mu4e-update-interval 300 ;; update every 5 minutes |
150 | mu4e-view-show-addresses t | |
151 | mu4e-headers-include-related t | |
7acb70d3 AB |
152 | mu4e-enable-notifications t |
153 | mu4e-enable-mode-line t | |
818a4af5 AB |
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" | |
de295c49 | 165 | user-mail-address "amin@aminb.org" |
f6b1eaf9 | 166 | mu4e-context-policy 'pick-first |
de295c49 AB |
167 | mu4e-contexts |
168 | (list (make-mu4e-context | |
169 | :name "amin" | |
170 | :enter-func (lambda () (mu4e-message "Switch to the amin context")) | |
171 | :match-func (lambda (msg) | |
172 | (when msg | |
173 | (s-prefix? "/amin/" (mu4e-message-field msg :maildir)))) | |
174 | :vars '((user-mail-address . "amin@aminb.org") | |
175 | (mu4e-sent-folder . "/amin/Sent") | |
176 | (mu4e-drafts-folder . "/amin/Drafts") | |
177 | (mu4e-trash-folder . "/amin/Trash") | |
178 | (mu4e-sent-messages-behavior . sent) | |
179 | (smtpmail-default-smtp-server . "nix.aminb.org") | |
180 | (smtpmail-smtp-server . "nix.aminb.org") | |
181 | (smtpmail-stream-type . starttls) | |
182 | (smtpmail-smtp-service . 587))) | |
183 | (make-mu4e-context | |
184 | :name "gmail" | |
185 | :enter-func (lambda () (mu4e-message "Switch to the gmail context")) | |
186 | :match-func (lambda (msg) | |
187 | (when msg | |
188 | (s-prefix? "/gmail/" (mu4e-message-field msg :maildir)))) | |
189 | :vars '((user-mail-address . "amin.bandali@gmail.com") | |
190 | (mu4e-sent-folder . "/gmail/Sent") | |
191 | (mu4e-drafts-folder . "/gmail/Drafts") | |
192 | (mu4e-trash-folder . "/gmail/Trash") | |
193 | (mu4e-sent-messages-behavior . delete) | |
194 | (smtpmail-default-smtp-server . "smtp.gmail.com") | |
195 | (smtpmail-smtp-server . "smtp.gmail.com") | |
196 | (smtpmail-stream-type . starttls) | |
7acb70d3 AB |
197 | (smtpmail-smtp-service . 587))))) |
198 | (with-eval-after-load 'mu4e-alert | |
199 | ;; Enable Desktop notifications | |
200 | (mu4e-alert-set-default-style 'notifications)))) | |
818a4af5 AB |
201 | |
202 | (use-package gnus-dired | |
203 | ;; A special version of the gnus-dired-mail-buffers function | |
204 | ;; that understands mu4e buffers as well | |
205 | :defer t | |
206 | :config | |
207 | (progn | |
208 | ;; make the `gnus-dired-mail-buffers' function also work on | |
209 | ;; message-mode derived modes, such as mu4e-compose-mode | |
210 | (defun gnus-dired-mail-buffers () | |
211 | "Return a list of active message buffers." | |
212 | (let (buffers) | |
213 | (save-current-buffer | |
214 | (dolist (buffer (buffer-list t)) | |
215 | (set-buffer buffer) | |
216 | (when (and (derived-mode-p 'message-mode) | |
217 | (null message-sent-message-via)) | |
218 | (push (buffer-name buffer) buffers)))) | |
219 | (nreverse buffers))) | |
220 | (setq gnus-dired-mail-mode 'mu4e-user-agent) | |
221 | (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode)) | |
222 | ) | |
223 | ||
224 | (spacemacs/set-leader-keys | |
225 | "am" 'mu4e) | |
226 | ) | |
227 | ||
228 | (defun aminb/init-mu4e-contrib () | |
229 | (use-package mu4e-contrib | |
230 | :defer t | |
231 | :config | |
232 | (setq mu4e-html2text-command 'mu4e-shr2text | |
233 | mu4e-view-html-plaintext-ratio-heuristic 10 | |
234 | mu4e-view-prefer-html t))) | |
235 | ||
236 | (defun aminb/init-smtpmail () | |
237 | (use-package smtpmail | |
238 | :defer t | |
239 | :config | |
240 | (setq smtpmail-default-smtp-server "nix.aminb.org" | |
241 | smtpmail-local-domain "aminb.org" | |
242 | smtpmail-smtp-server "nix.aminb.org" | |
243 | smtpmail-stream-type 'starttls | |
244 | smtpmail-smtp-service 587))) | |
245 | ||
f138f1d7 | 246 | ;;; packages.el ends here |