diff options
| author | Stefan Kangas | 2019-11-07 04:10:43 +0100 |
|---|---|---|
| committer | Stefan Kangas | 2019-11-07 04:12:01 +0100 |
| commit | ddb797cf4c5f121a5ed003b9746ffaa849d42af5 (patch) | |
| tree | f118ff3dd9016848502f9021965060f3718ab5c0 | |
| parent | 1428dfe630ceccd3bec13a3f7f44ee67af88b99f (diff) | |
| download | emacs-ddb797cf4c5f121a5ed003b9746ffaa849d42af5.tar.gz emacs-ddb797cf4c5f121a5ed003b9746ffaa849d42af5.zip | |
Clean up major mode check in package-menu-mode
* lisp/emacs-lisp/package.el (package--ensure-package-menu-mode):
Extract function to warn about incorrect major mode...
(package-menu-toggle-hiding, package-menu-refresh)
(package-menu-execute): ...from here.
(package-menu--mark-upgrades-1): And here, but move call...
(package-menu-mark-upgrades): ...here instead.
(package-menu-hide-package, package-menu-mark-delete)
(package-menu-mark-install, package-menu-mark-unmark)
(package-menu-quick-help, package-menu-get-status)
(package-menu-filter-by-keyword, package-menu-filter-by-name)
(package-menu-clear-filter): Add call to new function. (Bug#37891)
| -rw-r--r-- | lisp/emacs-lisp/package.el | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 9f8ee8368e6..6b75ecf7832 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -2791,6 +2791,11 @@ package PKG-DESC, add one. The alist is keyed with PKG-DESC." | |||
| 2791 | (defvar package--emacs-version-list (version-to-list emacs-version) | 2791 | (defvar package--emacs-version-list (version-to-list emacs-version) |
| 2792 | "The value of variable `emacs-version' as a list.") | 2792 | "The value of variable `emacs-version' as a list.") |
| 2793 | 2793 | ||
| 2794 | (defun package--ensure-package-menu-mode () | ||
| 2795 | "Signal a user-error if major mode is not `package-menu-mode'." | ||
| 2796 | (unless (derived-mode-p 'package-menu-mode) | ||
| 2797 | (user-error "The current buffer is not a Package Menu"))) | ||
| 2798 | |||
| 2794 | (defun package--incompatible-p (pkg &optional shallow) | 2799 | (defun package--incompatible-p (pkg &optional shallow) |
| 2795 | "Return non-nil if PKG has no chance of being installable. | 2800 | "Return non-nil if PKG has no chance of being installable. |
| 2796 | PKG is a `package-desc' object. | 2801 | PKG is a `package-desc' object. |
| @@ -2866,8 +2871,7 @@ Installed obsolete packages are always displayed.") | |||
| 2866 | (defun package-menu-toggle-hiding () | 2871 | (defun package-menu-toggle-hiding () |
| 2867 | "In Package Menu, toggle visibility of obsolete available packages." | 2872 | "In Package Menu, toggle visibility of obsolete available packages." |
| 2868 | (interactive) | 2873 | (interactive) |
| 2869 | (unless (derived-mode-p 'package-menu-mode) | 2874 | (package--ensure-package-menu-mode) |
| 2870 | (user-error "The current buffer is not a Package Menu")) | ||
| 2871 | (setq package-menu--hide-packages | 2875 | (setq package-menu--hide-packages |
| 2872 | (not package-menu--hide-packages)) | 2876 | (not package-menu--hide-packages)) |
| 2873 | (if package-menu--hide-packages | 2877 | (if package-menu--hide-packages |
| @@ -3175,8 +3179,7 @@ user-error if there is already a refresh running asynchronously. | |||
| 3175 | `package-menu-mode' sets `revert-buffer-function' to this | 3179 | `package-menu-mode' sets `revert-buffer-function' to this |
| 3176 | function. The args ARG and NOCONFIRM, passed from | 3180 | function. The args ARG and NOCONFIRM, passed from |
| 3177 | `revert-buffer', are ignored." | 3181 | `revert-buffer', are ignored." |
| 3178 | (unless (derived-mode-p 'package-menu-mode) | 3182 | (package--ensure-package-menu-mode) |
| 3179 | (user-error "The current buffer is not a Package Menu")) | ||
| 3180 | (when (and package-menu-async package--downloads-in-progress) | 3183 | (when (and package-menu-async package--downloads-in-progress) |
| 3181 | (user-error "Package refresh is already in progress, please wait...")) | 3184 | (user-error "Package refresh is already in progress, please wait...")) |
| 3182 | (setq package-menu--old-archive-contents package-archive-contents) | 3185 | (setq package-menu--old-archive-contents package-archive-contents) |
| @@ -3188,6 +3191,7 @@ function. The args ARG and NOCONFIRM, passed from | |||
| 3188 | "Hide a package under point in Package Menu. | 3191 | "Hide a package under point in Package Menu. |
| 3189 | If optional arg BUTTON is non-nil, describe its associated package." | 3192 | If optional arg BUTTON is non-nil, describe its associated package." |
| 3190 | (interactive) | 3193 | (interactive) |
| 3194 | (package--ensure-package-menu-mode) | ||
| 3191 | (declare (interactive-only "change `package-hidden-regexps' instead.")) | 3195 | (declare (interactive-only "change `package-hidden-regexps' instead.")) |
| 3192 | (let* ((name (when (derived-mode-p 'package-menu-mode) | 3196 | (let* ((name (when (derived-mode-p 'package-menu-mode) |
| 3193 | (concat "\\`" (regexp-quote (symbol-name (package-desc-name | 3197 | (concat "\\`" (regexp-quote (symbol-name (package-desc-name |
| @@ -3221,6 +3225,7 @@ If optional arg BUTTON is non-nil, describe its associated package." | |||
| 3221 | (defun package-menu-mark-delete (&optional _num) | 3225 | (defun package-menu-mark-delete (&optional _num) |
| 3222 | "Mark a package for deletion and move to the next line." | 3226 | "Mark a package for deletion and move to the next line." |
| 3223 | (interactive "p") | 3227 | (interactive "p") |
| 3228 | (package--ensure-package-menu-mode) | ||
| 3224 | (if (member (package-menu-get-status) | 3229 | (if (member (package-menu-get-status) |
| 3225 | '("installed" "dependency" "obsolete" "unsigned")) | 3230 | '("installed" "dependency" "obsolete" "unsigned")) |
| 3226 | (tabulated-list-put-tag "D" t) | 3231 | (tabulated-list-put-tag "D" t) |
| @@ -3229,6 +3234,7 @@ If optional arg BUTTON is non-nil, describe its associated package." | |||
| 3229 | (defun package-menu-mark-install (&optional _num) | 3234 | (defun package-menu-mark-install (&optional _num) |
| 3230 | "Mark a package for installation and move to the next line." | 3235 | "Mark a package for installation and move to the next line." |
| 3231 | (interactive "p") | 3236 | (interactive "p") |
| 3237 | (package--ensure-package-menu-mode) | ||
| 3232 | (if (member (package-menu-get-status) '("available" "avail-obso" "new" "dependency")) | 3238 | (if (member (package-menu-get-status) '("available" "avail-obso" "new" "dependency")) |
| 3233 | (tabulated-list-put-tag "I" t) | 3239 | (tabulated-list-put-tag "I" t) |
| 3234 | (forward-line))) | 3240 | (forward-line))) |
| @@ -3236,17 +3242,20 @@ If optional arg BUTTON is non-nil, describe its associated package." | |||
| 3236 | (defun package-menu-mark-unmark (&optional _num) | 3242 | (defun package-menu-mark-unmark (&optional _num) |
| 3237 | "Clear any marks on a package and move to the next line." | 3243 | "Clear any marks on a package and move to the next line." |
| 3238 | (interactive "p") | 3244 | (interactive "p") |
| 3245 | (package--ensure-package-menu-mode) | ||
| 3239 | (tabulated-list-put-tag " " t)) | 3246 | (tabulated-list-put-tag " " t)) |
| 3240 | 3247 | ||
| 3241 | (defun package-menu-backup-unmark () | 3248 | (defun package-menu-backup-unmark () |
| 3242 | "Back up one line and clear any marks on that package." | 3249 | "Back up one line and clear any marks on that package." |
| 3243 | (interactive) | 3250 | (interactive) |
| 3251 | (package--ensure-package-menu-mode) | ||
| 3244 | (forward-line -1) | 3252 | (forward-line -1) |
| 3245 | (tabulated-list-put-tag " ")) | 3253 | (tabulated-list-put-tag " ")) |
| 3246 | 3254 | ||
| 3247 | (defun package-menu-mark-obsolete-for-deletion () | 3255 | (defun package-menu-mark-obsolete-for-deletion () |
| 3248 | "Mark all obsolete packages for deletion." | 3256 | "Mark all obsolete packages for deletion." |
| 3249 | (interactive) | 3257 | (interactive) |
| 3258 | (package--ensure-package-menu-mode) | ||
| 3250 | (save-excursion | 3259 | (save-excursion |
| 3251 | (goto-char (point-min)) | 3260 | (goto-char (point-min)) |
| 3252 | (while (not (eobp)) | 3261 | (while (not (eobp)) |
| @@ -3277,6 +3286,7 @@ If optional arg BUTTON is non-nil, describe its associated package." | |||
| 3277 | "Show short key binding help for `package-menu-mode'. | 3286 | "Show short key binding help for `package-menu-mode'. |
| 3278 | The full list of keys can be viewed with \\[describe-mode]." | 3287 | The full list of keys can be viewed with \\[describe-mode]." |
| 3279 | (interactive) | 3288 | (interactive) |
| 3289 | (package--ensure-package-menu-mode) | ||
| 3280 | (message (mapconcat #'package--prettify-quick-help-key | 3290 | (message (mapconcat #'package--prettify-quick-help-key |
| 3281 | package--quick-help-keys "\n"))) | 3291 | package--quick-help-keys "\n"))) |
| 3282 | 3292 | ||
| @@ -3285,6 +3295,7 @@ The full list of keys can be viewed with \\[describe-mode]." | |||
| 3285 | 3295 | ||
| 3286 | (defun package-menu-get-status () | 3296 | (defun package-menu-get-status () |
| 3287 | "Return status text of package at point in Package Menu." | 3297 | "Return status text of package at point in Package Menu." |
| 3298 | (package--ensure-package-menu-mode) | ||
| 3288 | (let* ((id (tabulated-list-get-id)) | 3299 | (let* ((id (tabulated-list-get-id)) |
| 3289 | (entry (and id (assoc id tabulated-list-entries)))) | 3300 | (entry (and id (assoc id tabulated-list-entries)))) |
| 3290 | (if entry | 3301 | (if entry |
| @@ -3340,8 +3351,6 @@ corresponding to the newer version." | |||
| 3340 | (defun package-menu--mark-upgrades-1 () | 3351 | (defun package-menu--mark-upgrades-1 () |
| 3341 | "Mark all upgradable packages in the Package Menu. | 3352 | "Mark all upgradable packages in the Package Menu. |
| 3342 | Implementation of `package-menu-mark-upgrades'." | 3353 | Implementation of `package-menu-mark-upgrades'." |
| 3343 | (unless (derived-mode-p 'package-menu-mode) | ||
| 3344 | (error "The current buffer is not a Package Menu")) | ||
| 3345 | (setq package-menu--mark-upgrades-pending nil) | 3354 | (setq package-menu--mark-upgrades-pending nil) |
| 3346 | (let ((upgrades (package-menu--find-upgrades))) | 3355 | (let ((upgrades (package-menu--find-upgrades))) |
| 3347 | (if (null upgrades) | 3356 | (if (null upgrades) |
| @@ -3373,6 +3382,7 @@ If there's an async refresh operation in progress, the flags will | |||
| 3373 | be placed as part of `package-menu--post-refresh' instead of | 3382 | be placed as part of `package-menu--post-refresh' instead of |
| 3374 | immediately." | 3383 | immediately." |
| 3375 | (interactive) | 3384 | (interactive) |
| 3385 | (package--ensure-package-menu-mode) | ||
| 3376 | (if (not package--downloads-in-progress) | 3386 | (if (not package--downloads-in-progress) |
| 3377 | (package-menu--mark-upgrades-1) | 3387 | (package-menu--mark-upgrades-1) |
| 3378 | (setq package-menu--mark-upgrades-pending t) | 3388 | (setq package-menu--mark-upgrades-pending t) |
| @@ -3466,8 +3476,7 @@ Packages marked for installation are downloaded and installed; | |||
| 3466 | packages marked for deletion are removed. | 3476 | packages marked for deletion are removed. |
| 3467 | Optional argument NOQUERY non-nil means do not ask the user to confirm." | 3477 | Optional argument NOQUERY non-nil means do not ask the user to confirm." |
| 3468 | (interactive) | 3478 | (interactive) |
| 3469 | (unless (derived-mode-p 'package-menu-mode) | 3479 | (package--ensure-package-menu-mode) |
| 3470 | (error "The current buffer is not in Package Menu mode")) | ||
| 3471 | (let (install-list delete-list cmd pkg-desc) | 3480 | (let (install-list delete-list cmd pkg-desc) |
| 3472 | (save-excursion | 3481 | (save-excursion |
| 3473 | (goto-char (point-min)) | 3482 | (goto-char (point-min)) |
| @@ -3693,6 +3702,7 @@ Statuses available include \"incompat\", \"available\", | |||
| 3693 | (interactive | 3702 | (interactive |
| 3694 | (list (completing-read-multiple | 3703 | (list (completing-read-multiple |
| 3695 | "Keywords (comma separated): " (package-all-keywords)))) | 3704 | "Keywords (comma separated): " (package-all-keywords)))) |
| 3705 | (package--ensure-package-menu-mode) | ||
| 3696 | (package-show-package-list t (if (stringp keyword) | 3706 | (package-show-package-list t (if (stringp keyword) |
| 3697 | (list keyword) | 3707 | (list keyword) |
| 3698 | keyword))) | 3708 | keyword))) |
| @@ -3702,6 +3712,7 @@ Statuses available include \"incompat\", \"available\", | |||
| 3702 | Show only those items whose name matches the regular expression | 3712 | Show only those items whose name matches the regular expression |
| 3703 | NAME. If NAME is nil or the empty string, show all packages." | 3713 | NAME. If NAME is nil or the empty string, show all packages." |
| 3704 | (interactive (list (read-from-minibuffer "Filter by name (regexp): "))) | 3714 | (interactive (list (read-from-minibuffer "Filter by name (regexp): "))) |
| 3715 | (package--ensure-package-menu-mode) | ||
| 3705 | (if (or (not name) (string-empty-p name)) | 3716 | (if (or (not name) (string-empty-p name)) |
| 3706 | (package-show-package-list t nil) | 3717 | (package-show-package-list t nil) |
| 3707 | ;; Update `tabulated-list-entries' so that it contains all | 3718 | ;; Update `tabulated-list-entries' so that it contains all |
| @@ -3719,6 +3730,7 @@ NAME. If NAME is nil or the empty string, show all packages." | |||
| 3719 | (defun package-menu-clear-filter () | 3730 | (defun package-menu-clear-filter () |
| 3720 | "Clear any filter currently applied to the \"*Packages*\" buffer." | 3731 | "Clear any filter currently applied to the \"*Packages*\" buffer." |
| 3721 | (interactive) | 3732 | (interactive) |
| 3733 | (package--ensure-package-menu-mode) | ||
| 3722 | (package-menu--generate t t)) | 3734 | (package-menu--generate t t)) |
| 3723 | 3735 | ||
| 3724 | (defun package-list-packages-no-fetch () | 3736 | (defun package-list-packages-no-fetch () |