annotate lisp/w3/w3-elisp.el @ 62:28a7c63c7e1e r19-16-pre6

Import from CVS: tag r19-16-pre6
author cvs
date Mon, 13 Aug 2007 08:59:13 +0200
parents ec9a17fef872
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
1 ;;; w3-elisp.el --- Scripting support for emacs-lisp
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
2 ;; Author: wmperry
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
3 ;; Created: 1997/03/07 14:14:02
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
4 ;; Version: 1.7
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
5 ;; Keywords: hypermedia, scripting
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
6
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
7 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
8 ;;; Copyright (c) 1997 Free Software Foundation, Inc.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
9 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
10 ;;; This file is part of GNU Emacs.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
11 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
12 ;;; GNU Emacs is free software; you can redistribute it and/or modify
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
13 ;;; it under the terms of the GNU General Public License as published by
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
14 ;;; the Free Software Foundation; either version 2, or (at your option)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
15 ;;; any later version.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
16 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
17 ;;; GNU Emacs is distributed in the hope that it will be useful,
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
18 ;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
19 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
20 ;;; GNU General Public License for more details.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
21 ;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
22 ;;; You should have received a copy of the GNU General Public License
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
23 ;;; along with GNU Emacs; see the file COPYING. If not, write to the
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
24 ;;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
25 ;;; Boston, MA 02111-1307, USA.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
26 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
27
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
28 (require 'cl)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
29
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
30 (mapcar
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
31 (function
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
32 (lambda (x)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
33 (put x 'w3-safe t)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
34 '(;; Any safe functions for untrusted scripts should go here.
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
35 ;; Basic stuff
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
36 message
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
37 format garbage-collect progn prog1 prog2 progn-with-message
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
38 while current-time current-time-string
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
39 plist-member plist-to-alist plist-get
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
40 assoc memq member function lambda point
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
41
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
42 ;; Device querying
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
43 device-pixel-height device-type device-color-cells
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
44 device-mm-height device-class device-bitplanes
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
45 device-on-window-system-p device-pixel-width
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
46 device-mm-width device-baud-rate
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
47
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
48 ;; Frame querying
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
49 frame-type frame-name frame-device frame-parameters
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
50 frame-height frame-pixel-width frame-pixel-height
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
51 frame-width frame-property
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
52
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
53 ;; Window querying
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
54 window-frame window-height window-width
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
55 window-pixel-width window-pixel-height
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
56
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
57 ;; Buffer querying
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
58 buffer-name buffer-substring buffer-substring-no-properties
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
59 buffer-size buffer-string
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
60
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
61 ;; Text properties, read-only
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
62 get-text-property text-properties-at text-property-bounds
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
63 text-property-not-all
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
64
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
65 ;; URL loading stuff
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
66 url-insert-file-contents url-view-url
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
67
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
68 ;; Interfacing to W3
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
69 w3-fetch w3-refresh-buffer w3-view-this-url
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
70
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
71 ;; All the XEmacs event manipulation functions
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
72 event-live-p event-glyph-extent event-glyph-y-pixel event-x-pixel
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
73 event-type event-glyph event-button event-over-text-area-p
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
74 event-glyph-x-pixel event-buffer event-device event-properties
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
75 event-process event-timestamp event-modifier-bits event-console
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
76 event-window-y-pixel event-window event-window-x-pixel event-point
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
77 event-function event-over-toolbar-p event-matches-key-specifier-p
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
78 event-over-glyph-p event-frame event-x event-channel event-y
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
79 event-screen event-to-character event-over-border-p
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
80 event-toolbar-button event-closest-point event-object event-key
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
81 event-modifiers event-y-pixel event-over-modeline-p
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
82 event-modeline-position
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
83 )
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
84 )
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
85
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
86 (defsubst w3-elisp-safe-function (func args)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
87 (let ((validator (get func 'w3-safe)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
88 (cond
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
89 ((eq t validator) t) ; Explicit allow
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
90 ((eq nil validator) nil) ; Explicit deny
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
91 ((fboundp validator) ; Function to call
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
92 (funcall validator func args))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
93 ((boundp validator) ; Variable to check
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
94 (symbol-value validator))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
95 (t nil)))) ; Fallback to unsafe
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
96
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
97 (defun w3-elisp-safe-expression (exp)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
98 "Return t if-and-only-if EXP is safe to evaluate."
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
99 (cond
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
100 ((and (listp exp) (not (listp (cdr exp)))) ; A cons cell
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
101 t)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
102 ((or ; self-quoters
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
103 (vectorp exp)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
104 (numberp exp)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
105 (symbolp exp)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
106 (stringp exp)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
107 (keymapp exp))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
108 t)
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
109 ((listp exp) ; Function call - check arguments
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
110 (if (w3-elisp-safe-function (car exp) (cdr exp))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
111 (let ((args (cdr exp))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
112 (rval t))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
113 (while args
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
114 (if (not (w3-elisp-safe-expression (pop args)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
115 (setq args nil
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
116 rval nil)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
117 rval)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
118 ;; How to handle the insane # of native types?
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
119 (t nil)))
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
120
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
121 (defun w3-elisp-safe-eval (form)
30
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
122 (if (w3-elisp-safe-expression form)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
123 (condition-case ()
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
124 (eval form)
ec9a17fef872 Import from CVS: tag r19-15b98
cvs
parents: 26
diff changeset
125 (error nil))))
26
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
126
441bb1e64a06 Import from CVS: tag r19-15b96
cvs
parents:
diff changeset
127 (provide 'w3-elisp)