Created
February 8, 2012 19:37
-
-
Save legumbre/1772727 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun erc-highlight-nicknames () | |
"Searches for nicknames and highlights them. Uses the first | |
twelve digits of the MD5 message digest of the nickname as | |
color (#rrrrggggbbbb)." | |
(with-syntax-table erc-button-syntax-table | |
(let (bounds word color new-nick-face) | |
(goto-char (point-min)) | |
(while (re-search-forward "\\w+" nil t) | |
(setq bounds (bounds-of-thing-at-point 'word)) | |
(setq word (buffer-substring-no-properties | |
(car bounds) (cdr bounds))) | |
(when (or (and erc-channel-users (erc-get-channel-user word)) | |
(and (not erc-channel-users) (erc-get-server-user word))) | |
(setq new-nick-face (gethash word erc-highlight-face-table)) | |
(unless new-nick-face | |
(setq color (concat "#" (substring (md5 (downcase word)) 0 12))) | |
(if (equal (cdr (assoc 'background-mode (frame-parameters))) 'dark) | |
;; if too dark for background | |
(when (< (hexcolor-luminance color) 85) | |
(setq color (invert-color color))) | |
;; if to bright for background | |
(when (> (hexcolor-luminance color) 170) | |
(setq color (invert-color color)))) | |
(setq new-nick-face (make-symbol (concat "erc-highlight-nick-" word "-face"))) | |
(copy-face 'erc-highlight-nick-base-face new-nick-face) | |
(set-face-foreground new-nick-face color) | |
(puthash word new-nick-face erc-highlight-face-table)) | |
(erc-button-add-face (car bounds) (cdr bounds) new-nick-face)))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment