[Top][All Lists]

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

Re: How to save custom variable programmatically?

From: Michael Heerdegen
Subject: Re: How to save custom variable programmatically?
Date: Tue, 10 Nov 2020 22:15:58 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux)

Jean Louis <> writes:

> Thank you. If you have ready simplest example it may be useful for
> review.

Simplest?  Ok, that might be possible.  Let's make a wrapper holding a
single value that is savable:

#+begin_src emacs-lisp
  (defclass my-persistent (eieio-persistent)
    ((data :initarg :data)))

  (defun my-save-in-location (thing file)
    (let ((obj (my-persistent :data thing)))
      (setf (oref obj file) file)
      (eieio-persistent-save obj)))

  ;; save a value to a file:
  (my-save-in-location (list 'x [] "Hello")
                       (expand-file-name "~/test"))

  ;; get it back:
  (oref (eieio-persistent-read
         (expand-file-name "~/test")
  ;; ==> (x [] "Hello")

This is not only a nice abstraction.  eieio-persistent has some
(programmable) knowledge about how to print and "restore" objects where
a normal print+read cycle would not work.


reply via email to

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