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

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

Re: loading hash-table from a file?


From: Eric Abrahamsen
Subject: Re: loading hash-table from a file?
Date: Sat, 07 Jan 2012 10:16:52 +0800
User-agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux)

On Sat, Jan 07 2012, Thierry Volpiatto wrote:

> Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>

[...]

>>
>> I found this on the internet (presumably authored by someone with the
>> initials T.V.), which does what you're asking (I used it to persist a
>> hash-table that I load on startup). I don't really know if it's superior
>> to the previous reply, but it certainly works. It produces a *.elc file,
>> which can be loaded with `load' (provided it's in your load-path, of
>> course). Whatever symbol name you originally dumped then becomes defined
>> again.
>>
>> Eric
>>
>> (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)))
>
> I use this always to save emacs session (buffers and variables), but it
> have limitations on complex hash-tables, windows objects etc...
> T.V are my initials ;-)

Hats off to you sir! I use it (or rather, its dumped files) every day.

-- 
GNU Emacs 24.0.92.2 (i686-pc-linux-gnu, GTK+ Version 2.24.8)
 of 2012-01-04 on pellet




reply via email to

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