Last edit
Ändrad:
< 004013 !!! ":tie 001 entropie :Welcome to the BitlBee gateway, entropie" (wrong-number-of-arguments (lambda (process sender response channel-buffer) (let ((target (with-current-buffer channel-buffer (or rcirc-target )))) (with-syntax-table rcirc-nick-syntax-table (while (re-search-forward \w+ nil t) (let ((face (gethash (match-string-no-properties 0) rcirc-color-mapping))) (when face (rcirc-add-face (match-beginning 0) (match-end 0) face))))))) 2)
till
> ##004013 !!! ":tie 001 entropie :Welcome to the BitlBee gateway, entropie" (wrong-number-of-arguments (lambda (process sender response channel-buffer) (let ((target (with-current-buffer channel-buffer (or rcirc-target )))) (with-syntax-table rcirc-nick-syntax-table (while (re-search-forward \w+ nil t) (let ((face (gethash (match-string-no-properties 0) rcirc-color-mapping))) (when face (rcirc-add-face (match-beginning 0) (match-end 0) face))))))) 2)##
Colored nicks for rcirc.
(There’s also a bigger screenshot.)
Source:
To install, put it in your LoadPath and add the following to your InitFile:
(eval-after-load 'rcirc '(require 'rcirc-color))
You can set your favorite colors manually:
(setq rcirc-colors '("lemon chiffon" "lavender" "cornflower blue"))Now new nicks will get assigned one of the three colors at random.
You can change the colors assigned to nicks using /color NICK COLOR. A list of available color names is available via ‘M-x list-colors-display’.
You can also use hex codes of the form #xxx or #xxxxxx to refer to a color: #000 is black, #f00 is red, #0f0 is green, #00f is blue, and #fff is white. Using three hex digits allows you to refer to 256 different colors, using six hex digits allows you to refer to 65536 colors. Whether your display can actually display these colors depends on your display. If you’re using Emacs in a terminal emulator or on the console, chances are that you’re limited to 16 colors anyway.
If you never want automatic colors, set ‘rcirc-colors’ to nil:
(setq rcirc-colors nil)
Only the colors you assign using /color NICK COLOR will take effect.
You need to disable the automatic color picking, and you need to initialize the mapping table. The alist you see in the code has elements with a color as the key and a list of nicks as the value.
(setq rcirc-colors nil
rcirc-color-mapping (make-hash-table :test 'equal))
(dolist (group '(("red" "forcer" "kilobug")
("green" "kensanata")
("gray" "fsbot" "birny" "lisppaste" "specbot")))
(dolist (nick (cdr group))
(puthash nick (cons 'foreground (car group)) rcirc-color-mapping)))Without any parameters, /color lists all nicks in their respective colors (and the name of the color is shown in the help echo).
In the screenshot you can see how my own nick, kensanata, has been highlighted.
At the same time, I’ve used /KEYWORD to highlight bpalmer, just to confuse you. ;)
Here’s an implementation of color-distance for Emacs 21, originally from fledermaus from the EmacsChannel [1]. It is based on the same colour metrics [2] Emacs 22 uses.
(defconst colour-triplet-regex
"\\([0-9A-Fa-f]\\{2\\}\\)\\([0-9A-Fa-f]\\{2\\}\\)\\([0-9A-Fa-f]\\{2\\}\\)")
(defun parse-colour (colour frame)
(cond ((and (stringp colour) (string-match colour-triplet-regex colour))
(mapcar
(lambda (x)
(* (string-to-int (match-string x colour) 16) 257)) '(1 2 3)))
((stringp colour)
(if (fboundp 'color-values)
(color-values colour frame)
(x-color-values colour frame)))
((consp colour) colour)
(t (error "colour (%S) is not a colour name, #xxxxxx or list"))) )
(defun colour-distance (colour-a colour-b &optional frame)
"Return an integer distance between COLOUR-A and COLOUR-B on FRAME.
COLOUR-A and COLOUR-B may be either strings containing the color name,
or lists of the form (RED GREEN BLUE).
If FRAME is unspecified or nil, the current frame is used."
(if frame nil (setq frame (selected-frame)))
(let* ((colour-a (parse-colour colour-a frame))
(colour-b (parse-colour colour-b frame))
;; now work out the various bit-shift values
(r (lsh (- (car colour-a) (car colour-b)) -8))
(g (lsh (- (cadr colour-a) (cadr colour-b)) -8))
(b (lsh (- (caddr colour-a) (caddr colour-b)) -8))
(rmu (lsh (+ (car colour-a) (car colour-b)) -9)))
;; and now the magic formula-fu
(+ (lsh (* (+ 512 rmu) r r) -8) (* 4 g g) (lsh (* (- 767 rmu) b b) -8)) ))
An alternative for systems where color-gray-p doesn’t work in Emacs CVS (bug report submitted):
(setq rcirc-colors
(let (candidates)
(dolist (item color-name-rgb-alist)
(destructuring-bind (color r g b) item
(let ((d (sqrt (+ (* (/ r 512) (/ r 512))
(* (/ g 512) (/ g 512))
(* (/ b 512) (/ b 512))))))
(if (and (not (= r g))
(not (= r b)); grey
(> d 10)
(< d 150))
(setq candidates (cons color candidates))))))
candidates))
I always get the error:
004013 !!! ":tie 001 entropie :Welcome to the BitlBee gateway, entropie" (wrong-number-of-arguments (lambda (process sender response channel-buffer) (let ((target (with-current-buffer channel-buffer (or rcirc-target )))) (with-syntax-table rcirc-nick-syntax-table (while (re-search-forward \w+ nil t) (let ((face (gethash (match-string-no-properties 0) rcirc-color-mapping))) (when face (rcirc-add-face (match-beginning 0) (match-end 0) face))))))) 2)
Any ideas?
Perhaps you’re using an incompatible version of rcirc? I’m using the rcirc that comes with 22.1, and the current version of rcirc-color.el.
After install, I restarted my Emacs and got “recursive loading while loading .emacs” kind of error. As suggested in the error message, I restarted with --debug-init which confirmed there was a recursive loading. After fiddling around I found that there is an autoload in rcirc-color which generates an autoload file which contains this line (eval-after-load ‘rcirc ‘(require rcirc-color)) while in the beginning of the file rcirc-color.el there is a (require ‘rcirc). In order to prevent the issue, I removed the ‘require’ line at the beginning of the rcirc-color.el file. And it works now. But I am not sure it is the best solution. I am wondering, maybe removing the eval-after-load line?
I have no idea where this auto load comes from. – Alex