Function: eieio-persistent-read

eieio-persistent-read is a byte-compiled function defined in eieio-base.el.gz.

Signature

(eieio-persistent-read FILENAME &optional CLASS ALLOW-SUBCLASS)

Documentation

Read a persistent object from FILENAME, and return it.

Signal an error if the object in FILENAME is not a constructor for CLASS. Optional ALLOW-SUBCLASS says that it is ok for eieio-persistent-read to load in subclasses of class instead of being pedantic.

Probably introduced at or before Emacs version 24.3.

Source Code

;; Defined in /usr/src/emacs/lisp/emacs-lisp/eieio-base.el.gz
(defun eieio-persistent-read (filename &optional class allow-subclass)
  "Read a persistent object from FILENAME, and return it.
Signal an error if the object in FILENAME is not a constructor
for CLASS.  Optional ALLOW-SUBCLASS says that it is ok for
`eieio-persistent-read' to load in subclasses of class instead of
being pedantic."
  (unless class
    (warn "`eieio-persistent-read' called without specifying a class"))
  (when class (cl-check-type class class))
  (let ((ret nil)
	(buffstr nil))
    (unwind-protect
	(progn
	  (with-current-buffer (get-buffer-create " *tmp eieio read*")
	    (insert-file-contents filename nil nil nil t)
	    (goto-char (point-min))
	    (setq buffstr (buffer-string)))
	  ;; Do the read in the buffer the read was initialized from
	  ;; so that any initialize-instance calls that depend on
	  ;; the current buffer will work.
	  (setq ret (read buffstr))
	  (when (not (child-of-class-p (car ret) 'eieio-persistent))
	    (error
             "Invalid object: %s is not a subclass of `eieio-persistent'"
             (car ret)))
	  (when (and class
		     (not (or (eq (car ret) class) ; same class
			      (and allow-subclass  ; subclass
				   (child-of-class-p (car ret) class)))))
	    (error
             "Invalid object: %s is not an object of class %s nor a subclass"
             (car ret) class))
          (setq ret (eieio-persistent-make-instance (car ret) (cdr ret)))
	  (oset ret file filename))
      (kill-buffer " *tmp eieio read*"))
    ret))