Bind shortcut for counsel-esh-history, also prefer text over html
[~bandali/configs] / spacemacs / .emacs.d / private / aminb / packages.el
... / ...
CommitLineData
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 (defun vbe:znc-add-server (server port user networks)
74 "Add a server to the list of ZNC servers.
75We use SSL inconditionaly. Moreover, we don't store the password
76but put nil instead. At least, we tweak the username to contain
77the network name later, this will be separated again."
78 (add-to-list 'znc-servers
79 (list server
80 port
81 t ; SSL enabled
82 (mapcar (function (lambda (slug) (list slug
83 (format "%s/%s" user slug)
84 nil)))
85 networks))))
86
87 (defun vbe:znc-erc-ssl-connector (&rest R)
88 "Connect to ERC using SSL and retrieve password with `auth-source-search'.
89Moreover, handle multiple networks by sending the password with
90the appropriate network slug that we extract from the nick."
91 (let* ((user (nth 0 (split-string (plist-get R :nick) "/")))
92 (slug (nth 1 (split-string (plist-get R :nick) "/")))
93 (found (nth 0 (auth-source-search :host (plist-get R :server)
94 :user user
95 :require '(:user :secret)
96 :max 1))))
97 (if found
98 (let ((password (let ((secret (plist-get found :secret)))
99 (if (functionp secret)
100 (funcall secret)
101 secret))))
102 (plist-put R :password (format "%s/%s:%s" user slug password))
103 (plist-put R :nick user)
104 (apply 'erc-tls R)))))
105 (setq znc-erc-ssl-connector 'vbe:znc-erc-ssl-connector)
106
107 ;; Define networks
108 (vbe:znc-add-server "nix.aminb.org" 6669 "amin"
109 '(freenode mozilla))
110
111 ;; https://www.emacswiki.org/emacs/ErcBar
112 ;; Display a bar before unread messages
113 (eval-after-load 'erc-track
114 '(progn
115 (defun erc-bar-move-back (n)
116 "Moves back n message lines. Ignores wrapping, and server messages."
117 (interactive "nHow many lines ? ")
118 (re-search-backward "^.*<.*>" nil t n))
119
120 (defun erc-bar-update-overlay ()
121 "Update the overlay for current buffer, based on the content of
122erc-modified-channels-alist. Should be executed on window change."
123 (interactive)
124 (let* ((info (assq (current-buffer) erc-modified-channels-alist))
125 (count (cadr info)))
126 (if (and info (> count erc-bar-threshold))
127 (save-excursion
128 (end-of-buffer)
129 (when (erc-bar-move-back count)
130 (let ((inhibit-field-text-motion t))
131 (move-overlay erc-bar-overlay
132 (line-beginning-position)
133 (line-end-position)
134 (current-buffer)))))
135 (delete-overlay erc-bar-overlay))))
136
137 (defvar erc-bar-threshold 1
138 "Display bar when there are more than erc-bar-threshold unread messages.")
139 (defvar erc-bar-overlay nil
140 "Overlay used to set bar")
141 (setq erc-bar-overlay (make-overlay 0 0))
142 (overlay-put erc-bar-overlay 'face '(:underline "purple"))
143 ;;put the hook before erc-modified-channels-update
144 (defadvice erc-track-mode (after erc-bar-setup-hook
145 (&rest args) activate)
146 ;;remove and add, so we know it's in the first place
147 (remove-hook 'window-configuration-change-hook 'erc-bar-update-overlay)
148 (add-hook 'window-configuration-change-hook 'erc-bar-update-overlay))
149 (add-hook 'erc-send-completed-hook (lambda (str)
150 (erc-bar-update-overlay)))))
151
152 )))
153
154(defun aminb/post-init-mu4e ()
155 (setq maildir "~/mail")
156 (use-package mu4e
157 :defer t
158 :config
159 (progn
160 (setq mu4e-maildir maildir
161 mu4e-get-mail-command "true"
162 mu4e-update-interval 300
163 mu4e-view-show-addresses t
164 mu4e-headers-include-related t
165 mu4e-enable-notifications t
166 mu4e-enable-mode-line t
167 mu4e-compose-signature-auto-include t
168 mu4e-compose-signature
169 (concat
170 "Amin Bandali\n"
171 "<aminb.org>\n")
172 message-kill-buffer-on-exit t ; don't keep message buffers around
173 mu4e-attachment-dir "~/dls"
174 mu4e-sent-folder "/amin/Sent"
175 mu4e-drafts-folder "/amin/Drafts"
176 mu4e-trash-folder "/amin/Trash"
177 user-full-name "Amin Bandali"
178 user-mail-address "amin@aminb.org"
179 mu4e-view-html-plaintext-ratio-heuristic most-positive-fixnum
180 mu4e-context-policy 'pick-first
181 mu4e-contexts
182 (list (make-mu4e-context
183 :name "Personal"
184 :enter-func (lambda () (mu4e-message "Switch to the Personal context"))
185 :match-func (lambda (msg)
186 (when msg
187 (s-prefix? "/amin/" (mu4e-message-field msg :maildir))))
188 :vars '((user-mail-address . "amin@aminb.org")
189 (mu4e-sent-folder . "/amin/Sent")
190 (mu4e-drafts-folder . "/amin/Drafts")
191 (mu4e-trash-folder . "/amin/Trash")
192 (mu4e-sent-messages-behavior . sent)
193 (smtpmail-default-smtp-server . "nix.aminb.org")
194 (smtpmail-smtp-server . "nix.aminb.org")
195 (smtpmail-stream-type . starttls)
196 (smtpmail-smtp-service . 587)))
197 (make-mu4e-context
198 :name "BB"
199 :enter-func (lambda () (mu4e-message "Switch to the BB context"))
200 :match-func (lambda (msg)
201 (when msg
202 (s-prefix? "/gmail/" (mu4e-message-field msg :maildir))))
203 :vars '((user-mail-address . "amin.bandali@gmail.com")
204 (mu4e-sent-folder . "/gmail/Sent")
205 (mu4e-drafts-folder . "/gmail/Drafts")
206 (mu4e-trash-folder . "/gmail/Trash")
207 (mu4e-sent-messages-behavior . delete)
208 (mu4e-compose-signature . nil)
209 (smtpmail-default-smtp-server . "smtp.gmail.com")
210 (smtpmail-smtp-server . "smtp.gmail.com")
211 (smtpmail-stream-type . starttls)
212 (smtpmail-smtp-service . 587)))
213 (make-mu4e-context
214 :name "GNU"
215 :enter-func (lambda () (mu4e-message "Switch to the GNU context"))
216 :match-func (lambda (msg)
217 (when msg
218 (s-prefix? "/gnu/" (mu4e-message-field msg :maildir))))
219 :vars '((user-mail-address . "aminb@gnu.org")
220 (mu4e-sent-folder . "/gnu/Sent")
221 (mu4e-drafts-folder . "/gnu/Drafts")
222 (mu4e-trash-folder . "/gnu/Trash")
223 (mu4e-sent-messages-behavior . sent)
224 (smtpmail-default-smtp-server . "fencepost.gnu.org")
225 (smtpmail-smtp-server . "fencepost.gnu.org")
226 (smtpmail-stream-type . starttls)
227 (smtpmail-smtp-service . 587)))))
228 (with-eval-after-load 'mu4e-alert
229 ;; Enable Desktop notifications
230 (mu4e-alert-set-default-style 'notifications))))
231
232 (use-package gnus-dired
233 ;; A special version of the gnus-dired-mail-buffers function
234 ;; that understands mu4e buffers as well.
235 ;; Usage: mark the file(s) in dired and press C-c RET C-a,
236 ;; then will be asked whether to attach them to an existing
237 ;; message, or create a new one.
238 :defer t
239 :config
240 (progn
241 ;; make the `gnus-dired-mail-buffers' function also work on
242 ;; message-mode derived modes, such as mu4e-compose-mode
243 (defun gnus-dired-mail-buffers ()
244 "Return a list of active message buffers."
245 (let (buffers)
246 (save-current-buffer
247 (dolist (buffer (buffer-list t))
248 (set-buffer buffer)
249 (when (and (derived-mode-p 'message-mode)
250 (null message-sent-message-via))
251 (push (buffer-name buffer) buffers))))
252 (nreverse buffers)))
253 (setq gnus-dired-mail-mode 'mu4e-user-agent)
254 (add-hook 'dired-mode-hook 'turn-on-gnus-dired-mode))
255 )
256
257 ;; Exclude the files in maildir from recents
258 (use-package recentf
259 :defer t
260 :config
261 (add-to-list 'recentf-exclude (expand-file-name maildir)))
262
263 (spacemacs/set-leader-keys
264 "am" 'mu4e)
265 )
266
267(defun aminb/init-smtpmail ()
268 (use-package smtpmail
269 :defer t
270 :config
271 (setq smtpmail-default-smtp-server "nix.aminb.org"
272 smtpmail-local-domain "aminb.org"
273 smtpmail-smtp-server "nix.aminb.org"
274 smtpmail-stream-type 'starttls
275 smtpmail-smtp-service 587
276 send-mail-function 'smtpmail-send-it)))
277
278;;; packages.el ends here