emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] enhancement to set-variable to set buffer-locally


From: Benjamin Rutt
Subject: [patch] enhancement to set-variable to set buffer-locally
Date: Wed, 07 Aug 2002 21:02:05 -0400
User-agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.3.50 (sparc-sun-solaris2.8)

I was trying to give a buffer-local binding to `ps-print-header'
today, and decided there should be an easier way to set variables
buffer-locally than

M-: (set (make-local-variable 'ps-print-header) nil)

So, I decided to write a patch that would watch for a prefix arg given
to the function `set-variable' such that the variable would be set in
a buffer-local fashion (by calling `make-local-variable').  Then, the
command becomes:

C-u M-x set-variable RET ps-print-header RET nil RET

Although it looks like just as many keystrokes, you can now complete
on the variable name, etc.  So I think it can save keystrokes that
way.  And, I think it's a natural extension to `set-variable'.  Here's
the patch.  If anyone thinks it's worth committing, I have signed the
necessary papers for GNU emacs.  There are two patches below, one for
simple.el and then one for ChangeLog, both against tonight's CVS head.
Thanks.

Index: simple.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/simple.el,v
retrieving revision 1.560
diff -c -r1.560 simple.el
*** simple.el   23 Jul 2002 19:25:27 -0000      1.560
--- simple.el   8 Aug 2002 00:57:26 -0000
***************
*** 3644,3650 ****
  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* ((default-var (variable-at-point))
            (var (if (symbolp default-var)
--- 3644,3652 ----
  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.
! 
! With a prefix argument, set VARIABLE to VALUE buffer-locally."
    (interactive
     (let* ((default-var (variable-at-point))
            (var (if (symbolp default-var)
***************
*** 3653,3659 ****
                   (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.
--- 3655,3664 ----
                   (read-variable "Set variable: ")))
                      (minibuffer-help-form '(describe-variable var))
                      (prop (get var 'variable-interactive))
!                     (prompt (format "Set %s to%svalue: " var
!                                     (if current-prefix-arg
!                                         " (buffer-local) "
!                                       " ")))
                      (val (if prop
                               ;; Use VAR's `variable-interactive' property
                               ;; as an interactive spec for prompting.
***************
*** 3673,3679 ****
        (unless (widget-apply type :match val)
        (error "Value `%S' does not match type %S of %S"
               val (car type) var))))
!   (set var val)
  
    ;; Force a thorough redisplay for the case that the variable
    ;; has an effect on the display, like `tab-width' has.
--- 3678,3688 ----
        (unless (widget-apply type :match val)
        (error "Value `%S' does not match type %S of %S"
               val (car type) var))))
! 
!   (set (if current-prefix-arg
!          (make-local-variable var)
!        var)
!        val)
  
    ;; Force a thorough redisplay for the case that the variable
    ;; has an effect on the display, like `tab-width' has.







Index: ChangeLog
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/ChangeLog,v
retrieving revision 1.4202
diff -c -r1.4202 ChangeLog
*** ChangeLog   7 Aug 2002 21:46:49 -0000       1.4202
--- ChangeLog   8 Aug 2002 00:57:14 -0000
***************
*** 1,3 ****
--- 1,8 ----
+ 2002-08-07  Benjamin Rutt  <address@hidden>
+ 
+       * simple.el (set-variable): If given a prefix argument, set
+       variable buffer-locally.
+ 
  2002-08-07  John Paul Wallington  <address@hidden>
  
        * xt-mouse.el (xterm-mouse-mode): Make it a global mode.

-- 
Benjamin



reply via email to

[Prev in Thread] Current Thread [Next in Thread]