* riece-doctor.el (riece-doctor-hello-regexp): Changed regexp.
[riece] / lisp / riece-eval-ruby.el
1 ;;; riece-eval-ruby.el --- evaluate ruby expression
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., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Commentary:
26
27 ;; To use, add the following line to your ~/.riece/init.el:
28 ;; (add-to-list 'riece-addons 'riece-eval-ruby)
29
30 ;;; Code:
31
32 (require 'riece-ruby)
33 (require 'riece-message)
34
35 (defvar riece-eval-ruby-enabled nil)
36
37 (defconst riece-eval-ruby-description
38   "Evaluate an input string as Ruby program.")
39
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))
44          (index 0))
45     (while (< index length)
46       (if (eq (aref data index) ?\n)
47           (aset data index ? ))
48       (setq index (1+ index)))
49     (riece-send-string
50      (format "NOTICE %s :%s\r\n"
51              (riece-identity-prefix
52               (riece-ruby-property name 'riece-eval-ruby-target))
53              data))
54     (riece-display-message
55      (riece-make-message (riece-current-nickname)
56                          (riece-ruby-property name 'riece-eval-ruby-target)
57                          data
58                          'notice))))
59
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)
66                               (match-end 0)))))
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))))
72
73 (defun riece-eval-ruby-insinuate ()
74   (add-hook 'riece-after-display-message-functions
75             'riece-eval-ruby-display-message-function))
76
77 (defun riece-eval-ruby-enable ()
78   (setq riece-eval-ruby-enabled t))
79
80 (defun riece-eval-ruby-disable ()
81   (setq riece-eval-ruby-enabled nil))
82
83 (provide 'riece-eval-ruby)
84
85 ;;; riece-eval-ruby.el ends here