diff options
| author | Artur Malabarba | 2015-04-22 09:31:16 +0100 |
|---|---|---|
| committer | Artur Malabarba | 2015-04-22 11:27:47 +0100 |
| commit | 8991937a746d2c941a4be05ae5d053df93f2537e (patch) | |
| tree | 2c656a6d06313729c0c3e78f7a64cf2d96388a7c | |
| parent | c3b41c6448f3be90667c0b8e26189226911eca52 (diff) | |
| download | emacs-8991937a746d2c941a4be05ae5d053df93f2537e.tar.gz emacs-8991937a746d2c941a4be05ae5d053df93f2537e.zip | |
* lisp/emacs-lisp/package.el: Hide lower-priority packages in menu
(package-menu-hide-low-priority): New variable, see its doc.
(package-archive-priorities): Update doc.
(package-desc-priority): New function.
(package-desc-priority-version): Use it.
(package--remove-hidden): New function.
(package-menu--refresh): Use it.
| -rw-r--r-- | lisp/emacs-lisp/package.el | 63 |
1 files changed, 59 insertions, 4 deletions
diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index f712b5b48f9..999e857346b 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el | |||
| @@ -225,6 +225,30 @@ a package can run arbitrary code." | |||
| 225 | :group 'package | 225 | :group 'package |
| 226 | :version "24.1") | 226 | :version "24.1") |
| 227 | 227 | ||
| 228 | (defcustom package-menu-hide-low-priority 'archive | ||
| 229 | "If non-nil, hide low priority packages from the packages menu. | ||
| 230 | A package is considered low priority if there's another version | ||
| 231 | of it available such that: | ||
| 232 | (a) the archive of the other package is higher priority than | ||
| 233 | this one, as per `package-archive-priorities'; | ||
| 234 | or | ||
| 235 | (b) they both have the same archive priority but the other | ||
| 236 | package has a higher version number. | ||
| 237 | |||
| 238 | This variable has three possible values: | ||
| 239 | nil: no packages are hidden; | ||
| 240 | archive: only criteria (a) is used; | ||
| 241 | t: both criteria are used. | ||
| 242 | |||
| 243 | This variable has no effect if `package-menu--hide-obsolete' is | ||
| 244 | nil, so it can be toggled with \\<package-menu-mode-map> \\[package-menu-hide-obsolete]." | ||
| 245 | :type '(choice (const :tag "Don't hide anything" nil) | ||
| 246 | (const :tag "Hide per package-archive-priorities" | ||
| 247 | archive) | ||
| 248 | (const :tag "Hide per archive and version number" t)) | ||
| 249 | :group 'package | ||
| 250 | :version "25.1") | ||
| 251 | |||
| 228 | (defcustom package-archive-priorities nil | 252 | (defcustom package-archive-priorities nil |
| 229 | "An alist of priorities for packages. | 253 | "An alist of priorities for packages. |
| 230 | 254 | ||
| @@ -235,7 +259,9 @@ number from the archive with the highest priority is | |||
| 235 | selected. When higher versions are available from archives with | 259 | selected. When higher versions are available from archives with |
| 236 | lower priorities, the user has to select those manually. | 260 | lower priorities, the user has to select those manually. |
| 237 | 261 | ||
| 238 | Archives not in this list have the priority 0." | 262 | Archives not in this list have the priority 0. |
| 263 | |||
| 264 | See also `package-menu-hide-low-priority'." | ||
| 239 | :type '(alist :key-type (string :tag "Archive name") | 265 | :type '(alist :key-type (string :tag "Archive name") |
| 240 | :value-type (integer :tag "Priority (default is 0)")) | 266 | :value-type (integer :tag "Priority (default is 0)")) |
| 241 | :risky t | 267 | :risky t |
| @@ -467,6 +493,10 @@ This is, approximately, the inverse of `version-to-list'. | |||
| 467 | (nth 1 keywords) | 493 | (nth 1 keywords) |
| 468 | keywords))) | 494 | keywords))) |
| 469 | 495 | ||
| 496 | (defun package-desc-priority (p) | ||
| 497 | "Return the priority of the archive of package-desc object P." | ||
| 498 | (package-archive-priority (package-desc-archive p))) | ||
| 499 | |||
| 470 | ;; Package descriptor format used in finder-inf.el and package--builtins. | 500 | ;; Package descriptor format used in finder-inf.el and package--builtins. |
| 471 | (cl-defstruct (package--bi-desc | 501 | (cl-defstruct (package--bi-desc |
| 472 | (:constructor package-make-builtin (version summary)) | 502 | (:constructor package-make-builtin (version summary)) |
| @@ -2471,6 +2501,32 @@ Installed obsolete packages are always displayed.") | |||
| 2471 | "Hiding" "Displaying")) | 2501 | "Hiding" "Displaying")) |
| 2472 | (revert-buffer nil 'no-confirm)) | 2502 | (revert-buffer nil 'no-confirm)) |
| 2473 | 2503 | ||
| 2504 | (defun package--remove-hidden (pkg-list) | ||
| 2505 | "Filter PKG-LIST according to `package-archive-priorities'. | ||
| 2506 | PKG-LIST must be a list of package-desc objects sorted by | ||
| 2507 | decreasing version number. | ||
| 2508 | Return a list of packages tied for the highest priority according | ||
| 2509 | to their archives." | ||
| 2510 | (when pkg-list | ||
| 2511 | ;; The first is a variable toggled with | ||
| 2512 | ;; `package-menu-hide-obsolete', the second is a static user | ||
| 2513 | ;; option that defines *what* we hide. | ||
| 2514 | (if (and package-menu--hide-obsolete | ||
| 2515 | package-menu-hide-low-priority) | ||
| 2516 | (let ((max-priority (package-desc-priority (car pkg-list))) | ||
| 2517 | (out (list (pop pkg-list)))) | ||
| 2518 | (dolist (p pkg-list (nreverse out)) | ||
| 2519 | (let ((priority (package-desc-priority p))) | ||
| 2520 | (cond | ||
| 2521 | ((> priority max-priority) | ||
| 2522 | (setq max-priority priority) | ||
| 2523 | (setq out (list p))) | ||
| 2524 | ;; This assumes pkg-list is sorted by version number. | ||
| 2525 | ((and (= priority max-priority) | ||
| 2526 | (eq package-menu-hide-low-priority 'archive)) | ||
| 2527 | (push p out)))))) | ||
| 2528 | pkg-list))) | ||
| 2529 | |||
| 2474 | (defun package-menu--refresh (&optional packages keywords) | 2530 | (defun package-menu--refresh (&optional packages keywords) |
| 2475 | "Re-populate the `tabulated-list-entries'. | 2531 | "Re-populate the `tabulated-list-entries'. |
| 2476 | PACKAGES should be nil or t, which means to display all known packages. | 2532 | PACKAGES should be nil or t, which means to display all known packages. |
| @@ -2500,7 +2556,7 @@ KEYWORDS should be nil or a list of keywords." | |||
| 2500 | (dolist (elt package-archive-contents) | 2556 | (dolist (elt package-archive-contents) |
| 2501 | (setq name (car elt)) | 2557 | (setq name (car elt)) |
| 2502 | (when (or (eq packages t) (memq name packages)) | 2558 | (when (or (eq packages t) (memq name packages)) |
| 2503 | (dolist (pkg (cdr elt)) | 2559 | (dolist (pkg (package--remove-hidden (cdr elt))) |
| 2504 | ;; Hide available obsolete packages. | 2560 | ;; Hide available obsolete packages. |
| 2505 | (when (and (not (and package-menu--hide-obsolete | 2561 | (when (and (not (and package-menu--hide-obsolete |
| 2506 | (package-installed-p (package-desc-name pkg) | 2562 | (package-installed-p (package-desc-name pkg) |
| @@ -2731,8 +2787,7 @@ defaults to 0." | |||
| 2731 | This allows for easy comparison of package versions from | 2787 | This allows for easy comparison of package versions from |
| 2732 | different archives if archive priorities are meant to be taken in | 2788 | different archives if archive priorities are meant to be taken in |
| 2733 | consideration." | 2789 | consideration." |
| 2734 | (cons (package-archive-priority | 2790 | (cons (package-desc-priority pkg-desc) |
| 2735 | (package-desc-archive pkg-desc)) | ||
| 2736 | (package-desc-version pkg-desc))) | 2791 | (package-desc-version pkg-desc))) |
| 2737 | 2792 | ||
| 2738 | (defun package-menu--find-upgrades () | 2793 | (defun package-menu--find-upgrades () |