1 ;;; riece-eval-ruby.el --- evaluate ruby expression
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 (defvar riece-eval-ruby-enabled nil)
37 (defconst riece-eval-ruby-description
38 "Evaluate an input string as Ruby program.")
40 (defun riece-eval-ruby-exit-handler (name)
41 (riece-ruby-inspect name)
42 (let* ((data (copy-sequence riece-ruby-data))
43 (length (length data))
45 (while (< index length)
46 (if (eq (aref data index) ?\n)
48 (setq index (1+ index)))
50 (format "NOTICE %s :%s\r\n"
51 (riece-identity-prefix
52 (riece-ruby-property name 'riece-eval-ruby-target))
54 (riece-display-message
55 (riece-make-message (riece-current-nickname)
56 (riece-ruby-property name 'riece-eval-ruby-target)
60 (defun riece-eval-ruby-display-message-function (message)
61 (if (and riece-eval-ruby-enabled
62 (riece-message-own-p message)
63 (string-match "^,ruby\\s-+" (riece-message-text message)))
64 (let ((name (riece-ruby-execute
65 (substring (riece-message-text message)
67 (riece-ruby-set-property name
68 'riece-eval-ruby-target
69 (riece-message-target message))
70 (riece-ruby-set-exit-handler name
71 #'riece-eval-ruby-exit-handler))))
73 (defun riece-eval-ruby-insinuate ()
74 (add-hook 'riece-after-display-message-functions
75 'riece-eval-ruby-display-message-function))
77 (defun riece-eval-ruby-enable ()
78 (setq riece-eval-ruby-enabled t))
80 (defun riece-eval-ruby-disable ()
81 (setq riece-eval-ruby-enabled nil))
83 (provide 'riece-eval-ruby)
85 ;;; riece-eval-ruby.el ends here