Initial Commit
[packages] / xemacs-packages / zenirc / src / zenirc-eval.el
1 ;;; zenirc-eval.el --- join the "mi emacs es tu emacs" club
2
3 ;; Copyright (C) 1997, 1998 Ray Jones
4
5 ;; Author: Ray Jones <rjones@pobox.com>
6 ;; Maintainer: rjones@pobox.com
7 ;; Keywords: zenirc, extensions, eval, oink
8 ;; Created: 1998-01-09
9
10
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
14 ;; any later version.
15 ;;
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19 ;; GNU General Public License for more details.
20 ;;
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with this program; if not, you can either send email to this
23 ;; program's maintainer or write to: The Free Software Foundation,
24 ;; Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
25
26 ;;; Commentary:
27
28 ;; Whip me, beat me, make my emacs calculate primes via church
29 ;; numerals.
30
31 ;; WARNING WARNING WARNING WARNING WARNING WARNING WARNING
32 ;;
33 ;; *** DO NOT RUN THIS CODE UNLESS YOU KNOW WHAT IT DOES ***
34 ;;
35 ;; Running this code could be hazardous to your emacs, your files,
36 ;; the machine you're using, and several other things you may not
37 ;; wish to expose to the ministrations of random lusers, particularly
38 ;; in the IRC world.  You have been warned.
39 ;;
40 ;; WARNING WARNING WARNING WARNING WARNING WARNING WARNING
41
42 ;;; Code:
43
44 (require 'zenirc)
45 (require 'zenirc-trigger)
46
47 (defun zenirc-eval (&optional msg)
48   ;; parse out the (e)valuable bit
49   (string-match "(eval \\(.*\\))" msg)
50
51   ;; provide a modicum of protection from malicious parties.
52   ;; NB it can be circumvented via a similar expression.
53   (let ((kill-emacs-hook 
54          #'(lambda () (error "kill-emacs called from zenirc-eval"))))
55     (condition-case err
56         (let ((res (prin1-to-string (eval (read (match-string 1 msg))))))
57           (if (string= "" res)
58               "OJNK!"
59             res))
60       (error (format "Error: %s" err)))))
61
62 (zenirc-trigger-register "eval" 'zenirc-eval "(eval \\(.*\\))" t)
63
64 ;;; zenirc-eval.el ends here.
65