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
23 ;; mu4e has to be installed manually,
24 ;; and make sure it's in load-path
29 "The list of Lisp packages required by the aminb layer.")
31 (defun aminb/post-init-counsel
()
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
)))
43 (defun aminb/init-creamsody-theme
())
45 (defun aminb/init-crux
()
48 :bind
(("C-c d" . crux-duplicate-current-line-or-region
)
49 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region
)
52 (defun aminb/init-writeroom-mode
()
53 (use-package writeroom-mode
; Distraction-free editing
55 :config
(setq writeroom-width
82)
56 :bind
(("C-c W" . writeroom-mode
)
57 ("s-?" . writeroom-toggle-mode-line
))))
59 (defun aminb/init-znc
()
63 (spacemacs/set-leader-keys
67 ;; Set the erc nick completion postfix to ", "
68 (setq erc-pcomplete-nick-postfix
", ")
70 ;; Restore channel buffers from logs
71 (setq erc-log-insert-log-on-open t
)
73 ;;; (BEGIN) work around log restoration bug
74 ;; taken from https://www.emacswiki.org/emacs/ErcLogging
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."
81 ;; (save-window-excursion
82 ;; (set-buffer buffer)
83 ;; (not (erc-server-buffer-p)))))
86 (defun erc-log-all-but-server-buffers (buffer)
87 (with-current-buffer buffer
88 (not (erc-server-buffer-p))))
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)))
96 (require 'notifications
)
97 (defun erc-global-notify (match-type nick message
)
98 "Notify when a message is recieved."
102 ;; :app-icon (concat spacemacs-assets-directory "spacemacs.svg")
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
114 (mapcar (function (lambda (slug) (list slug
115 (format "%s/%s" user slug
)
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
)
127 :require
'(:user
:secret
)
130 (let ((password (let ((secret (plist-get found
:secret
)))
131 (if (functionp 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
)
140 (vbe:znc-add-server
"nix.aminb.org" 6669 "amin"
143 ;; https://www.emacswiki.org/emacs/ErcBar
144 ;; Display a bar before unread messages
145 (eval-after-load 'erc-track
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
))
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."
156 (let* ((info (assq (current-buffer) erc-modified-channels-alist
))
158 (if (and info
(> count erc-bar-threshold
))
161 (when (erc-bar-move-back count
)
162 (let ((inhibit-field-text-motion t
))
163 (move-overlay erc-bar-overlay
164 (line-beginning-position)
167 (delete-overlay erc-bar-overlay
))))
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)))))
186 (defun aminb/post-init-mu4e
()
187 (setq maildir
"~/mail")
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
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
214 (list (make-mu4e-context
216 :enter-func
(lambda () (mu4e-message "Switch to the Personal context"))
217 :match-func
(lambda (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)))
231 :enter-func
(lambda () (mu4e-message "Switch to the BB context"))
232 :match-func
(lambda (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)))
247 :enter-func
(lambda () (mu4e-message "Switch to the GNU context"))
248 :match-func
(lambda (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
))))
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.
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."
279 (dolist (buffer (buffer-list t
))
281 (when (and (derived-mode-p 'message-mode
)
282 (null message-sent-message-via
))
283 (push (buffer-name buffer
) buffers
))))
285 (setq gnus-dired-mail-mode
'mu4e-user-agent
)
286 (add-hook 'dired-mode-hook
'turn-on-gnus-dired-mode
))
289 ;; Exclude the files in maildir from recents
293 (add-to-list 'recentf-exclude
(expand-file-name maildir
)))
295 (spacemacs/set-leader-keys
299 (defun aminb/init-smtpmail
()
300 (use-package smtpmail
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
)))
310 ;;; packages.el ends here