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 (setq buffer (generate-new-buffer
125 (concat (if arg "*" " *")
126 (liece-version) "*")))
127 (switch-to-buffer buffer)
130 ((and (fboundp 'image-type-available-p)
131 (image-type-available-p 'xpm))
133 (insert (plist-get (cdr liece-splash-image) :data))
134 (goto-char (point-min))
135 (skip-syntax-forward "^\"")
136 (when (looking-at "\"[ \t]*\\([0-9]+\\)[ \t]*\\([0-9]+\\)")
137 (setq pixel-width (string-to-int (match-string 1))
138 pixel-height (string-to-int (match-string 2)))))
139 (insert (make-string (max 0 (/ (- (frame-height)
141 (frame-char-height)))
144 (make-string (max 0 (/ (- (frame-width)
149 (static-if (condition-case nil
150 (progn (insert-image '(image)) nil)
151 (wrong-number-of-arguments t))
152 (insert-image liece-splash-image "x")
153 (insert-image liece-splash-image))
156 (bitmap-stipple-insert-pixmap liece-splash-image 'center)))
158 (insert-char ?\ (max 0 (/ (- (window-width)
159 (length (liece-version)))
161 (put-text-property (point) (prog2 (insert (liece-version))(point)
164 (or arg (sit-for 2)))
167 (set-window-configuration config)))))
169 ;;; @ modeline decoration
171 (defconst liece-mode-line-image nil)
173 (defun liece-emacs-create-mode-line-image ()
174 (static-when (fboundp 'image-type-available-p)
175 (let ((file (liece-locate-icon-file
177 ((image-type-available-p 'xpm)
179 ((image-type-available-p 'xbm)
180 "liece-pointer.xbm")))))
181 (and file (file-exists-p file)
182 (create-image file nil nil :ascent 99)))))
184 (defun liece-emacs-mode-line-buffer-identification (line)
185 (let ((id (copy-sequence (car line))) image)
186 (if (and (stringp id) (string-match "^Liece:" id)
187 (setq liece-mode-line-image
188 (liece-emacs-create-mode-line-image)))
190 (add-text-properties 0 (length id)
192 liece-mode-line-image
193 'rear-nonsticky (list 'display))
198 (fset 'liece-mode-line-buffer-identification
199 'liece-emacs-mode-line-buffer-identification)
201 ;;; @ nick buffer decoration
203 (defun liece-emacs-create-nick-image (file)
204 (static-when (and (fboundp 'image-type-available-p)
205 (image-type-available-p 'xpm))
206 (let ((file (liece-locate-icon-file file)))
207 (and file (file-exists-p file)
208 (create-image file nil nil :ascent 99)))))
210 (defun liece-emacs-nick-image-region (start end)
217 (beginning-of-line 2)
221 (narrow-to-region start end)
222 (let ((buffer-read-only nil)
223 (inhibit-read-only t)
224 (case-fold-search nil)
226 (dolist (entry liece-nick-image-alist)
227 (setq mark (car entry)
231 (setcdr entry (liece-emacs-create-nick-image image))))
234 (when (eq (char-after) mark)
235 (add-text-properties (point) (1+ (point))
238 'rear-nonsticky (list 'display))))
239 (beginning-of-line 2)))))))
243 (defun liece-emacs-unread-mark (chnl)
244 (if liece-display-unread-mark
245 (with-current-buffer liece-channel-list-buffer
246 (let ((buffer-read-only nil))
247 (goto-char (point-min))
248 (when (re-search-forward (concat "^ ?[0-9]+: " chnl "$") nil t)
249 (goto-char (match-end 0))
250 (insert (concat " " liece-emacs-unread-character)))))))
252 (defun liece-emacs-read-mark (chnl)
253 (if liece-display-unread-mark
254 (with-current-buffer liece-channel-list-buffer
255 (let ((buffer-read-only nil))
256 (goto-char (point-min))
257 (when (re-search-forward
258 (concat "^ ?[0-9]+: " chnl " "
259 liece-emacs-unread-character "$") nil t)
260 (goto-char (- (match-end 0) 2))
263 (defun liece-emacs-redisplay-unread-mark ()
264 (if liece-display-unread-mark
266 (dolist (chnl liece-channel-unread-list)
267 (liece-emacs-unread-mark chnl)))))
269 (add-hook 'liece-nick-insert-hook 'liece-emacs-nick-image-region)
270 (add-hook 'liece-nick-replace-hook 'liece-emacs-nick-image-region)
272 (and liece-splash-image window-system
273 (liece-emacs-splash))
275 (fset 'liece-redisplay-unread-mark 'liece-emacs-redisplay-unread-mark)
276 (add-hook 'liece-channel-unread-hook 'liece-emacs-unread-mark)
277 (add-hook 'liece-channel-read-hook 'liece-emacs-read-mark)
279 (provide 'liece-emacs)
281 ;;; liece-emacs.el ends here