-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.ercrc.el
350 lines (320 loc) · 15.4 KB
/
.ercrc.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
;; -*- eval: (flycheck-mode -1) -*-
(setq erc-prompt (concat (propertize "-" 'display '(space :width (25))
'erc-padding t)
"> "))
;; security
(setq erc-system-name ""
erc-paranoid t
erc-disable-ctcp-replies t
erc-part-reason (lambda (_) "quit")
erc-quit-reason (lambda (_) "quit")
erc-accidental-paste-threshold-seconds 0.1
erc-prompt-for-password t
erc-join-buffer 'buffer
erc-hide-list '("JOIN" "PART" "QUIT")
erc-fill-column most-positive-fixnum
erc-insert-timestamp-function #'erc-insert-timestamp-left
erc-insert-away-timestamp-function erc-insert-timestamp-function)
;; appearance
(require 'general)
(set-face 'erc-default-face 'default :family "Cantarell")
(set-face 'erc-timestamp-face 'face-faded :height 0.9)
(set-face 'erc-notice-face 'face-salient-yellow :family "Cantarell")
(set-face 'erc-current-nick-face 'face-pre)
(set-face 'erc-prompt-face 'face-faded :weight 'bold)
(set-face 'erc-error-face 'face-identifier)
(set-face 'erc-direct-msg-face 'face-salient)
(set-face 'erc-nick-msg-face 'face-salient-green)
(set-face 'erc-input-face 'face-light :family "Cantarell")
(set-face 'erc-my-nick-face 'face-light :family "Cantarell" :weight 'bold)
(set-face 'erc-action-face 'face-strong :family "Cantarell" :weight 'light)
(set-face 'erc-nick-default-face 'face-identifier :family "Cantarell" :height 1.0)
(set-face 'erc-current-nick-face 'face-salient :family "Cantarell" :weight 'bold)
(add-hook 'erc-mode-hook (lambda ()
(setq-local line-spacing 0.25)
(company-mode -1)
(face-remap-add-relative 'default :family "Cantarell")))
;; custom
(define-erc-module align-nicks nil
"align nicks"
((add-hook 'erc-insert-modify-hook #'rayes/erc-align-nicks)
(add-hook 'erc-send-modify-hook #'rayes/erc-align-nicks))
((remove-hook 'erc-insert-modify-hook #'rayes/erc-align-nicks)
(remove-hook 'erc-send-modify-hook #'rayes/erc-align-nicks)))
(defun rayes/erc-align-pad-nick (beg end)
(let ((n (car (window-text-pixel-size nil beg end)))
(inhibit-read-only t))
(goto-char end)
(when (and (looking-at-p ">")
(number-or-marker-p n))
(delete-char 1)
(beginning-of-line)
(delete-char 1)
(insert (propertize "-" 'display `(space :width (,(- 100 n)))
'erc-padding t))
(end-of-line))))
(defun rayes/erc-align-nicks ()
"aligns nicknames in buffer"
(unless wrap-prefix
(setq-local wrap-prefix (propertize "-" 'display '(space :width (115))
'erc-padding t)))
(save-excursion
(goto-char (point-min))
(save-match-data
(while (setq match (text-property-search-forward 'face 'erc-nick-default-face t))
(rayes/erc-align-pad-nick (prop-match-beginning match)
(prop-match-end match)))))
;; (goto-char (point-min))
;; (while (setq match (text-property-search-forward 'face '(erc-nick-default-face erc-nick-default-face)))
;; (rayes/erc-align-pad-nick (prop-match-beginning match)
;; (prop-match-end match)))
;; (goto-char (point-min))
;; (while (not (eobp))
;; (when (not (save-excursion
;; (beginning-of-line)
;; (get-text-property (point) 'erc-padding)))
;; (let ((n (car (window-text-pixel-size nil
;; (save-excursion
;; (beginning-of-line)
;; (point))
;; (save-excursion
;; (back-to-indentation)
;; (point)))))
;; (inhibit-read-only t))
;; (when (not (eq n 0))
;; (beginning-of-line)
;; (insert (propertize "-"
;; 'display `(space :width (,(- 200 n)))
;; 'erc-padding t)))))
;; (forward-line))
)
;; (defun bitlbee-discord-list ()
;; ""
;; ())
;; (defun erc-channel-names ()
;; "Run \"/names #channel\" in the current channel."
;; (interactive)
;; (erc-set-active-buffer (current-buffer))
;; (let ((tgt (erc-default-target)))
;; (if tgt (erc-load-irc-script-lines (list (concat "/names " tgt)))
;; (erc-display-message nil 'error (current-buffer) 'no-target))))
(define-erc-module inline-images nil
"display links to images inline"
((add-hook 'erc-insert-modify-hook #'rayes/erc-inline-images)
(add-hook 'erc-send-modify-hook #'rayes/erc-inline-images))
((remove-hook 'erc-insert-modify-hook #'rayes/erc-inline-images)
(remove-hook 'erc-send-modify-hook #'rayes/erc-inline-images)))
(defvar-local erc-displaying-inline-images nil)
(defun rayes/erc-inline-images ()
(unless erc-displaying-inline-images
(save-excursion
(goto-char (point-min))
(let ((inhibit-read-only t)
(buf (current-buffer)))
(save-match-data
(while (setq match (text-property-search-forward 'erc-data nil (lambda (_ val)
(when val
(string-match-p "^https?://.*\\.\\(png\\|jpg\\)"
(car val))))))
(let ((url (buffer-substring-no-properties (prop-match-beginning match)
(prop-match-end match))))
(url-retrieve url
#'rayes/erc-inline-images-callback
(list match
buf
(string-match-p "^https?://cdn.discordapp.com/emojis/[0-9]*\\.png$" url))
t t))))))
(setq-local erc-displaying-inline-images t)))
(defun rayes/erc-inline-images-callback (_ match buf &optional emoji)
(let ((img (create-image (buffer-substring (progn
(goto-char url-http-end-of-headers)
(while (looking-at-p "\n")
(forward-line))
(point))
(point-max))
nil t
:max-width (if emoji
25
800)
:max-height (if emoji
25
200))))
(let ((inhibit-read-only t))
(with-current-buffer buf
;; (when emoji
;; (delete-region (prop-match-beginning match)
;; (prop-match-end match)))
(goto-char (prop-match-end match))
(end-of-line)
(insert (if emoji
(propertize " " 'erc-image t)
(propertize (concat "\n" (or wrap-prefix ""))
'erc-image t)))
(insert-image img)))
(kill-buffer (current-buffer))))
(defun rayes/erc-clear-images ()
(save-excursion
(let ((inhibit-read-only t))
(goto-char (point-min))
(save-match-data
(while (setq match (text-property-search-forward 'display nil (lambda (_ val) (imagep val))))
(let ((prev (previous-single-property-change (prop-match-beginning match) 'erc-image)))
(delete-region prev
(prop-match-end match)))))))
(setq-local erc-displaying-inline-images nil))
;; (setq erc-replace-alist '(("IN_REPLY_TO: \\(.*\\)> \\(.*\\)$" . (concat "╭─"
;; (propertize (concat "@ " (match-string 1)) 'face 'erc-current-nick-face)
;; (match-string 2)))))
(setq erc-replace-alist '(("IN_REPLY_TO: \\(.*\\)> \\(.*\\)$" . (lambda (_)
(concat
;; (propertize "-" 'display `(space :width (,(car-safe (debug (window-text-pixel-size (debug (selected-window)) (match-beginning 1) (match-end 1)))))))
;; (match-string 1)
(propertize (concat "╭─" (match-string 1)) 'face 'erc-current-nick-face)
" "
(propertize (match-string 2) 'face 'face-faded))))
("EDIT: " . (lambda (_) (downcase (propertize "(edited) " 'face 'face-faded))))))
;; replace sidebar function
(require 'tree-widget)
(setq erc-status-sidebar-width 20)
(define-key erc-mode-map (kbd "C-c C-s") #'erc-status-sidebar-toggle)
(defun erc-status-sidebar-refresh (&optional redraw)
(interactive)
(let ((l))
(dolist (chanbuf (erc-channel-list nil))
(setq l (erc-status-sidebar-push-channel l chanbuf)))
(with-current-buffer
;; "test"
(erc-status-sidebar-get-buffer)
(let ((inhibit-read-only t))
(if (and (not redraw)
(boundp 'erc-status-sidebar-widgets)
erc-status-sidebar-widgets)
(dolist (w erc-status-sidebar-widgets)
(erc-status-sidebar-label-update w))
(make-local-variable 'erc-status-sidebar-widgets)
(delete-region (point-min) (point-max))
(remove-overlays)
(goto-char (point-min))
(tree-widget-set-theme "folder")
(setq-local erc-status-sidebar-widgets
(cl-loop for server in l
collect (widget-create 'tree-widget
:tag (car server)
:open t
:keep '(:open)
:expander (lambda (tree)
(erc-status-sidebar-server-tree tree server)))
into widgets
finally return widgets))
(widget-setup))))))
(defun erc-status-sidebar-label-update (widget)
(let ((children (widget-get widget :args)))
(if children
(dolist (child children)
(erc-status-sidebar-label-update child))
(widget-put widget :tag (erc-status-sidebar-format (widget-get widget :erc-buf)))
;; (widget-browse widget)
;; (when (marker-position (widget-get widget :from))
;; (widget-value-set widget (widget-value widget)))
;; (widget-setup)
)
(while (setq parent (widget-get widget :parent))
(widget-value-set widget (widget-value widget)))))
(defun erc-status-sidebar-push-channel (l chanbuf)
(with-current-buffer chanbuf
(save-match-data
(if (string-match "^#\\(.*\\)\\.\\(.*\\)$" (buffer-name chanbuf))
(erc-status-sidebar-push-nested l erc-server-announced-name
(list (match-string-no-properties 1 (buffer-name chanbuf))
chanbuf))
(erc-status-sidebar-push-nested l erc-server-announced-name chanbuf)))))
(defun erc-status-sidebar-push-nested (l cat val)
(if (and l (assoc cat l))
(if (listp val)
(setf (alist-get cat l nil nil #'equal)
(erc-status-sidebar-push-nested (alist-get cat l nil nil #'equal)
(car val)
(cadr val)))
(setf (alist-get cat l nil nil #'equal)
(append (cdr (assoc cat l)) (list val))))
(push (list cat val) l))
l)
(defun erc-status-sidebar-server-tree (parent server &optional sort)
(cl-loop for chanbuf in (if sort
(apply erc-status-sidebar-channel-sort (cdr server) nil)
(cdr server))
collect (if (listp chanbuf)
(widget-convert 'tree-widget
:tag (car chanbuf)
:open t
:channels chanbuf
:keep '(:open :channels)
:expander (lambda (tree) (erc-status-sidebar-server-tree tree (widget-get tree :channels) t))
:expander-p (lambda (&rest _) t))
(widget-convert 'item :tag (erc-status-sidebar-format chanbuf)
:erc-buf chanbuf
:keep '(:erc-buf)))
into children
finally return children))
(defun erc-status-sidebar-format (chanbuf)
(save-match-data
(let* ((tup (seq-find (lambda (tup) (eq (car tup) chanbuf))
erc-modified-channels-alist))
(count (if tup (cadr tup)))
(face (if tup (cddr tup)))
(channame (apply erc-status-sidebar-channel-format
(buffer-name chanbuf) count face nil)))
(propertize (if (string-match "^#.*\\.\\(.*\\)$" channame)
(concat "#" (match-string 1 channame))
channame)
'erc-buf chanbuf
'mouse-face 'highlight
'help-echo channame))))
(with-eval-after-load 'erc-status-sidebar
(defun erc-status-sidebar-refresh ()
"Update the content of the sidebar."
(interactive)
(let ((chanlist (apply erc-status-sidebar-channel-sort
(erc-channel-list nil) nil)))
(with-current-buffer (erc-status-sidebar-get-buffer)
(erc-status-sidebar-writable
(delete-region (point-min) (point-max))
(goto-char (point-min))
(dolist (chanbuf chanlist)
(let* ((tup (seq-find (lambda (tup) (eq (car tup) chanbuf))
erc-modified-channels-alist))
(count (if tup (cadr tup)))
(face (if tup (cddr tup)))
(channame (apply erc-status-sidebar-channel-format
(buffer-name chanbuf) count face nil))
(cnlen (length channame)))
(put-text-property 0 cnlen 'erc-buf chanbuf channame)
(put-text-property 0 cnlen 'mouse-face 'highlight channame)
(put-text-property 0 cnlen 'help-echo channame channame)
(insert channame "\n"))))))))
(add-hook 'erc-status-sidebar-mode-hook #'my/sans-serif-font)
(setq erc-modules '(completion
button
irccontrols
match
menu
netsplit
noncommands
readonly
smiley
spelling
stamp
track
;; fill
networks
ring
autojoin
move-to-prompt
list
notifications
replace
netsplit
;; align-nicks
;; inline-images
))
(erc-update-modules)