all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Chong Yidong <cyd@stupidchicken.com>
To: David Engster <deng@randomsample.de>
Cc: 8720@debbugs.gnu.org
Subject: bug#8720: 24.0.50; load-theme in .emacs makes it easy to inadvertently delete custom-set variables
Date: Sat, 04 Jun 2011 19:59:25 -0400	[thread overview]
Message-ID: <87hb855esi.fsf@stupidchicken.com> (raw)
In-Reply-To: <87vcx1tciy.fsf@engster.org> (David Engster's message of "Mon, 23 May 2011 21:58:13 +0200")

David Engster <deng@randomsample.de> writes:

> the existing customization for user-mail-address was deleted; in fact,
> every existing entry there will be deleted.  I know this can be fixed
> by putting the `load-theme' at the end of the .emacs file, but this
> isn't mentioned in the doc-string and I'd still consider this at least
> as unexpected behavior.

This is certainly a problem, but I don't know a good fix.

It's not limited to themes; another way to trigger it is to add a line
(find-file "foo") in your init file, where "foo" contains an unsafe
local variable; then tell Emacs to mark the variable as safe for future
visits.  The customizations in your init file are similarly wiped out.

One possibility is to do something like the following patch.  If Emacs
needs to save a variable in a function that could be called during
startup, it calls a new function customize-save-list-variable-safely
instead of customize-save-variables.  That function records the stuff to
be saved into a list, which is acted on after initialization.


=== modified file 'lisp/cus-edit.el'
*** lisp/cus-edit.el	2011-04-19 13:44:55 +0000
--- lisp/cus-edit.el	2011-06-04 23:50:48 +0000
***************
*** 1037,1042 ****
--- 1037,1059 ----
    value)
  
  ;;;###autoload
+ (defun customize-save-list-variable-safely (list-var entries)
+   "Add ENTRIES to LIST-VAR, saving the customization safely.
+ Each element in ENTRIES is added to LIST-VAR using `add-to-list'.
+ If Emacs is already initialized, call `customize-save-variable'
+ to save the resulting list value.
+ Otherwise, record args into `custom-save-after-load-list-vars',
+ so that this function is called again after initialization."
+   (dolist (elt entries)
+     (add-to-list list-var elt))
+   (cond
+    ((null after-init-time)
+     (push (list list-var entries) custom-save-after-load-list-vars))
+    ((or custom-file user-init-file)
+     (let ((coding-system-for-read nil))
+       (customize-save-variable list-var (eval list-var))))))
+ 
+ ;;;###autoload
  (defun customize ()
    "Select a customization buffer which you can use to set user options.
  User options are structured into \"groups\".

=== modified file 'lisp/files.el'
*** lisp/files.el	2011-05-28 19:26:25 +0000
--- lisp/files.el	2011-06-04 23:43:46 +0000
***************
*** 3031,3046 ****
  	    (setq char nil)))
  	(kill-buffer buf)
  	(when (and offer-save (= char ?!) unsafe-vars)
! 	  (dolist (elt unsafe-vars)
! 	    (add-to-list 'safe-local-variable-values elt))
! 	  ;; When this is called from desktop-restore-file-buffer,
! 	  ;; coding-system-for-read may be non-nil.  Reset it before
! 	  ;; writing to .emacs.
! 	  (if (or custom-file user-init-file)
! 	      (let ((coding-system-for-read nil))
! 		(customize-save-variable
! 		 'safe-local-variable-values
! 		 safe-local-variable-values))))
  	(memq char '(?! ?\s ?y))))))
  
  (defun hack-local-variables-prop-line (&optional mode-only)
--- 3031,3038 ----
  	    (setq char nil)))
  	(kill-buffer buf)
  	(when (and offer-save (= char ?!) unsafe-vars)
! 	  (customize-save-list-variable-safely 'safe-local-variable-values
! 					       unsafe-vars))
  	(memq char '(?! ?\s ?y))))))
  
  (defun hack-local-variables-prop-line (&optional mode-only)

=== modified file 'lisp/startup.el'
*** lisp/startup.el	2011-05-28 23:30:17 +0000
--- lisp/startup.el	2011-06-04 23:51:44 +0000
***************
*** 305,310 ****
--- 305,315 ----
  Setting `init-file-user' does not prevent Emacs from loading
  `site-start.el'.  The only way to do that is to use `--no-site-file'.")
  
+ (defvar custom-save-after-load-list-vars nil
+   "List of delayed customization save data.
+ After initialization, call `customize-save-list-variable-safely'
+ with each element as the list of arguments.")
+ 
  (defcustom site-run-file (purecopy "site-start")
    "File containing site-wide run-time initializations.
  This file is loaded at run-time before `~/.emacs'.  It contains inits
***************
*** 1212,1217 ****
--- 1217,1224 ----
         (package-initialize))
  
    (setq after-init-time (current-time))
+   (dolist (args custom-save-after-load-list-vars)
+     (apply 'customize-save-list-variable-safely args))
    (run-hooks 'after-init-hook)
  
    ;; Decode all default-directory.

=== modified file 'lisp/custom.el'
*** lisp/custom.el	2011-04-25 16:52:51 +0000
--- lisp/custom.el	2011-06-04 23:56:08 +0000
***************
*** 1211,1220 ****
  	  ;; Offer to save to `custom-safe-themes'.
  	  (and (or custom-file user-init-file)
  	       (y-or-n-p "Treat this theme as safe in future sessions? ")
! 	       (let ((coding-system-for-read nil))
! 		 (push hash custom-safe-themes)
! 		 (customize-save-variable 'custom-safe-themes
! 					  custom-safe-themes)))
  	  t)))))
  
  (defun custom-theme-name-valid-p (name)
--- 1211,1218 ----
  	  ;; Offer to save to `custom-safe-themes'.
  	  (and (or custom-file user-init-file)
  	       (y-or-n-p "Treat this theme as safe in future sessions? ")
! 	       (customize-save-list-variable-safely 'custom-safe-themes
! 						    (list hash)))
  	  t)))))
  
  (defun custom-theme-name-valid-p (name)






  reply	other threads:[~2011-06-04 23:59 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-23 19:58 bug#8720: 24.0.50; load-theme in .emacs makes it easy to inadvertently delete custom-set variables David Engster
2011-06-04 23:59 ` Chong Yidong [this message]
2011-06-05  8:41   ` David Engster
2011-06-28  4:34     ` Chong Yidong
2011-06-06 17:13   ` 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=87hb855esi.fsf@stupidchicken.com \
    --to=cyd@stupidchicken.com \
    --cc=8720@debbugs.gnu.org \
    --cc=deng@randomsample.de \
    /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.