* riece-mcat.el (riece-mcat-update): Suppress
[riece] / lisp / riece-eval-ruby.el
1 ;;; riece-eval-ruby.el --- evaluate input string as a Ruby program
2 ;; Copyright (C) 1998-2005 Daiki Ueno
3
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
5 ;; Created: 1998-09-28
6 ;; Keywords: IRC, riece, Ruby
7
8 ;; This file is part of Riece.
9
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)
13 ;; any later version.
14
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.
19
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.
24
25 ;;; Commentary:
26
27 ;; NOTE: This is an add-on module for Riece.
28
29 ;;; Code:
30
31 (require 'riece-ruby)
32 (require 'riece-message)
33
34 (defgroup riece-eval-ruby nil
35   "Evaluate input string as a Ruby program."
36   :prefix "riece-"
37   :group 'riece)
38
39 (defcustom riece-eval-ruby-prefix-regexp "^,ruby\\s-+"
40   "Pattern of of the prefix for sending Ruby programs."
41   :type 'string
42   :group 'riece-eval-ruby)
43
44 (defconst riece-eval-ruby-description
45   "Evaluate input string as a Ruby program.")
46
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))
51          (index 0))
52     (while (< index length)
53       (if (eq (aref data index) ?\n)
54           (aset data index ? ))
55       (setq index (1+ index)))
56     (riece-send-string
57      (format "NOTICE %s :%s\r\n"
58              (riece-identity-prefix
59               (riece-ruby-property name 'riece-eval-ruby-target))
60              data))
61     (riece-display-message
62      (riece-make-message (riece-current-nickname)
63                          (riece-ruby-property name 'riece-eval-ruby-target)
64                          data
65                          'notice))))
66
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)
74                               (match-end 0)))))
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))))
80
81 (defun riece-eval-ruby-insinuate ()
82   (add-hook 'riece-after-display-message-functions
83             'riece-eval-ruby-display-message-function))
84
85 (defun riece-eval-ruby-uninstall ()
86   (remove-hook 'riece-after-display-message-functions
87                'riece-eval-ruby-display-message-function))
88
89 (provide 'riece-eval-ruby)
90
91 ;;; riece-eval-ruby.el ends here