unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [patch] enhancement to set-variable to set buffer-locally
@ 2002-08-08  1:02 Benjamin Rutt
  2002-08-09  0:28 ` John Paul Wallington
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Benjamin Rutt @ 2002-08-08  1:02 UTC (permalink / raw)


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  <rutt@cis.ohio-state.edu>
+ 
+ 	* simple.el (set-variable): If given a prefix argument, set
+ 	variable buffer-locally.
+ 
  2002-08-07  John Paul Wallington  <jpw@shootybangbang.com>
  
  	* xt-mouse.el (xterm-mouse-mode): Make it a global mode.

-- 
Benjamin

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] enhancement to set-variable to set buffer-locally
  2002-08-08  1:02 [patch] enhancement to set-variable to set buffer-locally Benjamin Rutt
@ 2002-08-09  0:28 ` John Paul Wallington
  2002-08-09  0:37 ` Miles Bader
  2002-08-09 16:39 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: John Paul Wallington @ 2002-08-09  0:28 UTC (permalink / raw)


Benjamin Rutt <rutt+news@cis.ohio-state.edu> wrote:

> 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'.

This looks neat.  Perhaps `set-variable' should also change its
prompt when var satisfies `local-variable-if-set-p' ?

e.g.:

*** 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,3665 ----
                   (read-variable "Set variable: ")))
  		      (minibuffer-help-form '(describe-variable var))
  		      (prop (get var 'variable-interactive))
! 		      (prompt (format "Set %s to%svalue: " var
!  				      (if (or current-prefix-arg
! 					      (local-variable-if-set-p var))
! 					  " (buffer-local) "
! 					" ")))
  		      (val (if prop
  			       ;; Use VAR's `variable-interactive' property
  			       ;; as an interactive spec for prompting.

-- 
John Paul Wallington

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] enhancement to set-variable to set buffer-locally
  2002-08-08  1:02 [patch] enhancement to set-variable to set buffer-locally Benjamin Rutt
  2002-08-09  0:28 ` John Paul Wallington
@ 2002-08-09  0:37 ` Miles Bader
  2002-08-09 16:39 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: Miles Bader @ 2002-08-09  0:37 UTC (permalink / raw)


On Wed, Aug 07, 2002 at 09:02:05PM -0400, Benjamin Rutt wrote:
> 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').

This seems like a nice idea, but the prompt `Set foo to local value' is wierd
-- it seems to associate `local' with the value _before_ setting, which
doesn't make any sense.

I think something like `Set foo locally in buffer to value' would be better
(if you don't like the length, you could get rid of `in buffer', but I think
it makes the meaning much more clear).

-Miles
-- 
P.S.  All information contained in the above letter is false,
      for reasons of military security.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [patch] enhancement to set-variable to set buffer-locally
  2002-08-08  1:02 [patch] enhancement to set-variable to set buffer-locally Benjamin Rutt
  2002-08-09  0:28 ` John Paul Wallington
  2002-08-09  0:37 ` Miles Bader
@ 2002-08-09 16:39 ` Richard Stallman
  2 siblings, 0 replies; 4+ messages in thread
From: Richard Stallman @ 2002-08-09 16:39 UTC (permalink / raw)
  Cc: emacs-devel

I installed this, with the other improvements.  Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-08-09 16:39 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-08-08  1:02 [patch] enhancement to set-variable to set buffer-locally Benjamin Rutt
2002-08-09  0:28 ` John Paul Wallington
2002-08-09  0:37 ` Miles Bader
2002-08-09 16:39 ` Richard Stallman

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).