Merge remote-tracking branch 'sourceforge/master'
[emacs-jabber.git] / jabber-muc-nick-coloring.el
blobb5781fc83e7a609e9b21d1dcfaa49add79d4b7e6
1 ;;; jabber-muc-nick-coloring.el --- Add nick coloring abilyty to emacs-jabber
3 ;; Copyright 2009, 2010 Terechkov Evgenii - evg@altlinux.org
5 ;; This program is free software; you can redistribute it and/or modify
6 ;; it under the terms of the GNU General Public License as published by
7 ;; the Free Software Foundation; either version 2, or (at your option)
8 ;; any later version.
9 ;;
10 ;; This program is distributed in the hope that it will be useful,
11 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 ;; GNU General Public License for more details.
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with this program; if not, write to the Free Software
17 ;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ;;; Commentary:
21 ;;; Code:
23 (require 'hexrgb) ;we need hexrgb-hsv-to-hex
24 (require 'assoc) ;we need aget/aput
26 ;;;;##########################################################################
27 ;;;; User Options, Variables
28 ;;;;##########################################################################
30 (defcustom jabber-muc-participant-colors nil
31 "Alist of used colors. Format is (nick . color). Color may be
32 in #RGB or textual (like red or blue) notation. Colors will be
33 added in #RGB notation for unknown nicks."
34 :type '(alist :key-type string :value-type color)
35 :group 'jabber-chat)
37 (defcustom jabber-muc-colorize-local nil
38 "Colorize MUC messages from you."
39 :type 'boolean
40 :group 'jabber-chat)
42 (defcustom jabber-muc-colorize-foreign nil
43 "Colorize MUC messages not from you."
44 :type 'boolean
45 :group 'jabber-chat)
47 (defcustom jabber-muc-nick-saturation 1.0
48 "Default saturation for nick coloring."
49 :type 'float
50 :group 'jabber-chat)
52 (defcustom jabber-muc-nick-value 1.0
53 "Default value for nick coloring."
54 :type 'float
55 :group 'jabber-chat)
57 (defun jabber-muc-nick-gen-color (nick)
58 "Return good enough color from available pool"
59 (let ((hue (/ (mod (string-to-number (md5 nick) 16) 360) 360.0)))
60 (hexrgb-hsv-to-hex hue jabber-muc-nick-saturation jabber-muc-nick-value)))
62 (defun jabber-muc-nick-get-color (nick)
63 "Get NICKs color"
64 (let ((color (aget jabber-muc-participant-colors nick)))
65 (if color
66 color
67 (progn
68 (unless jabber-muc-participant-colors )
69 (aput 'jabber-muc-participant-colors nick (jabber-muc-nick-gen-color nick))
70 (aget jabber-muc-participant-colors nick)))))
72 (provide 'jabber-muc-nick-coloring)
74 ;;; jabber-muc-nick-coloring.el ends here