all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Stefan Monnier <monnier@IRO.UMontreal.CA>
To: Jan Tatarik <jan.tatarik@gmail.com>
Cc: 20972@debbugs.gnu.org
Subject: bug#20972: 25.0.50; eieio-persistent broken
Date: Sat, 04 Jul 2015 15:16:36 -0400	[thread overview]
Message-ID: <jwvtwtjn39f.fsf-monnier+emacsbugs@gnu.org> (raw)
In-Reply-To: <874mlltqyp.fsf@xing.com> (Jan Tatarik's message of "Fri, 03 Jul 2015 13:34:22 +0200")

> ;; In theory, calling it like this should override the :file slot
> ;; defined in eieio-persistent
> (eieio-persistent-save (test-persist :slot "foo") "/tmp/test.eieio")

Indeed, the code seems completely broken in this respect (it mostly
ignores the `file' argument, tho not completely).

I'm not 100% sure what the code *should* do, but can you try the patch
below for you use case and confirm that it does the right thing for you?


        Stefan


diff --git a/lisp/emacs-lisp/eieio-base.el b/lisp/emacs-lisp/eieio-base.el
index 2e28036..400bdb9 100644
--- a/lisp/emacs-lisp/eieio-base.el
+++ b/lisp/emacs-lisp/eieio-base.el
@@ -429,37 +429,28 @@ Optional argument COMMENT is a header line comment."
   "Save persistent object THIS to disk.
 Optional argument FILE overrides the file name specified in the object
 instance."
-  (save-excursion
-    (let ((b (set-buffer (get-buffer-create " *tmp object write*")))
-	  (default-directory (file-name-directory (oref this file)))
-	  (cfn (oref this file)))
-      (unwind-protect
-	  (save-excursion
-	    (erase-buffer)
-	    (let ((standard-output (current-buffer)))
-	      (oset this file
-		    (if file
-			(eieio-persistent-path-relative this file)
-		      (file-name-nondirectory cfn)))
-	      (object-write this (oref this file-header-line)))
-	    (let ((backup-inhibited (not (oref this do-backups)))
-		  (cs (car (find-coding-systems-region
-			    (point-min) (point-max)))))
-	      (unless (eq cs 'undecided)
-		(setq buffer-file-coding-system cs))
-	      ;; Old way - write file.  Leaves message behind.
-	      ;;(write-file cfn nil)
-
-	      ;; New way - Avoid the vast quantities of error checking
-	      ;; just so I can get at the special flags that disable
-	      ;; displaying random messages.
-	      (write-region (point-min) (point-max)
-			    cfn nil 1)
-	      ))
-	;; Restore :file, and kill the tmp buffer
-	(oset this file cfn)
-	(setq buffer-file-name nil)
-	(kill-buffer b)))))
+  (when file (setq file (expand-file-name file)))
+  (with-temp-buffer
+    (let* ((cfn (or file (oref this file)))
+           (default-directory (file-name-directory cfn)))
+      (cl-letf ((standard-output (current-buffer))
+                ((oref this file)       ;FIXME: Why change it?
+                 (if file
+                     ;; FIXME: Makes a name relative to (oref this file),
+                     ;; whereas I think it should be relative to cfn.
+                     (eieio-persistent-path-relative this file)
+                   (file-name-nondirectory cfn))))
+        (object-write this (oref this file-header-line)))
+      (let ((backup-inhibited (not (oref this do-backups)))
+            (coding-system-for-write 'utf-8-emacs))
+        ;; Old way - write file.  Leaves message behind.
+        ;;(write-file cfn nil)
+
+        ;; New way - Avoid the vast quantities of error checking
+        ;; just so I can get at the special flags that disable
+        ;; displaying random messages.
+        (write-region (point-min) (point-max) cfn nil 1)
+        ))))
 
 ;; Notes on the persistent object:
 ;; It should also set up some hooks to help it keep itself up to date.





  parent reply	other threads:[~2015-07-04 19:16 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-03 11:34 bug#20972: 25.0.50; eieio-persistent broken Jan Tatarik
2015-07-03 15:28 ` Stefan Monnier
2015-07-04 19:16 ` Stefan Monnier [this message]
     [not found]   ` <87wpyd7lfz.fsf@xing.com>
2015-07-06 15:56     ` Stefan Monnier

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=jwvtwtjn39f.fsf-monnier+emacsbugs@gnu.org \
    --to=monnier@iro.umontreal.ca \
    --cc=20972@debbugs.gnu.org \
    --cc=jan.tatarik@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.