aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard M. Stallman1997-04-30 18:57:35 +0000
committerRichard M. Stallman1997-04-30 18:57:35 +0000
commit610c1c68c1dd1fecd07cabd24d9ea8341e768c74 (patch)
tree31bdd9698f490e4a3c50c41da5f703e539139401
parent7b396c6c70b81391cfc1b0e3a144e6c0ca8af07f (diff)
downloademacs-610c1c68c1dd1fecd07cabd24d9ea8341e768c74.tar.gz
emacs-610c1c68c1dd1fecd07cabd24d9ea8341e768c74.zip
(set-variable): Check VALUE against type info if available.
Don't evaluate VALUE. Use a separate history list for the values.
-rw-r--r--lisp/simple.el63
1 files changed, 45 insertions, 18 deletions
diff --git a/lisp/simple.el b/lisp/simple.el
index 92da208797a..2d8cffe9c52 100644
--- a/lisp/simple.el
+++ b/lisp/simple.el
@@ -3006,6 +3006,49 @@ Each action has the form (FUNCTION . ARGS)."
3006 (compose-mail to subject other-headers continue 3006 (compose-mail to subject other-headers continue
3007 'switch-to-buffer-other-frame yank-action send-actions)) 3007 'switch-to-buffer-other-frame yank-action send-actions))
3008 3008
3009(defvar set-variable-value-history nil
3010 "History of values entered with `set-variable'.")
3011
3012(defun set-variable (var val)
3013 "Set VARIABLE to VALUE. VALUE is a Lisp object.
3014When using this interactively, enter a Lisp object for VALUE.
3015If you want VALUE to be a string, you must surround it with doublequotes.
3016VALUE is used literally, not evaluated.
3017
3018If VARIABLE has a `variable-interactive' property, that is used as if
3019it were the arg to `interactive' (which see) to interactively read VALUE.
3020
3021If VARIABLE has been defined with `defcustom', then the type information
3022in the definition is used to check that VALUE is valid."
3023 (interactive (let* ((var (read-variable "Set variable: "))
3024 (minibuffer-help-form '(describe-variable var))
3025 (prop (get var 'variable-interactive))
3026 (prompt (format "Set %s to value: " var))
3027 (val (if prop
3028 ;; Use VAR's `variable-interactive' property
3029 ;; as an interactive spec for prompting.
3030 (call-interactively `(lambda (arg)
3031 (interactive ,prop)
3032 arg))
3033 (read
3034 (read-string prompt nil
3035 'set-variable-value-history)))))
3036 (list var val)))
3037
3038 (let ((type (get var 'custom-type))
3039 widget)
3040 (when type
3041 ;; Match with custom type.
3042 (require 'wid-edit)
3043 (unless (listp type)
3044 (setq widget (list type)))
3045 (setq type (widget-convert type))
3046 (unless (widget-apply type :match val)
3047 (error "Value `%S' does not match type %S of %S"
3048 val (car type) var))))
3049 (set var val))
3050
3051
3009(defun set-variable (var val) 3052(defun set-variable (var val)
3010 "Set VARIABLE to VALUE. VALUE is a Lisp object. 3053 "Set VARIABLE to VALUE. VALUE is a Lisp object.
3011When using this interactively, supply a Lisp expression for VALUE. 3054When using this interactively, supply a Lisp expression for VALUE.
@@ -3022,24 +3065,7 @@ it were the arg to `interactive' (which see) to interactively read the value."
3022 "Set variable: ") 3065 "Set variable: ")
3023 obarray 'user-variable-p t)) 3066 obarray 'user-variable-p t))
3024 (var (if (equal val "") v (intern val))) 3067 (var (if (equal val "") v (intern val)))
3025 (minibuffer-help-form 3068)
3026 '(funcall myhelp))
3027 (myhelp
3028 (function
3029 (lambda ()
3030 (with-output-to-temp-buffer "*Help*"
3031 (prin1 var)
3032 (princ "\nDocumentation:\n")
3033 (princ (substring (documentation-property var 'variable-documentation)
3034 1))
3035 (if (boundp var)
3036 (let ((print-length 20))
3037 (princ "\n\nCurrent value: ")
3038 (prin1 (symbol-value var))))
3039 (save-excursion
3040 (set-buffer standard-output)
3041 (help-mode))
3042 nil)))))
3043 (list var 3069 (list var
3044 (let ((prop (get var 'variable-interactive))) 3070 (let ((prop (get var 'variable-interactive)))
3045 (if prop 3071 (if prop
@@ -3050,6 +3076,7 @@ it were the arg to `interactive' (which see) to interactively read the value."
3050 'arg)) 3076 'arg))
3051 (eval-minibuffer (format "Set %s to value: " var))))))) 3077 (eval-minibuffer (format "Set %s to value: " var)))))))
3052 (set var val)) 3078 (set var val))
3079
3053 3080
3054;; Define the major mode for lists of completions. 3081;; Define the major mode for lists of completions.
3055 3082