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 ;;; @ widget emulation
46 (defvar liece-widget-keymap nil)
48 (unless liece-widget-keymap
50 (setq liece-widget-keymap (copy-keymap widget-keymap))
51 (substitute-key-definition
52 'widget-button-click 'liece-widget-button-click
54 (define-key liece-widget-keymap (if (featurep 'xemacs) 'button3
56 'liece-widget-button-click))
58 (defun liece-emacs-widget-convert-button (type from to &rest args)
59 (apply 'widget-convert-button type from to args)
60 (let ((map (copy-keymap liece-widget-keymap)))
61 (set-keymap-parent map (current-local-map))
62 (overlay-put (make-overlay from to) 'local-map map)))
64 (defun liece-emacs-widget-button-click (event)
67 (let ((window (posn-window (event-start event))))
68 (and (windowp window) (window-buffer window)))
69 (goto-char (widget-event-point event))
72 ((> (point) (save-excursion
76 ((< (point) (save-excursion
80 (widget-button-click event)))
82 (fset 'liece-widget-convert-button
83 'liece-emacs-widget-convert-button)
84 (fset 'liece-widget-button-click
85 'liece-emacs-widget-button-click)
89 (defconst liece-splash-image
92 ((and (fboundp 'image-type-available-p)
93 (image-type-available-p 'xpm))
94 (let ((file (expand-file-name "liece.xpm" default-directory)))
95 (if (file-exists-p file)
98 :data (with-temp-buffer
99 (insert-file-contents-as-binary file)
101 ((fboundp 'set-face-stipple)
102 (let ((file (expand-file-name "liece.xbm" default-directory)))
103 (if (file-exists-p file)
104 (bitmap-stipple-xbm-file-to-stipple file)))))))
106 (defun liece-emacs-splash (&optional arg)
108 (let* ((font (cdr (assq 'font (frame-parameters))))
109 (liece-insert-environment-version nil)
110 config buffer pixel-width pixel-height)
113 (setq config (current-window-configuration))
115 (switch-to-buffer (setq buffer (liece-get-buffer-create
116 (concat (if arg "*" " *")
117 (liece-version) "*"))))
120 ((and (fboundp 'image-type-available-p)
121 (image-type-available-p 'xpm))
123 (insert (plist-get (cdr liece-splash-image) :data))
124 (goto-char (point-min))
125 (skip-syntax-forward "^\"")
126 (when (looking-at "\"[ \t]*\\([0-9]+\\)[ \t]*\\([0-9]+\\)")
127 (setq pixel-width (string-to-int (match-string 1))
128 pixel-height (string-to-int (match-string 2)))))
129 (insert (make-string (max 0 (/ (- (frame-height)
131 (frame-char-height)))
134 (make-string (max 0 (/ (- (frame-width)
139 (static-if (condition-case nil
140 (progn (insert-image '(image)) nil)
141 (wrong-number-of-arguments t))
142 (insert-image liece-splash-image "x")
143 (insert-image liece-splash-image))
146 (bitmap-stipple-insert-pixmap liece-splash-image 'center)))
148 (insert-char ?\ (max 0 (/ (- (window-width)
149 (length (liece-version)))
151 (put-text-property (point) (prog2 (insert (liece-version))(point)
154 (or arg (sit-for 2)))
157 (set-window-configuration config)))))
159 ;;; @ modeline decoration
161 (defconst liece-mode-line-image nil)
163 (static-unless (or (not (fboundp 'create-image))
164 (memq 'data-p (aref (symbol-function 'create-image) 0)))
165 (defadvice create-image
166 (before data-p (file-or-data &optional type data-p &rest props) activate)
167 (ad-set-args 0 (list (ad-get-arg 0) (ad-get-arg 1) (ad-get-arg 3)))))
169 (defun liece-emacs-create-mode-line-image ()
170 (static-when (fboundp 'image-type-available-p)
171 (let ((file (liece-locate-icon-file
173 ((image-type-available-p 'xpm)
175 ((image-type-available-p 'xbm)
176 "liece-pointer.xbm")))))
177 (and file (file-exists-p file)
178 (create-image file nil nil :ascent 99)))))
180 (defun liece-emacs-mode-line-buffer-identification (line)
181 (let ((id (copy-sequence (car line))) image)
182 (if (and (stringp id) (string-match "^Liece:" id)
183 (setq liece-mode-line-image
184 (liece-emacs-create-mode-line-image)))
186 (add-text-properties 0 (length id)
188 liece-mode-line-image
189 'rear-nonsticky (list 'display))
194 (fset 'liece-mode-line-buffer-identification
195 'liece-emacs-mode-line-buffer-identification)
197 ;;; @ nick buffer decoration
199 (defun liece-emacs-create-nick-image (file)
200 (static-when (and (fboundp 'image-type-available-p)
201 (image-type-available-p 'xpm))
202 (let ((file (liece-locate-icon-file file)))
203 (and file (file-exists-p file)
204 (create-image file nil nil :ascent 99)))))
206 (defun liece-emacs-nick-image-region (start end)
213 (beginning-of-line 2)
217 (narrow-to-region start end)
218 (let ((buffer-read-only nil)
219 (inhibit-read-only t)
220 (case-fold-search nil)
222 (dolist (entry liece-nick-image-alist)
223 (setq mark (car entry)
227 (setcdr entry (liece-emacs-create-nick-image image))))
230 (when (eq (char-after) mark)
231 (add-text-properties (point) (1+ (point))
234 'rear-nonsticky (list 'display))))
235 (beginning-of-line 2)))))))
237 (add-hook 'liece-nick-insert-hook 'liece-emacs-nick-image-region)
238 (add-hook 'liece-nick-replace-hook 'liece-emacs-nick-image-region)
240 (and liece-splash-image window-system
241 (liece-emacs-splash))
243 (provide 'liece-emacs)
245 ;;; liece-emacs.el ends here