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 "The list of Lisp packages required by the aminb layer.")
23 (defun aminb/init-crux
()
26 :bind
(("C-c d" . crux-duplicate-current-line-or-region
)
27 ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region
)
30 (defun aminb/init-writeroom-mode
()
31 (use-package writeroom-mode
; Distraction-free editing
33 :config
(setq writeroom-width
82)
34 :bind
(("C-c W" . writeroom-mode
)
35 ("s-?" . writeroom-toggle-mode-line
))))
37 (defun aminb/init-znc
()
41 (spacemacs/set-leader-keys
45 ;; Set the erc nick completion postfix to ", "
46 (setq erc-pcomplete-nick-postfix
", ")
48 ;; Restore channel buffers from logs
49 (setq erc-log-insert-log-on-open t
)
51 (defun vbe:znc-add-server
(server port user networks
)
52 "Add a server to the list of ZNC servers.
53 We use SSL inconditionaly. Moreover, we don't store the password
54 but put nil instead. At least, we tweak the username to contain
55 the network name later, this will be separated again."
56 (add-to-list 'znc-servers
60 (mapcar (function (lambda (slug) (list slug
61 (format "%s/%s" user slug
)
65 (defun vbe:znc-erc-ssl-connector
(&rest R
)
66 "Connect to ERC using SSL and retrieve password with `auth-source-search'.
67 Moreover, handle multiple networks by sending the password with
68 the appropriate network slug that we extract from the nick."
69 (let* ((user (nth 0 (split-string (plist-get R
:nick
) "/")))
70 (slug (nth 1 (split-string (plist-get R
:nick
) "/")))
71 (found (nth 0 (auth-source-search :host
(plist-get R
:server
)
73 :require
'(:user
:secret
)
76 (let ((password (let ((secret (plist-get found
:secret
)))
77 (if (functionp secret
)
80 (plist-put R
:password
(format "%s/%s:%s" user slug password
))
81 (plist-put R
:nick user
)
82 (apply 'erc-tls R
)))))
83 (setq znc-erc-ssl-connector
'vbe
:znc-erc-ssl-connector
)
86 (vbe:znc-add-server
"nix.aminb.org" 6669 "amin"
89 ;; https://www.emacswiki.org/emacs/ErcBar
90 ;; Display a bar before unread messages
91 (eval-after-load 'erc-track
93 (defun erc-bar-move-back (n)
94 "Moves back n message lines. Ignores wrapping, and server messages."
95 (interactive "nHow many lines ? ")
96 (re-search-backward "^.*<.*>" nil t n
))
98 (defun erc-bar-update-overlay ()
99 "Update the overlay for current buffer, based on the content of
100 erc-modified-channels-alist. Should be executed on window change."
102 (let* ((info (assq (current-buffer) erc-modified-channels-alist
))
104 (if (and info
(> count erc-bar-threshold
))
107 (when (erc-bar-move-back count
)
108 (let ((inhibit-field-text-motion t
))
109 (move-overlay erc-bar-overlay
110 (line-beginning-position)
113 (delete-overlay erc-bar-overlay
))))
115 (defvar erc-bar-threshold
1
116 "Display bar when there are more than erc-bar-threshold unread messages.")
117 (defvar erc-bar-overlay nil
118 "Overlay used to set bar")
119 (setq erc-bar-overlay
(make-overlay 0 0))
120 (overlay-put erc-bar-overlay
'face
'(:underline
"purple"))
121 ;;put the hook before erc-modified-channels-update
122 (defadvice erc-track-mode
(after erc-bar-setup-hook
123 (&rest args
) activate
)
124 ;;remove and add, so we know it's in the first place
125 (remove-hook 'window-configuration-change-hook
'erc-bar-update-overlay
)
126 (add-hook 'window-configuration-change-hook
'erc-bar-update-overlay
))
127 (add-hook 'erc-send-completed-hook
(lambda (str)
128 (erc-bar-update-overlay)))))
132 ;;; packages.el ends here