unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#37891: [PATCH] Clean up error on wrong major mode in package-menu-mode
@ 2019-10-23 16:09 Stefan Kangas
  2019-11-07  3:14 ` Stefan Kangas
  0 siblings, 1 reply; 2+ messages in thread
From: Stefan Kangas @ 2019-10-23 16:09 UTC (permalink / raw)
  To: 37891

[-- Attachment #1: Type: text/plain, Size: 468 bytes --]

Four package-menu-mode specific commands currently signal an error if
called when not in package-menu-mode.  One of them uses 'user-error',
the others 'error'.  All other commands don't signal an error.

The attached patch makes the behaviour more consistent by:
1) Factoring out the error signalling into a new function to make it
more consistent.
2) Calling this function in all other relevant package-mode-menu commands.

Any comments?

Best regards,
Stefan Kangas

[-- Attachment #2: 0001-Clean-up-error-on-wrong-major-mode-in-package-menu-m.patch --]
[-- Type: application/octet-stream, Size: 7429 bytes --]

From cb72551acfdd27aae4e2eaadb43c074d966dd458 Mon Sep 17 00:00:00 2001
From: Stefan Kangas <stefankangas@gmail.com>
Date: Wed, 23 Oct 2019 17:46:29 +0200
Subject: [PATCH] Clean up error on wrong major mode 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.
---
 lisp/emacs-lisp/package.el | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
index 645e831bcc..2da3b461ef 100644
--- a/lisp/emacs-lisp/package.el
+++ b/lisp/emacs-lisp/package.el
@@ -2783,6 +2783,11 @@ package-list-unsigned
 (defvar package--emacs-version-list (version-to-list emacs-version)
   "The value of variable `emacs-version' as a list.")
 
