diff options
| author | Artur Malabarba | 2015-04-07 18:59:40 +0100 |
|---|---|---|
| committer | Artur Malabarba | 2015-04-08 19:18:30 +0100 |
| commit | 0465c9dd42a969aec375e6828ea70c3ad4c72c1c (patch) | |
| tree | 5d51ac167d2bd14aba4947ab748873849e919974 | |
| parent | bf87b4d5a83cff934b469a95c14d782f68ea963a (diff) | |
| download | emacs-0465c9dd42a969aec375e6828ea70c3ad4c72c1c.tar.gz emacs-0465c9dd42a969aec375e6828ea70c3ad4c72c1c.zip | |
* lisp/emacs-lisp/package.el: More conservative `ensure-init-file'
(package--ensure-init-file): Check file contents before visiting.
(package-initialize): Call it.
(package-install-from-buffer, package-install): Don't call it.
| -rw-r--r-- | lisp/emacs-lisp/package.el | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 3188da5f439..10003c42085 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -1315,9 +1315,12 @@ If successful, set `package-archive-contents'." | |||
| 1315 | (defun package-initialize (&optional no-activate) | 1315 | (defun package-initialize (&optional no-activate) |
| 1316 | "Load Emacs Lisp packages, and activate them. | 1316 | "Load Emacs Lisp packages, and activate them. |
| 1317 | The variable `package-load-list' controls which packages to load. | 1317 | The variable `package-load-list' controls which packages to load. |
| 1318 | If optional arg NO-ACTIVATE is non-nil, don't activate packages." | 1318 | If optional arg NO-ACTIVATE is non-nil, don't activate packages. |
| 1319 | If `user-init-file' does not mention `(package-initialize)', add | ||
| 1320 | it to the file." | ||
| 1319 | (interactive) | 1321 | (interactive) |
| 1320 | (setq package-alist nil) | 1322 | (setq package-alist nil) |
| 1323 | (package--ensure-init-file) | ||
| 1321 | (package-load-all-descriptors) | 1324 | (package-load-all-descriptors) |
| 1322 | (package-read-all-archive-contents) | 1325 | (package-read-all-archive-contents) |
| 1323 | (unless no-activate | 1326 | (unless no-activate |
| @@ -1752,25 +1755,33 @@ using `package-compute-transaction'." | |||
| 1752 | "Ensure that the user's init file calls `package-initialize'." | 1755 | "Ensure that the user's init file calls `package-initialize'." |
| 1753 | ;; Don't mess with the init-file from "emacs -Q". | 1756 | ;; Don't mess with the init-file from "emacs -Q". |
| 1754 | (when user-init-file | 1757 | (when user-init-file |
| 1755 | (let ((buffer (find-buffer-visiting user-init-file))) | 1758 | (let* ((buffer (find-buffer-visiting user-init-file)) |
| 1756 | (with-current-buffer (or buffer (find-file-noselect user-init-file)) | 1759 | (contains-init |
| 1757 | (save-excursion | 1760 | (if buffer |
| 1758 | (save-restriction | 1761 | (with-current-buffer buffer |
| 1759 | (widen) | 1762 | (search-forward "(package-initialize)" nil 'noerror)) |
| 1760 | (goto-char (point-min)) | 1763 | (with-temp-buffer |
| 1761 | (unless (search-forward "(package-initialize)" nil 'noerror) | 1764 | (insert-file-contents user-init-file) |
| 1765 | (goto-char (point-min)) | ||
| 1766 | (search-forward "(package-initialize)" nil 'noerror))))) | ||
| 1767 | (unless contains-init | ||
| 1768 | (with-current-buffer (or buffer (find-file-noselect user-init-file)) | ||
| 1769 | (save-excursion | ||
| 1770 | (save-restriction | ||
| 1771 | (widen) | ||
| 1762 | (goto-char (point-min)) | 1772 | (goto-char (point-min)) |
| 1763 | (insert | 1773 | (insert |
| 1764 | ";; Added by Package.el. This must come before configurations of\n" | 1774 | ";; Added by Package.el. This must come before configurations of\n" |
| 1765 | ";; installed packages. Don't delete this line. If you don't want it,\n" | 1775 | ";; installed packages. Don't delete this line. If you don't want it,\n" |
| 1766 | ";; just comment it out by adding a semicolon to the start of the line.\n" | 1776 | ";; just comment it out by adding a semicolon to the start of the line.\n" |
| 1777 | ";; You may delete these explanatory comments.\n" | ||
| 1767 | "(package-initialize)\n") | 1778 | "(package-initialize)\n") |
| 1768 | (unless (looking-at-p "$") | 1779 | (unless (looking-at-p "$") |
| 1769 | (insert "\n")) | 1780 | (insert "\n")) |
| 1770 | (let ((file-precious-flag t)) | 1781 | (let ((file-precious-flag t)) |
| 1771 | (save-buffer))) | 1782 | (save-buffer)) |
| 1772 | (unless buffer | 1783 | (unless buffer |
| 1773 | (kill-buffer (current-buffer))))))))) | 1784 | (kill-buffer (current-buffer)))))))))) |
| 1774 | 1785 | ||
| 1775 | ;;;###autoload | 1786 | ;;;###autoload |
| 1776 | (defun package-install (pkg &optional dont-select async callback) | 1787 | (defun package-install (pkg &optional dont-select async callback) |
| @@ -1803,7 +1814,6 @@ to install it but still mark it as selected." | |||
| 1803 | package-archive-contents)) | 1814 | package-archive-contents)) |
| 1804 | nil t)) | 1815 | nil t)) |
| 1805 | nil))) | 1816 | nil))) |
| 1806 | (package--ensure-init-file) | ||
| 1807 | (let ((name (if (package-desc-p pkg) | 1817 | (let ((name (if (package-desc-p pkg) |
| 1808 | (package-desc-name pkg) | 1818 | (package-desc-name pkg) |
| 1809 | pkg))) | 1819 | pkg))) |
| @@ -1846,7 +1856,6 @@ is derived from the main .el file in the directory. | |||
| 1846 | 1856 | ||
| 1847 | Downloads and installs required packages as needed." | 1857 | Downloads and installs required packages as needed." |
| 1848 | (interactive) | 1858 | (interactive) |
| 1849 | (package--ensure-init-file) | ||
| 1850 | (let* ((pkg-desc | 1859 | (let* ((pkg-desc |
| 1851 | (cond | 1860 | (cond |
| 1852 | ((derived-mode-p 'dired-mode) | 1861 | ((derived-mode-p 'dired-mode) |