(cf. the last paragraph of `kill-buffer' docstring)
[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 t)
31
32 ;;; Code:
33
34 (eval-when-compile (require 'riece-message))
35
36 (defvar riece-unread-channels nil)
37
38 (defun riece-unread-display-message-function (message)
39   (unless (or (riece-message-own-p message)
40               (equal (riece-message-target message) riece-current-channel))
41     (add-to-list 'riece-unread-channels
42                  (riece-message-target message))
43     (riece-unread-update-channel-list-buffer)))
44
45 (defun riece-unread-channel-switch-hook ()
46   (setq riece-unread-channels
47         (delete riece-current-channel
48                 riece-unread-channels))
49   (riece-unread-update-channel-list-buffer))
50
51 (defun riece-unread-update-channel-list-buffer ()
52   (if riece-channel-list-buffer-mode
53       (save-excursion
54         (set-buffer riece-channel-list-buffer)
55         (let ((inhibit-read-only t)
56               buffer-read-only)
57           (goto-char (point-min))
58           (while (not (eobp))
59             (if (looking-at "\\( ?[0-9]+:\\)\\([ !]\\)\\(.+\\)")
60                 (let ((channel (match-string 3)))
61                   (replace-match
62                    (concat "\\1"
63                            (if (member channel riece-unread-channels)
64                                "!"
65                              " ")
66                            "\\3"))))
67             (forward-line))))))
68       
69 (defun riece-unread-insinuate ()
70   (add-hook 'riece-after-display-message-functions
71             'riece-unread-display-message-function)
72   (add-hook 'riece-channel-switch-hook
73             'riece-unread-channel-switch-hook)
74   (add-hook 'riece-update-buffers-hook
75             'riece-unread-update-channel-list-buffer))
76
77 (provide 'riece-unread)
78
79 ;;; riece-unread.el ends here