1 ;;; riece-history.el --- channel history management 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 ;; You can check recently visited channels via `C-c g' in the commands
27 ;; buffer, by adding the following lines to ~/.riece/init.el:
29 ;; (add-hook 'riece-guess-channel-try-functions
30 ;; 'riece-guess-channel-from-history)
34 (require 'riece-options)
35 (require 'riece-globals)
36 (require 'riece-highlight)
37 (require 'riece-identity)
38 (require 'riece-signal)
41 (defgroup riece-history nil
47 (defcustom riece-channel-history-length 3
48 "Length of riece-channel-history."
50 :group 'riece-history)
52 (defface riece-channel-list-history-face
55 (:foreground "PaleTurquoise"))
58 (:foreground "SeaGreen3"))
61 "Face used for displaying history channels."
62 :group 'riece-highlight-faces)
63 (defvar riece-channel-list-history-face 'riece-channel-list-history-face)
65 (defvar riece-channel-history nil)
67 (defvar riece-history-enabled nil)
69 (defconst riece-history-description
70 "Keep track channel history")
72 (defun riece-guess-channel-from-history ()
73 (let ((length (ring-length riece-channel-history))
76 (while (< index length)
77 (setq result (cons (ring-ref riece-channel-history index) result)
81 (defun riece-history-format-identity-for-channel-list-buffer (index identity)
82 (if (and riece-history-enabled
83 (not (ring-empty-p riece-channel-history))
84 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
85 (concat (format "%2d:+" index)
86 (riece-format-identity identity))))
88 (defun riece-history-format-identity-for-channel-list-indicator (index
90 (if (and riece-history-enabled
91 (not (ring-empty-p riece-channel-history))
92 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
93 (let ((string (riece-format-identity identity))
96 (while (string-match "%" string start)
97 (setq start (1+ (match-end 0))
98 string (replace-match "%%" nil nil string)))
99 (list (format "%d:" index)
100 (riece-propertize-modeline-string
101 string 'face 'riece-channel-list-history-face)))))
103 ;;; (defun riece-history-requires ()
104 ;;; (if (memq 'riece-guess riece-addons)
107 (defun riece-history-insinuate ()
108 (add-hook 'riece-after-switch-to-channel-functions
110 (if (and riece-history-enabled last
111 (not (riece-identity-equal last riece-current-channel)))
112 (ring-insert riece-channel-history last))))
113 (add-hook 'riece-format-identity-for-channel-list-buffer-functions
114 'riece-history-format-identity-for-channel-list-buffer)
115 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
116 'riece-history-format-identity-for-channel-list-indicator)
117 (if (memq 'riece-highlight riece-addons)
118 (setq riece-channel-list-mark-face-alist
119 (cons '(?+ . riece-channel-list-history-face)
120 riece-channel-list-mark-face-alist)))
121 ;;; (if (memq 'riece-guess riece-addons)
122 ;;; (add-hook 'riece-guess-channel-try-functions
123 ;;; 'riece-guess-channel-from-history))
126 (defun riece-history-enable ()
127 (setq riece-channel-history
128 (make-ring riece-channel-history-length))
129 (setq riece-history-enabled t)
130 (riece-emit-signal 'channel-list-changed))
132 (defun riece-history-disable ()
133 (setq riece-channel-history nil
134 riece-history-enabled nil)
135 (riece-emit-signal 'channel-list-changed))
137 (provide 'riece-history)
139 ;;; riece-history.el ends here