changeset 17606:d8cd49a0529c

(set-variable): Check VALUE against type info if available. Don't evaluate VALUE. Use a separate history list for the values.
author Richard M. Stallman <rms@gnu.org>
date Wed, 30 Apr 1997 18:57:35 +0000
parents 83850481ae70
children 251e103f2d53
files lisp/simple.el
diffstat 1 files changed, 45 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/lisp/simple.el	Wed Apr 30 18:41:53 1997 +0000
+++ b/lisp/simple.el	Wed Apr 30 18:57:35 1997 +0000
@@ -3006,6 +3006,49 @@
   (compose-mail to subject other-headers continue
 		'switch-to-buffer-other-frame yank-action send-actions))
 
+(defvar set-variable-value-history nil
+  "History of values entered with `set-variable'.")
+
+(defun set-variable (var val)
+  "Set VARIABLE to VALUE.  VALUE is a Lisp object.
+When using this interactively, enter a Lisp object for VALUE.
+If you want VALUE to be a string, you must surround it with doublequotes.
+VALUE is used literally, not evaluated.
+
+If VARIABLE has a `variable-interactive' property, that is used as if
+it were the arg to `interactive' (which see) to interactively read VALUE.
+
+If VARIABLE has been defined with `defcustom', then the type information
+in the definition is used to check that VALUE is valid."
+  (interactive (let* ((var (read-variable "Set variable: "))
+		      (minibuffer-help-form '(describe-variable var))
+		      (prop (get var 'variable-interactive))
+		      (prompt (format "Set %s to value: " var))
+		      (val (if prop
+			       ;; Use VAR's `variable-interactive' property
+			       ;; as an interactive spec for prompting.
+			       (call-interactively `(lambda (arg)
+						      (interactive ,prop)
+						      arg))
+			     (read
+			      (read-string prompt nil
+					   'set-variable-value-history)))))
+		 (list var val)))
+
+  (let ((type (get var 'custom-type))
+	widget)
+    (when type
+      ;; Match with custom type.
+      (require 'wid-edit)
+      (unless (listp type)
+	(setq widget (list type)))
+      (setq type (widget-convert type))
+      (unless (widget-apply type :match val)
+	(error "Value `%S' does not match type %S of %S" 
+	       val (car type) var))))
+  (set var val))
+
+
 (defun set-variable (var val)
   "Set VARIABLE to VALUE.  VALUE is a Lisp object.
 When using this interactively, supply a Lisp expression for VALUE.
@@ -3022,24 +3065,7 @@
 		  "Set variable: ")
 		obarray 'user-variable-p t))
 	  (var (if (equal val "") v (intern val)))
-	  (minibuffer-help-form
-	   '(funcall myhelp))
-	  (myhelp
-	   (function
-	    (lambda ()
-	      (with-output-to-temp-buffer "*Help*"
-		(prin1 var)
-		(princ "\nDocumentation:\n")
-		(princ (substring (documentation-property var 'variable-documentation)
-				  1))
-		(if (boundp var)
-		    (let ((print-length 20))
-		      (princ "\n\nCurrent value: ")
-		      (prin1 (symbol-value var))))
-		(save-excursion
-		  (set-buffer standard-output)
-		  (help-mode))
-		nil)))))
+)
      (list var
 	   (let ((prop (get var 'variable-interactive)))
 	     (if prop
@@ -3050,6 +3076,7 @@
 					   'arg))
 	       (eval-minibuffer (format "Set %s to value: " var)))))))
   (set var val))
+
 
 ;; Define the major mode for lists of completions.