1 ;;; riece-unread.el --- mark channels where new messages arrived
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 ;; NOTE: This is an add-on module for Riece.
28 ;; This add-on marks channels where new messages arrived.
30 ;; You can check the unread channels via `C-c g' in the commands
31 ;; buffer, by adding the following lines to ~/.riece/init.el:
33 ;; (add-hook 'riece-guess-channel-try-functions
34 ;; 'riece-guess-channel-from-unread)
38 (require 'riece-message)
39 (require 'riece-commands)
40 (require 'riece-signal)
42 (eval-when-compile (require 'riece-highlight))
44 (defgroup riece-unread nil
45 "Mark unread channels."
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)
61 (defvar riece-channel-list-unread-face 'riece-channel-list-unread-face)
63 (unless (riece-facep 'riece-modeline-unread-face)
64 (make-face 'riece-modeline-unread-face
65 "Face used for displaying unread channels in modeline.")
66 (if (featurep 'xemacs)
67 (set-face-parent 'riece-modeline-unread-face 'modeline))
68 (set-face-foreground 'riece-modeline-unread-face
69 (face-foreground 'riece-channel-list-unread-face)))
71 (defvar riece-unread-channels nil)
73 (defvar riece-unread-enabled nil)
75 (defconst riece-unread-description
76 "Mark channels where new messages arrived.")
78 (defun riece-unread-after-display-message-function (message)
79 (if riece-unread-enabled
80 (let ((target (if (riece-message-private-p message)
81 (riece-message-speaker message)
82 (riece-message-target message))))
83 (unless (or (riece-message-own-p message)
84 (riece-message-type message)
85 (riece-identity-equal target riece-current-channel)
86 (riece-identity-member target riece-unread-channels))
87 (setq riece-unread-channels (cons target riece-unread-channels))
88 (riece-emit-signal 'channel-list-changed)))))
90 (defun riece-unread-after-switch-to-channel-function (last)
91 (if riece-unread-enabled
92 (setq riece-unread-channels
93 (delq (car (riece-identity-member riece-current-channel
94 riece-unread-channels))
95 riece-unread-channels))))
97 (defun riece-unread-format-identity-for-channel-list-buffer (index identity)
98 (if (and riece-unread-enabled
99 (riece-identity-member identity riece-unread-channels))
100 (concat (format "%2d:!" index)
101 (riece-format-identity identity))))
103 (defun riece-unread-format-identity-for-channel-list-indicator (index identity)
104 (if (and riece-unread-enabled
105 (riece-identity-member identity riece-unread-channels))
106 (let ((string (riece-format-identity identity))
109 (while (string-match "%" string start)
110 (setq start (1+ (match-end 0))
111 string (replace-match "%%" nil nil string)))
112 (list (format "%d:" index)
113 (riece-propertize-modeline-string
114 string 'face 'riece-modeline-unread-face)))))
116 (defun riece-unread-switch-to-channel ()
118 (if riece-unread-channels
119 (let ((channel (car riece-unread-channels)))
120 (if (riece-identity-member channel riece-current-channels)
121 (riece-command-switch-to-channel channel)
122 (setq riece-unread-channels
123 (delete channel riece-unread-channels))
124 (riece-unread-switch-to-channel)))
125 (error "No unread channel!")))
127 (defun riece-guess-channel-from-unread ()
128 (reverse riece-unread-channels))
130 (defun riece-unread-requires ()
132 (if (memq 'riece-highlight riece-addons)
133 (setq requires (cons 'riece-highlight requires)))
134 ;;; (if (memq 'riece-guess riece-addons)
135 ;;; (setq requires (cons 'riece-guess requires)))
138 (defun riece-unread-insinuate ()
139 (add-hook 'riece-after-display-message-functions
140 'riece-unread-after-display-message-function)
141 (add-hook 'riece-after-switch-to-channel-functions
142 'riece-unread-after-switch-to-channel-function)
143 (add-hook 'riece-format-identity-for-channel-list-buffer-functions
144 'riece-unread-format-identity-for-channel-list-buffer)
145 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
146 'riece-unread-format-identity-for-channel-list-indicator)
147 (if (memq 'riece-highlight riece-addons)
148 (setq riece-channel-list-mark-face-alist
149 (cons '(?! . riece-channel-list-unread-face)
150 riece-channel-list-mark-face-alist)))
151 ;;; (if (memq 'riece-guess riece-addons)
152 ;;; (add-hook 'riece-guess-channel-try-functions
153 ;;; 'riece-guess-channel-from-unread))
156 (defvar riece-command-mode-map)
157 (defvar riece-dialogue-mode-map)
158 (defvar riece-channel-list-mode-map)
159 (defun riece-unread-enable ()
160 (define-key riece-command-mode-map
161 "\C-c\C-u" 'riece-unread-switch-to-channel)
162 (define-key riece-dialogue-mode-map
163 "u" 'riece-unread-switch-to-channel)
164 (define-key riece-channel-list-mode-map
165 "u" 'riece-unread-switch-to-channel)
166 (setq riece-unread-enabled t)
167 (riece-emit-signal 'channel-list-changed))
169 (defun riece-unread-disable ()
170 (define-key riece-command-mode-map
172 (define-key riece-dialogue-mode-map
174 (define-key riece-channel-list-mode-map
176 (setq riece-unread-channels nil
177 riece-unread-enabled nil)
178 (riece-emit-signal 'channel-list-changed))
180 (provide 'riece-unread)
182 ;;; riece-unread.el ends here