Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
marvel
GitHub Repository: marvel/qnf
Path: blob/master/elisp/erc-nick-colors.el
987 views
1
(setq nick-face-list '())
2
3
;; Define the list of colors to use when coloring IRC nicks.
4
(setq-default erc-colors-list '("blue" "green" "yellow"
5
"gray" "brown" "red"
6
"purple" "white" "cyan"))
7
8
(defun build-nick-face-list ()
9
"build-nick-face-list builds a list of new faces using the
10
foreground colors specified in erc-colors-list. The nick faces
11
created here will be used to format IRC nicks."
12
(setq i -1)
13
(setq nick-face-list
14
(mapcar
15
(lambda (COLOR)
16
(setq i (1+ i))
17
(list (custom-declare-face
18
(make-symbol (format "erc-nick-face-%d" i))
19
(list (list t (list :foreground COLOR)))
20
(format "Nick face %d" i))))
21
erc-colors-list)))
22
23
(defun my-insert-modify-hook ()
24
"This insert-modify hook looks for nicks in new messages and
25
computes md5(nick) and uses substring(md5_value, 0, 4) mod (length
26
nick-face-list) to index the face list and produce the same face for a
27
given nick each time it is seen. We get a lot of collisions this way,
28
unfortunately, but it's better than some other methods I tried.
29
Additionally, if you change the order or size of the erc-colors-list,
30
you'll change the colors used for nicks."
31
(if (null nick-face-list) (build-nick-face-list))
32
(save-excursion
33
(goto-char (point-min))
34
(if (looking-at "<\\([^>]*\\)>")
35
(let ((nick (match-string 1)))
36
(put-text-property (match-beginning 1) (match-end 1)
37
'face (nth
38
(mod (string-to-number
39
(substring (md5 nick) 0 4) 16)
40
(length nick-face-list))
41
nick-face-list))))))
42
43
;; This adds the ERC message insert hook.
44
(add-hook 'erc-insert-modify-hook 'my-insert-modify-hook)
45
46
(provide 'erc-nick-colors)
47
48
(add-hook 'erc-mode-hook (lambda ()
49
(modify-syntax-entry ?\_ "w" nil)
50
(modify-syntax-entry ?\- "w" nil)))
51
52
53