;; available on disk.
(defvar package--initialized nil)
+(defvar package--init-file-ensured nil
+ "Whether we know the init file has package-initialize.")
+
;;;###autoload
(defun package-initialize (&optional no-activate)
"Load Emacs Lisp packages, and activate them.
it to the file."
(interactive)
(setq package-alist nil)
- (package--ensure-init-file)
+ (if (equal user-init-file load-file-name)
+ ;; If `package-initialize' is being called as part of loading
+ ;; the init file, it's obvious we don't need to ensure-init.
+ (setq package--init-file-ensured t)
+ (package--ensure-init-file))
(package-load-all-descriptors)
(package-read-all-archive-contents)
(unless no-activate
add a call to it along with some explanatory comments."
;; Don't mess with the init-file from "emacs -Q".
(when (and (stringp user-init-file)
+ (not package--init-file-ensured)
(file-readable-p user-init-file)
(file-writable-p user-init-file))
(let* ((buffer (find-buffer-visiting user-init-file))
(let ((file-precious-flag t))
(save-buffer))
(unless buffer
- (kill-buffer (current-buffer))))))))))
+ (kill-buffer (current-buffer)))))))))
+ (setq package--init-file-ensured t))
;;;###autoload
(defun package-install (pkg &optional dont-select async callback)