Fixed.
[riece] / lisp / riece-guess.el
1 ;;; riece-guess.el --- guess the next channel, using multiple methods
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 ;; NOTE: This is an add-on module for Riece.
27
28 ;;; Code:
29
30 (require 'riece-identity)
31 (require 'riece-commands)
32
33 (defgroup riece-guess nil
34   "Guess the next channel."
35   :tag "Guess"
36   :prefix "riece-"
37   :group 'riece)
38
39 (defcustom riece-guess-channel-try-functions nil
40   "Functions which returns a list of channels the user wants to switch."
41   :type '(repeat function)
42   :group 'riece-guess)
43
44 (defconst riece-guess-description
45   "Guess the next channel, using multiple methods.")
46
47 (defvar riece-current-channels)
48
49 (defun riece-guess-candidates ()
50   "Build candidate list.
51 This function calls \\[riece-guess-channel-try-functions] in turn and
52 merge the results."
53   (let ((functions riece-guess-channel-try-functions)
54         candidates)
55     (while functions
56       (setq candidates
57             (nconc candidates
58                    (delq nil (mapcar
59                               (lambda (channel)
60                                 (unless (riece-identity-member
61                                          channel candidates)
62                                   channel))
63                               (funcall (car functions)))))
64             functions (cdr functions)))
65     ;; Merge the default.
66     (setq candidates
67           (nconc candidates
68                  (delq nil (mapcar
69                             (lambda (channel)
70                               (if (and channel
71                                        (not (riece-identity-member
72                                              channel candidates)))
73                                   channel))
74                             riece-current-channels))))
75     candidates))
76
77 (defvar riece-guess-candidates nil)
78
79 (defun riece-command-guess-switch-to-channel ()
80   "Try to switch to the channel where the user is interested in."
81   (interactive)
82   (unless (and (eq last-command this-command)
83                riece-guess-candidates)
84     (setq riece-guess-candidates (riece-guess-candidates)))
85   (unless riece-guess-candidates
86     (error "No channel"))
87   (riece-command-switch-to-channel
88    (prog1 (car riece-guess-candidates)
89      (setq riece-guess-candidates (cdr riece-guess-candidates)))))
90
91 (defvar riece-command-mode-map)
92 (defvar riece-dialogue-mode-map)
93 (defvar riece-channel-list-mode-map)
94
95 (defun riece-guess-insinuate ()
96   )
97
98 (defun riece-guess-enable ()
99   (define-key riece-command-mode-map
100     "\C-cg" 'riece-command-guess-switch-to-channel)
101   (define-key riece-dialogue-mode-map
102     "g" 'riece-command-guess-switch-to-channel)
103   (define-key riece-channel-list-mode-map
104     "g" 'riece-command-guess-switch-to-channel))
105
106 (defun riece-guess-disable ()
107   (define-key riece-command-mode-map
108     "\C-cg" nil)
109   (define-key riece-dialogue-mode-map
110     "g" nil)
111   (define-key riece-channel-list-mode-map
112     "g" nil))
113
114 (provide 'riece-guess)
115
116 ;;; riece-guess.el ends here