Undo.
[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 (defvar riece-channel-history nil)
48
49 (defun riece-guess-channel-from-history ()
50   (let ((length (ring-length riece-channel-history))
51         (index 0)
52         result)
53     (while (< index length)
54       (setq result (cons (ring-ref riece-channel-history index) result)
55             index (1+ index)))
56     (nreverse result)))
57
58 ;;; (defun riece-history-requires ()
59 ;;;   (if (memq 'riece-guess riece-addons)
60 ;;;       '(riece-guess)))
61
62 (defun riece-history-insinuate ()
63   (add-hook 'riece-startup-hook
64             (lambda ()
65               (setq riece-channel-history
66                     (make-ring riece-channel-history-length))))
67   (add-hook 'riece-exit-hook
68             (lambda ()
69               (setq riece-channel-history nil)))
70   (add-hook 'riece-after-switch-to-channel-functions
71             (lambda (last)
72               (ring-insert riece-channel-history last)))
73 ;;;  (if (memq 'riece-guess riece-addons)
74 ;;;      (add-hook 'riece-guess-channel-try-functions
75 ;;;             'riece-guess-channel-from-history))
76   )
77
78 (provide 'riece-history)
79
80 ;;; riece-history.el ends here
81