1 ;;; riece-history.el --- manage history of channel shifting -*- lexical-binding: t -*-
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 ;; In Emacs, set-face-doc-string is an alias to
69 ;; set-face-documentation, but we use the former since it is
70 ;; available in both Emacs and XEmacs.
71 (make-face 'riece-modeline-history-face)
73 'riece-modeline-history-face
74 "Face used for displaying history channels in modeline.")
75 (if (featurep 'xemacs)
76 (set-face-parent 'riece-modeline-history-face 'modeline))
77 (set-face-foreground 'riece-modeline-history-face
78 (face-foreground 'riece-channel-list-history-face)))
80 (defvar riece-modeline-history-face 'riece-modeline-history-face)
82 (defvar riece-channel-history nil)
84 (defconst riece-history-description
85 "Manage history of channel shifting.")
87 (defun riece-guess-channel-from-history ()
88 (let ((length (ring-length riece-channel-history))
91 (while (< index length)
92 (setq result (cons (ring-ref riece-channel-history index) result)
96 (defun riece-history-format-identity-for-channel-list-buffer (index identity)
97 (if (and (get 'riece-history 'riece-addon-enabled)
98 (not (ring-empty-p riece-channel-history))
99 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
100 (concat (format "%2d:+" index)
101 (riece-format-identity identity))))
103 (defun riece-history-format-identity-for-channel-list-indicator (index
105 (if (and (get 'riece-history 'riece-addon-enabled)
106 (not (ring-empty-p riece-channel-history))
107 (riece-identity-equal identity (ring-ref riece-channel-history 0)))
108 (let ((string (riece-format-identity identity))
111 (while (string-match "%" string start)
112 (setq start (1+ (match-end 0))
113 string (replace-match "%%" nil nil string)))
114 (list (format "%d:" index)
115 (riece-propertize-modeline-string
116 string 'face 'riece-modeline-history-face)))))
118 ;;; (defun riece-history-requires ()
119 ;;; (if (memq 'riece-guess riece-addons)
122 (defun riece-history-after-switch-to-channel-functions (last)
123 (if (and (get 'riece-history 'riece-addon-enabled) last
124 (not (riece-identity-equal last riece-current-channel)))
125 (ring-insert riece-channel-history last)))
127 (defun riece-history-requires ()
128 (if (memq 'riece-highlight riece-addons)
131 (defun riece-history-insinuate ()
132 (add-hook 'riece-after-switch-to-channel-functions
133 'riece-history-after-switch-to-channel-functions)
134 (add-hook 'riece-format-identity-for-channel-list-buffer-functions
135 'riece-history-format-identity-for-channel-list-buffer)
136 (add-hook 'riece-format-identity-for-channel-list-indicator-functions
137 'riece-history-format-identity-for-channel-list-indicator)
138 (if (memq 'riece-highlight riece-addons)
139 (setq riece-channel-list-mark-face-alist
140 (cons '(?+ . riece-channel-list-history-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-history))
147 (defun riece-history-uninstall ()
148 (remove-hook 'riece-after-switch-to-channel-functions
149 'riece-history-after-switch-to-channel-functions)
150 (remove-hook 'riece-format-identity-for-channel-list-buffer-functions
151 'riece-history-format-identity-for-channel-list-buffer)
152 (remove-hook 'riece-format-identity-for-channel-list-indicator-functions
153 'riece-history-format-identity-for-channel-list-indicator)
154 (setq riece-channel-list-mark-face-alist
155 (delq (assq ?+ riece-channel-list-mark-face-alist)
156 riece-channel-list-mark-face-alist)))
158 (defun riece-history-enable ()
159 (setq riece-channel-history
160 (make-ring riece-channel-history-length))
161 (riece-emit-signal 'channel-list-changed))
163 (defun riece-history-disable ()
164 (setq riece-channel-history nil)
165 (riece-emit-signal 'channel-list-changed))
167 (provide 'riece-history)
169 ;;; riece-history.el ends here