1 ;;; riece-eval-ruby.el --- evaluate input string as a Ruby program
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., 51 Franklin Street, Fifth Floor,
23 ;; Boston, MA 02110-1301, USA.
27 ;; NOTE: This is an add-on module for Riece.
32 (require 'riece-message)
34 (defgroup riece-eval-ruby nil
35 "Evaluate input string as a Ruby program."
39 (defcustom riece-eval-ruby-prefix-regexp "^,ruby\\s-+"
40 "Pattern of of the prefix for sending Ruby programs."
42 :group 'riece-eval-ruby)
44 (defconst riece-eval-ruby-description
45 "Evaluate input string as a Ruby program.")
47 (defun riece-eval-ruby-exit-handler (name)
48 (riece-ruby-inspect name)
49 (let* ((data (copy-sequence (or riece-ruby-data "nil")))
50 (length (length data))
52 (while (< index length)
53 (if (eq (aref data index) ?\n)
55 (setq index (1+ index)))
57 (format "NOTICE %s :%s\r\n"
58 (riece-identity-prefix
59 (riece-ruby-property name 'riece-eval-ruby-target))
61 (riece-display-message
62 (riece-make-message (riece-current-nickname)
63 (riece-ruby-property name 'riece-eval-ruby-target)
67 (defun riece-eval-ruby-display-message-function (message)
68 (if (and (get 'riece-eval-ruby 'riece-addon-enabled)
69 (riece-message-own-p message)
70 (string-match riece-eval-ruby-prefix-regexp
71 (riece-message-text message)))
72 (let ((name (riece-ruby-execute
73 (substring (riece-message-text message)
75 (riece-ruby-set-property name
76 'riece-eval-ruby-target
77 (riece-message-target message))
78 (riece-ruby-set-exit-handler name
79 #'riece-eval-ruby-exit-handler))))
81 (defun riece-eval-ruby-insinuate ()
82 (add-hook 'riece-after-display-message-functions
83 'riece-eval-ruby-display-message-function))
85 (defun riece-eval-ruby-uninstall ()
86 (remove-hook 'riece-after-display-message-functions
87 'riece-eval-ruby-display-message-function))
89 (provide 'riece-eval-ruby)
91 ;;; riece-eval-ruby.el ends here