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