1 ;;; riece-eval-ruby.el --- evaluate Ruby programs in channels
2 ;; Copyright (C) 1998-2005 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; Keywords: IRC, riece, Ruby
8 ;; This file is part of Riece.
10 ;; This program is free software; you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation; either version 2, or (at your option)
15 ;; This program is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs; see the file COPYING. If not, write to the
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-eval-ruby)
33 (require 'riece-message)
35 (defgroup riece-eval-ruby nil
36 "Evaluate Ruby programs in channels."
40 (defcustom riece-eval-ruby-prefix-regexp "^,ruby\\s-+"
41 "Pattern of of the prefix for sending Ruby programs."
43 :group 'riece-eval-ruby)
45 (defvar riece-eval-ruby-enabled nil)
47 (defconst riece-eval-ruby-description
48 "Evaluate an input string as Ruby program.")
50 (defun riece-eval-ruby-exit-handler (name)
51 (riece-ruby-inspect name)
52 (let* ((data (copy-sequence (or riece-ruby-data "nil")))
53 (length (length data))
55 (while (< index length)
56 (if (eq (aref data index) ?\n)
58 (setq index (1+ index)))
60 (format "NOTICE %s :%s\r\n"
61 (riece-identity-prefix
62 (riece-ruby-property name 'riece-eval-ruby-target))
64 (riece-display-message
65 (riece-make-message (riece-current-nickname)
66 (riece-ruby-property name 'riece-eval-ruby-target)
70 (defun riece-eval-ruby-display-message-function (message)
71 (if (and riece-eval-ruby-enabled
72 (riece-message-own-p message)
73 (string-match riece-eval-ruby-prefix-regexp
74 (riece-message-text message)))
75 (let ((name (riece-ruby-execute
76 (substring (riece-message-text message)
78 (riece-ruby-set-property name
79 'riece-eval-ruby-target
80 (riece-message-target message))
81 (riece-ruby-set-exit-handler name
82 #'riece-eval-ruby-exit-handler))))
84 (defun riece-eval-ruby-insinuate ()
85 (add-hook 'riece-after-display-message-functions
86 'riece-eval-ruby-display-message-function))
88 (defun riece-eval-ruby-enable ()
89 (setq riece-eval-ruby-enabled t))
91 (defun riece-eval-ruby-disable ()
92 (setq riece-eval-ruby-enabled nil))
94 (provide 'riece-eval-ruby)
96 ;;; riece-eval-ruby.el ends here