1 ;;; riece-unread.el --- "unread message mark" add-on
2 ;; Copyright (C) 1998-2003 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
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)
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.
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.
26 ;; This add-on displays unread mark ("!") for channels which have
29 ;; To use, add the following line to your ~/.riece/init.el:
30 ;; (add-to-list 'riece-addons 'riece-unread)
34 (require 'riece-message)
35 (require 'riece-commands)
37 (eval-when-compile (require 'riece-highlight))
39 (defgroup riece-unread nil
40 "Mark unread channels"
45 (defcustom riece-channel-list-unread-face 'riece-channel-list-unread-face
46 "Face used for displaying unread channels."
48 :group 'riece-highlight-faces)
50 (defface riece-channel-list-unread-face
56 (:foreground "firebrick"))
59 "Face used for displaying unread channels."
60 :group 'riece-highlight-faces)
62 (defvar riece-unread-channels nil)
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)))
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))
79 (defun riece-unread-update-channel-list-buffer ()
80 (if riece-channel-list-buffer-mode
82 (set-buffer riece-channel-list-buffer)
83 (let ((inhibit-read-only t)
85 (goto-char (point-min))
87 (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)\\(.+\\)")
88 (let ((channel (save-match-data
89 (riece-parse-identity (match-string 3)))))
92 (if (member channel riece-unread-channels)
98 (defun riece-unread-switch-to-channel ()
100 (if (car riece-unread-channels)
101 (riece-command-switch-to-channel (car riece-unread-channels))
102 (error "No unread channel!")))
104 (defvar riece-command-mode-map)
105 (defvar riece-dialogue-mode-map)
106 (defvar riece-channel-list-mode-map)
108 (defun riece-unread-requires ()
109 (if (memq 'riece-highlight riece-addons)
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))))
130 (provide 'riece-unread)
132 ;;; riece-unread.el ends here