+(defun package--ensure-package-menu-mode ()
+  "Signal a user-error if major mode is not `package-menu-mode'."
+  (unless (derived-mode-p 'package-menu-mode)
+    (user-error "The current buffer is not a Package Menu")))
+
 (defun package--incompatible-p (pkg &optional shallow)
   "Return non-nil if PKG has no chance of being installable.
 PKG is a `package-desc' object.
@@ -2858,8 +2863,7 @@ package-menu--hide-packages
 (defun package-menu-toggle-hiding ()
   "In Package Menu, toggle visibility of obsolete available packages."
   (interactive)
-  (unless (derived-mode-p 'package-menu-mode)
-    (user-error "The current buffer is not a Package Menu"))
+  (package--ensure-package-menu-mode)
   (setq package-menu--hide-packages
         (not package-menu--hide-packages))
   (if package-menu--hide-packages
@@ -3164,8 +3168,7 @@ package-menu-refresh
 `package-archives', and then refresh the package menu.  Signal a
 user-error if there is already a refresh running asynchronously."
   (interactive)
-  (unless (derived-mode-p 'package-menu-mode)
-    (user-error "The current buffer is not a Package Menu"))
+  (package--ensure-package-menu-mode)
   (when (and package-menu-async package--downloads-in-progress)
     (user-error "Package refresh is already in progress, please wait..."))
   (setq package-menu--old-archive-contents package-archive-contents)
@@ -3176,6 +3179,7 @@ package-menu-hide-package
   "Hide a package under point in Package Menu.
 If optional arg BUTTON is non-nil, describe its associated package."
   (interactive)
+  (package--ensure-package-menu-mode)
   (declare (interactive-only "change `package-hidden-regexps' instead."))
   (let* ((name (when (derived-mode-p 'package-menu-mode)
                  (concat "\\`" (regexp-quote (symbol-name (package-desc-name
@@ -3209,6 +3213,7 @@ package-menu-describe-package
 (defun package-menu-mark-delete (&optional _num)
   "Mark a package for deletion and move to the next line."
   (interactive "p")
+  (package--ensure-package-menu-mode)
   (if (member (package-menu-get-status)
               '("installed" "dependency" "obsolete" "unsigned"))
       (tabulated-list-put-tag "D" t)
@@ -3217,6 +3222,7 @@ package-menu-mark-delete
 (defun package-menu-mark-install (&optional _num)
   "Mark a package for installation and move to the next line."
   (interactive "p")
+  (package--ensure-package-menu-mode)
   (if (member (package-menu-get-status) '("available" "avail-obso" "new" "dependency"))
       (tabulated-list-put-tag "I" t)
     (forward-line)))
@@ -3224,17 +3230,20 @@ package-menu-mark-install
 (defun package-menu-mark-unmark (&optional _num)
   "Clear any marks on a package and move to the next line."
   (interactive "p")
+  (package--ensure-package-menu-mode)
   (tabulated-list-put-tag " " t))
 
 (defun package-menu-backup-unmark ()
   "Back up one line and clear any marks on that package."
   (interactive)
+  (package--ensure-package-menu-mode)
   (forward-line -1)
   (tabulated-list-put-tag " "))
 
 (defun package-menu-mark-obsolete-for-deletion ()
   "Mark all obsolete packages for deletion."
   (interactive)
+  (package--ensure-package-menu-mode)
   (save-excursion
     (goto-char (point-min))
     (while (not (eobp))
@@ -3265,6 +3274,7 @@ package-menu-quick-help
   "Show short key binding help for `package-menu-mode'.
 The full list of keys can be viewed with \\[describe-mode]."
   (interactive)
+  (package--ensure-package-menu-mode)
   (message (mapconcat #'package--prettify-quick-help-key
                       package--quick-help-keys "\n")))
 
@@ -3273,6 +3283,7 @@ package-menu-quick-help
 
 (defun package-menu-get-status ()
   "Return status text of package at point in Package Menu."
+  (package--ensure-package-menu-mode)
   (let* ((id (tabulated-list-get-id))
          (entry (and id (assoc id tabulated-list-entries))))
     (if entry
@@ -3328,8 +3339,6 @@ package-menu--mark-upgrades-pending
 (defun package-menu--mark-upgrades-1 ()
   "Mark all upgradable packages in the Package Menu.
 Implementation of `package-menu-mark-upgrades'."
-  (unless (derived-mode-p 'package-menu-mode)
-    (error "The current buffer is not a Package Menu"))
   (setq package-menu--mark-upgrades-pending nil)
   (let ((upgrades (package-menu--find-upgrades)))
     (if (null upgrades)
@@ -3361,6 +3370,7 @@ package-menu-mark-upgrades
 be placed as part of `package-menu--post-refresh' instead of
 immediately."
   (interactive)
+  (package--ensure-package-menu-mode)
   (if (not package--downloads-in-progress)
       (package-menu--mark-upgrades-1)
     (setq package-menu--mark-upgrades-pending t)
@@ -3454,8 +3464,7 @@ package-menu-execute
 packages marked for deletion are removed.
 Optional argument NOQUERY non-nil means do not ask the user to confirm."
   (interactive)
-  (unless (derived-mode-p 'package-menu-mode)
-    (error "The current buffer is not in Package Menu mode"))
+  (package--ensure-package-menu-mode)
   (let (install-list delete-list cmd pkg-desc)
     (save-excursion
       (goto-char (point-min))
@@ -3681,6 +3690,7 @@ package-menu-filter-by-keyword
   (interactive
    (list (completing-read-multiple
           "Keywords (comma separated): " (package-all-keywords))))
+  (package--ensure-package-menu-mode)
   (package-show-package-list t (if (stringp keyword)
                                    (list keyword)
                                  keyword)))
@@ -3690,6 +3700,7 @@ package-menu-filter-by-name
 Show only those items whose name matches the regular expression
 NAME.  If NAME is nil or the empty string, show all packages."
   (interactive (list (read-from-minibuffer "Filter by name (regexp): ")))
+  (package--ensure-package-menu-mode)
   (if (or (not name) (string-empty-p name))
       (package-show-package-list t nil)
     ;; Update `tabulated-list-entries' so that it contains all
@@ -3707,6 +3718,7 @@ package-menu-filter-by-name
 (defun package-menu-clear-filter ()
   "Clear any filter currently applied to the \"*Packages*\" buffer."
   (interactive)
+  (package--ensure-package-menu-mode)
   (package-menu--generate t t))
 
 (defun package-list-packages-no-fetch ()
-- 
2.23.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* bug#37891: [PATCH] Clean up error on wrong major mode in package-menu-mode
  2019-10-23 16:09 bug#37891: [PATCH] Clean up error on wrong major mode in package-menu-mode Stefan Kangas
@ 2019-11-07  3:14 ` Stefan Kangas
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Kangas @ 2019-11-07  3:14 UTC (permalink / raw)
  To: 37891

close 37891 27.1
thanks

Stefan Kangas <stefan@marxist.se> writes:

> Four package-menu-mode specific commands currently signal an error if
> called when not in package-menu-mode.  One of them uses 'user-error',
> the others 'error'.  All other commands don't signal an error.
>
> The attached patch makes the behaviour more consistent by:
> 1) Factoring out the error signalling into a new function to make it
> more consistent.
> 2) Calling this function in all other relevant package-mode-menu commands.
>
> Any comments?

No comments in 14 days; now pushed to master as commit ddb797cf4c.

Best regards,
Stefan Kangas





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-07  3:14 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-23 16:09 bug#37891: [PATCH] Clean up error on wrong major mode in package-menu-mode Stefan Kangas
2019-11-07  3:14 ` Stefan Kangas

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).