1 ;;; riece-eval.el --- evaluate input string as an elisp form
2 ;; Copyright (C) 2005 OHASHI Akira
4 ;; Author: OHASHI Akira <bg66@koka-in.org>
5 ;; Keywords: IRC, riece
7 ;; This file is part of Riece.
9 ;; This program is free software; you can redistribute it and/or modify
10 ;; it under the terms of the GNU General Public License as published by
11 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; This program is distributed in the hope that it will be useful,
15 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ;; GNU General Public License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GNU Emacs; see the file COPYING. If not, write to the
21 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22 ;; Boston, MA 02111-1307, USA.
26 ;; NOTE: This is an add-on module for Riece.
31 (require 'riece-message)
33 (defgroup riece-eval nil
34 "Evaluate an input string as an elisp form."
38 (defcustom riece-eval-regexp "^, \\(.+\\)"
39 "*Pattern of string evaluating."
43 (defcustom riece-eval-ignore-error nil
44 "*If non-nil, an error is ignored."
48 (defvar riece-eval-enabled nil)
50 (defconst riece-eval-description
51 "Evaluate an input string as an elisp form.")
53 (defun riece-eval-display-message-function (message)
54 (when (and riece-eval-enabled
55 (riece-message-own-p message)
56 (string-match riece-eval-regexp (riece-message-text message)))
57 (let* ((form (match-string 1 (riece-message-text message)))
58 (string (riece-eval-form form)))
59 (unless (equal string "")
61 (format "NOTICE %s :%s\r\n"
62 (riece-identity-prefix (riece-message-target message))
64 (riece-display-message
65 (riece-make-message (riece-current-nickname)
66 (riece-message-target message)
69 (defun riece-eval-form (form)
71 (let ((object (eval (read form))))
73 ((stringp object) object)
75 (not (eq object nil)))
76 (let ((string (pp-to-string object)))
77 (substring string 0 (1- (length string)))))
79 (number-to-string object))
81 (t (pp-to-string object))))
83 (unless riece-eval-ignore-error
84 (format "Error evaluating %s: %s" form err)))))
86 (defun riece-eval-insinuate ()
87 (add-hook 'riece-after-display-message-functions
88 'riece-eval-display-message-function))
90 (defun riece-eval-uninstall ()
91 (remove-hook 'riece-after-display-message-functions
92 'riece-eval-display-message-function))
94 (defun riece-eval-enable ()
95 (setq riece-eval-enabled t))
97 (defun riece-eval-disable ()
98 (setq riece-eval-enabled nil))
100 (provide 'riece-eval)
102 ;;; riece-eval.el ends here