1 ;;; riece-display.el --- buffer arrangement
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
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 (require 'riece-options)
28 (require 'riece-channel)
30 (require 'riece-layout)
32 (defvar riece-channel-buffer-format "*Channel:%s*"
33 "Format of channel message buffer.")
34 (defvar riece-channel-buffer-alist nil
35 "An alist mapping identities to channel buffers.")
37 (defvar riece-update-buffer-functions nil
38 "Functions to redisplay the buffer.
39 Local to the buffer in `riece-buffer-list'.")
41 (defvar riece-update-indicator-functions
42 '(riece-update-status-indicators
43 riece-update-channel-indicator
44 riece-update-long-channel-indicator
45 riece-update-channel-list-indicator)
46 "Functions to update modeline indicators.")
48 ;;; Qt like "signal-slot" abstraction for routing display events.
49 (defvar riece-signal-slot-obarray
52 (defun riece-make-slot (function &optional filter handback)
53 "Make an instance of slot object.
54 Arguments are corresponding to callback function, filter function, and
55 a handback object, respectively."
56 (vector function filter handback))
58 (defun riece-slot-function (slot)
59 "Return the callback function of SLOT."
62 (defun riece-slot-filter (slot)
63 "Return the filter function of SLOT."
66 (defun riece-slot-handback (slot)
67 "Return the handback object of SLOT."
70 (defun riece-make-signal (name &rest args)
71 "Make an instance of signal object.
72 The 1st arguments is the name of the signal and the rest of arguments
73 are the data of the signal."
76 (defun riece-signal-name (signal)
77 "Return the name of SIGNAL."
80 (defun riece-signal-args (signal)
81 "Return the data of SIGNAL."
84 (defun riece-connect-signal (signal-name slot)
85 "Add SLOT as a listener of a signal identified by SIGNAL-NAME."
86 (let ((symbol (intern (symbol-name signal-name) riece-signal-slot-obarray)))
87 (set symbol (cons slot (if (boundp symbol)
88 (symbol-value symbol))))))
90 (defun riece-emit-signal (signal)
92 (let ((symbol (intern-soft (symbol-name (riece-signal-name signal))
93 riece-signal-slot-obarray))
96 (setq slots (symbol-value symbol))
99 (if (or (null (riece-slot-filter (car slots)))
100 (funcall (riece-slot-filter (car slots)) signal))
101 (funcall (riece-slot-function (car slots))
102 signal (riece-slot-handback (car slots))))
105 (message "Error occurred in slot function for signal \"%S\": %S"
106 (riece-signal-name signal) error))))
107 (setq slots (cdr slots))))))
109 (defun riece-update-user-list-buffer ()
111 (set-buffer riece-user-list-buffer)
112 (if (and riece-current-channel
113 (riece-channel-p (riece-identity-prefix riece-current-channel)))
115 (with-current-buffer (process-buffer (riece-server-process
116 (riece-identity-server
117 riece-current-channel)))
118 (riece-channel-get-users (riece-identity-prefix
119 riece-current-channel))))
120 (inhibit-read-only t)
123 (riece-kill-all-overlays)
125 (insert (if (memq ?o (cdr (car users)))
127 (if (memq ?v (cdr (car users)))
130 (riece-format-identity
131 (riece-make-identity (car (car users))
132 (riece-identity-server
133 riece-current-channel))
136 (setq users (cdr users)))))))
138 (defun riece-update-channel-list-buffer ()
140 (set-buffer riece-channel-list-buffer)
141 (let ((inhibit-read-only t)
144 (channels riece-current-channels))
146 (riece-kill-all-overlays)
149 (insert (riece-format-channel-list-line
150 index (car channels))))
151 (setq index (1+ index)
152 channels (cdr channels))))))
154 (defun riece-format-channel-list-line (index channel)
155 (or (run-hook-with-args-until-success
156 'riece-format-channel-list-line-functions index channel)
157 (concat (format "%2d:%c" index
158 (if (riece-identity-equal channel riece-current-channel)
161 (riece-format-identity channel)
164 (defun riece-update-channel-indicator ()
165 (setq riece-channel-indicator
166 (if riece-current-channel
167 (riece-format-identity riece-current-channel)
170 (defun riece-update-long-channel-indicator ()
171 (setq riece-long-channel-indicator
172 (if riece-current-channel
173 (if (riece-channel-p (riece-identity-prefix riece-current-channel))
174 (riece-concat-channel-modes
175 riece-current-channel
176 (riece-concat-channel-topic
177 riece-current-channel
178 (riece-format-identity riece-current-channel)))
179 (riece-format-identity riece-current-channel))
182 (defun riece-update-channel-list-indicator ()
183 (if (and riece-current-channels
184 ;; There is at least one channel.
185 (delq nil (copy-sequence riece-current-channels)))
187 (setq riece-channel-list-indicator
195 (format "%d:%s" index
196 (riece-format-identity channel)))
197 (setq index (1+ index))))
198 riece-current-channels))
200 (setq riece-channel-list-indicator "No channel")))
202 (defun riece-update-status-indicators ()
203 (if riece-current-channel
204 (with-current-buffer riece-command-buffer
205 (riece-with-server-buffer (riece-identity-server riece-current-channel)
206 (setq riece-away-indicator
207 (if (and riece-real-nickname
208 (riece-user-get-away riece-real-nickname))
211 riece-operator-indicator
212 (if (and riece-real-nickname
213 (riece-user-get-operator riece-real-nickname))
216 riece-user-indicator riece-real-nickname))))
217 (setq riece-freeze-indicator
218 (with-current-buffer (if (and riece-channel-buffer-mode
219 riece-channel-buffer)
221 riece-dialogue-buffer)
222 (if (eq riece-freeze 'own)
228 (defun riece-update-buffers (&optional buffers)
230 (setq buffers riece-buffer-list))
233 (set-buffer (car buffers))
234 (run-hooks 'riece-update-buffer-functions))
235 (setq buffers (cdr buffers)))
236 (run-hooks 'riece-update-indicator-functions)
237 (force-mode-line-update t)
238 (run-hooks 'riece-update-buffer-hook))
240 (defun riece-channel-buffer-name (identity)
241 (let ((channels (riece-identity-member identity riece-current-channels)))
243 (setq identity (car channels))
245 (message "%S is not a member of riece-current-channels" identity)))
246 (format riece-channel-buffer-format (riece-format-identity identity))))
249 (autoload 'riece-channel-mode "riece"))
250 (defun riece-channel-buffer-create (identity)
252 (riece-get-buffer-create (riece-channel-buffer-name identity)
254 (setq riece-channel-buffer-alist
255 (cons (cons identity (current-buffer))
256 riece-channel-buffer-alist))
257 (unless (eq major-mode 'riece-channel-mode)
259 (let (buffer-read-only)
260 (riece-insert-info (current-buffer)
261 (concat "Created on "
262 (funcall riece-format-time-function
265 (run-hook-with-args 'riece-channel-buffer-create-functions identity)))
268 (defun riece-channel-buffer (identity)
269 (cdr (riece-identity-assoc identity riece-channel-buffer-alist)))
271 (defun riece-switch-to-channel (identity)
272 (let ((last riece-current-channel))
273 (setq riece-current-channel identity
274 riece-channel-buffer (riece-channel-buffer riece-current-channel))
275 (run-hook-with-args 'riece-after-switch-to-channel-functions last)))
277 (defun riece-join-channel (identity)
278 (unless (riece-identity-member identity riece-current-channels)
279 (setq riece-current-channels
280 (riece-identity-assign-binding
281 identity riece-current-channels
285 (riece-parse-identity channel)))
286 riece-default-channel-binding)))
287 (riece-channel-buffer-create identity)))
289 (defun riece-switch-to-nearest-channel (pointer)
290 (let ((start riece-current-channels)
292 (while (and start (not (eq start pointer)))
294 (setq identity (car start)))
295 (setq start (cdr start)))
298 (null (car pointer)))
299 (setq pointer (cdr pointer)))
300 (setq identity (car pointer)))
302 (riece-switch-to-channel identity)
303 (let ((last riece-current-channel))
304 (run-hook-with-args 'riece-after-switch-to-channel-functions last)
305 (setq riece-current-channel nil)))))
307 (defun riece-part-channel (identity)
308 (let ((pointer (riece-identity-member identity riece-current-channels)))
310 (setcar pointer nil))
311 (if (riece-identity-equal identity riece-current-channel)
312 (riece-switch-to-nearest-channel pointer))))
314 (defun riece-redisplay-buffers (&optional force)
315 (riece-update-buffers)
316 (riece-redraw-layout force)
317 (run-hooks 'riece-redisplay-buffers-hook))
319 (provide 'riece-display)
321 ;;; riece-display.el ends here