all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Teemu Likonen <tlikonen@iki.fi>
To: ishi soichi <soichi777@gmail.com>
Cc: help-gnu-emacs@gnu.org
Subject: Re: loading hash-table from a file?
Date: Thu, 05 Jan 2012 11:24:14 +0200	[thread overview]
Message-ID: <87ipkqo62p.fsf@imladris.arda> (raw)
In-Reply-To: <CAEjRLuSVMqrjXLX5nHwR08Hp3pmkTC-WsJnx5tj35bXAbQzMEQ@mail.gmail.com> (ishi soichi's message of "Thu, 5 Jan 2012 14:16:41 +0900")

* 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))))



      parent reply	other threads:[~2012-01-05  9:24 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-05  5:16 loading hash-table from a file? ishi soichi
2012-01-05  8:35 ` Valentin Baciu
2012-01-05  9:11   ` Teemu Likonen
2012-01-05  9:13     ` ishi soichi
2012-01-05  9:07 ` Eric Abrahamsen
2012-01-06 16:43   ` Thierry Volpiatto
2012-01-07  2:16     ` Eric Abrahamsen
2012-01-05  9:24 ` Teemu Likonen [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ipkqo62p.fsf@imladris.arda \
    --to=tlikonen@iki.fi \
    --cc=help-gnu-emacs@gnu.org \
    --cc=soichi777@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.