From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marcelo de Moraes Serpa Newsgroups: gmane.emacs.help Subject: Re: Saving a elisp data structure into string and evaluating itback into objects Date: Wed, 7 Oct 2009 13:22:17 -0500 Message-ID: <1e5bcefd0910071122n5ec29027m32b39575c3ab872a@mail.gmail.com> References: <1e5bcefd0910061608y54755a7ejbf5def5831443da7@mail.gmail.com> <1e5bcefd0910070809w2c985363p3bf90e5490342991@mail.gmail.com> <1e5bcefd0910070923w6af29d6eja4aa8a16fb3b5db8@mail.gmail.com> <0836EDD8E49943738E063EFE7FE312A5@us.oracle.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=0050450175fa4482c304755c6dbd X-Trace: ger.gmane.org 1254939792 1908 80.91.229.12 (7 Oct 2009 18:23:12 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 7 Oct 2009 18:23:12 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, Kevin Rodgers , Thierry Volpiatto To: Drew Adams Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 07 20:23:02 2009 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.50) id 1Mvb9y-0004DG-Vk for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Oct 2009 20:22:47 +0200 Original-Received: from localhost ([127.0.0.1]:33759 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mvb9x-0005iO-RW for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Oct 2009 14:22:45 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mvb9b-0005iB-Um for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 14:22:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mvb9W-0005hj-U0 for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 14:22:23 -0400 Original-Received: from [199.232.76.173] (port=50228 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mvb9W-0005hg-PZ for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 14:22:18 -0400 Original-Received: from mail-yw0-f200.google.com ([209.85.211.200]:65513) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mvb9W-0005NU-DH for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 14:22:18 -0400 Original-Received: by ywh38 with SMTP id 38so5161959ywh.6 for ; Wed, 07 Oct 2009 11:22:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=dYEIOR+LYNa6yfKyVSYcemN0G/+Ql6GyFdj3ukapkpA=; b=aBYR2aRFHDYUnzqoy251cXxg77jBU9RD8kUJfM4VO7lB5n+etqwzkvIOrYBGNKfS4N mYHHrixRDt1Gn8tbEqzO87U7GWv8aBPWsrycJaitGti0aqM2QcML+cN0UOBQjywsn3pE iVzTCrkwbBkQmohZNJ7ocPKm785+pA85/P4GE= 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=K+gAy+gk+sGn9hW8ryDdc8Ix3p8CVSIa4gEEXVeyPdqVODgdPZ9w9i6VLhtxyDqmIJ pmITv7yTxeJKmICfOa7BQE/P6kLWya5eDVKFwdjuVErbJ0lvhI7Nkmh6p3yT5YQF5l3T Su4pGsr0sLDcDvNr2cJv2MUOWSnGuGRVj5npQ= Original-Received: by 10.100.80.7 with SMTP id d7mr269822anb.43.1254939737489; Wed, 07 Oct 2009 11:22:17 -0700 (PDT) In-Reply-To: <0836EDD8E49943738E063EFE7FE312A5@us.oracle.com> X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:68740 Archived-At: --0050450175fa4482c304755c6dbd Content-Type: text/plain; charset=ISO-8859-1 @Drew: Thanks a lot for the comprehensive answer, I really appreciate that! So, I have two choices, as far as I can see: 1) Write my own serialize/deserialize function. Sounds feasible, but could someone give me a sample of that? I'm just beginning in elisp and all still sounds a little bit out of place for me; 2) Use the byte-complie thing. Also, I know I could use that, but how ? Thank you, Marcelo. On Wed, Oct 7, 2009 at 12:41 PM, Drew Adams wrote: > 1. There have been several examples of libraries that save and then restore > various sets of Lisp objects, typically in order to restore the state of an > Emacs session, or at least part of it. Some have already been mentioned > here. > > FWIW, I use Savehist, to restore both history variables and other variables > that > I choose (via option `savehist-additional-variables'): > http://www.emacswiki.org/emacs/SaveHist > > But it too doesn't help with Emacs objects whose print form is not > Lisp-readable. > > (I also have my own code that serializes completion alists, in such a way > that > it records and restores markers. But the serialization format I use is > particular to my code.) > > > 2. AFAIK, there is no general serialize/deserialize feature, as such, in > Emacs > Lisp. That is, there are no predefined functions that do just that: (1) You > provide a set of objects and a file name to a `serialize' function, and it > writes the objects to the file in a way that captures their current state. > (2) > You call a `deserialize' function to read the file (e.g. using the Lisp > reader) > and thus re-create the objects in the state in which they were saved. > > > 3. It might be worthwhile looking at this thread: > http://lists.gnu.org/archive/html/emacs-devel/2009-09/msg00846.html > > The thread is too short, IMO (it drew no real interest, for some reason), > and it > got side-tracked by a discussion of licensing. But the idea is simple: > > Thierry Volpiatto noticed that, at least for recent Emacs versions, > byte-compiling serializes Emacs objects in a fairly general way, so reading > (loading) a byte-compiled (*.elc) file then restores the objects as they > were. > > You can use this feature as is. Or you (or Emacs development) could use it > to > define `serialize' and `deserialize' functions for general use. > > Thierry pointed out the following URL to me in connection with this. It > mentions > using `#.' in Common Lisp, whereas for Emacs Lisp it is `eval-when-compile' > that > does the trick. > http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/lisp/part5/faq-doc-5.html > > HTH. > > --0050450175fa4482c304755c6dbd Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable @Drew: Thanks a lot for the comprehensive answer, I really appreciate that!=

