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
53 (:foreground "orange"))
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-after-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-after-switch-to-channel-function (last)
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 (defun riece-guess-channel-from-unread ()
105 riece-unread-channels)
107 (defvar riece-command-mode-map)
108 (defvar riece-dialogue-mode-map)
109 (defvar riece-channel-list-mode-map)
111 (defun riece-unread-requires ()
113 (if (memq 'riece-highlight riece-addons)
114 (setq requires (cons 'riece-highlight requires)))
115 (if (memq 'riece-guess riece-addons)
116 (setq requires (cons 'riece-guess requires)))
117 ;; riece-guess-channel-from-unread should be prior to
118 ;; riece-guess-channel-from-history.
119 (if (memq 'riece-history riece-addons)
120 (setq requires (cons 'riece-history requires)))
123 (defun riece-unread-insinuate ()
124 (add-hook 'riece-after-display-message-functions
125 'riece-unread-after-display-message-function)
126 (add-hook 'riece-after-switch-to-channel-functions
127 'riece-unread-after-switch-to-channel-function)
128 (add-hook 'riece-update-buffer-functions
129 'riece-unread-update-channel-list-buffer t)
130 (define-key riece-command-mode-map
131 "\C-c\C-u" 'riece-unread-switch-to-channel)
132 (define-key riece-dialogue-mode-map
133 "u" 'riece-unread-switch-to-channel)
134 (define-key riece-channel-list-mode-map
135 "u" 'riece-unread-switch-to-channel)
136 (if (memq 'riece-highlight riece-addons)
137 (setq riece-channel-list-mark-face-alist
138 (cons '(?! . riece-channel-list-unread-face)
139 riece-channel-list-mark-face-alist)))
140 (if (memq 'riece-guess riece-addons)
141 (add-hook 'riece-guess-channel-try-functions
142 'riece-guess-channel-from-unread)))
144 (provide 'riece-unread)
146 ;;; riece-unread.el ends here