From: ueno Date: Wed, 27 Aug 2003 08:03:31 +0000 (+0000) Subject: New file. X-Git-Tag: riece-0_1_1~4 X-Git-Url: http://git.chise.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3ace33170c3b9e25696842e84dc61a910e21f50f;p=elisp%2Friece.git New file. --- diff --git a/lisp/riece-guess.el b/lisp/riece-guess.el new file mode 100644 index 0000000..5c01215 --- /dev/null +++ b/lisp/riece-guess.el @@ -0,0 +1,92 @@ +;;; riece-guess.el --- guess the next channel, using multiple methods +;; Copyright (C) 1998-2003 Daiki Ueno + +;; Author: Daiki Ueno +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; To use, add the following line to your ~/.riece/init.el: +;; (add-to-list 'riece-addons 'riece-guess) + +;;; Code: + +(require 'riece-identity) +(require 'riece-commands) + +(defgroup riece-guess nil + "Guess the next channel" + :tag "Guess" + :prefix "riece-" + :group 'riece) + +(defcustom riece-guess-channel-try-functions + '(riece-default-guess-channel) + "Functions which returns a list of channels the user wants to switch." + :type '(repeat function) + :group 'riece-guess) + +(defvar riece-current-channels) +(defun riece-default-guess-channel () + (delq nil (copy-sequence riece-current-channels))) + +(defun riece-guess-candidates () + (let ((functions riece-guess-channel-try-functions) + candidates) + (while functions + (setq candidates + (nconc candidates + (delq nil (mapcar + (lambda (channel) + (if (riece-identity-member channel candidates) + nil + channel)) + (funcall (car functions))))) + functions (cdr functions))) + candidates)) + +(defvar riece-guess-candidates nil) + +(defun riece-command-guess-switch-to-channel () + "Try to switch to the channel where the user is interested in." + (interactive) + (unless (eq last-command this-command) + (setq riece-guess-candidates (riece-guess-candidates))) + (unless riece-guess-candidates + (error "No channel")) + (riece-command-switch-to-channel + (prog1 (car riece-guess-candidates) + (setq riece-guess-candidates (cdr riece-guess-candidates))))) + +(defvar riece-command-mode-map) +(defvar riece-dialogue-mode-map) +(defvar riece-channel-list-mode-map) + +(defun riece-guess-insinuate () + (define-key riece-command-mode-map + "\C-cg" 'riece-command-guess-switch-to-channel) + (define-key riece-dialogue-mode-map + "g" 'riece-command-guess-switch-to-channel) + (define-key riece-channel-list-mode-map + "g" 'riece-command-guess-switch-to-channel)) + +(provide 'riece-guess) + +;;; riece-guess.el ends here diff --git a/lisp/riece-history.el b/lisp/riece-history.el new file mode 100644 index 0000000..435c9fa --- /dev/null +++ b/lisp/riece-history.el @@ -0,0 +1,77 @@ +;;; riece-history.el --- channel history management add-on +;; Copyright (C) 1998-2003 Daiki Ueno + +;; Author: Daiki Ueno +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to the +;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, +;; Boston, MA 02111-1307, USA. + +;;; Commentary: + +;; To use, add the following line to your ~/.riece/init.el: +;; (add-to-list 'riece-addons 'riece-history) + +;;; Code: + +(require 'ring) + +(defgroup riece-history nil + "Channel history" + :tag "History" + :prefix "riece-" + :group 'riece) + +(defcustom riece-channel-history-length 3 + "Length of riece-channel-history." + :type 'integer + :group 'riece-history) + +(defvar riece-channel-history nil) + +(defun riece-guess-channel-from-history () + (let ((length (ring-length riece-channel-history)) + (index 0) + result) + (while (< index length) + (setq result (cons (ring-ref riece-channel-history index) result) + index (1+ index))) + (nreverse result))) + +(defun riece-history-requires () + (if (memq 'riece-guess riece-addons) + '(riece-guess))) + +(defun riece-history-insinuate () + (add-hook 'riece-startup-hook + (lambda () + (setq riece-channel-history + (make-ring riece-channel-history-length)))) + (add-hook 'riece-exit-hook + (lambda () + (setq riece-channel-history nil))) + (add-hook 'riece-after-switch-to-channel-functions + (lambda (last) + (ring-insert riece-channel-history last))) + (if (memq 'riece-guess riece-addons) + (add-hook 'riece-guess-channel-try-functions + 'riece-guess-channel-from-history))) + +(provide 'riece-history) + +;;; riece-history.el ends here +