From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Drew Adams" Newsgroups: gmane.emacs.help Subject: RE: Saving a elisp data structure into string and evaluating itback into objects Date: Wed, 7 Oct 2009 10:41:05 -0700 Message-ID: <0836EDD8E49943738E063EFE7FE312A5@us.oracle.com> References: <1e5bcefd0910061608y54755a7ejbf5def5831443da7@mail.gmail.com><1e5bcefd0910070809w2c985363p3bf90e5490342991@mail.gmail.com> <1e5bcefd0910070923w6af29d6eja4aa8a16fb3b5db8@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1254938197 28641 80.91.229.12 (7 Oct 2009 17:56:37 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 7 Oct 2009 17:56:37 +0000 (UTC) Cc: help-gnu-emacs@gnu.org, 'Kevin Rodgers' , 'Thierry Volpiatto' To: "'Marcelo de Moraes Serpa'" , "'Lennart Borgman'" Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Wed Oct 07 19:56:26 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 1MvakT-0005dL-7n for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Oct 2009 19:56:25 +0200 Original-Received: from localhost ([127.0.0.1]:39362 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvakS-0005PT-Ng for geh-help-gnu-emacs@m.gmane.org; Wed, 07 Oct 2009 13:56:24 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MvaWB-0006K8-37 for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 13:41:39 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MvaW6-0006H3-1d for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 13:41:38 -0400 Original-Received: from [199.232.76.173] (port=38902 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MvaW5-0006Gv-48 for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 13:41:33 -0400 Original-Received: from acsinet12.oracle.com ([141.146.126.234]:57348) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1MvaW4-0006hx-GK for help-gnu-emacs@gnu.org; Wed, 07 Oct 2009 13:41:32 -0400 Original-Received: from rgminet13.oracle.com (rcsinet13.oracle.com [148.87.113.125]) by acsinet12.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n97HfQxi001605 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Wed, 7 Oct 2009 17:41:27 GMT Original-Received: from acsmt357.oracle.com (acsmt357.oracle.com [141.146.40.157]) by rgminet13.oracle.com (Switch-3.3.1/Switch-3.3.1) with ESMTP id n975mLLq023238; Wed, 7 Oct 2009 17:41:54 GMT Original-Received: from abhmt014.oracle.com by acsmt357.oracle.com with ESMTP id 20267094681254937265; Wed, 07 Oct 2009 12:41:05 -0500 Original-Received: from dradamslap1 (/130.35.178.194) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 07 Oct 2009 10:41:05 -0700 X-Mailer: Microsoft Office Outlook 11 In-Reply-To: <1e5bcefd0910070923w6af29d6eja4aa8a16fb3b5db8@mail.gmail.com> Thread-Index: AcpHaxti541RZtpIS52DBlqC34fSxgAACS2w X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579 X-Source-IP: acsmt357.oracle.com [141.146.40.157] X-Auth-Type: Internal IP X-CT-RefId: str=0001.0A090208.4ACCD2C5.00F4:SCFMA4539814,ss=1,fgs=0 X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) 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:68739 Archived-At: 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.