erc-highlight-nicknames.el: review
This commit is contained in:
parent
72240ee488
commit
a168c92c18
1 changed files with 10 additions and 11 deletions
|
@ -88,8 +88,7 @@
|
|||
(require 'erc)
|
||||
(require 'erc-button)
|
||||
|
||||
(defvar erc-highlight-facec 16)
|
||||
(defvar erc-highlight-faces
|
||||
(defconst erc-highlight-faces
|
||||
'(fg:erc-color-face0
|
||||
fg:erc-color-face1
|
||||
fg:erc-color-face2
|
||||
|
@ -109,13 +108,13 @@
|
|||
|
||||
(defface erc-highlight-nick-base-face
|
||||
'((t nil))
|
||||
"Base face used for highlighting nicks in erc. (Before the nick
|
||||
color is added)"
|
||||
"Base face used for highlighting nicknames in ERC before the
|
||||
color is added."
|
||||
:group 'erc-faces)
|
||||
|
||||
(defvar erc-highlight-face-table
|
||||
(make-hash-table :test 'equal)
|
||||
"The hash table that contains unique erc nickname faces.")
|
||||
"Hash table containing unique ERC nickname faces.")
|
||||
|
||||
(defun hexcolor-luminance (color)
|
||||
"Returns the luminance of color COLOR. COLOR is a string \(e.g.
|
||||
|
@ -138,9 +137,7 @@ between 0 and 255."
|
|||
(- 65535 r) (- 65535 g) (- 65535 b))))
|
||||
|
||||
(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)."
|
||||
"Highlight nicknames using a random face from `erc-highlight-faces'."
|
||||
(with-syntax-table erc-button-syntax-table
|
||||
(let (bounds bound-start bound-end word color new-nick-face)
|
||||
(goto-char (point-min))
|
||||
|
@ -153,13 +150,15 @@ color (#rrrrggggbbbb)."
|
|||
(when (erc-get-server-user word)
|
||||
(setq new-nick-face (gethash word erc-highlight-face-table))
|
||||
(unless new-nick-face
|
||||
(setq new-nick-face (nth (random erc-highlight-facec) erc-highlight-faces))
|
||||
(setq new-nick-face
|
||||
(nth (random (length erc-highlight-faces))
|
||||
erc-highlight-faces))
|
||||
(setq color (face-foreground new-nick-face))
|
||||
(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
|
||||
;; if too bright for background
|
||||
(when (> (hexcolor-luminance color) 170)
|
||||
(setq color (invert-color color))))
|
||||
(copy-face 'erc-highlight-nick-base-face new-nick-face)
|
||||
|
@ -170,7 +169,7 @@ color (#rrrrggggbbbb)."
|
|||
))))
|
||||
|
||||
(define-erc-module highlight-nicknames nil
|
||||
"Search through the buffer for nicknames, and highlight."
|
||||
"Search through the buffer for nicknames, and highlight them."
|
||||
((add-hook 'erc-insert-modify-hook 'erc-highlight-nicknames t))
|
||||
((remove-hook 'erc-insert-modify-hook 'erc-highlight-nicknames)))
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue