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)
41 (require 'riece-highlight)
43 (defgroup riece-unread nil
44 "Mark unread channels."
49 (defface riece-channel-list-unread-face
52 (:foreground "orange"))
55 (:foreground "firebrick"))
58 "Face used for displaying unread channels."
59 :group 'riece-highlight-faces)
60 (defvar riece-channel-list-unread-face 'riece-channel-list-unread-face)
62 (unless (riece-facep 'riece-modeline-unread-face)
63 (make-face 'riece-modeline-unread-face
64 "Face used for displaying unread channels in modeline.")
65 (if (featurep 'xemacs)
66 (set-face-parent 'riece-modeline-unread-face 'modeline))
67 (set-face-foreground 'riece-modeline-unread-face
68 (face-foreground 'riece-channel-list-unread-face)))
70 (defvar riece-unread-channels nil)
72 (defvar riece-unread-enabled nil)
74 (defconst riece-unread-description
75 "Mark channels where new messages arrived.")
77 (defun riece-unread-after-display-message-function (message)
78 (if riece-unread-enabled
79 (let ((target (if (riece-message-private-p message)
80 (riece-message-speaker message)
81 (riece-message-target message))))
82 (unless (or (riece-message-own-p message)
83 (riece-message-type message)
84 (riece-identity-equal target riece-current-channel)
85 (riece-identity-member target riece-unread-channels))
86 (setq riece-unread-channels (cons target riece-unread-channels))
87 (riece-emit-signal 'channel-list-changed)))))
89 (defun riece-unread-after-switch-to-channel-function (last)
90 (if riece-unread-enabled
91 (setq riece-unread-channels
92 (delq (car (riece-identity-member riece-current-channel
93 riece-unread-channels))
94 riece-unread-channels))))
96 (defun riece-unread-format-identity-for-channel-list-buffer (index identity)
97 (if (and riece-unread-enabled
98 (riece-identity-member identity riece-unread-channels))
99 (concat (format "%2d:!" index)
100 (riece-format-identity identity))))
102 (defun riece-unread-format-identity-for-channel-list-indicator (index identity)
103 (if (and riece-unread-enabled
104 (riece-identity-member identity riece-unread-channels))
105 (let ((string (riece-format-identity identity))
108 (while (string-match "%" string start)
109 (setq start (1+ (match-end 0))
110 string (replace-match "%%" nil nil string)))
111 (list (format "%d:" index)
112 (riece-propertize-modeline-string
113 string 'face 'riece-modeline-unread-face)))))
115 (defun riece-unread-switch-to-channel ()
117 (if riece-unread-channels
118 (let ((channel (car riece-unread-channels)))
119 (if (riece-identity-member channel riece-current-channels)
120 (riece-command-switch-to-channel channel)
121 (setq riece-unread-channels
122 (delete channel riece-unread-channels))
123 (riece-unread-switch-to-channel)))
124 (error "No unread channel!")))
126 (defun riece-guess-channel-from-unread ()
127 (reverse riece-unread-channels))
129 (defun riece-unread-requires ()
131 (if (memq 'riece-highlight riece-addons)
132 (setq requires (cons 'riece-highlight requires)))
133 ;;; (if (memq 'riece-guess riece-addons)
134 ;;; (setq requires (cons 'riece-guess requires)))
137 (defun riece-unread-insinuate ()
138 (add-hook 'riece-after-display-message-functions
139 'riece-unread-after-display-message-function)
140 (add-hook 'riece-after-switch-to-channel-functions
141 'riece-unread-after-switch-to-channel-function)
142 (add-hook 'riece-format-identity-for-channel-list-buffer-functions
143 'riece-unread-format-identity-for-channel-list-buffer)
144 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
145 'riece-unread-format-identity-for-channel-list-indicator)
146 (if (memq 'riece-highlight riece-addons)
147 (setq riece-channel-list-mark-face-alist
148 (cons '(?! . riece-channel-list-unread-face)
149 riece-channel-list-mark-face-alist)))
150 ;;; (if (memq 'riece-guess riece-addons)
151 ;;; (add-hook 'riece-guess-channel-try-functions
152 ;;; 'riece-guess-channel-from-unread))
155 (defun riece-unread-uninstall ()
156 (remove-hook 'riece-after-display-message-functions
157 'riece-unread-after-display-message-function)
158 (remove-hook 'riece-after-switch-to-channel-functions
159 'riece-unread-after-switch-to-channel-function)
160 (remove-hook 'riece-format-identity-for-channel-list-buffer-functions
161 'riece-unread-format-identity-for-channel-list-buffer)
162 (remove-hook 'riece-format-identity-for-channel-list-indicator-functions
163 'riece-unread-format-identity-for-channel-list-indicator)
164 (setq riece-channel-list-mark-face-alist
165 (delq (assq ?! riece-channel-list-mark-face-alist)
166 riece-channel-list-mark-face-alist))
167 ;;; (if (memq 'riece-guess riece-addons)
168 ;;; (add-hook 'riece-guess-channel-try-functions
169 ;;; 'riece-guess-channel-from-unread))
172 (defvar riece-command-mode-map)
173 (defvar riece-dialogue-mode-map)
174 (defvar riece-channel-list-mode-map)
175 (defun riece-unread-enable ()
176 (define-key riece-command-mode-map
177 "\C-c\C-u" 'riece-unread-switch-to-channel)
178 (define-key riece-dialogue-mode-map
179 "u" 'riece-unread-switch-to-channel)
180 (define-key riece-channel-list-mode-map
181 "u" 'riece-unread-switch-to-channel)
182 (setq riece-unread-enabled t)
183 (riece-emit-signal 'channel-list-changed))
185 (defun riece-unread-disable ()
186 (define-key riece-command-mode-map
188 (define-key riece-dialogue-mode-map
190 (define-key riece-channel-list-mode-map
192 (setq riece-unread-channels nil
193 riece-unread-enabled nil)
194 (riece-emit-signal 'channel-list-changed))
196 (provide 'riece-unread)
198 ;;; riece-unread.el ends here