7c54a0574f2a2ce05ee23739297f2cd38615e63d
[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 (defvar riece-guess-enabled nil)
45
46 (defconst riece-guess-description
47   "Guess the next channel, using multiple methods.")
48
49 (defvar riece-current-channels)
50
51 (defun riece-guess-candidates ()
52   "Build candidate list.
53 This function calls \\[riece-guess-channel-try-functions] in turn and
54 merge the results."
55   (let ((functions riece-guess-channel-try-functions)
56         candidates)
57     (while functions
58       (setq candidates
59             (nconc candidates
60                    (delq nil (mapcar
61                               (lambda (channel)
62                                 (unless (riece-identity-member
63                                          channel candidates)
64                                   channel))
65                               (funcall (car functions)))))
66             functions (cdr functions)))
67     ;; Merge the default.
68     (setq candidates
69           (nconc candidates
70                  (delq nil (mapcar
71                             (lambda (channel)
72                               (if (and channel
73                                        (not (riece-identity-member
74                                              channel candidates)))
75                                   channel))
76                             riece-current-channels))))
77     candidates))
78
79 (defvar riece-guess-candidates nil)
80
81 (defun riece-command-guess-switch-to-channel ()
82   "Try to switch to the channel where the user is interested in."
83   (interactive)
84   (unless (and (eq last-command this-command)
85                riece-guess-candidates)
86     (setq riece-guess-candidates (riece-guess-candidates)))
87   (unless riece-guess-candidates
88     (error "No channel"))
89   (riece-command-switch-to-channel
90    (prog1 (car riece-guess-candidates)
91      (setq riece-guess-candidates (cdr riece-guess-candidates)))))
92
93 (defvar riece-command-mode-map)
94 (defvar riece-dialogue-mode-map)
95 (defvar riece-channel-list-mode-map)
96
97 (defun riece-guess-insinuate ()
98   )
99
100 (defun riece-guess-enable ()
101   (define-key riece-command-mode-map
102     "\C-cg" 'riece-command-guess-switch-to-channel)
103   (define-key riece-dialogue-mode-map
104     "g" 'riece-command-guess-switch-to-channel)
105   (define-key riece-channel-list-mode-map
106     "g" 'riece-command-guess-switch-to-channel)
107   (setq riece-guess-enabled t))
108
109 (defun riece-guess-disable ()
110   (define-key riece-command-mode-map
111     "\C-cg" nil)
112   (define-key riece-dialogue-mode-map
113     "g" nil)
114   (define-key riece-channel-list-mode-map
115     "g" nil)
116   (setq riece-guess-enabled nil))
117
118 (provide 'riece-guess)
119
120 ;;; riece-guess.el ends here