Fixed error message.
[riece] / lisp / riece-biff.el
1 ;;; riece-biff.el --- be notified if messages arrives
2 ;; Copyright (C) 2004 OHASHI Akira
3
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
12 ;; any later version.
13
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 ;; GNU General Public License for more details.
18
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
23
24 ;;; Commentary:
25
26 ;; NOTE: This is an add-on module for Riece.
27
28 ;;; Code:
29
30 (require 'riece-message)
31
32 (defgroup riece-biff nil
33   "Be notified if messages arrives."
34   :prefix "riece-"
35   :group 'riece)
36
37 (defcustom riece-biff-check-channels nil
38   "*If non-nil, riece-biff checks only the channel contained in this list."
39   :type '(repeat string)
40   :group 'riece-biff)
41
42 (defcustom riece-biff-default-mode-string "[-]"
43   "*String displayed when there is no arrival message."
44   :type 'string
45   :group 'riece-biff)
46
47 (defcustom riece-biff-biff-mode-string "[R]"
48   "*String displayed when there are new arrival messages."
49   :type 'string
50   :group 'riece-biff)
51
52 (defvar riece-biff-mode-string 'riece-biff-default-mode-string)
53
54 (defvar riece-biff-enabled nil)
55
56 (defconst riece-biff-description
57   "Be notified if messages arrives.")
58
59 (defun riece-biff-after-display-message-function (message)
60   (when (and riece-biff-enabled
61              (not (or (eq (window-buffer (selected-window))
62                           (get-buffer riece-command-buffer))
63                       (riece-message-own-p message)
64                       (riece-message-type message))))
65     (when (or (null riece-biff-check-channels)
66               (member (riece-format-identity (riece-message-target message))
67                       riece-biff-check-channels))
68       (setq riece-biff-mode-string 'riece-biff-biff-mode-string))))
69
70 (defun riece-biff-clear (&optional dummy)
71   (when riece-biff-enabled
72     (setq riece-biff-mode-string 'riece-biff-default-mode-string)))
73
74 (defun riece-biff-insinuate ()
75   (add-hook 'riece-after-display-message-functions
76             'riece-biff-after-display-message-function)
77   (add-hook 'riece-redisplay-buffers-hook 'riece-biff-clear)
78   (add-hook 'riece-after-switch-to-channel-functions 'riece-biff-clear)
79   (add-hook 'riece-exit-hook 'riece-biff-disable))
80
81 (defun riece-biff-uninstall ()
82   (remove-hook 'riece-after-display-message-functions
83                'riece-biff-after-display-message-function)
84   (remove-hook 'riece-redisplay-buffers-hook 'riece-biff-clear)
85   (remove-hook 'riece-after-switch-to-channel-functions 'riece-biff-clear)
86   (remove-hook 'riece-exit-hook 'riece-biff-disable))
87
88 (defun riece-biff-enable ()
89   (setq global-mode-string
90         (cond
91          ((nlistp global-mode-string)
92           (list "" 'riece-biff-mode-string global-mode-string))
93          ((not (memq 'riece-biff-mode-string global-mode-string))
94           (append '("" riece-biff-mode-string)
95                   (remove "" global-mode-string)))
96          (t
97           global-mode-string)))
98   (setq riece-biff-enabled t))
99
100 (defun riece-biff-disable ()
101   (setq global-mode-string
102         (cond
103          ((and (listp global-mode-string)
104                (memq 'riece-biff-mode-string global-mode-string))
105           (remq 'riece-biff-mode-string global-mode-string))
106          (t
107           global-mode-string)))
108   (riece-biff-clear)
109   (setq riece-biff-enabled nil))
110
111 (provide 'riece-biff)
112
113 ;;; riece-biff.el ends here