aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Kangas2022-07-31 12:01:01 +0200
committerStefan Kangas2022-07-31 12:04:17 +0200
commitca2d3ed74c63167c7d8378482016efea9756dd17 (patch)
tree1754fd06858a05a4936bdc13c756354a6f130a13
parentef5abcd4cc61791fe6d19d187e03f4e3ba33891f (diff)
downloademacs-ca2d3ed74c63167c7d8378482016efea9756dd17.tar.gz
emacs-ca2d3ed74c63167c7d8378482016efea9756dd17.zip
* lisp/emacs-lisp/eieio-base.el (eieio-persistent-read): Simplify.
-rw-r--r--lisp/emacs-lisp/eieio-base.el46
1 files changed, 20 insertions, 26 deletions
diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 4c702deaa95..ef02216411d 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -281,32 +281,26 @@ being pedantic."
281 (unless class 281 (unless class
282 (warn "`eieio-persistent-read' called without specifying a class")) 282 (warn "`eieio-persistent-read' called without specifying a class"))
283 (when class (cl-check-type class class)) 283 (when class (cl-check-type class class))
284 (let ((ret nil) 284 (let* ((buffstr (with-temp-buffer
285 (buffstr nil)) 285 (insert-file-contents filename)
286 (unwind-protect 286 (buffer-string)))
287 (progn 287 ;; Do the read in the buffer the read was initialized from
288 (with-current-buffer (get-buffer-create " *tmp eieio read*") 288 ;; so that any initialize-instance calls that depend on
289 (insert-file-contents filename nil nil nil t) 289 ;; the current buffer will work.
290 (goto-char (point-min)) 290 (ret (read buffstr)))
291 (setq buffstr (buffer-string))) 291 (when (not (child-of-class-p (car ret) 'eieio-persistent))
292 ;; Do the read in the buffer the read was initialized from 292 (error
293 ;; so that any initialize-instance calls that depend on 293 "Invalid object: %s is not a subclass of `eieio-persistent'"
294 ;; the current buffer will work. 294 (car ret)))
295 (setq ret (read buffstr)) 295 (when (and class
296 (when (not (child-of-class-p (car ret) 'eieio-persistent)) 296 (not (or (eq (car ret) class) ; same class
297 (error 297 (and allow-subclass ; subclass
298 "Invalid object: %s is not a subclass of `eieio-persistent'" 298 (child-of-class-p (car ret) class)))))
299 (car ret))) 299 (error
300 (when (and class 300 "Invalid object: %s is not an object of class %s nor a subclass"
301 (not (or (eq (car ret) class) ; same class 301 (car ret) class))
302 (and allow-subclass ; subclass 302 (setq ret (eieio-persistent-make-instance (car ret) (cdr ret)))
303 (child-of-class-p (car ret) class))))) 303 (oset ret file filename)
304 (error
305 "Invalid object: %s is not an object of class %s nor a subclass"
306 (car ret) class))
307 (setq ret (eieio-persistent-make-instance (car ret) (cdr ret)))
308 (oset ret file filename))
309 (kill-buffer " *tmp eieio read*"))
310 ret)) 304 ret))
311 305
312(cl-defgeneric eieio-persistent-make-instance (objclass inputlist) 306(cl-defgeneric eieio-persistent-make-instance (objclass inputlist)