From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Le Wang Newsgroups: gmane.emacs.help Subject: Re: re-loading an elisp file Date: Sun, 6 Mar 2011 16:36:12 +0800 Message-ID: References: <87bp1ptwn6.fsf@kuiper.lan.informatimago.com> <87r5alb4b2.fsf@rapttech.com.au> <2700f0cc-7c2a-46a3-a2d2-c2a34f3ddae9@z27g2000prz.googlegroups.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=bcaec501652986eb91049dcc457b X-Trace: dough.gmane.org 1299400607 25004 80.91.229.12 (6 Mar 2011 08:36:47 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 6 Mar 2011 08:36:47 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: rusi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sun Mar 06 09:36:43 2011 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Pw9SC-0001h8-SV for geh-help-gnu-emacs@m.gmane.org; Sun, 06 Mar 2011 09:36:41 +0100 Original-Received: from localhost ([127.0.0.1]:36112 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pw9SB-0005fm-TU for geh-help-gnu-emacs@m.gmane.org; Sun, 06 Mar 2011 03:36:39 -0500 Original-Received: from [140.186.70.92] (port=37753 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Pw9Rm-0005ff-Ve for help-gnu-emacs@gnu.org; Sun, 06 Mar 2011 03:36:15 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Pw9Rl-0006XX-R5 for help-gnu-emacs@gnu.org; Sun, 06 Mar 2011 03:36:14 -0500 Original-Received: from mail-vx0-f169.google.com ([209.85.220.169]:44063) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Pw9Rl-0006XO-HW for help-gnu-emacs@gnu.org; Sun, 06 Mar 2011 03:36:13 -0500 Original-Received: by vxc38 with SMTP id 38so3822219vxc.0 for ; Sun, 06 Mar 2011 00:36:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=b2HrZyNXGcpKCgQMnwGCqvnYj9P+EYYgwDV+sQ3jB0A=; b=i3v9MpgQbbS3nO/SCooh9okkJefUiep5CL4q2vl0eLlu/tOwxI5yGrLIJVsEJkhQqY 3mnaUWyrwLH9+L6eohIbl2kJBf/6+YOL7gJNccaw28yBbHEhxJeYpceSaKDqXM48nd2W hOxGtyc6JgKMt3BE7jqlzIQLAwUvDyg2Tv2YA= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=x1Mmo73tFsara+R1+0Q11mZveJuPl9wEp+G8Ra6oycL3WYaXeCGqQlpU6Q6WhK/7N0 twRw7CPe7oy3Qck+OSmq0BAV/IVod4l1M23dKkQjwxnGBB3RQUJ6Y+3H23VdT5HFZAN9 Ji7kKHx+T1Wy9nYuBlAxO1U+eXsJ4sdiGkswk= Original-Received: by 10.52.92.1 with SMTP id ci1mr3607747vdb.90.1299400572201; Sun, 06 Mar 2011 00:36:12 -0800 (PST) Original-Received: by 10.52.158.193 with HTTP; Sun, 6 Mar 2011 00:36:12 -0800 (PST) In-Reply-To: <2700f0cc-7c2a-46a3-a2d2-c2a34f3ddae9@z27g2000prz.googlegroups.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 209.85.220.169 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:79814 Archived-At: --bcaec501652986eb91049dcc457b Content-Type: text/plain; charset=ISO-8859-1 On Sun, Mar 6, 2011 at 1:32 PM, rusi wrote: > On Mar 6, 4:21 am, PJ Weisberg wrote: > > On Sat, Mar 5, 2011 at 2:17 PM, Tim X 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 --bcaec501652986eb91049dcc457b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
On Sun, Mar 6, 2011 at 1:32 PM, rusi <rustompmody@gmail.com= > wrote:
On Mar 6, 4:21=A0am, PJ Weisberg <p...@irregularexpressions.net> wrote:
> On Sat, Mar 5, 2011 at 2:17 PM, Tim X <t...@nospa= m.dev.null> 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. =A0If the variable is set at all, ev= en to nil, defvar respects
> it and doesn't overwrite it with the default. =A0Otherwise 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. =A0I
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 th= at reloads defvars and defcustoms like so:

(defmacro replacement-def (sym val &rest args)
=A0=A0`(s= etq ,sym ,val))


(defun force-eval-b= uffer (&optional buf)
=A0=A0(interactive)
=A0=A0(ev= al-buffer buf) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 ; define var= iables properly at least once
=A0=A0(let ((func-alist (mapcar (lambda (func)
=A0=A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(cons func (symbol-funct= ion func)))
=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0'(defvar defcustom))))
=A0=A0 =A0(unwind-protect
=A0=A0 =A0 =A0 =A0(progn
=A0=A0 =A0 =A0 =A0 =A0(mapc (lambda= (func-cons)
=A0=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(fset (car fun= c-cons) (symbol-function 'replacement-def)))
=A0=A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0func-alist)
=A0=A0 =A0 =A0 =A0 =A0(eval-buffer= buf))
=A0=A0 =A0 =A0(mapcar (lambda (func-cons)
=A0=A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0(fset (car func-cons) (cdr func-cons)))
=A0=A0 = =A0 =A0 =A0 =A0 =A0 =A0func-alist))))

I'm not sure if this introduces any problems.
--
Le
--bcaec501652986eb91049dcc457b--