So, I have two choices, as far as I can see:

1) Write my own= serialize/deserialize function. Sounds feasible, but could someone give me= a sample of that? I'm just beginning in elisp and all still sounds a l= ittle bit out of place for me;
2) Use the byte-complie thing. Also, I know I could use that, but how ?
=
Thank you,

Marcelo.

On Wed, Oc= t 7, 2009 at 12:41 PM, Drew Adams <drew.adams@oracle.com> wrote:
1. There have bee= n several examples of libraries that save and then restore
various sets of Lisp objects, typically in order to restore the state of an=
Emacs session, or at least part of it. Some have already been mentioned her= e.

FWIW, I use Savehist, to restore both history variables and other variables= that
I choose (via option `savehist-additional-variables'):
http:= //www.emacswiki.org/emacs/SaveHist

But it too doesn't help with Emacs objects whose print form is not
Lisp-readable.

(I also have my own code that serializes completion alists, in such a way t= hat
it records and restores markers. But the serialization format I use is
particular to my code.)


2. AFAIK, there is no general serialize/deserialize feature, as such, in Em= acs
Lisp. That is, there are no predefined functions that do just that: (1) You=
provide a set of objects and a file name to a `serialize' function, and= it
writes the objects to the file in a way that captures their current state. = (2)
You call a `deserialize' function to read the file (e.g. using the Lisp= reader)
and thus re-create the objects in the state in which they were saved.


3. It might be worthwhile looking at this thread:
http://lists.gnu.org/archive/html/emacs-devel/2009-0= 9/msg00846.html

The thread is too short, IMO (it drew no real interest, for some reason), a= nd it
got side-tracked by a discussion of licensing. But the idea is simple:

Thierry Volpiatto noticed that, at least for recent Emacs versions,
byte-compiling serializes Emacs objects in a fairly general way, so reading=
(loading) a byte-compiled (*.elc) file then restores the objects as they we= re.

You can use this feature as is. Or you (or Emacs development) could use it = to
define `serialize' and `deserialize' functions for general use.

Thierry pointed out the following URL to me in connection with this. It men= tions
using `#.' in Common Lisp, whereas for Emacs Lisp it is `eval-when-comp= ile' that
does the trick.
http://www.cs.cmu.edu/Groups/AI/html/faqs/lang/= lisp/part5/faq-doc-5.html

HTH.


--0050450175fa4482c304755c6dbd--