|
|
Up |
|
|
  |
Author: XahXah Date: Aug 27, 2008 18:01
if i have a hash table in elisp, is there a way to save it to disk and
reread in when starting emacs?
Thanks.
Xah
∑ http://xahlee.org/
☄
|
| |
|
| | 8 Comments |
|
  |
Author: Thierry VolpiattoThierry Volpiatto Date: Aug 27, 2008 22:21
Xah gmail.com> writes:
> if i have a hash table in elisp, is there a way to save it to disk and
> reread in when starting emacs?
What you can do is creating a named hash-table at each time you start
emacs and load a file containing (puthash that...) (puthash this...)
etc... Here an example of one of my files:
,----
| ;;; dvc-bookmarks-cache -*- mode: emacs-lisp; coding: utf-8; -*-
| (puthash 'MAIL '((color . dvc-excluded) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
| (puthash 'CONFIG '((color . dvc-source) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
| (puthash 'DVC '((color . dvc-mark) (state . "open") (time-stamp . "2008.08.15")) dvc-bookmarks-cache)
| (puthash 'SOURCES '((color . dvc-unknown) (state . "open") (time-stamp . "2008.06.23")) dvc-bookmarks-cache)
`----
The hash-table here is `dvc-bookmark-cache'
--
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France
|
| |
|
| | no comments |
|
  |
Author: XahXah Date: Aug 27, 2008 22:27
but is there a function or lib to save hashtable to disk? i.e.
sometimes called serializing?
Xah
∑ http://xahlee.org/
☄
On Aug 27, 10:21 pm, Thierry Volpiatto gmail.com>
wrote:
> Xah gmail.com> writes:
>> if i have a hash table in elisp, is there a way to save it to disk and
>> reread in when...
|
| Show full article (1.19Kb) |
| no comments |
|
  |
Author: Thierry VolpiattoThierry Volpiatto Date: Aug 27, 2008 23:17
Xah gmail.com> writes:
> but is there a function or lib to save hashtable to disk? i.e.
> sometimes called serializing?
AFAIK no, may be use some python dictionary and pickle it.
> Xah
> ∑ http://xahlee.org/
>
> ☄
>
> On Aug 27, 10:21 pm, Thierry Volpiatto gmail.com>
> wrote:
>> Xah gmail.com> writes:
>>> if i have a hash table in elisp, is there a...
|
| Show full article (1.39Kb) |
| no comments |
|
  |
Author: Niels GiesenNiels Giesen Date: Aug 28, 2008 01:36
Xah gmail.com> writes:
> if i have a hash table in elisp, is there a way to save it to disk and
> reread in when starting emacs?
>
> Thanks.
>
> Xah
> ∑ http://xahlee.org/
>
> ☄
You might use this code (I use it in gimp-mode):
(defmacro gimp-hash-to-list (hash-table)
(let ((nl (gensym)))
`(let (,nl)
(maphash (lambda (k v)
(push (list k v) ,nl)) ,hash-table)
,nl)))
|
| Show full article (0.63Kb) |
| no comments |
|
  |
Author: Ted ZlatanovTed Zlatanov Date: Aug 28, 2008 07:03
On Wed, 27 Aug 2008 22:27:47 -0700 (PDT) Xah gmail.com> wrote:
X> but is there a function or lib to save hashtable to disk? i.e.
X> sometimes called serializing?
No. It's easy to convert a hashtable to a list, and Emacs makes it easy
to serialize a list, so that's what people do. I have code in
gnus-registry.el (copied in part from the way Gnus saves its newsrc
file) to do this. The combination of two easy things is not,
unfortunately, simple anymore.
I like the (puthash ...) approach suggested by Thierry Volpiatto but
it's a lot of function calls for a large hashtable (which the Gnus
registry creates). So I'm not sure it's the right approach either.
BBDB has a similar problem; it saves vectors instead of lists.
If there's no library for serialization, it should definitely be
written. Emacs Lisp has only a few basic data types, and not all of
them have to be supported anyhow.
Ted
|
| |
| no comments |
|
  |
Author: Ted ZlatanovTed Zlatanov Date: Aug 29, 2008 07:06
On Thu, 28 Aug 2008 21:10:56 +0300 Eli Zaretskii gnu.org> wrote:
>> From: Ted Zlatanov lifelogs.com>
>> Date: Thu, 28 Aug 2008 09:03:53 -0500
>>
>> If there's no library for serialization, it should definitely be
>> written.
EZ> You mean, like bindat.el?
That looks useful for binary data. I don't see from the code how to use
it to save and load a hashtable. The spec format supports these types:
|
| Show full article (1.43Kb) |
| no comments |
|
  |
Author: Eli ZaretskiiEli Zaretskii Date: Aug 29, 2008 07:52
> From: Ted Zlatanov lifelogs.com>
> Date: Fri, 29 Aug 2008 09:06:02 -0500
>
> On Thu, 28 Aug 2008 21:10:56 +0300 Eli Zaretskii gnu.org> wrote:
>
>>> From: Ted Zlatanov lifelogs.com>
>>> Date: Thu, 28 Aug 2008 09:03:53 -0500
>>>
>>> If there's no library for serialization, it should definitely be
>>> written.
>
>> You mean, like bindat.el?
>
> That looks useful for binary data. I don't see from the code how to use
> it to save and load a hashtable.
I never used it, I just advertised the closest hit for what you seemed
to be looking.
|
| Show full article (0.80Kb) |
| no comments |
|
  |
|
|
  |
Author: Ted ZlatanovTed Zlatanov Date: Aug 29, 2008 11:10
On Fri, 29 Aug 2008 17:52:07 +0300 Eli Zaretskii gnu.org> wrote:
EZ> You mean, like bindat.el?
>>
>> That looks useful for binary data. I don't see from the code how to use
>> it to save and load a hashtable.
EZ> I never used it, I just advertised the closest hit for what you seemed
EZ> to be looking.
>> In addition, this library doesn't manage file I/O. I'd expect the
>> library do do content coding and error handling internally. This is,
>> actually, the most tedious part.
EZ> A cause for a small project, I guess. ;-)
I can just copy the code out of gnus-registry.el and abstract the
functionality to do a first cut of such a library. For a large
hashtable, though, converting to a list on the way in and out is
inefficient compared to storing it in a more "native" format. Is there
such a format, comparable to the native list read-eval format, as seen
in gnus-load:
|
| Show full article (1.17Kb) |
| no comments |
|
|