41a152c7209df13e691839db0d71987b02b266ea
[~bandali/configs] / .emacs.d / lisp / bandali-erc.el
1 ;;; bandali-erc.el --- bandali's ERC setup -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2018-2020 Amin Bandali
4
5 ;; Author: Amin Bandali <bandali@gnu.org>
6 ;; Keywords: tools
7
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation, either version 3 of the License, or
11 ;; (at your option) any later version.
12
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
17
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with this program. If not, see <https://www.gnu.org/licenses/>.
20
21 ;;; Commentary:
22
23 ;; My ERC setup for IRC. It uses my fork of ZNC.el.
24
25 ;;; Code:
26
27 (defvar b/erc-detach-on-kill t
28 "Whether killing a channel should send a DETACH command (for ZNC).")
29
30 (with-eval-after-load 'erc
31 (make-directory (b/var "erc/dcc/") t)
32 (csetq
33 erc-auto-query 'bury
34 erc-autojoin-domain-only nil
35 erc-dcc-get-default-directory (b/var "erc/dcc/")
36 erc-format-nick-function 'erc-format-@nick
37 erc-join-buffer 'bury
38 erc-log-channels-directory (b/var "erc/log-channels/")
39 erc-lurker-hide-list '("JOIN" "PART" "QUIT")
40 erc-nick "bandali"
41 erc-prompt "erc>"
42 erc-prompt-for-password nil
43 erc-rename-buffers t
44 erc-server-reconnect-attempts 5
45 erc-server-reconnect-timeout 3)
46
47 (declare-function erc-message "erc-backend"
48 (message-command line &optional force))
49 (declare-function erc-default-target "erc")
50 (declare-function erc-current-nick "erc")
51 (defun erc-cmd-OPME ()
52 "Request chanserv to op me."
53 (erc-message "PRIVMSG"
54 (format "chanserv op %s %s"
55 (erc-default-target)
56 (erc-current-nick)) nil))
57 (declare-function erc-cmd-DEOP "erc" (&rest people))
58 (defun erc-cmd-DEOPME ()
59 "Deop myself from current channel."
60 (erc-cmd-DEOP (format "%s" (erc-current-nick))))
61 (add-to-list 'erc-modules 'keep-place)
62 (add-to-list 'erc-modules 'notifications)
63 (add-to-list 'erc-modules 'smiley)
64 (add-to-list 'erc-modules 'spelling)
65 (declare-function erc-update-modules "erc")
66 (erc-update-modules)
67
68 (set-face-attribute
69 'erc-nick-default-face nil
70 ;; :weight 'semibold
71 ;; :background "#f2f2f2"
72 ;; :foreground "#222222"
73 :weight 'bold
74 :background "#f8f8f8"
75 :foreground "#6a6a6a")
76
77 ;; (set-face-attribute
78 ;; 'erc-notice-face nil
79 ;; ;; :background "#fffadf"
80 ;; ;; :background "#f9f9f9"
81 ;; :background 'unspecified
82 ;; ;; :foreground "#809de5"
83 ;; :foreground "steel blue")
84
85 ;; erc-fill
86 ;; (csetq
87 ;; erc-fill-column 77
88 ;; erc-fill-function 'erc-fill-variable
89 ;; erc-fill-static-center 18)
90 ;; to disable:
91 ;; (erc-fill-mode -1)
92
93 ;; erc-match
94 (csetq
95 erc-pal-highlight-type 'nick
96 erc-pals
97 '("aindilis" "blackbeard" "bremner" "brettgilio" "civodul"
98 "dto" "ggoes" "jrasata" "mplsCorwin" "rwp" "technomancy"))
99 (with-eval-after-load 'erc-match
100 (set-face-attribute
101 'erc-pal-face nil
102 :foreground 'unspecified
103 :weight 'unspecified
104 :inherit 'erc-nick-default-face
105 :background (face-attribute 'font-lock-string-face :background)))
106
107 ;; erc-pcomplete
108 (csetq erc-pcomplete-nick-postfix ", ")
109
110 ;; erc-stamp
111 (csetq erc-timestamp-only-if-changed-flag nil
112 erc-timestamp-format "%T "
113 erc-insert-timestamp-function 'erc-insert-timestamp-left)
114 (with-eval-after-load 'erc-match
115 (set-face-attribute
116 'erc-timestamp-face nil
117 :foreground "#aaaaaa"
118 :weight 'unspecified
119 :background 'unspecified))
120
121 ;; erc-track
122 (csetq
123 erc-track-enable-keybindings nil
124 erc-track-exclude-types '("JOIN" "MODE" "NICK" "PART" "QUIT"
125 "324" "329" "332" "333" "353" "477")
126 erc-track-position-in-mode-line t
127 erc-track-priority-faces-only 'all
128 erc-track-shorten-function nil
129 erc-track-showcount t)
130
131 ;; key bindings
132 (global-set-key (kbd "C-c w e") #'erc-switch-to-buffer-other-window)
133 (define-key erc-mode-map (kbd "M-a") #'erc-track-switch-buffer)
134
135 ;; hooks
136 (defun b/erc-detach-or-kill-channel ()
137 (if b/erc-detach-on-kill
138 (when (erc-server-process-alive)
139 (let ((tgt (erc-default-target)))
140 (erc-server-send (format "DETACH %s" tgt) nil tgt)))
141 (erc-kill-channel)))
142 (add-hook 'erc-kill-channel-hook #'b/erc-detach-or-kill-channel)
143 (remove-hook 'erc-kill-channel-hook #'erc-kill-channel))
144
145 ;; global key bindings
146 (global-set-key
147 (kbd "C-c a e f")
148 (lambda ()
149 (interactive)
150 (let* ((auth (auth-source-search :host "znca"))
151 (p (if (null auth)
152 (error "Couldn't find znca's authinfo")
153 (funcall (plist-get (car auth) :secret)))))
154 (erc-tls :server "znc.emacsconf.org" :port 6697
155 :password (concat "bandali/freenode:" p)))))
156 (global-set-key
157 (kbd "C-c a e o")
158 (lambda ()
159 (interactive)
160 (let* ((auth (auth-source-search :host "znca"))
161 (p (if (null auth)
162 (error "Couldn't find znca's authinfo")
163 (funcall (plist-get (car auth) :secret)))))
164 (erc-tls :server "znc.emacsconf.org" :port 6697
165 :password (concat "bandali/oftc:" p)))))
166 (global-set-key
167 (kbd "C-c a e t")
168 (lambda ()
169 (interactive)
170 (let* ((auth (auth-source-search :host "znca"))
171 (p (if (null auth)
172 (error "Couldn't find znca's authinfo")
173 (funcall (plist-get (car auth) :secret)))))
174 (erc-tls :server "znc.emacsconf.org" :port 6697
175 :password (concat "bandali/tildechat:" p)))))
176
177 (provide 'bandali-erc)
178 ;;; bandali-erc.el ends here