1 ;;; liece-message.el --- generate and display message line
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.
31 (eval-when-compile (require 'liece-misc))
33 (defgroup liece-message nil
39 (defcustom liece-message-brackets
42 ((and (type action) (direction outgoing))
46 ((and (range private) (direction incoming))
55 :group 'liece-message)
57 (defcustom liece-message-tags
58 '(((and (direction outgoing) (range private))
59 (liece-message-target liece-message-target))
61 (liece-message-speaker liece-message-speaker))
63 (liece-message-speaker
64 (concat liece-message-target ":" liece-message-speaker))))
66 :group 'liece-message)
68 (defcustom liece-message-empty-predicate
69 (function (lambda (message) (string-equal "" message)))
70 "Return non-nil if message is regarded as empty string."
71 :group 'liece-message)
73 (defvar liece-message-type nil)
74 (defvar liece-message-target nil)
75 (defvar liece-message-speaker nil)
76 (defvar liece-message-direction nil)
78 (defun liece-message-predicate (val)
85 (let ((pred (pop val)))
88 (apply 'liece-or (mapcar 'liece-message-predicate val)))
90 (apply 'liece-and (mapcar 'liece-message-predicate val)))
92 (not (liece-message-predicate (car val))))
94 (eq liece-message-type (car val)))
97 ((eq (car val) 'outgoing)
98 liece-message-direction)
99 ((eq (car val) 'incoming)
100 (not liece-message-direction))))
102 (eq liece-command-buffer-mode (car val)))
105 ((eq (car val) 'private)
106 (not (liece-channel-p (liece-channel-real liece-message-target))))
107 ((eq (car val) 'external)
108 (not (liece-channel-member
109 liece-message-target (liece-nick-get-joined-channels
110 liece-message-speaker))))))
111 ((liece-functionp pred)
112 (liece-eval-form (cons pred val)))
114 (liece-message-predicate pred)))))
116 (liece-eval-form val))))
118 (defun liece-message-brackets-function ()
119 (let* ((specs liece-message-brackets) spec
123 (setq spec (pop specs))
124 (if (liece-message-predicate (car spec))
125 (throw 'found (cadr spec)))))))
128 (defun liece-message-tags-function ()
129 (let* ((specs liece-message-tags) spec
133 (setq spec (pop specs))
134 (if (liece-message-predicate (car spec))
135 (throw 'found (cadr spec)))))))
136 (list (eval (car tags)) (eval (cadr tags)))))
138 (defun liece-message-buffer-function ()
139 (let* ((target (if (liece-message-predicate
140 '(and (range private) (direction incoming)))
141 liece-message-speaker
142 liece-message-target))
143 (buffer (liece-pick-buffer target)))
145 ((car buffer) buffer)
146 (liece-auto-join-partner
147 (liece-channel-prepare-partner target)
148 (liece-pick-buffer target)))))
150 (defun liece-message-parent-buffer (cbuffer)
151 (if (or (and (car cbuffer) (liece-frozen (car cbuffer)))
152 (and (eq liece-command-buffer-mode 'channel)
153 liece-current-channel
154 (not (liece-channel-equal liece-message-target
155 liece-current-channel)))
156 (and (eq liece-command-buffer-mode 'chat)
157 liece-current-chat-partner
158 (not (eq liece-message-direction 'outgoing))
160 (not (liece-nick-equal liece-message-speaker
161 liece-current-chat-partner))
162 (not (liece-nick-equal liece-message-target
163 (liece-current-nickname))))))
164 (append liece-D-buffer liece-O-buffer)
168 (defun liece-display-message (temp)
169 (let* ((brackets (liece-message-brackets-function))
170 (tags (liece-message-tags-function))
171 (buffer (liece-message-buffer-function))
172 (parent (liece-message-parent-buffer buffer)))
174 (concat (car brackets) (car tags) (cadr brackets)
177 (concat (car brackets) (cadr tags) (cadr brackets)
179 (run-hook-with-args 'liece-display-message-hook temp)))
181 (provide 'liece-message)
183 ;;; liece-message.el ends here