1 ;;; riece-history.el --- manage history of channel shifting
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., 51 Franklin Street, Fifth Floor,
22 ;; Boston, MA 02110-1301, USA.
26 ;; NOTE: This is an add-on module for Riece.
28 ;; You can check recently visited 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-history)
36 (require 'riece-options)
37 (require 'riece-globals)
38 (require 'riece-identity)
39 (require 'riece-signal)
41 (require 'riece-highlight)
43 (defgroup riece-history nil
44 "Manage history of channel shifting."
49 (defcustom riece-channel-history-length 3
50 "Length of riece-channel-history."
52 :group 'riece-history)
54 (defface riece-channel-list-history-face
57 (:foreground "PaleTurquoise"))
60 (:foreground "SeaGreen3"))
63 "Face used for displaying history channels."
64 :group 'riece-highlight-faces)
65 (defvar riece-channel-list-history-face 'riece-channel-list-history-face)
67 (unless (riece-facep 'riece-modeline-history-face)
68 (make-face 'riece-modeline-history-face
69 "Face used for displaying history channels in modeline.")
70 (if (featurep 'xemacs)
71 (set-face-parent 'riece-modeline-history-face 'modeline))
72 (set-face-foreground 'riece-modeline-history-face
73 (face-foreground 'riece-channel-list-history-face)))
75 (defvar riece-modeline-history-face 'riece-modeline-history-face)
77 (defvar riece-channel-history nil)
79 (defconst riece-history-description
80 "Manage history of channel shifting.")
82 (defun riece-guess-channel-from-history ()
83 (let ((length (ring-length riece-channel-history))
86 (while (< index length)
87 (setq result (cons (ring-ref riece-channel-history index) result)
91 (defun riece-history-format-identity-for-channel-list-buffer (index identity)
92 (if (and (get 'riece-history 'riece-addon-enabled)
93 (not (ring-empty-p riece-channel-history))
94 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
95 (concat (format "%2d:+" index)
96 (riece-format-identity identity))))
98 (defun riece-history-format-identity-for-channel-list-indicator (index
100 (if (and (get 'riece-history 'riece-addon-enabled)
101 (not (ring-empty-p riece-channel-history))
102 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
103 (let ((string (riece-format-identity identity))
106 (while (string-match "%" string start)
107 (setq start (1+ (match-end 0))
108 string (replace-match "%%" nil nil string)))
109 (list (format "%d:" index)
110 (riece-propertize-modeline-string
111 string 'face 'riece-modeline-history-face)))))
113 ;;; (defun riece-history-requires ()
114 ;;; (if (memq 'riece-guess riece-addons)
117 (defun riece-history-after-switch-to-channel-functions (last)
118 (if (and (get 'riece-history 'riece-addon-enabled) last
119 (not (riece-identity-equal last riece-current-channel)))
120 (ring-insert riece-channel-history last)))
122 (defun riece-history-requires ()
123 (if (memq 'riece-highlight riece-addons)
126 (defun riece-history-insinuate ()
127 (add-hook 'riece-after-switch-to-channel-functions
128 'riece-history-after-switch-to-channel-functions)
129 (add-hook 'riece-format-identity-for-channel-list-buffer-functions
130 'riece-history-format-identity-for-channel-list-buffer)
131 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
132 'riece-history-format-identity-for-channel-list-indicator)
133 (if (memq 'riece-highlight riece-addons)
134 (setq riece-channel-list-mark-face-alist
135 (cons '(?+ . riece-channel-list-history-face)
136 riece-channel-list-mark-face-alist)))
137 ;;; (if (memq 'riece-guess riece-addons)
138 ;;; (add-hook 'riece-guess-channel-try-functions
139 ;;; 'riece-guess-channel-from-history))
142 (defun riece-history-uninstall ()
143 (remove-hook 'riece-after-switch-to-channel-functions
144 'riece-history-after-switch-to-channel-functions)
145 (remove-hook 'riece-format-identity-for-channel-list-buffer-functions
146 'riece-history-format-identity-for-channel-list-buffer)
147 (remove-hook 'riece-format-identity-for-channel-list-indicator-functions
148 'riece-history-format-identity-for-channel-list-indicator)
149 (setq riece-channel-list-mark-face-alist
150 (delq (assq ?+ riece-channel-list-mark-face-alist)
151 riece-channel-list-mark-face-alist)))
153 (defun riece-history-enable ()
154 (setq riece-channel-history
155 (make-ring riece-channel-history-length))
156 (riece-emit-signal 'channel-list-changed))
158 (defun riece-history-disable ()
159 (setq riece-channel-history nil)
160 (riece-emit-signal 'channel-list-changed))
162 (provide 'riece-history)
164 ;;; riece-history.el ends here