1 ;;; packages.el --- aminb layer packages file for Spacemacs.
3 ;; Copyright (c) 2016 Amin Bandali
5 ;; Author: Amin Bandali <amin@aminb.org>
6 ;; URL: https://github.com/aminb/dotfiles
8 ;; This file is not part of GNU Emacs.
14 ;; This file is a collection of my settings and customizations on top of
19 (defconst aminb-packages
20 '(crux writeroom-mode znc
21 ;; mu4e has to be installed manually,
22 ;; and make sure it's in load-path
24 (mu4e-contrib :location site
)
27 "The list of Lisp packages required by the aminb layer.")
29 (defun aminb/init-crux
()
32 :bind
(("C-c d" . crux-duplicate-current-line-or-region
)
33 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region
)
36 (defun aminb/init-writeroom-mode
()
37 (use-package writeroom-mode
; Distraction-free editing
39 :config
(setq writeroom-width
82)
40 :bind
(("C-c W" . writeroom-mode
)
41 ("s-?" . writeroom-toggle-mode-line
))))
43 (defun aminb/init-znc
()
47 (spacemacs/set-leader-keys
51 ;; Set the erc nick completion postfix to ", "
52 (setq erc-pcomplete-nick-postfix
", ")
54 ;; Restore channel buffers from logs
55 (setq erc-log-insert-log-on-open t
)
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
66 (mapcar (function (lambda (slug) (list slug
67 (format "%s/%s" user slug
)
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
)
79 :require
'(:user
:secret
)
82 (let ((password (let ((secret (plist-get found
:secret
)))
83 (if (functionp 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
)
92 (vbe:znc-add-server
"nix.aminb.org" 6669 "amin"
95 ;; https://www.emacswiki.org/emacs/ErcBar
96 ;; Display a bar before unread messages
97 (eval-after-load 'erc-track
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
))
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."
108 (let* ((info (assq (current-buffer) erc-modified-channels-alist
))
110 (if (and info
(> count erc-bar-threshold
))
113 (when (erc-bar-move-back count
)
114 (let ((inhibit-field-text-motion t
))
115 (move-overlay erc-bar-overlay
116 (line-beginning-position)
119 (delete-overlay erc-bar-overlay
))))
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)))))
138 (defun aminb/post-init-mu4e
()
143 (setq mu4e-maildir
"~/mail"
144 mu4e-get-mail-command
"mbsync -a" ;; 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-enable-notifications t
149 mu4e-enable-mode-line t
150 mu4e-compose-signature-auto-include t
151 mu4e-compose-signature
155 ;; don't keep message buffers around
156 message-kill-buffer-on-exit t
157 mu4e-attachment-dir
"~/dls"
158 mu4e-sent-folder
"/amin/Sent"
159 mu4e-drafts-folder
"/amin/Drafts"
160 mu4e-trash-folder
"/amin/Trash"
161 user-mail-address
"amin@aminb.org"
162 mu4e-context-policy
'pick-first
164 (list (make-mu4e-context
166 :enter-func
(lambda () (mu4e-message "Switch to the amin context"))
167 :match-func
(lambda (msg)
169 (s-prefix?
"/amin/" (mu4e-message-field msg
:maildir
))))
170 :vars
'((user-mail-address .
"amin@aminb.org")
171 (mu4e-sent-folder .
"/amin/Sent")
172 (mu4e-drafts-folder .
"/amin/Drafts")
173 (mu4e-trash-folder .
"/amin/Trash")
174 (mu4e-sent-messages-behavior . sent
)
175 (smtpmail-default-smtp-server .
"nix.aminb.org")
176 (smtpmail-smtp-server .
"nix.aminb.org")
177 (smtpmail-stream-type . starttls
)
178 (smtpmail-smtp-service .
587)))
181 :enter-func
(lambda () (mu4e-message "Switch to the gmail context"))
182 :match-func
(lambda (msg)
184 (s-prefix?
"/gmail/" (mu4e-message-field msg
:maildir
))))
185 :vars
'((user-mail-address .
"amin.bandali@gmail.com")
186 (mu4e-sent-folder .
"/gmail/Sent")
187 (mu4e-drafts-folder .
"/gmail/Drafts")
188 (mu4e-trash-folder .
"/gmail/Trash")
189 (mu4e-sent-messages-behavior . delete
)
190 (smtpmail-default-smtp-server .
"smtp.gmail.com")
191 (smtpmail-smtp-server .
"smtp.gmail.com")
192 (smtpmail-stream-type . starttls
)
193 (smtpmail-smtp-service .
587)))))
194 (with-eval-after-load 'mu4e-alert
195 ;; Enable Desktop notifications
196 (mu4e-alert-set-default-style 'notifications
))))
198 (use-package gnus-dired
199 ;; A special version of the gnus-dired-mail-buffers function
200 ;; that understands mu4e buffers as well
204 ;; make the `gnus-dired-mail-buffers' function also work on
205 ;; message-mode derived modes, such as mu4e-compose-mode
206 (defun gnus-dired-mail-buffers ()
207 "Return a list of active message buffers."
210 (dolist (buffer (buffer-list t
))
212 (when (and (derived-mode-p 'message-mode
)
213 (null message-sent-message-via
))
214 (push (buffer-name buffer
) buffers
))))
216 (setq gnus-dired-mail-mode
'mu4e-user-agent
)
217 (add-hook 'dired-mode-hook
'turn-on-gnus-dired-mode
))
220 (spacemacs/set-leader-keys
224 (defun aminb/init-mu4e-contrib
()
225 (use-package mu4e-contrib
228 (setq mu4e-html2text-command
'mu4e-shr2text
229 mu4e-view-html-plaintext-ratio-heuristic
10
230 mu4e-view-prefer-html t
)))
232 (defun aminb/init-smtpmail
()
233 (use-package smtpmail
236 (setq smtpmail-default-smtp-server
"nix.aminb.org"
237 smtpmail-local-domain
"aminb.org"
238 smtpmail-smtp-server
"nix.aminb.org"
239 smtpmail-stream-type
'starttls
240 smtpmail-smtp-service
587)))
242 ;;; packages.el ends here