Fixed.
[riece] / lisp / riece-eval.el
index b5aaca5..c54079f 100644 (file)
@@ -23,7 +23,7 @@
 
 ;;; Commentary:
 
-;; This add-on evaluate an input string as lisp object and send a result
+;; This add-on evaluates an input string as lisp object and sends a result
 ;; as notice. Note the risky of this add-on.
 
 ;; To use, add the following line to your ~/.riece/init.el:
@@ -39,7 +39,7 @@
   :prefix "riece-"
   :group 'riece)
 
-(defcustom riece-eval-regexp "^, "
+(defcustom riece-eval-regexp "^, \\(.+\\)"
   "*Pattern of string evaluating."
   :type 'string
   :group 'riece-eval)
   (when (and riece-eval-enabled
             (riece-message-own-p message)
             (string-match riece-eval-regexp (riece-message-text message)))
-    (let ((form (substring (riece-message-text message) 2))
-         object string)
-      (condition-case err
-         (progn
-           (setq object (eval (read form)))
-           (setq string
-                 (cond
-                  ((stringp object) object)
-                  ((and (listp object)
-                        (not (eq object nil)))
-                   (let ((string (pp-to-string object)))
-                     (substring string 0 (1- (length string)))))
-                  ((numberp object)
-                   (number-to-string object))
-                  ((eq object nil) "")
-                  (t (pp-to-string object)))))
-       (error
-        (unless riece-eval-ignore-error
-            (setq string (format "Error evaluating %s: %s" form err)))))
+    (let* ((form (match-string 1 (riece-message-text message)))
+          (string (riece-eval-form form)))
       (unless (equal string "")
        (riece-send-string
         (format "NOTICE %s :%s\r\n"
                             (riece-message-target message)
                             string 'notice))))))
 
+(defun riece-eval-form (form)
+  (condition-case err
+      (let ((object (eval (read form))))
+       (cond
+        ((stringp object) object)
+        ((and (listp object)
+              (not (eq object nil)))
+         (let ((string (pp-to-string object)))
+           (substring string 0 (1- (length string)))))
+        ((numberp object)
+         (number-to-string object))
+        ((eq object nil) "")
+        (t (pp-to-string object))))
+    (error
+     (unless riece-eval-ignore-error
+       (format "Error evaluating %s: %s" form err)))))
+
 (defun riece-eval-insinuate ()
   (add-hook 'riece-after-display-message-functions
            'riece-eval-display-message-function))