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 (defvar riece-channel-list-icons
34 static char * blank_xpm[] = {
50 static char * balloon_xpm[] = {
68 static char * check_xpm[] = {
86 static char * active_xpm[] = {
104 (defvar riece-user-list-icons
106 static char * blank_xpm[] = {
122 static char * spiral_xpm[] = {
140 static char * cross_xpm[] = {
158 (defvar riece-pointer-icon
160 static char * a_xpm[] = {
182 (defun riece-icon-available-p ()
183 (if (featurep 'xemacs)
185 (if (fboundp 'image-type-available-p)
186 (image-type-available-p 'xpm))))
189 (if (featurep 'xemacs)
190 (defun riece-icon-make-image (data string)
191 (make-glyph (list (vector 'xpm :data data)
192 (vector 'string :data string))))
193 (defun riece-icon-make-image (data string)
194 (create-image data 'xpm t :ascent 'center))))
196 (defun riece-icon-make-images (alist)
197 (let ((pointer (setq alist (copy-alist alist))))
199 (setcdr (car pointer)
200 (riece-icon-make-image (cdr (car pointer)) (car (car pointer))))
201 (setq pointer (cdr pointer)))
205 (if (featurep 'xemacs)
206 (defun riece-icon-add-image-region (image start end)
208 (lambda (extent ignore)
209 (if (or (extent-property extent 'riece-icon-user-list-extent)
210 (extent-property extent 'riece-icon-user-list-annotation))
211 (delete-extent extent)))
212 (current-buffer) start end)
213 (let ((extent (make-extent start end))
214 (annotation (make-annotation image end 'text)))
215 (set-extent-property extent 'end-open t)
216 (set-extent-property extent 'start-open t)
217 (set-extent-property extent 'invisible t)
218 (set-extent-property extent 'intangible t)
219 (set-extent-property annotation
220 'riece-icon-user-list-extent extent)
221 (set-extent-property extent
222 'riece-icon-user-list-annotation annotation)))
223 (defun riece-icon-add-image-region (image start end)
224 (let ((inhibit-read-only t)
226 (add-text-properties start end
229 'rear-nonsticky (list 'display)))))))
231 (defun riece-icon-update-user-list-buffer ()
232 (let ((images (riece-icon-make-images riece-user-list-icons)))
234 (goto-char (point-min))
235 (while (re-search-forward "^[ @+]" nil t)
236 (riece-icon-add-image-region
237 (cdr (assoc (match-string 0) images))
238 (1- (point)) (point))))))
240 (defun riece-icon-update-channel-list-buffer ()
241 (let ((images (riece-icon-make-images riece-channel-list-icons)))
243 (goto-char (point-min))
244 (while (re-search-forward "^ ?[0-9]+:\\([ !+*]\\)" nil t)
245 (riece-icon-add-image-region
246 (cdr (assoc (match-string 1) images))
247 (match-beginning 1) (match-end 1))))))
250 (if (featurep 'xemacs)
252 (defvar riece-icon-xemacs-modeline-left-extent
253 (copy-extent modeline-buffer-id-left-extent))
255 (defvar riece-icon-xemacs-modeline-right-extent
256 (copy-extent modeline-buffer-id-right-extent))
258 (defun riece-icon-modeline-buffer-identification (line)
259 "Decorate 1st element of `mode-line-buffer-identification' LINE.
260 Modify whole identification by side effect."
261 (let ((id (car line)) chopped)
262 (if (and (stringp id) (string-match "^Riece:" id))
264 (setq chopped (substring id 0 (match-end 0))
265 id (substring id (match-end 0)))
272 (list (vector 'xpm :data
273 riece-pointer-icon)))
274 (list (vector 'string :data chopped))))))
275 (set-glyph-face glyph 'modeline-buffer-id)
276 (cons riece-icon-xemacs-modeline-left-extent glyph))
277 (cons riece-icon-xemacs-modeline-right-extent id))
283 (defun riece-icon-modeline-buffer-identification (line)
284 "Decorate 1st element of `mode-line-buffer-identification' LINE.
285 Modify whole identification by side effect."
286 (let ((id (copy-sequence (car line)))
288 (if (image-type-available-p 'xpm)
289 (create-image riece-pointer-icon 'xpm t
292 (stringp id) (string-match "^Riece:" id))
293 (add-text-properties 0 (length id)
295 'rear-nonsticky (list 'display))
300 (defalias 'riece-icon-modeline-buffer-identification 'identity)))))
302 (defun riece-icon-insinuate ()
303 (defalias 'riece-mode-line-buffer-identification
304 'riece-icon-modeline-buffer-identification)
305 (add-hook 'riece-user-list-mode-hook
307 (if (riece-icon-available-p)
308 (add-hook 'riece-update-buffer-functions
309 'riece-icon-update-user-list-buffer t t))))
310 (add-hook 'riece-channel-list-mode-hook
312 (if (riece-icon-available-p)
313 (add-hook 'riece-update-buffer-functions
314 'riece-icon-update-channel-list-buffer t t)))))
316 (provide 'riece-icon)
318 ;;; riece-icon.el ends here