Fix byte-compile error
[riece] / lisp / riece-biff.el
1 ;;; riece-biff.el --- be notified if messages arrives -*- lexical-binding: t -*-
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., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, 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 (defconst riece-biff-description
55   "Be notified if messages arrives.")
56
57 (defun riece-biff-after-display-message-function (message)
58   (when (and (get 'riece-biff 'riece-addon-enabled)
59              (not (or (eq (window-buffer (selected-window))
60                           (get-buffer riece-command-buffer))
61                       (riece-message-own-p message)
62                       (riece-message-type message))))
63     (when (or (null riece-biff-check-channels)
64               (member (riece-format-identity (riece-message-target message))
65                       riece-biff-check-channels))
66       (setq riece-biff-mode-string 'riece-biff-biff-mode-string))))
67
68 (defun riece-biff-clear (&optional _dummy)
69   (when (get 'riece-biff 'riece-addon-enabled)
70     (setq riece-biff-mode-string 'riece-biff-default-mode-string)))
71
72 (defun riece-biff-insinuate ()
73   (add-hook 'riece-after-display-message-functions
74             'riece-biff-after-display-message-function)
75   (add-hook 'riece-redisplay-buffers-hook 'riece-biff-clear)
76   (add-hook 'riece-after-switch-to-channel-functions 'riece-biff-clear)
77   (add-hook 'riece-exit-hook 'riece-biff-disable))
78
79 (defun riece-biff-uninstall ()
80   (remove-hook 'riece-after-display-message-functions
81                'riece-biff-after-display-message-function)
82   (remove-hook 'riece-redisplay-buffers-hook 'riece-biff-clear)
83   (remove-hook 'riece-after-switch-to-channel-functions 'riece-biff-clear)
84   (remove-hook 'riece-exit-hook 'riece-biff-disable))
85
86 (defun riece-biff-enable ()
87   (setq global-mode-string
88         (cond
89          ((nlistp global-mode-string)
90           (list "" 'riece-biff-mode-string global-mode-string))
91          ((not (memq 'riece-biff-mode-string global-mode-string))
92           (append '("" riece-biff-mode-string)
93                   (remove "" global-mode-string)))
94          (t
95           global-mode-string))))
96
97 (defun riece-biff-disable ()
98   (setq global-mode-string
99         (cond
100          ((and (listp global-mode-string)
101                (memq 'riece-biff-mode-string global-mode-string))
102           (remq 'riece-biff-mode-string global-mode-string))
103          (t
104           global-mode-string)))
105   (riece-biff-clear))
106
107 (provide 'riece-biff)
108
109 ;;; riece-biff.el ends here