1 ;;; liece-emacs.el --- FSF Emacs specific routines.
2 ;; Copyright (C) 1999 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
8 ;; This file is part of Liece.
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.
33 (require 'liece-compat)
34 (require 'liece-vars))
36 (eval-when-compile (ignore-errors (require 'image)))
41 (autoload 'bitmap-stipple-xbm-file-to-stipple "bitmap-stipple")
42 (autoload 'bitmap-stipple-insert-pixmap "bitmap-stipple"))
44 (defcustom liece-emacs-unread-character "!"
49 ;;; @ widget emulation
51 (defvar liece-widget-keymap nil)
53 (unless liece-widget-keymap
55 (setq liece-widget-keymap (copy-keymap widget-keymap))
56 (substitute-key-definition
57 'widget-button-click 'liece-widget-button-click
59 (define-key liece-widget-keymap [mouse-3]
60 'liece-widget-button-click))
62 (defun liece-emacs-widget-convert-button (type from to &rest args)
63 (apply 'widget-convert-button type from to args)
64 (let ((map (copy-keymap liece-widget-keymap)))
65 (set-keymap-parent map (current-local-map))
66 (overlay-put (make-overlay from to) 'local-map map)))
68 (defun liece-emacs-widget-button-click (event)
70 (let* ((window (posn-window (event-start event)))
71 (point (window-point window))
72 (buffer (window-buffer window)))
73 (with-current-buffer buffer
76 (goto-char (widget-event-point event))
79 ((> (point) (save-excursion
83 ((< (point) (save-excursion
87 (call-interactively (function widget-button-click)))
88 (if (windowp (setq window (get-buffer-window buffer)))
89 (set-window-point window point))))))
91 (fset 'liece-widget-convert-button
92 'liece-emacs-widget-convert-button)
93 (fset 'liece-widget-button-click
94 'liece-emacs-widget-button-click)
98 (defconst liece-splash-image
101 ((and (fboundp 'image-type-available-p)
102 (image-type-available-p 'xpm))
103 (let ((file (expand-file-name "liece.xpm" default-directory)))
104 (if (file-exists-p file)
107 :data (with-temp-buffer
108 (insert-file-contents-as-binary file)
110 ((fboundp 'set-face-stipple)
111 (let ((file (expand-file-name "liece.xbm" default-directory)))
112 (if (file-exists-p file)
113 (bitmap-stipple-xbm-file-to-stipple file)))))))
115 (defun liece-emacs-splash (&optional arg)
117 (let* ((font (cdr (assq 'font (frame-parameters))))
118 (liece-insert-environment-version nil)
119 config buffer pixel-width pixel-height)
122 (setq config (current-window-configuration))
124 (switch-to-buffer (setq buffer (liece-get-buffer-create
125 (concat (if arg "*" " *")
126 (liece-version) "*"))))
129 ((and (fboundp 'image-type-available-p)
130 (image-type-available-p 'xpm))
132 (insert (plist-get (cdr liece-splash-image) :data))
133 (goto-char (point-min))
134 (skip-syntax-forward "^\"")
135 (when (looking-at "\"[ \t]*\\([0-9]+\\)[ \t]*\\([0-9]+\\)")
136 (setq pixel-width (string-to-int (match-string 1))
137 pixel-height (string-to-int (match-string 2)))))
138 (insert (make-string (max 0 (/ (- (frame-height)
140 (frame-char-height)))
143 (make-string (max 0 (/ (- (frame-width)
148 (static-if (condition-case nil
149 (progn (insert-image '(image)) nil)
150 (wrong-number-of-arguments t))
151 (insert-image liece-splash-image "x")
152 (insert-image liece-splash-image))
155 (bitmap-stipple-insert-pixmap liece-splash-image 'center)))
157 (insert-char ?\ (max 0 (/ (- (window-width)
158 (length (liece-version)))
160 (put-text-property (point) (prog2 (insert (liece-version))(point)
163 (or arg (sit-for 2)))
166 (set-window-configuration config)))))
168 ;;; @ modeline decoration
170 (defconst liece-mode-line-image nil)
172 (defun liece-emacs-create-mode-line-image ()
173 (static-when (fboundp 'image-type-available-p)
174 (let ((file (liece-locate-icon-file
176 ((image-type-available-p 'xpm)
178 ((image-type-available-p 'xbm)
179 "liece-pointer.xbm")))))
180 (and file (file-exists-p file)
181 (create-image file nil nil :ascent 99)))))
183 (defun liece-emacs-mode-line-buffer-identification (line)
184 (let ((id (copy-sequence (car line))) image)
185 (if (and (stringp id) (string-match "^Liece:" id)
186 (setq liece-mode-line-image
187 (liece-emacs-create-mode-line-image)))
189 (add-text-properties 0 (length id)
191 liece-mode-line-image
192 'rear-nonsticky (list 'display))
197 (fset 'liece-mode-line-buffer-identification
198 'liece-emacs-mode-line-buffer-identification)
200 ;;; @ nick buffer decoration
202 (defun liece-emacs-create-nick-image (file)
203 (static-when (and (fboundp 'image-type-available-p)
204 (image-type-available-p 'xpm))
205 (let ((file (liece-locate-icon-file file)))
206 (and file (file-exists-p file)
207 (create-image file nil nil :ascent 99)))))
209 (defun liece-emacs-nick-image-region (start end)
216 (beginning-of-line 2)
220 (narrow-to-region start end)
221 (let ((buffer-read-only nil)
222 (inhibit-read-only t)
223 (case-fold-search nil)
225 (dolist (entry liece-nick-image-alist)
226 (setq mark (car entry)
230 (setcdr entry (liece-emacs-create-nick-image image))))
233 (when (eq (char-after) mark)
234 (add-text-properties (point) (1+ (point))
237 'rear-nonsticky (list 'display))))
238 (beginning-of-line 2)))))))
242 (defun liece-emacs-unread-mark (chnl)
243 (if liece-display-unread-mark
244 (with-current-buffer liece-channel-list-buffer
245 (let ((buffer-read-only nil))
246 (goto-char (point-min))
247 (when (re-search-forward (concat "^ ?[0-9]+: " chnl "$") nil t)
248 (goto-char (match-end 0))
249 (insert (concat " " liece-emacs-unread-character)))))))
251 (defun liece-emacs-read-mark (chnl)
252 (if liece-display-unread-mark
253 (with-current-buffer liece-channel-list-buffer
254 (let ((buffer-read-only nil))
255 (goto-char (point-min))
256 (when (re-search-forward
257 (concat "^ ?[0-9]+: " chnl " "
258 liece-emacs-unread-character "$") nil t)
259 (goto-char (- (match-end 0) 2))
262 (defun liece-emacs-redisplay-unread-mark ()
263 (if liece-display-unread-mark
265 (dolist (chnl liece-channel-unread-list)
266 (liece-emacs-unread-mark chnl)))))
268 (add-hook 'liece-nick-insert-hook 'liece-emacs-nick-image-region)
269 (add-hook 'liece-nick-replace-hook 'liece-emacs-nick-image-region)
271 (and liece-splash-image window-system
272 (liece-emacs-splash))
274 (fset 'liece-redisplay-unread-mark 'liece-emacs-redisplay-unread-mark)
275 (add-hook 'liece-channel-unread-hook 'liece-emacs-unread-mark)
276 (add-hook 'liece-channel-read-hook 'liece-emacs-read-mark)
278 (provide 'liece-emacs)
280 ;;; liece-emacs.el ends here