1 ;;; riece-icon.el --- iconify buffer strings
2 ;; Copyright (C) 1'center8-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1'center8-09-28
6 ;; Keywords: IRC, riece
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-icon)
32 (require 'riece-globals)
33 (require 'riece-signal)
35 (defvar riece-channel-list-icons
37 static char * blank_xpm[] = {
53 static char * balloon_xpm[] = {
71 static char * check_xpm[] = {
89 static char * active_xpm[] = {
107 (defvar riece-user-list-icons
109 static char * blank_xpm[] = {
125 static char * spiral_xpm[] = {
143 static char * cross_xpm[] = {
161 (defvar riece-pointer-icon
163 static char * a_xpm[] = {
185 (defvar riece-icon-enabled nil)
187 (defconst riece-icon-description
188 "Add icon images on IRC buffers")
190 (defun riece-icon-available-p ()
191 (if (featurep 'xemacs)
193 (if (fboundp 'image-type-available-p)
194 (image-type-available-p 'xpm))))
197 (if (featurep 'xemacs)
198 (defun riece-icon-make-image (data string)
199 (make-glyph (list (vector 'xpm :data data)
200 (vector 'string :data string))))
201 (defun riece-icon-make-image (data string)
202 (create-image data 'xpm t :ascent 'center))))
204 (defun riece-icon-make-images (alist)
205 (let ((pointer (setq alist (copy-alist alist))))
207 (setcdr (car pointer)
208 (riece-icon-make-image (cdr (car pointer)) (car (car pointer))))
209 (setq pointer (cdr pointer)))
213 (if (featurep 'xemacs)
214 (defun riece-icon-add-image-region (image start end)
216 (lambda (extent ignore)
217 (if (or (extent-property extent 'riece-icon-user-list-extent)
218 (extent-property extent 'riece-icon-user-list-annotation))
219 (delete-extent extent)))
220 (current-buffer) start end)
221 (let ((extent (make-extent start end))
222 (annotation (make-annotation image end 'text)))
223 (set-extent-property extent 'end-open t)
224 (set-extent-property extent 'start-open t)
225 (set-extent-property extent 'invisible t)
226 (set-extent-property extent 'intangible t)
227 (set-extent-property annotation
228 'riece-icon-user-list-extent extent)
229 (set-extent-property extent
230 'riece-icon-user-list-annotation annotation)))
231 (defun riece-icon-add-image-region (image start end)
232 (let ((inhibit-read-only t)
234 (add-text-properties start end
237 'rear-nonsticky (list 'display)))))))
239 (defun riece-icon-update-user-list-buffer ()
240 (if riece-icon-enabled
241 (let ((images (riece-icon-make-images riece-user-list-icons)))
243 (goto-char (point-min))
244 (while (re-search-forward "^[ @+]" nil t)
245 (riece-icon-add-image-region
246 (cdr (assoc (match-string 0) images))
247 (1- (point)) (point)))))))
249 (defun riece-icon-update-channel-list-buffer ()
250 (if riece-icon-enabled
251 (let ((images (riece-icon-make-images riece-channel-list-icons)))
253 (goto-char (point-min))
254 (while (re-search-forward "^ ?[0-9]+:\\([ !+*]\\)" nil t)
255 (riece-icon-add-image-region
256 (cdr (assoc (match-string 1) images))
257 (match-beginning 1) (match-end 1)))))))
260 (if (featurep 'xemacs)
262 (defvar riece-icon-xemacs-modeline-left-extent
263 (copy-extent modeline-buffer-id-left-extent))
265 (defvar riece-icon-xemacs-modeline-right-extent
266 (copy-extent modeline-buffer-id-right-extent))
268 (defun riece-icon-modeline-buffer-identification (line)
269 "Decorate 1st element of `mode-line-buffer-identification' LINE.
270 Modify whole identification by side effect."
271 (let ((id (car line)) chopped)
272 (if (and (stringp id) (string-match "^Riece:" id))
274 (setq chopped (substring id 0 (match-end 0))
275 id (substring id (match-end 0)))
282 (list (vector 'xpm :data
283 riece-pointer-icon)))
284 (list (vector 'string :data chopped))))))
285 (set-glyph-face glyph 'modeline-buffer-id)
286 (cons riece-icon-xemacs-modeline-left-extent glyph))
287 (cons riece-icon-xemacs-modeline-right-extent id))
293 (defun riece-icon-modeline-buffer-identification (line)
294 "Decorate 1st element of `mode-line-buffer-identification' LINE.
295 Modify whole identification by side effect."
296 (let ((id (copy-sequence (car line)))
298 (if (image-type-available-p 'xpm)
299 (create-image riece-pointer-icon 'xpm t
302 (stringp id) (string-match "^Riece:" id))
303 (add-text-properties 0 (length id)
305 'rear-nonsticky (list 'display))
310 (defalias 'riece-icon-modeline-buffer-identification 'identity)))))
312 (defun riece-icon-insinuate ()
313 (defalias 'riece-mode-line-buffer-identification
314 #'riece-icon-modeline-buffer-identification)
315 (add-hook 'riece-user-list-mode-hook
317 (if (riece-icon-available-p)
318 (add-hook 'riece-update-buffer-functions
319 'riece-icon-update-user-list-buffer t t))))
320 (add-hook 'riece-channel-list-mode-hook
322 (if (riece-icon-available-p)
323 (add-hook 'riece-update-buffer-functions
324 'riece-icon-update-channel-list-buffer t t)))))
326 (defun riece-icon-enable ()
327 (setq riece-icon-enabled t)
328 (if riece-current-channel
329 (riece-emit-signal 'user-list-changed riece-current-channel))
330 (riece-emit-signal 'channel-list-changed))
332 (defun riece-icon-disable ()
333 (setq riece-icon-enabled nil)
334 (if riece-current-channel
335 (riece-emit-signal 'user-list-changed riece-current-channel))
336 (riece-emit-signal 'channel-list-changed))
338 (provide 'riece-icon)
340 ;;; riece-icon.el ends here