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 marks channels where new messages are arrived.
28 ;; You can check the unread channels via `C-c g' in the commands
29 ;; buffer, by adding the following lines to ~/.riece/init.el:
31 ;; (add-hook 'riece-guess-channel-try-functions
32 ;; 'riece-guess-channel-from-unread)
36 (require 'riece-message)
37 (require 'riece-commands)
39 (eval-when-compile (require 'riece-highlight))
41 (defgroup riece-unread nil
42 "Mark unread channels"
47 (defface riece-channel-list-unread-face
50 (:foreground "orange"))
53 (:foreground "firebrick"))
56 "Face used for displaying unread channels."
57 :group 'riece-highlight-faces)
58 (defvar riece-channel-list-unread-face 'riece-channel-list-unread-face)
60 (defvar riece-unread-channels nil)
62 (defun riece-unread-after-display-message-function (message)
63 (unless (or (riece-message-own-p message)
64 (equal (riece-message-target message) riece-current-channel))
65 (setq riece-unread-channels
66 (delete (riece-message-target message) riece-unread-channels))
67 (add-to-list 'riece-unread-channels
68 (riece-message-target message))
69 (riece-unread-update-channel-list-buffer)))
71 (defun riece-unread-after-switch-to-channel-function (last)
72 (setq riece-unread-channels
73 (delete riece-current-channel
74 riece-unread-channels))
75 (riece-unread-update-channel-list-buffer))
77 (defun riece-unread-update-channel-list-buffer ()
78 (if riece-channel-list-buffer-mode
80 (set-buffer riece-channel-list-buffer)
81 (let ((inhibit-read-only t)
83 (goto-char (point-min))
85 (if (looking-at "\\( ?[0-9]+:\\)\\(.\\)\\(.+\\)")
86 (let ((channel (save-match-data
87 (riece-parse-identity (match-string 3)))))
90 (if (member channel riece-unread-channels)
96 (defun riece-unread-switch-to-channel ()
98 (if (car riece-unread-channels)
99 (riece-command-switch-to-channel (car riece-unread-channels))
100 (error "No unread channel!")))
102 (defun riece-guess-channel-from-unread ()
103 riece-unread-channels)
105 (defvar riece-command-mode-map)
106 (defvar riece-dialogue-mode-map)
107 (defvar riece-channel-list-mode-map)
109 (defun riece-unread-requires ()
111 (if (memq 'riece-highlight riece-addons)
112 (setq requires (cons 'riece-highlight requires)))
113 ;;; (if (memq 'riece-guess riece-addons)
114 ;;; (setq requires (cons 'riece-guess requires)))
117 (defun riece-unread-insinuate ()
118 (add-hook 'riece-after-display-message-functions
119 'riece-unread-after-display-message-function)
120 (add-hook 'riece-after-switch-to-channel-functions
121 'riece-unread-after-switch-to-channel-function)
122 (add-hook 'riece-update-buffer-functions
123 'riece-unread-update-channel-list-buffer t)
124 (define-key riece-command-mode-map
125 "\C-c\C-u" 'riece-unread-switch-to-channel)
126 (define-key riece-dialogue-mode-map
127 "u" 'riece-unread-switch-to-channel)
128 (define-key riece-channel-list-mode-map
129 "u" 'riece-unread-switch-to-channel)
130 (if (memq 'riece-highlight riece-addons)
131 (setq riece-channel-list-mark-face-alist
132 (cons '(?! . riece-channel-list-unread-face)
133 riece-channel-list-mark-face-alist)))
134 ;;; (if (memq 'riece-guess riece-addons)
135 ;;; (add-hook 'riece-guess-channel-try-functions
136 ;;; 'riece-guess-channel-from-unread))
139 (provide 'riece-unread)
141 ;;; riece-unread.el ends here