* riece-button.el (riece-button-insinuate): Buttonize channel buffers.
[riece] / lisp / riece-history.el
1 ;;; riece-history.el --- channel history management add-on
2 ;; Copyright (C) 1998-2003 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Keywords: IRC, riece
6
7 ;; This file is part of Riece.
8
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)
12 ;; any later version.
13
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.
18
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.
23
24 ;;; Commentary:
25
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:
28
29 ;;   (add-hook 'riece-guess-channel-try-functions
30 ;;             'riece-guess-channel-from-history)
31
32 ;;; Code:
33
34 (require 'ring)
35
36 (defgroup riece-history nil
37   "Channel history"
38   :tag "History"
39   :prefix "riece-"
40   :group 'riece)
41
42 (defcustom riece-channel-history-length 3
43   "Length of riece-channel-history."
44   :type 'integer
45   :group 'riece-history)
46
47 (defface riece-channel-list-history-face
48   '((((class color)
49       (background dark))
50      (:foreground "PaleTurquoise"))
51     (((class color)
52       (background light))
53      (:foreground "SeaGreen3"))
54     (t
55      (:bold t)))
56   "Face used for displaying history channels."
57   :group 'riece-highlight-faces)
58 (defvar riece-channel-list-history-face 'riece-channel-list-history-face)
59
60 (defvar riece-channel-history nil)
61
62 (defun riece-guess-channel-from-history ()
63   (let ((length (ring-length riece-channel-history))
64         (index 0)
65         result)
66     (while (< index length)
67       (setq result (cons (ring-ref riece-channel-history index) result)
68             index (1+ index)))
69     (nreverse result)))
70
71 (defun riece-history-format-channel-list-line (index channel)
72   (if (and (not (ring-empty-p riece-channel-history))
73            (riece-identity-equal channel (ring-ref riece-channel-history 0)))
74       (concat (format "%2d:+" index)
75                 (riece-format-identity channel)
76                 "\n")))
77
78 ;;; (defun riece-history-requires ()
79 ;;;   (if (memq 'riece-guess riece-addons)
80 ;;;       '(riece-guess)))
81
82 (defun riece-history-insinuate ()
83   (add-hook 'riece-startup-hook
84             (lambda ()
85               (setq riece-channel-history
86                     (make-ring riece-channel-history-length))))
87   (add-hook 'riece-exit-hook
88             (lambda ()
89               (setq riece-channel-history nil)))
90   (add-hook 'riece-after-switch-to-channel-functions
91             (lambda (last)
92               (unless (riece-identity-equal last riece-current-channel)
93                 (ring-insert riece-channel-history last))))
94   (add-hook 'riece-format-channel-list-line-functions
95             'riece-history-format-channel-list-line)
96   (if (memq 'riece-highlight riece-addons)
97       (setq riece-channel-list-mark-face-alist
98             (cons '(?+ . riece-channel-list-history-face)
99                   riece-channel-list-mark-face-alist)))
100 ;;;  (if (memq 'riece-guess riece-addons)
101 ;;;      (add-hook 'riece-guess-channel-try-functions
102 ;;;             'riece-guess-channel-from-history))
103   )
104
105 (provide 'riece-history)
106
107 ;;; riece-history.el ends here
108