[PATCH] fix corruption of ~/.emacs when trying to migrate an init file XEmacs can't fully load

Jason Spiro jasonspiro4 at gmail.com
Wed Oct 3 10:07:39 EDT 2007


Hi all,

This is a patch for a preference-corruption issue.  XEmacs (I use
xemacs-21.5.27) corrupts the ~/.emacs file when you follow the steps below.  It
has happened to me both on Ubuntu Linux and on FreeBSD.  The poor guy posting at
https://stat.ethz.ch/pipermail/ess-help/2005-September/002851.html
also experienced it.

== Steps to reproduce ==

* Make a new user on your *nix PC
* Log on as that user
* Make a ~/.emacs file
* Use GNU Emacs's custom.el tool, or use vi, to customize one or more variables
* Add something to the top of the ~/.emacs file (somewhere above the
custom-set-variables statement) that xemacs can't understand, such as
the lone word:
   foobarbazquux
* As that user, start xemacs for the first time
* At the "Migrate init file to ~/.xemacs/? (yes or no)" prompt, enter "no"

== What happened ==

Now XEmacs will clobber the custom-set-variables and custom-set-fonts clauses in
your ~/.emacs file.  It replaces them with:

(custom-set-variables
 '(load-home-init-file t t))
(custom-set-faces)

== What should have happened ==

XEmacs should not have tried to modify the ~/.emacs file.  It should
have known that if it tried to save a new custom-set-variables clause
that the clause might have been missing all the preset variables.

== My proposed fix ==

See patch below.  To make the patch, I copied two lines from
http://cvs.savannah.gnu.org/viewvc/emacs/emacs/lisp/cus-edit.el?revision=1.321&view=markup
into the xemacs21-devel-mule port's unpacked source.  Then I modified it to
check even more aggressively: it refuses to try to save a user's customizations
any time the init file didn't fully load, even if the custom file is a different
file than the init file.  This is because it seems that the variable custom-file
was set (to /home/j/.emacs) on my PC and I am worried it may be set
elsewhere too.

I tested the patch by deleting my cus-edit.elc and pasting in the new
cus-edit.el in my xemacs lisp directory.  It works fine.

I sent the patch to the FreeBSD folk (at
http://www.freebsd.org/cgi/query-pr.cgi?pr=114031 you can see my bug
report) and they merged the patch into their own XEmacs distribution.
But they did not send the patch to you folks.  So, I am sending it to
you now.

The patch is below.

Cheers,
Jason

--- xemacs-21.5.27/lisp/cus-edit.el.orig        Tue Jun 26 04:10:18 2007
+++ xemacs-21.5.27/lisp/cus-edit.el     Tue Jun 26 04:14:52 2007
@@ -3756,6 +3756,8 @@
 ;;;###autoload
 (defun custom-save-all ()
  "Save all customizations in `custom-file'."
+  (when init-file-had-error
+    (error "Cannot save customizations; init file was not fully loaded"))
  (let ((inhibit-read-only t))
    (custom-save-variables)
    (custom-save-faces)



More information about the XEmacs-Beta mailing list