New file.
[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 ;; To use, add the following line to your ~/.riece/init.el:
27 ;; (add-to-list 'riece-addons 'riece-history)
28
29 ;;; Code:
30
31 (require 'ring)
32
33 (defgroup riece-history nil
34   "Channel history"
35   :tag "History"
36   :prefix "riece-"
37   :group 'riece)
38
39 (defcustom riece-channel-history-length 3
40   "Length of riece-channel-history."
41   :type 'integer
42   :group 'riece-history)
43
44 (defvar riece-channel-history nil)
45
46 (defun riece-guess-channel-from-history ()
47   (let ((length (ring-length riece-channel-history))
48         (index 0)
49         result)
50     (while (< index length)
51       (setq result (cons (ring-ref riece-channel-history index) result)
52             index (1+ index)))
53     (nreverse result)))
54
55 (defun riece-history-requires ()
56   (if (memq 'riece-guess riece-addons)
57       '(riece-guess)))
58
59 (defun riece-history-insinuate ()
60   (add-hook 'riece-startup-hook
61             (lambda ()
62               (setq riece-channel-history
63                     (make-ring riece-channel-history-length))))
64   (add-hook 'riece-exit-hook
65             (lambda ()
66               (setq riece-channel-history nil)))
67   (add-hook 'riece-after-switch-to-channel-functions
68             (lambda (last)
69               (ring-insert riece-channel-history last)))
70   (if (memq 'riece-guess riece-addons)
71       (add-hook 'riece-guess-channel-try-functions
72                 'riece-guess-channel-from-history)))
73
74 (provide 'riece-history)
75
76 ;;; riece-history.el ends here
77