| 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 | '(crux writeroom-mode znc) |
| 21 | "The list of Lisp packages required by the aminb layer.") |
| 22 | |
| 23 | (defun aminb/init-crux () |
| 24 | (use-package crux |
| 25 | :defer t |
| 26 | :bind (("C-c d" . crux-duplicate-current-line-or-region) |
| 27 | ("C-c M-d" . crux-duplicate-and-comment-current-line-or-region) |
| 28 | ))) |
| 29 | |
| 30 | (defun aminb/init-writeroom-mode () |
| 31 | (use-package writeroom-mode ; Distraction-free editing |
| 32 | :defer t |
| 33 | :config (setq writeroom-width 82) |
| 34 | :bind (("C-c W" . writeroom-mode) |
| 35 | ("s-?" . writeroom-toggle-mode-line)))) |
| 36 | |
| 37 | (defun aminb/init-znc () |
| 38 | (use-package znc |
| 39 | :defer t |
| 40 | :init |
| 41 | (spacemacs/set-leader-keys |
| 42 | "aiz" 'znc-erc) |
| 43 | :config |
| 44 | (progn |
| 45 | (defun vbe:znc-add-server (server port user networks) |
| 46 | "Add a server to the list of ZNC servers. |
| 47 | We use SSL inconditionaly. Moreover, we don't store the password |
| 48 | but put nil instead. At least, we tweak the username to contain |
| 49 | the network name later, this will be separated again." |
| 50 | (add-to-list 'znc-servers |
| 51 | (list server |
| 52 | port |
| 53 | t ; SSL enabled |
| 54 | (mapcar (function (lambda (slug) (list slug |
| 55 | (format "%s/%s" user slug) |
| 56 | nil))) |
| 57 | networks)))) |
| 58 | |
| 59 | (defun vbe:znc-erc-ssl-connector (&rest R) |
| 60 | "Connect to ERC using SSL and retrieve password with `auth-source-search'. |
| 61 | Moreover, handle multiple networks by sending the password with |
| 62 | the appropriate network slug that we extract from the nick." |
| 63 | (let* ((user (nth 0 (split-string (plist-get R :nick) "/"))) |
| 64 | (slug (nth 1 (split-string (plist-get R :nick) "/"))) |
| 65 | (found (nth 0 (auth-source-search :host (plist-get R :server) |
| 66 | :user user |
| 67 | :require '(:user :secret) |
| 68 | :max 1)))) |
| 69 | (if found |
| 70 | (let ((password (let ((secret (plist-get found :secret))) |
| 71 | (if (functionp secret) |
| 72 | (funcall secret) |
| 73 | secret)))) |
| 74 | (plist-put R :password (format "%s/%s:%s" user slug password)) |
| 75 | (plist-put R :nick user) |
| 76 | (apply 'erc-tls R))))) |
| 77 | (setq znc-erc-ssl-connector 'vbe:znc-erc-ssl-connector) |
| 78 | |
| 79 | ;; Define networks |
| 80 | (vbe:znc-add-server "nix.aminb.org" 6669 "amin" |
| 81 | '(freenode mozilla)) |
| 82 | ))) |
| 83 | |
| 84 | ;;; packages.el ends here |