emacs-devel
[Top][All Lists]
Advanced

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

Re: persistent lisp objects


From: Thierry Volpiatto
Subject: Re: persistent lisp objects
Date: Thu, 01 Oct 2009 10:14:24 +0200
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.1 (gnu/linux)

Thierry Volpiatto <address@hidden> writes:

> Hi all,
> it seem using `setf' combined with `eval-when-compile' is a convenient
> way to save lisp object like hash-table.
> It is not documented.
> What do you think?

Maybe i was not clear enough.
We can actually save any lisp object in a compiled file:

,----
| (defun tv-dump-object-to-file (obj file)
|   "Save symbol object `obj' to the byte compiled version of `file'.
| `obj' can be any lisp object, list, hash-table, etc...
| `file' is an elisp file with ext *.el.
| Loading the *.elc file will restitute object."
|   (require 'cl) ; Be sure we use the CL version of `eval-when-compile'.
|   (if (file-exists-p file)
|       (error "File already exists.")
|       (with-temp-file file
|         (erase-buffer)
|         (let* ((str-obj (symbol-name obj))
|                (fmt-obj (format "(setq %s (eval-when-compile %s))" str-obj 
str-obj)))
|           (insert fmt-obj)))
|       (byte-compile-file file) (delete-file file)
|       (message "`%s' dumped to %sc" obj file)))
`----

This is a feature of `eval-when-compile' that is not documented.
It can be interesting as AFAIK there is no way to save object.

-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





reply via email to

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