help-gnu-emacs
[Top][All Lists]
Advanced

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

Re: re-loading an elisp file


From: Tim X
Subject: Re: re-loading an elisp file
Date: Sun, 06 Mar 2011 09:17:21 +1100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)

ken <gebser@mousecar.com> writes:

> On 03/05/2011 10:27 AM Pascal J. Bourguignon wrote:
>> ken <gebser@mousecar.com> writes:
>> 
>>> Is there a way, when reloading an elisp file, to have it examine (and
>>> reload new) values of variables?  
>> 
>> There's a reason it's done: if you've painfully customized a module, you
>> wouldn't want all your settings to be reset to default just because you
>> reload its sources.
>
> That's what I *am* doing-- *quite* and unnecessarily painfully
> customizing a module-- and I *do* want variables to be re-initialized.
>
>
>> 
>> So defvar is defined to set the value of the variable only if the
>> variable is not already defined.
>
> Then the name of the function should be called
> "load-everything-except-variables".  The "load" and
> "eval-current-buffer" functions should do what their names say.
>
>
>> 
>> 
>> In Common Lisp, there's also a defparameter macro that always sets the
>> value of the variable.  But of course, you wouldn't do that for
>> customization variables, or for variables storing important state (eg. a
>> database).
>
> Are you saying I need to switch from elisp to common lisp or make a call
> to common lisp just to change the value of a variable?
>
>
>> 
>> 
>> So you may put:
>> 
>> (defmacro defconstant (symbol initvalue &optional docstring)
>>   `(defconst ,symbol ,initvalue ,docstring))
>> 
>> (defmacro defparameter (symbol &optional initvalue docstring)
>>   `(progn
>>      (defvar ,symbol nil ,docstring)
>>      (setq   ,symbol ,initvalue)))
>> 
>> in your ~/.emacs and use defparameter instead of defvar in some cases.
>> But in general you don't want to.
>
> So I need to put all this code in my ~/.emacs (and then of course
> re-initialize ~/.emacs) whenever I need to re-initialize one variable?
> But then wouldn't I need to take this code back out and re-initialize
> ~/.emacs again when I don't want to change the value of a variable?
>
> I think it would be simpler and easier just to reboot all of emacs.  But
> quitting-and-restarting emacs seems like a radical procedure just to
> re-initialize one variable.
>
>
>> 
>> 
>> What you may do, is to provide a reset command to reinitialize the state
>> of your module.
>
> I was hoping I wouldn't have to write that code myself...  I was
> thinking that elisp should have a way to re-initialize a variable in a
> module.  That was really the point of my original post.
>
>

No you don't need to add all the code Pascal included and probably best
not to unless you understand it. 

The problem is that while you may know which variables you want re-set,
emacs doesn't know which ones have been deliberately set to a value by
you because that is the default you want and which ones should be reset
to their default values. 

The way I usually deal with this is to either reset the variable in the
scratch buffer i.e. 

(setq var nil)

then when I re-evaluate the buffer, var will be set if it is in a defvar
statement. If you have a few of these variables, then I would just put
them in a simple funciton (which I also define in the scratch buffer)
i.e.

(defun my-reset ()
       (interactive)
       (setq var1 nil)
       (setq var2 nile)
       ... 
       )

and then just type M-x my-reset whenever I want to reset that set of
variables. 

However, it is possible that you may be approaching hings from the wrong
direction. I rarely need to re-evaluate a whole buffer, unless I'm
developing something from scratch. If your just modifying some existing
code, you normally only need to evaluate individual functions. For
customization, the custom interface provides a good high-level way to
try out various settings without having to re-evaluate a buffer etc. 

Maybe provide some more explination about what your trying to do and we
can provide better answers.

Tim

-- 
tcross (at) rapttech dot com dot au


reply via email to

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