From ec3875e0ab058cbb68526b52395c8745c72f30b3 Mon Sep 17 00:00:00 2001 From: bg66 Date: Tue, 1 Feb 2005 01:32:43 +0000 Subject: [PATCH] * riece-eval.el: New add-on. * COMPILE (riece-modules): Add riece-eval. * Makefile.am (EXTRA_DIST): Add riece-eval.el. --- doc/riece-ja.texi | 4 +++ lisp/COMPILE | 3 +- lisp/ChangeLog | 6 ++++ lisp/Makefile.am | 2 +- lisp/riece-eval.el | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 115 insertions(+), 2 deletions(-) create mode 100644 lisp/riece-eval.el diff --git a/doc/riece-ja.texi b/doc/riece-ja.texi index 969a273..790788a 100644 --- a/doc/riece-ja.texi +++ b/doc/riece-ja.texi @@ -560,6 +560,10 @@ PING に応答する local proxy 経由で IRC サーバに接続 日本語の通らない端末で、日本語をローマ字で表示 @item riece-yank @kbd{C-c y} で kill-ring から文字列を送信 +@item riece-toolbar +ツールバーを表示 +@item riece-eval +入力された文字列を lisp オブジェクトとして評価 @end table これらのうち、@samp{riece-highlight} と @samp{riece-ctcp}、 diff --git a/lisp/COMPILE b/lisp/COMPILE index d74f998..99de9fd 100644 --- a/lisp/COMPILE +++ b/lisp/COMPILE @@ -72,7 +72,8 @@ riece-biff riece-kakasi riece-yank - riece-toolbar)))) + riece-toolbar + riece-eval)))) (defvar riece-icons '(riece-command-previous-channel diff --git a/lisp/ChangeLog b/lisp/ChangeLog index 7d6680e..dc806e1 100644 --- a/lisp/ChangeLog +++ b/lisp/ChangeLog @@ -1,3 +1,9 @@ +2005-02-01 OHASHI Akira + + * riece-eval.el: New add-on. + * COMPILE (riece-modules): Add riece-eval. + * Makefile.am (EXTRA_DIST): Add riece-eval.el. + 2005-01-30 TAKAHASHI Kaoru * riece-display.el (riece-display-connect-signals): Check nick or diff --git a/lisp/Makefile.am b/lisp/Makefile.am index 9da7b61..1c527ea 100644 --- a/lisp/Makefile.am +++ b/lisp/Makefile.am @@ -15,7 +15,7 @@ EXTRA_DIST = COMPILE ChangeLog ChangeLog.Liece \ riece-menu.el riece-icon.el riece-async.el riece-lsdb.el \ riece-xface.el riece-ctlseq.el riece-ignore.el riece-hangman.el \ riece-biff.el riece-kakasi.el riece-foolproof.el riece-yank.el \ - riece-toolbar.el url-riece.el + riece-toolbar.el riece-eval.el url-riece.el CLEANFILES = auto-autoloads.el custom-load.el *.elc FLAGS ?= -batch -q -no-site-file diff --git a/lisp/riece-eval.el b/lisp/riece-eval.el new file mode 100644 index 0000000..b5aaca5 --- /dev/null +++ b/lisp/riece-eval.el @@ -0,0 +1,102 @@ +;;; riece-eval.el --- eval add-on +;; Copyright (C) 2005 OHASHI Akira + +;; Author: OHASHI Akira +;; Keywords: IRC, riece + +;; This file is part of Riece. + +;; This program is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This program is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; 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. + +;;; Commentary: + +;; This add-on evaluate an input string as lisp object and send 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) + +;;; Code: + +(require 'pp) +(require 'riece-message) + +(defgroup riece-eval nil + "Evaluate an input string as lisp object." + :prefix "riece-" + :group 'riece) + +(defcustom riece-eval-regexp "^, " + "*Pattern of string evaluating." + :type 'string + :group 'riece-eval) + +(defcustom riece-eval-ignore-error nil + "*If non-nil, an error is ignored." + :type 'boolean + :group 'riece-eval) + +(defvar riece-eval-enabled nil) + +(defconst riece-eval-description + "Evaluate an input string as lisp object.") + +(defun riece-eval-display-message-function (message) + (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))))) + (unless (equal string "") + (riece-send-string + (format "NOTICE %s :%s\r\n" + (riece-identity-prefix (riece-message-target message)) + string)) + (riece-display-message + (riece-make-message (riece-current-nickname) + (riece-message-target message) + string 'notice)))))) + +(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)) + +(provide 'riece-eval) + +;;; riece-eval.el ends here -- 1.7.10.4