-;;; riece-eval.el --- eval add-on
+;;; riece-eval.el --- evaluate input string as an elisp form
;; Copyright (C) 2005 OHASHI Akira
;; Author: OHASHI Akira <bg66@koka-in.org>
;; You should have received a copy of the GNU General Public License
;; along with GNU Emacs; see the file COPYING. If not, write to the
-;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-;; Boston, MA 02111-1307, USA.
+;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+;; Boston, MA 02110-1301, USA.
;;; Commentary:
-;; 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:
-;; (add-to-list 'riece-addons 'riece-eval)
+;; NOTE: This is an add-on module for Riece.
;;; Code:
(require 'riece-message)
(defgroup riece-eval nil
- "Evaluate an input string as lisp object."
+ "Evaluate an input string as an elisp form."
:prefix "riece-"
:group 'riece)
:type 'boolean
:group 'riece-eval)
-(defvar riece-eval-enabled nil)
-
(defconst riece-eval-description
- "Evaluate an input string as lisp object.")
+ "Evaluate an input string as an elisp form.")
(defun riece-eval-display-message-function (message)
- (when (and riece-eval-enabled
+ (when (and (get 'riece-eval 'riece-addon-enabled)
(riece-message-own-p message)
(string-match riece-eval-regexp (riece-message-text message)))
- (let ((form (match-string 1 (riece-message-text message)))
- 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))
-(defun riece-eval-enable ()
- (setq riece-eval-enabled t))
-
-(defun riece-eval-disable ()
- (setq riece-eval-enabled nil))
+(defun riece-eval-uninstall ()
+ (remove-hook 'riece-after-display-message-functions
+ 'riece-eval-display-message-function))
(provide 'riece-eval)