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