From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Teemu Likonen Newsgroups: gmane.emacs.help Subject: Re: loading hash-table from a file? Date: Thu, 05 Jan 2012 11:24:14 +0200 Message-ID: <87ipkqo62p.fsf@imladris.arda> References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: dough.gmane.org 1325755474 16643 80.91.229.12 (5 Jan 2012 09:24:34 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 5 Jan 2012 09:24:34 +0000 (UTC) Cc: help-gnu-emacs@gnu.org To: ishi soichi Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Jan 05 10:24:25 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 1RijYd-0004cH-Rv for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jan 2012 10:24:24 +0100 Original-Received: from localhost ([::1]:35062 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RijYc-0006CF-Ov for geh-help-gnu-emacs@m.gmane.org; Thu, 05 Jan 2012 04:24:22 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:58284) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RijYY-0006C7-0S for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 04:24:18 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RijYW-0006wr-Rh for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 04:24:17 -0500 Original-Received: from mta-out.inet.fi ([195.156.147.13]:50606 helo=jenni2.inet.fi) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RijYW-0006wh-Hy for help-gnu-emacs@gnu.org; Thu, 05 Jan 2012 04:24:16 -0500 Original-Received: from imladris.arda (62.237.32.162) by jenni2.inet.fi (8.5.140.02) (authenticated as likote-3) id 4EB3AFE102DAEEC9; Thu, 5 Jan 2012 11:24:14 +0200 Original-Received: from dtw by imladris.arda with local (Exim 4.72) (envelope-from ) id 1RijYU-0006fm-Hf; Thu, 05 Jan 2012 11:24:14 +0200 In-Reply-To: (ishi soichi's message of "Thu, 5 Jan 2012 14:16:41 +0900") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 195.156.147.13 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:83349 Archived-At: * 2012-01-05T14:16:41+09:00 * ishi soichi wrote: > Say, I have a hundred key-value pairs, which are to be stored as > hash-table. Can I save this as a (text?) file so that Emacs can load > it when booting up? Yes. Use the Lisp object printing functions to print to a buffer: PRINT, PRIN1 or (FORMAT "%S" ...). Then read the printed object with READ which turns it to a Lisp object again. Here's an example of the idea: ;; Print (with-temp-file "/tmp/test" (let ((ht (make-hash-table))) (puthash 'a 1 ht) (puthash 'b 2 ht) (print ht (current-buffer)))) ;; Read (with-current-buffer (find-file-noselect "/tmp/test") (let ((ht (read (current-buffer)))) (list (gethash 'a ht) (gethash 'b ht))))