@@ -2767,7 +2767,7 @@ Letters do not insert themselves; instead, they are commands.
2767
2767
(setq tabulated-list-sort-key (cons "Status" nil))
2768
2768
(add-hook 'tabulated-list-revert-hook #'package-menu--refresh nil t)
2769
2769
(tabulated-list-init-header)
2770
- (setq revert-buffer-function 'package-menu--refresh)
2770
+ (setq revert-buffer-function 'package-menu--refresh-contents )
2771
2771
(setf imenu-prev-index-position-function
2772
2772
#'package--imenu-prev-index-position-function)
2773
2773
(setf imenu-extract-index-name-function
@@ -2791,6 +2791,11 @@ package PKG-DESC, add one. The alist is keyed with PKG-DESC."
2791
2791
(defvar package--emacs-version-list (version-to-list emacs-version)
2792
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
2799
(defun package--incompatible-p (pkg &optional shallow)
2795
2800
"Return non-nil if PKG has no chance of being installable.
2796
2801
PKG is a `package-desc' object.
@@ -2866,8 +2871,7 @@ Installed obsolete packages are always displayed.")
2866
2871
(defun package-menu-toggle-hiding ()
2867
2872
"In Package Menu, toggle visibility of obsolete available packages."
2868
2873
(interactive)
2869
- (unless (derived-mode-p 'package-menu-mode)
2870
- (user-error "The current buffer is not a Package Menu"))
2874
+ (package--ensure-package-menu-mode)
2871
2875
(setq package-menu--hide-packages
2872
2876
(not package-menu--hide-packages))
2873
2877
(if package-menu--hide-packages
@@ -3166,7 +3170,7 @@ Return (PKG-DESC [NAME VERSION STATUS DOC])."
3166
3170
(defvar package-menu--old-archive-contents nil
3167
3171
"`package-archive-contents' before the latest refresh.")
3168
3172
3169
- (defun package-menu--refresh (&optional _arg _noconfirm)
3173
+ (defun package-menu--refresh-contents (&optional _arg _noconfirm)
3170
3174
"In Package Menu, download the Emacs Lisp package archive.
3171
3175
Fetch the contents of each archive specified in
3172
3176
`package-archives', and then refresh the package menu. Signal a
@@ -3175,8 +3179,7 @@ user-error if there is already a refresh running asynchronously.
3175
3179
`package-menu-mode' sets `revert-buffer-function' to this
3176
3180
function. The args ARG and NOCONFIRM, passed from
3177
3181
`revert-buffer', are ignored."
3178
- (unless (derived-mode-p 'package-menu-mode)
3179
- (user-error "The current buffer is not a Package Menu"))
3182
+ (package--ensure-package-menu-mode)
3180
3183
(when (and package-menu-async package--downloads-in-progress)
3181
3184
(user-error "Package refresh is already in progress, please wait..."))
3182
3185
(setq package-menu--old-archive-contents package-archive-contents)
@@ -3188,6 +3191,7 @@ function. The args ARG and NOCONFIRM, passed from
3188
3191
"Hide a package under point in Package Menu.
3189
3192
If optional arg BUTTON is non-nil, describe its associated package."
3190
3193
(interactive)
3194
+ (package--ensure-package-menu-mode)
3191
3195
(declare (interactive-only "change `package-hidden-regexps' instead."))
3192
3196
(let* ((name (when (derived-mode-p 'package-menu-mode)
3193
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
3225
(defun package-menu-mark-delete (&optional _num)
3222
3226
"Mark a package for deletion and move to the next line."
3223
3227
(interactive "p")
3228
+ (package--ensure-package-menu-mode)
3224
3229
(if (member (package-menu-get-status)
3225
3230
'("installed" "dependency" "obsolete" "unsigned"))
3226
3231
(tabulated-list-put-tag "D" t)
@@ -3229,24 +3234,28 @@ If optional arg BUTTON is non-nil, describe its associated package."
3229
3234
(defun package-menu-mark-install (&optional _num)
3230
3235
"Mark a package for installation and move to the next line."
3231
3236
(interactive "p")
3237
+ (package--ensure-package-menu-mode)
3232
3238
(if (member (package-menu-get-status) '("available" "avail-obso" "new" "dependency"))
3233
3239
(tabulated-list-put-tag "I" t)
3234
3240
(forward-line)))
3235
3241
3236
3242
(defun package-menu-mark-unmark (&optional _num)
3237
3243
"Clear any marks on a package and move to the next line."
3238
3244
(interactive "p")
3245
+ (package--ensure-package-menu-mode)
3239
3246
(tabulated-list-put-tag " " t))
3240
3247
3241
3248
(defun package-menu-backup-unmark ()
3242
3249
"Back up one line and clear any marks on that package."
3243
3250
(interactive)
3251
+ (package--ensure-package-menu-mode)
3244
3252
(forward-line -1)
3245
3253
(tabulated-list-put-tag " "))
3246
3254
3247
3255
(defun package-menu-mark-obsolete-for-deletion ()
3248
3256
"Mark all obsolete packages for deletion."
3249
3257
(interactive)
3258
+ (package--ensure-package-menu-mode)
3250
3259
(save-excursion
3251
3260
(goto-char (point-min))
3252
3261
(while (not (eobp))
@@ -3277,6 +3286,7 @@ If optional arg BUTTON is non-nil, describe its associated package."
3277
3286
"Show short key binding help for `package-menu-mode'.
3278
3287
The full list of keys can be viewed with \\[describe-mode]."
3279
3288
(interactive)
3289
+ (package--ensure-package-menu-mode)
3280
3290
(message (mapconcat #'package--prettify-quick-help-key
3281
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
3296
(defun package-menu-get-status ()
3287
3297
"Return status text of package at point in Package Menu."
3298
+ (package--ensure-package-menu-mode)
3288
3299
(let* ((id (tabulated-list-get-id))
3289
3300
(entry (and id (assoc id tabulated-list-entries))))
3290
3301
(if entry
@@ -3340,8 +3351,6 @@ corresponding to the newer version."
3340
3351
(defun package-menu--mark-upgrades-1 ()
3341
3352
"Mark all upgradable packages in the Package Menu.
3342
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
3354
(setq package-menu--mark-upgrades-pending nil)
3346
3355
(let ((upgrades (package-menu--find-upgrades)))
3347
3356
(if (null upgrades)
@@ -3373,6 +3382,7 @@ If there's an async refresh operation in progress, the flags will
3373
3382
be placed as part of `package-menu--post-refresh' instead of
3374
3383
immediately."
3375
3384
(interactive)
3385
+ (package--ensure-package-menu-mode)
3376
3386
(if (not package--downloads-in-progress)
3377
3387
(package-menu--mark-upgrades-1)
3378
3388
(setq package-menu--mark-upgrades-pending t)
@@ -3466,8 +3476,7 @@ Packages marked for installation are downloaded and installed;
3466
3476
packages marked for deletion are removed.
3467
3477
Optional argument NOQUERY non-nil means do not ask the user to confirm."
3468
3478
(interactive)
3469
- (unless (derived-mode-p 'package-menu-mode)
3470
- (error "The current buffer is not in Package Menu mode"))
3479
+ (package--ensure-package-menu-mode)
3471
3480
(let (install-list delete-list cmd pkg-desc)
3472
3481
(save-excursion
3473
3482
(goto-char (point-min))
@@ -3646,7 +3655,7 @@ short description."
3646
3655
(package-menu-mode)
3647
3656
3648
3657
;; Fetch the remote list of packages.
3649
- (unless no-fetch (package-menu--refresh))
3658
+ (unless no-fetch (package-menu--refresh-contents ))
3650
3659
3651
3660
;; If we're not async, this would be redundant.
3652
3661
(when package-menu-async
@@ -3693,6 +3702,7 @@ Statuses available include \"incompat\", \"available\",
3693
3702
(interactive
3694
3703
(list (completing-read-multiple
3695
3704
"Keywords (comma separated): " (package-all-keywords))))
3705
+ (package--ensure-package-menu-mode)
3696
3706
(package-show-package-list t (if (stringp keyword)
3697
3707
(list keyword)
3698
3708
keyword)))
@@ -3702,6 +3712,7 @@ Statuses available include \"incompat\", \"available\",
3702
3712
Show only those items whose name matches the regular expression
3703
3713
NAME. If NAME is nil or the empty string, show all packages."
3704
3714
(interactive (list (read-from-minibuffer "Filter by name (regexp): ")))
3715
+ (package--ensure-package-menu-mode)
3705
3716
(if (or (not name) (string-empty-p name))
3706
3717
(package-show-package-list t nil)
3707
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
3730
(defun package-menu-clear-filter ()
3720
3731
"Clear any filter currently applied to the \"*Packages*\" buffer."
3721
3732
(interactive)
3733
+ (package--ensure-package-menu-mode)
3722
3734
(package-menu--generate t t))
3723
3735
3724
3736
(defun package-list-packages-no-fetch ()
0 commit comments