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)
38 (require 'riece-signal)
40 (eval-when-compile (require 'riece-highlight))
42 (defgroup riece-unread nil
43 "Mark unread channels"
48 (defface riece-channel-list-unread-face
51 (:foreground "orange"))
54 (:foreground "firebrick"))
57 "Face used for displaying unread channels."
58 :group 'riece-highlight-faces)
59 (defvar riece-channel-list-unread-face 'riece-channel-list-unread-face)
61 (defvar riece-unread-channels nil)
63 (defun riece-unread-after-display-message-function (message)
64 (unless (or (riece-message-own-p message)
65 (riece-message-type message)
66 (riece-identity-equal (riece-message-target message)
67 riece-current-channel)
68 (riece-identity-member (riece-message-target message)
69 riece-unread-channels))
70 (setq riece-unread-channels
71 (cons (riece-message-target message) riece-unread-channels))
72 (riece-emit-signal 'channel-list-changed)))
74 (defun riece-unread-after-switch-to-channel-function (last)
75 (setq riece-unread-channels
76 (delete riece-current-channel
77 riece-unread-channels)))
79 (defun riece-unread-format-identity-for-channel-list-buffer (index identity)
80 (if (riece-identity-member identity riece-unread-channels)
81 (concat (format "%2d:!" index)
82 (riece-format-identity identity))))
84 (defun riece-unread-format-identity-for-channel-list-indicator (index identity)
85 (if (riece-identity-member identity riece-unread-channels)
86 (let ((string (riece-format-identity identity))
90 (while (string-match "%" string start)
91 (setq start (1+ (match-end 0))
92 string (replace-match "%%" nil nil string)))
93 (list (format "%d:" index)
94 (riece-propertize-modeline-string
95 string 'face 'riece-channel-list-unread-face)))))
97 (defun riece-unread-switch-to-channel ()
99 (if riece-unread-channels
100 (let ((channel (car riece-unread-channels)))
101 (if (riece-identity-member channel riece-current-channels)
102 (riece-command-switch-to-channel channel)
103 (setq riece-unread-channels
104 (delete channel riece-unread-channels))
105 (riece-unread-switch-to-channel)))
106 (error "No unread channel!")))
108 (defun riece-guess-channel-from-unread ()
109 riece-unread-channels)
111 (defvar riece-command-mode-map)
112 (defvar riece-dialogue-mode-map)
113 (defvar riece-channel-list-mode-map)
115 (defun riece-unread-requires ()
117 (if (memq 'riece-highlight riece-addons)
118 (setq requires (cons 'riece-highlight requires)))
119 ;;; (if (memq 'riece-guess riece-addons)
120 ;;; (setq requires (cons 'riece-guess 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-format-identity-for-channel-list-buffer-functions
129 'riece-unread-format-identity-for-channel-list-buffer)
130 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
131 'riece-unread-format-identity-for-channel-list-indicator)
132 (define-key riece-command-mode-map
133 "\C-c\C-u" 'riece-unread-switch-to-channel)
134 (define-key riece-dialogue-mode-map
135 "u" 'riece-unread-switch-to-channel)
136 (define-key riece-channel-list-mode-map
137 "u" 'riece-unread-switch-to-channel)
138 (if (memq 'riece-highlight riece-addons)
139 (setq riece-channel-list-mark-face-alist
140 (cons '(?! . riece-channel-list-unread-face)
141 riece-channel-list-mark-face-alist)))
142 ;;; (if (memq 'riece-guess riece-addons)
143 ;;; (add-hook 'riece-guess-channel-try-functions
144 ;;; 'riece-guess-channel-from-unread))
147 (provide 'riece-unread)
149 ;;; riece-unread.el ends here