aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChong Yidong2011-06-29 21:39:52 -0400
committerChong Yidong2011-06-29 21:39:52 -0400
commit658d8eb8fceb1d5f0f7a71c4f7145dd43b78081b (patch)
treefac3229b9f3f5ed01817341dfa23a295c0c0937d
parent732b9594ceab70733e55dba8dec85e7def3824b0 (diff)
downloademacs-658d8eb8fceb1d5f0f7a71c4f7145dd43b78081b.tar.gz
emacs-658d8eb8fceb1d5f0f7a71c4f7145dd43b78081b.zip
Avoid calling customize-save-variable during startup (Bug#8720).
* lisp/cus-edit.el (customize-push-and-save): New function. * lisp/files.el (hack-local-variables-confirm): Use it. * lisp/custom.el (load-theme): New arg NO-CONFIRM. Use customize-push-and-save (Bug#8720). (custom-enabled-themes): Doc fix. * lisp/cus-theme.el (customize-create-theme) (custom-theme-merge-theme): Callers to load-theme changed.
-rw-r--r--lisp/ChangeLog13
-rw-r--r--lisp/cus-edit.el23
-rw-r--r--lisp/cus-theme.el4
-rw-r--r--lisp/custom.el32
-rw-r--r--lisp/files.el11
5 files changed, 60 insertions, 23 deletions
diff --git a/lisp/ChangeLog b/lisp/ChangeLog
index 29ae3715531..7deafcaa647 100644
--- a/lisp/ChangeLog
+++ b/lisp/ChangeLog
@@ -1,3 +1,16 @@
12011-06-30 Chong Yidong <cyd@stupidchicken.com>
2
3 * cus-edit.el (customize-push-and-save): New function.
4
5 * files.el (hack-local-variables-confirm): Use it.
6
7 * custom.el (load-theme): New arg NO-CONFIRM. Use
8 customize-push-and-save (Bug#8720).
9 (custom-enabled-themes): Doc fix.
10
11 * cus-theme.el (customize-create-theme)
12 (custom-theme-merge-theme): Callers to load-theme changed.
13
12011-06-30 Lars Magne Ingebrigtsen <larsi@gnus.org> 142011-06-30 Lars Magne Ingebrigtsen <larsi@gnus.org>
2 15
3 * progmodes/grep.el (rgrep): Bind `process-connection-type' to 16 * progmodes/grep.el (rgrep): Bind `process-connection-type' to
diff --git a/lisp/cus-edit.el b/lisp/cus-edit.el
index 7c96b526f41..693b36040ea 100644
--- a/lisp/cus-edit.el
+++ b/lisp/cus-edit.el
@@ -1036,6 +1036,29 @@ If given a prefix (or a COMMENT argument), also prompt for a comment."
1036 (custom-save-all) 1036 (custom-save-all)
1037 value) 1037 value)
1038 1038
1039;; Some parts of Emacs might prompt the user to save customizations,
1040;; during startup before customizations are loaded. This function
1041;; handles this corner case by avoiding calling `custom-save-variable'
1042;; too early, which could wipe out existing customizations.
1043
1044;;;###autoload
1045(defun customize-push-and-save (list-var elts)
1046 "Add ELTS to LIST-VAR and save for future sessions, safely.
1047ELTS should be a list. This function adds each entry to the
1048value of LIST-VAR using `add-to-list'.
1049
1050If Emacs is initialized, call `customize-save-variable' to save
1051the resulting list value now. Otherwise, add an entry to
1052`after-init-hook' to save it after initialization."
1053 (dolist (entry elts)
1054 (add-to-list list-var entry))
1055 (if after-init-time
1056 (let ((coding-system-for-read nil))
1057 (customize-save-variable list-var (eval list-var)))
1058 (add-hook 'after-init-hook
1059 `(lambda ()
1060 (customize-push-and-save ',list-var ',elts)))))
1061
1039;;;###autoload 1062;;;###autoload
1040(defun customize () 1063(defun customize ()
1041 "Select a customization buffer which you can use to set user options. 1064 "Select a customization buffer which you can use to set user options.
diff --git a/lisp/cus-theme.el b/lisp/cus-theme.el
index 7f926c85e56..04a9e728b22 100644
--- a/lisp/cus-theme.el
+++ b/lisp/cus-theme.el
@@ -157,7 +157,7 @@ remove them from your saved Custom file.\n\n"))
157 ;; Load the theme settings. 157 ;; Load the theme settings.
158 (when theme 158 (when theme
159 (unless (eq theme 'user) 159 (unless (eq theme 'user)
160 (load-theme theme t)) 160 (load-theme theme nil t))
161 (dolist (setting (get theme 'theme-settings)) 161 (dolist (setting (get theme 'theme-settings))
162 (if (eq (car setting) 'theme-value) 162 (if (eq (car setting) 'theme-value)
163 (progn (push (nth 1 setting) vars) 163 (progn (push (nth 1 setting) vars)
@@ -326,7 +326,7 @@ SPEC, if non-nil, should be a face spec to which to set the widget."
326 (unless (eq theme 'user) 326 (unless (eq theme 'user)
327 (unless (custom-theme-name-valid-p theme) 327 (unless (custom-theme-name-valid-p theme)
328 (error "Invalid theme name `%s'" theme)) 328 (error "Invalid theme name `%s'" theme))
329 (load-theme theme t)) 329 (load-theme theme nil t))
330 (let ((settings (reverse (get theme 'theme-settings)))) 330 (let ((settings (reverse (get theme 'theme-settings))))
331 (dolist (setting settings) 331 (dolist (setting settings)
332 (funcall (if (eq (car setting) 'theme-value) 332 (funcall (if (eq (car setting) 'theme-value)
diff --git a/lisp/custom.el b/lisp/custom.el
index 8295777f1f1..2504b4f2cd9 100644
--- a/lisp/custom.el
+++ b/lisp/custom.el
@@ -1119,20 +1119,29 @@ Emacs theme directory (a directory named \"themes\" in
1119 :risky t 1119 :risky t
1120 :version "24.1") 1120 :version "24.1")
1121 1121
1122(defun load-theme (theme &optional no-enable) 1122(defun load-theme (theme &optional no-confirm no-enable)
1123 "Load Custom theme named THEME from its file. 1123 "Load Custom theme named THEME from its file.
1124Normally, this also enables THEME. If optional arg NO-ENABLE is
1125non-nil, load THEME but don't enable it.
1126
1127The theme file is named THEME-theme.el, in one of the directories 1124The theme file is named THEME-theme.el, in one of the directories
1128specified by `custom-theme-load-path'. 1125specified by `custom-theme-load-path'.
1129 1126
1127If THEME is not in `custom-safe-themes', prompt the user for
1128confirmation, unless optional arg NO-CONFIRM is non-nil.
1129
1130Normally, this function also enables THEME; if optional arg
1131NO-ENABLE is non-nil, load the theme but don't enable it.
1132
1133This function is normally called through Customize when setting
1134`custom-enabled-themes'. If used directly in your init file, it
1135should be called with a non-nil NO-CONFIRM argument, or after
1136`custom-safe-themes' has been loaded.
1137
1130Return t if THEME was successfully loaded, nil otherwise." 1138Return t if THEME was successfully loaded, nil otherwise."
1131 (interactive 1139 (interactive
1132 (list 1140 (list
1133 (intern (completing-read "Load custom theme: " 1141 (intern (completing-read "Load custom theme: "
1134 (mapcar 'symbol-name 1142 (mapcar 'symbol-name
1135 (custom-available-themes)))))) 1143 (custom-available-themes))))
1144 nil nil))
1136 (unless (custom-theme-name-valid-p theme) 1145 (unless (custom-theme-name-valid-p theme)
1137 (error "Invalid theme name `%s'" theme)) 1146 (error "Invalid theme name `%s'" theme))
1138 ;; If reloading, clear out the old theme settings. 1147 ;; If reloading, clear out the old theme settings.
@@ -1152,7 +1161,8 @@ Return t if THEME was successfully loaded, nil otherwise."
1152 (setq hash (sha1 (current-buffer))) 1161 (setq hash (sha1 (current-buffer)))
1153 ;; Check file safety with `custom-safe-themes', prompting the 1162 ;; Check file safety with `custom-safe-themes', prompting the
1154 ;; user if necessary. 1163 ;; user if necessary.
1155 (when (or (and (memq 'default custom-safe-themes) 1164 (when (or no-confirm
1165 (and (memq 'default custom-safe-themes)
1156 (equal (file-name-directory fn) 1166 (equal (file-name-directory fn)
1157 (expand-file-name "themes/" data-directory))) 1167 (expand-file-name "themes/" data-directory)))
1158 (member hash custom-safe-themes) 1168 (member hash custom-safe-themes)
@@ -1211,10 +1221,7 @@ query also about adding HASH to `custom-safe-themes'."
1211 ;; Offer to save to `custom-safe-themes'. 1221 ;; Offer to save to `custom-safe-themes'.
1212 (and (or custom-file user-init-file) 1222 (and (or custom-file user-init-file)
1213 (y-or-n-p "Treat this theme as safe in future sessions? ") 1223 (y-or-n-p "Treat this theme as safe in future sessions? ")
1214 (let ((coding-system-for-read nil)) 1224 (customize-push-and-save 'custom-safe-themes (list hash)))
1215 (push hash custom-safe-themes)
1216 (customize-save-variable 'custom-safe-themes
1217 custom-safe-themes)))
1218 t))))) 1225 t)))))
1219 1226
1220(defun custom-theme-name-valid-p (name) 1227(defun custom-theme-name-valid-p (name)
@@ -1291,7 +1298,10 @@ This list does not include the `user' theme, which is set by
1291Customize and always takes precedence over other Custom Themes. 1298Customize and always takes precedence over other Custom Themes.
1292 1299
1293This variable cannot be defined inside a Custom theme; there, it 1300This variable cannot be defined inside a Custom theme; there, it
1294is simply ignored." 1301is simply ignored.
1302
1303Setting this variable through Customize calls `enable-theme' or
1304`load-theme' for each theme in the list."
1295 :group 'customize 1305 :group 'customize
1296 :type '(repeat symbol) 1306 :type '(repeat symbol)
1297 :set-after '(custom-theme-directory custom-theme-load-path 1307 :set-after '(custom-theme-directory custom-theme-load-path
diff --git a/lisp/files.el b/lisp/files.el
index 895cbba0ede..c2c2eae9d05 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -2943,16 +2943,7 @@ n -- to ignore the local variables list.")
2943 (setq char nil))) 2943 (setq char nil)))
2944 (kill-buffer buf) 2944 (kill-buffer buf)
2945 (when (and offer-save (= char ?!) unsafe-vars) 2945 (when (and offer-save (= char ?!) unsafe-vars)
2946 (dolist (elt unsafe-vars) 2946 (customize-push-and-save 'safe-local-variable-values unsafe-vars))
2947 (add-to-list 'safe-local-variable-values elt))
2948 ;; When this is called from desktop-restore-file-buffer,
2949 ;; coding-system-for-read may be non-nil. Reset it before
2950 ;; writing to .emacs.
2951 (if (or custom-file user-init-file)
2952 (let ((coding-system-for-read nil))
2953 (customize-save-variable
2954 'safe-local-variable-values
2955 safe-local-variable-values))))
2956 (memq char '(?! ?\s ?y)))))) 2947 (memq char '(?! ?\s ?y))))))
2957 2948
2958(defun hack-local-variables-prop-line (&optional mode-only) 2949(defun hack-local-variables-prop-line (&optional mode-only)