Mercurial > emacs
comparison lisp/simple.el @ 46845:e06b5768debd
(set-variable): If given a prefix argument, set variable buffer-locally.
Give locality status in prompt.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Fri, 09 Aug 2002 14:14:06 +0000 |
parents | cdd51b0b1929 |
children | 543ab39f153c |
comparison
equal
deleted
inserted
replaced
46844:76c69bfa8ba8 | 46845:e06b5768debd |
---|---|
3632 'switch-to-buffer-other-frame yank-action send-actions)) | 3632 'switch-to-buffer-other-frame yank-action send-actions)) |
3633 | 3633 |
3634 (defvar set-variable-value-history nil | 3634 (defvar set-variable-value-history nil |
3635 "History of values entered with `set-variable'.") | 3635 "History of values entered with `set-variable'.") |
3636 | 3636 |
3637 (defun set-variable (var val) | 3637 (defun set-variable (var val &optional make-local) |
3638 "Set VARIABLE to VALUE. VALUE is a Lisp object. | 3638 "Set VARIABLE to VALUE. VALUE is a Lisp object. |
3639 When using this interactively, enter a Lisp object for VALUE. | 3639 When using this interactively, enter a Lisp object for VALUE. |
3640 If you want VALUE to be a string, you must surround it with doublequotes. | 3640 If you want VALUE to be a string, you must surround it with doublequotes. |
3641 VALUE is used literally, not evaluated. | 3641 VALUE is used literally, not evaluated. |
3642 | 3642 |
3643 If VARIABLE has a `variable-interactive' property, that is used as if | 3643 If VARIABLE has a `variable-interactive' property, that is used as if |
3644 it were the arg to `interactive' (which see) to interactively read VALUE. | 3644 it were the arg to `interactive' (which see) to interactively read VALUE. |
3645 | 3645 |
3646 If VARIABLE has been defined with `defcustom', then the type information | 3646 If VARIABLE has been defined with `defcustom', then the type information |
3647 in the definition is used to check that VALUE is valid." | 3647 in the definition is used to check that VALUE is valid. |
3648 | |
3649 With a prefix argument, set VARIABLE to VALUE buffer-locally." | |
3648 (interactive | 3650 (interactive |
3649 (let* ((default-var (variable-at-point)) | 3651 (let* ((default-var (variable-at-point)) |
3650 (var (if (symbolp default-var) | 3652 (var (if (symbolp default-var) |
3651 (read-variable (format "Set variable (default %s): " default-var) | 3653 (read-variable (format "Set variable (default %s): " default-var) |
3652 default-var) | 3654 default-var) |
3653 (read-variable "Set variable: "))) | 3655 (read-variable "Set variable: "))) |
3654 (minibuffer-help-form '(describe-variable var)) | 3656 (minibuffer-help-form '(describe-variable var)) |
3655 (prop (get var 'variable-interactive)) | 3657 (prop (get var 'variable-interactive)) |
3656 (prompt (format "Set %s to value: " var)) | 3658 (prompt (format "Set %s%s to value: " var |
3659 (cond ((local-variable-p var) | |
3660 " (buffer-local)") | |
3661 ((or current-prefix-arg | |
3662 (local-variable-if-set-p var)) | |
3663 " buffer-locally") | |
3664 (t " globally")))) | |
3657 (val (if prop | 3665 (val (if prop |
3658 ;; Use VAR's `variable-interactive' property | 3666 ;; Use VAR's `variable-interactive' property |
3659 ;; as an interactive spec for prompting. | 3667 ;; as an interactive spec for prompting. |
3660 (call-interactively `(lambda (arg) | 3668 (call-interactively `(lambda (arg) |
3661 (interactive ,prop) | 3669 (interactive ,prop) |
3662 arg)) | 3670 arg)) |
3663 (read | 3671 (read |
3664 (read-string prompt nil | 3672 (read-string prompt nil |
3665 'set-variable-value-history))))) | 3673 'set-variable-value-history))))) |
3666 (list var val))) | 3674 (list var val current-prefix-arg))) |
3667 | 3675 |
3668 (let ((type (get var 'custom-type))) | 3676 (let ((type (get var 'custom-type))) |
3669 (when type | 3677 (when type |
3670 ;; Match with custom type. | 3678 ;; Match with custom type. |
3671 (require 'cus-edit) | 3679 (require 'cus-edit) |
3672 (setq type (widget-convert type)) | 3680 (setq type (widget-convert type)) |
3673 (unless (widget-apply type :match val) | 3681 (unless (widget-apply type :match val) |
3674 (error "Value `%S' does not match type %S of %S" | 3682 (error "Value `%S' does not match type %S of %S" |
3675 val (car type) var)))) | 3683 val (car type) var)))) |
3684 | |
3685 (if make-local | |
3686 (make-local-variable var)) | |
3687 | |
3676 (set var val) | 3688 (set var val) |
3677 | 3689 |
3678 ;; Force a thorough redisplay for the case that the variable | 3690 ;; Force a thorough redisplay for the case that the variable |
3679 ;; has an effect on the display, like `tab-width' has. | 3691 ;; has an effect on the display, like `tab-width' has. |
3680 (force-mode-line-update)) | 3692 (force-mode-line-update)) |