From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chong Yidong Newsgroups: gmane.emacs.bugs 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 Message-ID: <87hb855esi.fsf@stupidchicken.com> References: <87vcx1tciy.fsf@engster.org> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1307232026 10136 80.91.229.12 (5 Jun 2011 00:00:26 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 5 Jun 2011 00:00:26 +0000 (UTC) Cc: 8720@debbugs.gnu.org To: David Engster Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Jun 05 02:00:22 2011 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QT0lR-0008Mv-3J for geb-bug-gnu-emacs@m.gmane.org; Sun, 05 Jun 2011 02:00:21 +0200 Original-Received: from localhost ([::1]:52772 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QT0lQ-0001CL-52 for geb-bug-gnu-emacs@m.gmane.org; Sat, 04 Jun 2011 20:00:20 -0400 Original-Received: from eggs.gnu.org ([140.186.70.92]:35900) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QT0lB-0001C7-VH for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2011 20:00:06 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QT0lA-0000C1-HQ for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2011 20:00:05 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:44645) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QT0lA-0000Bw-ET for bug-gnu-emacs@gnu.org; Sat, 04 Jun 2011 20:00:04 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.69) (envelope-from ) id 1QT0l9-0003ql-7h; Sat, 04 Jun 2011 20:00:03 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Chong Yidong Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-To: owner@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 05 Jun 2011 00:00:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 8720 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 8720-submit@debbugs.gnu.org id=B8720.130723197514746 (code B ref 8720); Sun, 05 Jun 2011 00:00:03 +0000 Original-Received: (at 8720) by debbugs.gnu.org; 4 Jun 2011 23:59:35 +0000 Original-Received: from localhost ([127.0.0.1] helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QT0kh-0003pn-AG for submit@debbugs.gnu.org; Sat, 04 Jun 2011 19:59:35 -0400 Original-Received: from vm-emlprdomr-06.its.yale.edu ([130.132.50.147]) by debbugs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1QT0kf-0003pa-5D for 8720@debbugs.gnu.org; Sat, 04 Jun 2011 19:59:33 -0400 Original-Received: from furball ([64.134.101.122]) (authenticated bits=0) by vm-emlprdomr-06.its.yale.edu (8.14.4/8.14.4) with ESMTP id p54NxQcr021496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 4 Jun 2011 19:59:27 -0400 Original-Received: by furball (Postfix, from userid 1000) id 1DFCC16051D; Sat, 4 Jun 2011 19:59:26 -0400 (EDT) In-Reply-To: <87vcx1tciy.fsf@engster.org> (David Engster's message of "Mon, 23 May 2011 21:58:13 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Scanned-By: MIMEDefang 2.71 on 130.132.50.147 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.11 Precedence: list Resent-Date: Sat, 04 Jun 2011 20:00:03 -0400 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:46963 Archived-At: David Engster 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)