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: Le Wang
Subject: Re: re-loading an elisp file
Date: Sun, 6 Mar 2011 16:36:12 +0800

On Sun, Mar 6, 2011 at 1:32 PM, rusi <address@hidden> wrote:
On Mar 6, 4:21 am, PJ Weisberg <address@hidden> wrote:
> On Sat, Mar 5, 2011 at 2:17 PM, Tim X <address@hidden> wrote:
> > 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.
>
> Not true.  If the variable is set at all, even to nil, defvar respects
> it and doesn't overwrite it with the default.  Otherwise putting
> something like (setq flyspell-persistent-highlight nil) in your .emacs
> file would have no effect.
>
> The way to actually do that is:
>
> (makunbound 'var)
>
> -PJ

This points out the real problem -- elisp is not a functional
language.
In (pure) functional languages the pattern (for loading) is to 'clean
the slate' and then load. IOW everything -- variable, function, type
-- that was defined in this module is first 'makunbounded' and then
the module is loaded.

It would certainly be worthwhile to have such a feature in emacs.  I
guess its not easy to do unless one has available the pair-list of the
form: ((var defined-in-file)...).
Another problem that would probably muddy the waters are macros...

You can roll your own eval-buffer that reloads defvars and defcustoms like so:

(defmacro replacement-def (sym val &rest args)
  `(setq ,sym ,val))


(defun force-eval-buffer (&optional buf)
  (interactive)
  (eval-buffer buf)                         ; define variables properly at least once
  (let ((func-alist (mapcar (lambda (func)
                              (cons func (symbol-function func)))
                            '(defvar defcustom))))
    (unwind-protect
        (progn
          (mapc (lambda (func-cons)
                  (fset (car func-cons) (symbol-function 'replacement-def)))
                func-alist)
          (eval-buffer buf))
      (mapcar (lambda (func-cons)
                (fset (car func-cons) (cdr func-cons)))
              func-alist))))

I'm not sure if this introduces any problems.

--
Le

reply via email to

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