* riece-unread.el (riece-channel-list-unread-face): Change colors.
[riece] / lisp / riece-unread.el
1 ;;; riece-unread.el --- "unread message mark" add-on
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.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 ;; This add-on displays unread mark ("!") for channels which have
27 ;; "unread messages".
28
29 ;; To use, add the following line to your ~/.riece/init.el:
30 ;; (add-to-list 'riece-addons 'riece-unread)
31
32 ;;; Code:
33
34 (require 'riece-message)
35 (require 'riece-commands)
36
37 (eval-when-compile (require 'riece-highlight))
38
39 (defgroup riece-unread nil
40   "Mark unread channels"
41   :tag "Unread"
42   :prefix "riece-"
43   :group 'riece)
44
45 (defcustom riece-channel-list-unread-face 'riece-channel-list-unread-face
46   "Face used for displaying unread channels."
47   :type 'face
48   :group 'riece-highlight-faces)
49
50 (defface riece-channel-list-unread-face
51   '((((class color)
52       (background dark))
53      (:foreground "orange"))
54     (((class color)
55       (background light))
56      (:foreground "firebrick"))
57     (t
58      (:bold t)))
59   "Face used for displaying unread channels."
60   :group 'riece-highlight-faces)
61
62 (defvar riece-unread-channels nil)
63
64 (defun riece-unread-display-message-function (message)
65   (unless (or (riece-message-own-p message)
66               (equal (riece-message-target message) riece-current-channel))
67     (setq riece-unread-channels
68           (delete (riece-message-target message) riece-unread-channels))
69     (add-to-list 'riece-unread-channels
70                  (riece-message-target message))
71     (riece-unread-update-channel-list-buffer)))
72
73 (defun riece-unread-channel-switch-hook ()
74   (setq riece-unread-channels
75         (delete riece-current-channel
76                 riece-unread-channels))
77   (riece-unread-update-channel-list-buffer))
78
79 (defun riece-unread-update-channel-list-buffer ()
80   (if riece-channel-list-buffer-mode
81       (save-excursion
82         (set-buffer riece-channel-list-buffer)
83         (let ((inhibit-read-only t)
84               buffer-read-only)
85           (goto-char (point-min))
86           (while (not (eobp))
87             (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)\\(.+\\)")
88                 (let ((channel (save-match-data
89                                  (riece-parse-identity (match-string 3)))))
90                   (replace-match
91                    (concat "\\1"
92                            (if (member channel riece-unread-channels)
93                                "!"
94                              "\\2")
95                            "\\3"))))
96             (forward-line))))))
97       
98 (defun riece-unread-switch-to-channel ()
99   (interactive)
100   (if (car riece-unread-channels)
101       (riece-command-switch-to-channel (car riece-unread-channels))
102     (error "No unread channel!")))
103
104 (defvar riece-command-mode-map)
105 (defvar riece-dialogue-mode-map)
106 (defvar riece-channel-list-mode-map)
107
108 (defun riece-unread-requires ()
109   (if (memq 'riece-highlight riece-addons)
110       '(riece-highlight)))
111
112 (defun riece-unread-insinuate ()
113   (add-hook 'riece-after-display-message-functions
114             'riece-unread-display-message-function)
115   (add-hook 'riece-channel-switch-hook
116             'riece-unread-channel-switch-hook)
117   (add-hook 'riece-update-buffer-functions
118             'riece-unread-update-channel-list-buffer t)
119   (define-key riece-command-mode-map
120     "\C-c\C-u" 'riece-unread-switch-to-channel)
121   (define-key riece-dialogue-mode-map
122     "u" 'riece-unread-switch-to-channel)
123   (define-key riece-channel-list-mode-map
124     "u" 'riece-unread-switch-to-channel)
125   (if (memq 'riece-highlight riece-addons)
126       (setq riece-channel-list-mark-face-alist
127             (cons '(?! . riece-channel-list-unread-face)
128                   riece-channel-list-mark-face-alist))))
129
130 (provide 'riece-unread)
131
132 ;;; riece-unread.el ends here