Idiomatic way serialization in emacs lisp

Viewed 799

Currently I am working on a elisp major mode that makes uses of hashtables across sessions. So every time the major mode is initialized, the tables are loaded into memory. During and at the end of the session they are written to a file. My current implementation writes the data in the following way:

(with-temp-buffer
  (prin1 hash-table (current-buffer))
  (write-file ("path/to/file.el"))))

Loading the data at the beginning of the session is done via read and is something like this:

(setq name-of-table (car
        (read-from-string
         (with-temp-buffer
           (insert-file-contents path-of-file)
           (buffer-substring-no-properties
        (point-min)
        (point-max))))))))

It works but I have the feeling that this is not the most beautiful way to do it. My aim is: I want this major mode to turn into a nice clean package that stores it's own data in the folder where the other data of the package is stored.

3 Answers
Related