diff options
| author | Artur Malabarba | 2015-06-17 15:37:51 +0100 |
|---|---|---|
| committer | Artur Malabarba | 2015-06-17 15:40:58 +0100 |
| commit | a142b77028d6c418e0c26bfa093155f1a9cd433d (patch) | |
| tree | f874d73a8b868a48eaa839ec52edb533064b0913 | |
| parent | 4b1613762fec33cd12c8484820392c5d7c74c83c (diff) | |
| download | emacs-a142b77028d6c418e0c26bfa093155f1a9cd433d.tar.gz emacs-a142b77028d6c418e0c26bfa093155f1a9cd433d.zip | |
* lisp/emacs-lisp/package.el: Revert buffer after any operation
Call `package-menu--post-refresh' after any operation that changes
the package database (`package-install' and `package-delete'). To
avoid performance issues in large transactions, these functions
add `post-refresh' to `post-command-hook' instead of calling it
immediately.
(package-menu--mark-or-notify-upgrades): New function.
(list-packages): Add it to `package--post-download-archives-hook'.
(package-menu--post-refresh): Lose the upgrade-checking code, add
code to remove itself from `post-command-hook'.
(package-install, package-delete): Add it to `post-command-hook'.
(package-menu-execute): Don't call `package-menu--post-refresh'.
| -rw-r--r-- | lisp/emacs-lisp/package.el | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 6827cc9d17f..eef9ee10ecf 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -1873,6 +1873,7 @@ to install it but still mark it as selected." | |||
| 1873 | package-archive-contents)) | 1873 | package-archive-contents)) |
| 1874 | nil t)) | 1874 | nil t)) |
| 1875 | nil))) | 1875 | nil))) |
| 1876 | (add-hook 'post-command-hook #'package-menu--post-refresh) | ||
| 1876 | (let ((name (if (package-desc-p pkg) | 1877 | (let ((name (if (package-desc-p pkg) |
| 1877 | (package-desc-name pkg) | 1878 | (package-desc-name pkg) |
| 1878 | pkg))) | 1879 | pkg))) |
| @@ -2037,6 +2038,7 @@ If NOSAVE is non-nil, the package is not removed from | |||
| 2037 | (package-desc-full-name pkg-desc) | 2038 | (package-desc-full-name pkg-desc) |
| 2038 | (package-desc-name pkg-used-elsewhere-by))) | 2039 | (package-desc-name pkg-used-elsewhere-by))) |
| 2039 | (t | 2040 | (t |
| 2041 | (add-hook 'post-command-hook #'package-menu--post-refresh) | ||
| 2040 | (delete-directory dir t t) | 2042 | (delete-directory dir t t) |
| 2041 | ;; Remove NAME-VERSION.signed file. | 2043 | ;; Remove NAME-VERSION.signed file. |
| 2042 | (let ((signed-file (concat dir ".signed"))) | 2044 | (let ((signed-file (concat dir ".signed"))) |
| @@ -3059,9 +3061,7 @@ Optional argument NOQUERY non-nil means do not ask the user to confirm." | |||
| 3059 | (length removable) | 3061 | (length removable) |
| 3060 | "are no longer needed, type `M-x package-autoremove' to remove them") | 3062 | "are no longer needed, type `M-x package-autoremove' to remove them") |
| 3061 | (message (replace-regexp-in-string "__" "ed" message-template) | 3063 | (message (replace-regexp-in-string "__" "ed" message-template) |
| 3062 | "finished")))) | 3064 | "finished")))))))) |
| 3063 | ;; This calls `package-menu--generate'. | ||
| 3064 | (package-menu--post-refresh))))) | ||
| 3065 | 3065 | ||
| 3066 | (defun package-menu--version-predicate (A B) | 3066 | (defun package-menu--version-predicate (A B) |
| 3067 | (let ((vA (or (aref (cadr A) 1) '(0))) | 3067 | (let ((vA (or (aref (cadr A) 1) '(0))) |
| @@ -3135,15 +3135,30 @@ Store this list in `package-menu--new-package-list'." | |||
| 3135 | (if (= (length upgrades) 1) "it" "them")))) | 3135 | (if (= (length upgrades) 1) "it" "them")))) |
| 3136 | 3136 | ||
| 3137 | (defun package-menu--post-refresh () | 3137 | (defun package-menu--post-refresh () |
| 3138 | "Check for new packages, revert the *Packages* buffer, and check for upgrades. | 3138 | "If there's a *Packages* buffer, revert it and check for new packages and upgrades. |
| 3139 | This function is called after `package-refresh-contents' and | 3139 | Do nothing if there's no *Packages* buffer. |
| 3140 | after `package-menu--perform-transaction'." | 3140 | |
| 3141 | (package-menu--populate-new-package-list) | 3141 | This function is called after `package-refresh-contents' and it |
| 3142 | is added to `post-command-hook' by any function which alters the | ||
| 3143 | package database (`package-install' and `package-delete'). When | ||
| 3144 | run, it removes itself from `post-command-hook'." | ||
| 3145 | (remove-hook 'post-command-hook #'package-menu--post-refresh) | ||
| 3142 | (let ((buf (get-buffer "*Packages*"))) | 3146 | (let ((buf (get-buffer "*Packages*"))) |
| 3143 | (when (buffer-live-p buf) | 3147 | (when (buffer-live-p buf) |
| 3144 | (with-current-buffer buf | 3148 | (with-current-buffer buf |
| 3149 | (package-menu--populate-new-package-list) | ||
| 3145 | (run-hooks 'tabulated-list-revert-hook) | 3150 | (run-hooks 'tabulated-list-revert-hook) |
| 3146 | (tabulated-list-print 'remember 'update) | 3151 | (tabulated-list-print 'remember 'update))))) |
| 3152 | |||
| 3153 | (defun package-menu--mark-or-notify-upgrades () | ||
| 3154 | "If there's a *Packages* buffer, check for upgrades and possibly mark them. | ||
| 3155 | Do nothing if there's no *Packages* buffer. If there are | ||
| 3156 | upgrades, mark them if `package-menu--mark-upgrades-pending' is | ||
| 3157 | non-nil, otherwise just notify the user that there are upgrades. | ||
| 3158 | This function is called after `package-refresh-contents'." | ||
| 3159 | (let ((buf (get-buffer "*Packages*"))) | ||
| 3160 | (when (buffer-live-p buf) | ||
| 3161 | (with-current-buffer buf | ||
| 3147 | (if package-menu--mark-upgrades-pending | 3162 | (if package-menu--mark-upgrades-pending |
| 3148 | (package-menu--mark-upgrades-1) | 3163 | (package-menu--mark-upgrades-1) |
| 3149 | (package-menu--find-and-notify-upgrades)))))) | 3164 | (package-menu--find-and-notify-upgrades)))))) |
| @@ -3162,6 +3177,8 @@ The list is displayed in a buffer named `*Packages*'." | |||
| 3162 | ;; Integrate the package-menu with updating the archives. | 3177 | ;; Integrate the package-menu with updating the archives. |
| 3163 | (add-hook 'package--post-download-archives-hook | 3178 | (add-hook 'package--post-download-archives-hook |
| 3164 | #'package-menu--post-refresh) | 3179 | #'package-menu--post-refresh) |
| 3180 | (add-hook 'package--post-download-archives-hook | ||
| 3181 | #'package-menu--mark-or-notify-upgrades 'append) | ||
| 3165 | 3182 | ||
| 3166 | ;; Generate the Package Menu. | 3183 | ;; Generate the Package Menu. |
| 3167 | (let ((buf (get-buffer-create "*Packages*"))) | 3184 | (let ((buf (get-buffer-create "*Packages*"))) |