Fixed.
[riece] / lisp / riece-biff.el
1 ;;; riece-biff.el --- biff add-on
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 ;; To use, add the following line to your ~/.riece/init.el:
27 ;; (add-to-list 'riece-addons 'riece-biff)
28
29 ;;; Code:
30
31 (require 'riece-message)
32
33 (defgroup riece-biff nil
34   "Biff for new arrival messages."
35   :prefix "riece-"
36   :group 'riece)
37
38 (defcustom riece-biff-check-channels nil
39   "*If non-nil, riece-biff checks only the channel contained in this list."
40   :type '(repeat string)
41   :group 'riece-biff)
42
43 (defcustom riece-biff-default-mode-string "[-]"
44   "*String displayed when there is no arrival message."
45   :type 'string
46   :group 'riece-biff)
47
48 (defcustom riece-biff-biff-mode-string "[R]"
49   "*String displayed when there are new arrival messages."
50   :type 'string
51   :group 'riece-biff)
52
53 (defvar riece-biff-mode-string 'riece-biff-default-mode-string)
54
55 (defvar riece-biff-enabled nil)
56
57 (defconst riece-biff-description
58   "Biff for new arrival messages")
59
60 (defun riece-biff-after-display-message-function (message)
61   (when (and riece-biff-enabled
62              (not (or (eq (window-buffer (selected-window))
63                           (get-buffer riece-command-buffer))
64                       (riece-message-own-p message)
65                       (riece-message-type message))))
66     (when (or (null riece-biff-check-channels)
67               (member (riece-format-identity (riece-message-target message))
68                       riece-biff-check-channels))
69       (setq riece-biff-mode-string 'riece-biff-biff-mode-string))))
70
71 (defun riece-biff-clear (&optional dummy)
72   (when riece-biff-enabled
73     (setq riece-biff-mode-string 'riece-biff-default-mode-string)))
74
75 (defun riece-biff-insinuate ()
76   (add-hook 'riece-after-display-message-functions
77             'riece-biff-after-display-message-function)
78   (add-hook 'riece-redisplay-buffers-hook 'riece-biff-clear)
79   (add-hook 'riece-after-switch-to-channel-functions 'riece-biff-clear)
80   (add-hook 'riece-exit-hook 'riece-biff-disable))
81
82 (defun riece-biff-enable ()
83   (setq global-mode-string
84         (cond
85          ((nlistp global-mode-string)
86           (list "" 'riece-biff-mode-string global-mode-string))
87          ((not (memq 'riece-biff-mode-string global-mode-string))
88           (append '("" riece-biff-mode-string)
89                   (remove "" global-mode-string)))
90          (t
91           global-mode-string)))
92   (setq riece-biff-enabled t))
93
94 (defun riece-biff-disable ()
95   (setq global-mode-string
96         (cond
97          ((and (listp global-mode-string)
98                (memq 'riece-biff-mode-string global-mode-string))
99           (remq 'riece-biff-mode-string global-mode-string))
100          (t
101           global-mode-string)))
102   (riece-biff-clear)
103   (setq riece-biff-enabled nil))
104
105 (provide 'riece-biff)
106
107 ;;; riece-biff.el ends here