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

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

Re: Saving a elisp data structure into string and evaluating itback into


From: Marcelo de Moraes Serpa
Subject: Re: Saving a elisp data structure into string and evaluating itback into objects
Date: Wed, 7 Oct 2009 13:22:17 -0500

@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 <address@hidden> 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.



reply via email to

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