[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: re-loading an elisp file
Re: re-loading an elisp file
Sun, 06 Mar 2011 09:17:21 +1100
Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux)
ken <address@hidden> writes:
> On 03/05/2011 10:27 AM Pascal J. Bourguignon wrote:
>> ken <address@hidden> 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
> 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)
>> (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)
(defun my-reset ()
(setq var1 nil)
(setq var2 nile)
and then just type M-x my-reset whenever I want to reset that set of
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.
tcross (at) rapttech dot com dot au
Re: re-loading an elisp file, Pascal J. Bourguignon, 2011/03/05
Message not available
Message not availableRe: re-loading an elisp file, rusi, 2011/03/06
Re: re-loading an elisp file, Le Wang, 2011/03/06
Re: re-loading an elisp file, Kevin Rodgers, 2011/03/07
Message not availableRe: re-loading an elisp file, rusi, 2011/03/07
Re: re-loading an elisp file, rusi, 2011/03/07
Re: re-loading an elisp file, David Combs, 2011/03/24
Re: re-loading an elisp file, Tim X, 2011/03/25
Re: re-loading an elisp file, David Kastrup, 2011/03/25