SiteMap Search ElispArea HowTo Glossary RecentChanges News Problems Suggestions
Eritrea, Independence Day

ErcHighlightNicknames

This module highlights nicknames in ERC. It uses the first twelve digits of the MD5 message digest of the nickname as color (#rrrrggggbbbb).

Download

Lisp:erc-highlight-nicknames.el

Usage

To activate this module, put this in your init file:

    (require 'erc-highlight-nicknames)

and add highlight-nicknames to `erc-modules' by customizing it.

Or put this in your init file

    (and
     (require 'erc-highlight-nicknames)
     (add-to-list 'erc-modules 'highlight-nicknames)
     (erc-update-modules))

If you don’t just want the nicks colored, but also some other face properties, you can customize `erc-highlight-nick-base-face' and for example inherit from the face `bold' or `underline'.

    M-x customize-face RET erc-highlight-nick-base-face RET

XEmacs Usage

I tried this in XEmacs and it didn’t work, due to differences in the way Emacs and XEmacs handle text attributes. I modified erc-nighlight-nicknames to work with XEmacs faces instead. See Lisp:erc-highlight-nicknames-xemacs.el. – DaveMarquardt

I made the changes with your code and it works for Emacs too. Plus a new face every nick’s face is inherited from. (customizable, see description above) – AndreRiemann

Fix face bug

I found function ‘erc-highlight-nicknames’ have a bug that create many face to make Emacs slow, even crash. It create a new face when ERC insert text, and don’t care whether have a exist face for this nickname.

I add a hash-table named ‘erc-highlight-face-table’ to storage the nick’s face. Just create a new face when occur new nick, if find a old nick, get face from ‘erc-highlight-face-tabe’ instead of create new one.

And i have upload a new version, enjoy! – AndyStewart

Modification to avoid highlighting notices (and breaking erc-track)

You may wish to keep notices in a very low-contrast face to allow the actual messages to stand out. This advice will: 1. Mark notices as such with a text property, and then 2. Prevent nickname highlighting of so-marked notices.

Also, this code avoids nick-highlighting of (erc-current-nick), because that breaks erc-track highlighting.

Please feel free to edit this to make it more elegant and robust.

;; modify nickname highlighting
(defvar is-notice-property) ;; just a symbol for use as text prop name
(defadvice erc-highlight-notice (after note-notice-on-highlight activate)
  "Annotate notices with is-notice-property"
  (put-text-property 0 (length s) 'is-notice-property 't s))

;; unactivated modification to erc-get-server-user to reject self.
(defadvice erc-get-server-user (around erc-get-server-user-notself)
  (if (not (string-equal nick (erc-current-nick)))
    ad-do-it))
  
(defadvice erc-highlight-nicknames (around disable-nick-highlight-for-notice activate)
  "only allow nick highlighting when not a notice, and disable
   highlighting of own nick"
  (re-search-forward "\\w+" nil t 2) ;; make sure we skip leading timestamp
  (unless (get-text-property (point) 'is-notice-property)
    ;; don't re-highlight self, as it does nothing but break erc-track
    (ad-activate-regexp "erc-get-server-user-notself")
    ad-do-it
    (ad-deactivate-regexp "erc-get-server-user-notself")))

Colorize logs

I use this to colorize my log files

(setq erc-nick-color-alist '(("Bob" . "blue")
			     ("qdsklwhatever" . "somecolor")
			     ))

(defun erc-get-color-for-nick (nick)
  "Gets a color for NICK. If NICK is specified in erc-nick-color-alist, use it, else hash the nick and get a color from that"
  (or (cdr (assoc nick erc-nick-color-alist))
      (nth
       (mod (string-to-number
	     (substring (md5 nick) 0 6) 16)
	    (length erc-colors-list))
       erc-colors-list)))

(defun irc-log-colorize ()
  "Colorise the match with the appropriate color"
  (put-text-property
   (match-beginning 1) (match-end 1)
   'face `((:foreground ,(erc-get-color-for-nick (match-string 1)))
	   (:weight bold))))

(setq irc-log-keywords
      `((,(format "<\\(%s\\)>" erc-valid-nick-regexp) 1 (irc-log-colorize))))

;; undefine some syntax that's messing up with our coloring (for instance, "")
(defvar irc-log-mode-syntax-table
  (let ((st (make-syntax-table)))
    (modify-syntax-entry ?\" ".   " st)
    (modify-syntax-entry ?\\ ".   " st)
    st)
  "Syntax table used while in `irc-log-mode'.")

(define-derived-mode irc-log-mode fundamental-mode
  (setq font-lock-defaults '(irc-log-keywords))
  (setq mode-name "IRC Log"))

ERC, ErcExtraModules