all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* re-defvar a variable without reloading emacs
@ 2009-06-13 12:51 ken
  2009-06-13 13:15 ` Eli Zaretskii
  0 siblings, 1 reply; 5+ messages in thread
From: ken @ 2009-06-13 12:51 UTC (permalink / raw
  To: GNU Emacs List


I've got a defvar'd variable in my .emacs which I want to redefine.  But
rerunning (defvar somevar "someval") doesn't work... according to the
docs, this is the correct behavior.  So is there some way to redefine
this variable without reloading the whole of emacs?

Thanks vielmals.

-- 
"To make an apple pie from scratch,
first create the universe."
        -- Carl Sagan





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

* Re: re-defvar a variable without reloading emacs
  2009-06-13 12:51 ken
@ 2009-06-13 13:15 ` Eli Zaretskii
  2009-06-13 15:19   ` Drew Adams
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2009-06-13 13:15 UTC (permalink / raw
  To: help-gnu-emacs

> Date: Sat, 13 Jun 2009 08:51:11 -0400
> From: ken <gebser@mousecar.com>
> Reply-To: gebser@mousecar.com
> 
> 
> I've got a defvar'd variable in my .emacs which I want to redefine.  But
> rerunning (defvar somevar "someval") doesn't work... according to the
> docs, this is the correct behavior.  So is there some way to redefine
> this variable without reloading the whole of emacs?

Use setq.




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

* Re: re-defvar a variable without reloading emacs
       [not found] <mailman.563.1244897480.2239.help-gnu-emacs@gnu.org>
@ 2009-06-13 13:54 ` Markus Triska
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Triska @ 2009-06-13 13:54 UTC (permalink / raw
  To: help-gnu-emacs

ken <gebser@mousecar.com> writes:

> I've got a defvar'd variable in my .emacs which I want to redefine.  But
> rerunning (defvar somevar "someval") doesn't work

Use C-M-x (`eval-defun') on the form instead; from its docstring:

   If the current defun is actually a call to `defvar' or `defcustom',
   evaluating it this way resets the variable using its initial value
   expression even if the variable already has some other value.



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

* RE: re-defvar a variable without reloading emacs
  2009-06-13 13:15 ` Eli Zaretskii
@ 2009-06-13 15:19   ` Drew Adams
  2009-06-13 23:48     ` ken
  0 siblings, 1 reply; 5+ messages in thread
From: Drew Adams @ 2009-06-13 15:19 UTC (permalink / raw
  To: help-gnu-emacs

> > I've got a defvar'd variable in my .emacs which I want to 
> > redefine.  But rerunning (defvar somevar "someval") doesn't work... 
> > according to the docs, this is the correct behavior.  So is there
> > some way to redefine this variable without reloading the whole of emacs?
> 
> Use setq.

It depends what is meant:

1. If you mean that you have already evaluated (e.g. loaded) the code
(defvar somevar "someval"), and you have now edited that code to
(defvar somevar "newval"), and you want to evaluate that
interactively, see node `Evaluating Emacs Lisp Expressions' in the
Emacs manual. It says you can put the cursor somewhere on the
expression and hit `C-M-x', to do what you want.

2. If you mean that you have want to be able to evaluate (e.g. load)
the code (defvar somevar "someval") and then evaluate (load) some
other code that redefines `somevar', then use (setq somevar "newval")
as that other code.

`setq' always assigns a value. `defvar' assigns a value only the
first time it is evaluated, normally, but `C-M-x' overrides this,
making it assign a value again.





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

* Re: re-defvar a variable without reloading emacs
  2009-06-13 15:19   ` Drew Adams
@ 2009-06-13 23:48     ` ken
  0 siblings, 0 replies; 5+ messages in thread
From: ken @ 2009-06-13 23:48 UTC (permalink / raw
  To: help-gnu-emacs

Drew,

Excellent answer... 400% better than an expert's... it reminds us that
the meaning of "guru" is "teacher".

But much thanks to all who replied.


On 06/13/2009 11:19 AM Drew Adams wrote:
>>> I've got a defvar'd variable in my .emacs which I want to 
>>> redefine.  But rerunning (defvar somevar "someval") doesn't work... 
>>> according to the docs, this is the correct behavior.  So is there
>>> some way to redefine this variable without reloading the whole of emacs?
>> Use setq.
> 
> It depends what is meant:
> 
> 1. If you mean that you have already evaluated (e.g. loaded) the code
> (defvar somevar "someval"), and you have now edited that code to
> (defvar somevar "newval"), and you want to evaluate that
> interactively, see node `Evaluating Emacs Lisp Expressions' in the
> Emacs manual. It says you can put the cursor somewhere on the
> expression and hit `C-M-x', to do what you want.
> 
> 2. If you mean that you have want to be able to evaluate (e.g. load)
> the code (defvar somevar "someval") and then evaluate (load) some
> other code that redefines `somevar', then use (setq somevar "newval")
> as that other code.
> 
> `setq' always assigns a value. `defvar' assigns a value only the
> first time it is evaluated, normally, but `C-M-x' overrides this,
> making it assign a value again.
> 
> 
> 




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

end of thread, other threads:[~2009-06-13 23:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <mailman.563.1244897480.2239.help-gnu-emacs@gnu.org>
2009-06-13 13:54 ` re-defvar a variable without reloading emacs Markus Triska
2009-06-13 12:51 ken
2009-06-13 13:15 ` Eli Zaretskii
2009-06-13 15:19   ` Drew Adams
2009-06-13 23:48     ` ken

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.