From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eric Abrahamsen Newsgroups: gmane.emacs.help Subject: Re: loading hash-table from a file? Date: Sat, 07 Jan 2012 10:16:52 +0800 Message-ID: <87k4548dez.fsf@ericabrahamsen.net> References: <87r4zecybg.fsf@ericabrahamsen.net> <8762gou6gy.fsf@gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1325902637 383 80.91.229.12 (7 Jan 2012 02:17:17 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 7 Jan 2012 02:17:17 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Jan 07 03:17:14 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RjLqJ-0004wv-Kt for geh-help-gnu-emacs@m.gmane.org; Sat, 07 Jan 2012 03:17:11 +0100 Original-Received: from localhost ([::1]:38325 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjLqE-0007bb-2Z for geh-help-gnu-emacs@m.gmane.org; Fri, 06 Jan 2012 21:17:06 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:60968) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjLq9-0007bT-K1 for help-gnu-emacs@gnu.org; Fri, 06 Jan 2012 21:17:02 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RjLq8-0007kL-B5 for help-gnu-emacs@gnu.org; Fri, 06 Jan 2012 21:17:01 -0500 Original-Received: from lo.gmane.org ([80.91.229.12]:53298) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RjLq7-0007kH-Vf for help-gnu-emacs@gnu.org; Fri, 06 Jan 2012 21:17:00 -0500 Original-Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1RjLq6-0004r1-TS for help-gnu-emacs@gnu.org; Sat, 07 Jan 2012 03:16:58 +0100 Original-Received: from 114.250.117.176 ([114.250.117.176]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 07 Jan 2012 03:16:58 +0100 Original-Received: from eric by 114.250.117.176 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sat, 07 Jan 2012 03:16:58 +0100 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 43 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: 114.250.117.176 User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.92 (gnu/linux) Cancel-Lock: sha1:WUNl3cl391r2H+zL+UshkiVzmU0= X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 80.91.229.12 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:83388 Archived-At: On Sat, Jan 07 2012, Thierry Volpiatto wrote: > Eric Abrahamsen 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