]> code.delx.au - gnu-emacs/blobdiff - lisp/emacs-lisp/unsafep.el
(find-function-search-for-symbol): Add comments.
[gnu-emacs] / lisp / emacs-lisp / unsafep.el
index 9ac3beb194938ae7440216127a9a1201e8ee942c..aeaf653aef6792391e2d2d3ca3caac4fc14e31a6 100644 (file)
@@ -1,9 +1,9 @@
 ;;;; unsafep.el -- Determine whether a Lisp form is safe to evaluate
 
-;; Copyright (C) Free Software Foundation, Inc.
+;; Copyright (C) 2002, 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
 
-;; Author: Jonathan Yavner <jyavner@engineer.com>
-;; Maintainer: Jonathan Yavner <jyavner@engineer.com>
+;; Author: Jonathan Yavner <jyavner@member.fsf.org>
+;; Maintainer: Jonathan Yavner <jyavner@member.fsf.org>
 ;; Keywords: safety lisp utility
 
 ;; This file is part of GNU Emacs.
@@ -20,8 +20,8 @@
 
 ;; 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:
 
 ;;      passed a circular list to `assoc', Emacs would crash.  Historically,
 ;;      problems of this kind have been few and short-lived.
 
+;;; Code:
+
 (provide 'unsafep)
 (require 'byte-opt)  ;Set up the `side-effect-free' properties
 
 (defcustom safe-functions nil
-  "t to disable `unsafep', or a list of assumed-safe functions."
+  "A list of assumed-safe functions, or t to disable `unsafep'."
   :group 'lisp
   :type  '(choice (const :tag "No" nil) (const :tag "Yes" t) hook))
 
@@ -146,10 +148,10 @@ of symbols with local bindings."
        ((eq fun 'lambda)
        ;;First arg is temporary bindings
        (mapc #'(lambda (x)
-                 (let ((y (unsafep-variable x t)))
-                   (if y (throw 'unsafep y)))
                  (or (memq x '(&optional &rest))
-                     (push x unsafep-vars)))
+                     (let ((y (unsafep-variable x t)))
+                       (if y (throw 'unsafep y))
+                       (push x unsafep-vars))))
              (cadr form))
        (unsafep-progn (cddr form)))
        ((eq fun 'let)
@@ -210,9 +212,9 @@ of symbols with local bindings."
 
 
 (defun unsafep-function (fun)
-  "Return nil if FUN is a safe function
+  "Return nil iff FUN is a safe function.
 \(either a safe lambda or a symbol that names a safe function).  Otherwise
-result is a reason code." 
+result is a reason code."
   (cond
    ((eq (car-safe fun) 'lambda)
     (unsafep fun unsafep-vars))
@@ -233,7 +235,8 @@ for the first unsafe form."
        (if reason (throw 'unsafep-progn reason))))))
 
 (defun unsafep-let (clause)
-  "CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL).  Checks VAL
+  "Check the safety of a let binding.
+CLAUSE is a let-binding, either SYM or (SYM) or (SYM VAL).  Checks VAL
 and throws a reason to `unsafep' if unsafe.  Returns SYM."
   (let (reason sym)
     (if (atom clause)
@@ -244,19 +247,19 @@ and throws a reason to `unsafep' if unsafe.  Returns SYM."
     (if reason (throw 'unsafep reason))
     sym))
 
-(defun unsafep-variable (sym global-okay)
-  "Returns nil if SYM is safe as a let-binding sym
-\(because it already has a temporary binding or is a non-risky buffer-local
-variable), otherwise a reason why it is unsafe.  Failing to be locally bound
-is okay if GLOBAL-OKAY is non-nil."
+(defun unsafep-variable (sym to-bind)
+  "Return nil if SYM is safe to set or bind, or a reason why not.
+If TO-BIND is nil, check whether SYM is safe to set.
+If TO-BIND is t, check whether SYM is safe to bind."
   (cond
    ((not (symbolp sym))
     `(variable ,sym))
    ((risky-local-variable-p sym nil)
     `(risky-local-variable ,sym))
-   ((not (or global-okay
+   ((not (or to-bind
             (memq sym unsafep-vars)
             (local-variable-p sym)))
     `(global-variable ,sym))))
 
-;; unsafep.el ends here.
+;; arch-tag: 6216f98b-eb8f-467a-9c33-7a7644f50658
+;;; unsafep.el ends here