From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Artur Malabarba Newsgroups: gmane.emacs.devel Subject: Re: Calling (package-initialize) sooner during initialization Date: Tue, 31 Mar 2015 11:52:34 +0100 Message-ID: References: Reply-To: bruce.connor.am@gmail.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: ger.gmane.org 1427799176 21624 80.91.229.3 (31 Mar 2015 10:52:56 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 31 Mar 2015 10:52:56 +0000 (UTC) Cc: emacs-devel To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Tue Mar 31 12:52:56 2015 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Yctmw-0007CY-CP for ged-emacs-devel@m.gmane.org; Tue, 31 Mar 2015 12:52:54 +0200 Original-Received: from localhost ([::1]:37972 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yctmv-0004cc-UZ for ged-emacs-devel@m.gmane.org; Tue, 31 Mar 2015 06:52:53 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56740) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yctme-0004an-V1 for emacs-devel@gnu.org; Tue, 31 Mar 2015 06:52:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Yctmd-0005jv-OR for emacs-devel@gnu.org; Tue, 31 Mar 2015 06:52:36 -0400 Original-Received: from mail-la0-x235.google.com ([2a00:1450:4010:c03::235]:35043) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Yctmd-0005jq-F8 for emacs-devel@gnu.org; Tue, 31 Mar 2015 06:52:35 -0400 Original-Received: by lahf3 with SMTP id f3so9088394lah.2 for ; Tue, 31 Mar 2015 03:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:sender:in-reply-to:references:date:message-id :subject:from:to:cc:content-type; bh=Zcw5Rod+SziNfm7nDazbjPJC+8wnVR3PYxFdGrFLMrw=; b=cOZw3GaTqW7rBUIk2F/vqssr+P/O4Qoga3+MHNYa5zKiW0RPlNjtH864ID1xhdQ8iD 7Cz5/aNm5Q2eiATZyA+4xgrqrz9uNr4POwtsOjO7xluel1qb38d6Q6ehM+yVQzpNtNfv OyLLYdwbpDWv8gCo64w5OzUYqww3PxREv98pNOLBQsQRp8h4zYMmeuF9Px9QJjlGFHHC EkJ6bEkUzqgEsltEProY+Zg+9Movk6F6fQo5x+O3z0NDEQo/sMRrgPauYJm6IC5gBs1s LEuZgLXjXFD0oS8LR+DFLBsgCIw1mvkqBLYLeaGRzrF5SYizhdEwzN7e8rjP1CfhKecD yyVQ== X-Received: by 10.152.163.35 with SMTP id yf3mr3963295lab.86.1427799154628; Tue, 31 Mar 2015 03:52:34 -0700 (PDT) Original-Received: by 10.112.207.225 with HTTP; Tue, 31 Mar 2015 03:52:34 -0700 (PDT) In-Reply-To: X-Google-Sender-Auth: t8Ulxn4q2CnKMpkDbthd3b6ktpQ X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:4010:c03::235 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:184601 Archived-At: Something like this? diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 526c0b4..cf92557 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1628,6 +1628,28 @@ PACKAGES are satisfied, i.e. that PACKAGES is computed using `package-compute-transaction'." (mapc #'package-install-from-archive packages)) +(defun package--ensure-init-file () + "Ensure that the user's init file calls `package-initialize'." + (let ((buffer (find-buffer-visiting user-init-file))) + (with-current-buffer (or buffer (find-file-noselect user-init-file)) + (save-excursion + (save-restriction + (widen) + (goto-char (point-min)) + (unless (search-forward "(package-initialize)" nil 'noerror) + (goto-char (point-min)) + (insert + ";; Added by Package.el. This must come before configurations of\n" + ";; installed packages. Don't delete this line. If you don't want it,\n" + ";; just comment it out by adding a semicolon to the start of the line.\n" + "(package-initialize)\n") + (unless (looking-at-p "$") + (insert "\n")) + (let ((file-precious-flag t)) + (save-buffer))) + (unless buffer + (kill-buffer (current-buffer)))))))) + ;;;###autoload (defun package-install (pkg &optional dont-select) "Install the package PKG. @@ -1656,6 +1678,7 @@ to install it but still mark it as selected." package-archive-contents)) nil t)) nil))) + (package--ensure-init-file) (let ((name (if (package-desc-p pkg) (package-desc-name pkg) pkg))) @@ -1699,6 +1722,7 @@ is derived from the main .el file in the directory. Downloads and installs required packages as needed." (interactive) + (package--ensure-init-file) (let* ((pkg-desc (cond ((derived-mode-p 'dired-mode)