The idea is to split the list to 3 parts and to sort each of them by version-list-< separately (but I am not sure which combination of preference is correct) and to flatten at the end

((VC packages) (builtin packages) (the rest))

I use (package-vc-p p1) and (assq p1 package--builtins) predicates for splitting (not sure for builtin). The code below needs refactoring.

(require 'cl)
(defun package--get-activatable-pkg (pkg-name)
  ;; Is "activatable" a word?
  (let ((pkg-descs
         (flatten-list
          (mapcar (lambda (x)
                    (sort x
                          (lambda (p1 p2)
                            (let ((v1 (package-desc-version p1))
                                  (v2 (package-desc-version p2)))
                              (version-list-< v2 v1)))))
                  (let ((y (reduce
                            (lambda (p1 p2)
                              (if (package-vc-p p1)
                                  (push p1 (first p2))
                                (push p1 (second p2)))
                              p2)
                            (cdr (assq pkg-name package-alist))
                            :initial-value (list nil nil)
                            :from-end t)))
                    (append (list (car y))
                            (reduce
                             (lambda (p1 p2)
                               (if (assq p1 package--builtins)
                                   (push p1 (first p2))
                                 (push p1 (second p2))
                                 p2))
                             (cadr y)
                             :initial-value (list nil nil)
                             :from-end t)))))))
    ;; Check if PACKAGE is available in `package-alist'.
    (while
        (when pkg-descs
          (let ((available-version (package-desc-version (car pkg-descs))))
            (package-disabled-p pkg-name available-version)))
      (setq pkg-descs (cdr pkg-descs)))
    (car pkg-descs)))



On Sat, Jun 3, 2023 at 9:50 PM Евгений Бойков <artscan@list.ru> wrote:
The fix above will not work.

I can do it for "Prefer VC packages" only:

(require 'cl)
(defun package--get-activatable-pkg (pkg-name)
  ;; Is "activatable" a word?
  (let ((pkg-descs
         (flatten-list
          (mapcar (lambda (x)
                    (sort x
                          (lambda (p1 p2)
                            (let ((v1 (package-desc-version p1))
                                  (v2 (package-desc-version p2)))
                              (version-list-< v2 v1)))))
                  (reduce
                   (lambda (p1 p2)
                     (if (package-vc-p p1)
                         (push p1 (first p2))
                       (push p1 (second p2)))
                     p2)
                   (cdr (assq pkg-name package-alist))
                   :initial-value (list nil nil)
                   :from-end t)))))
    ;; Check if PACKAGE is available in `package-alist'.
    (while
        (when pkg-descs
          (let ((available-version (package-desc-version (car pkg-descs))))
            (package-disabled-p pkg-name available-version)))
      (setq pkg-descs (cdr pkg-descs)))
    (car pkg-descs)))


Still can't for "Prefer builtin packages".


On Sat, Jun 3, 2023 at 8:37 PM Eli Zaretskii <eliz@gnu.org> wrote:
> From: Philip Kaludercic <philipk@posteo.net>
> Cc: Евгений Бойков <artscan@list.ru>,
>   63757@debbugs.gnu.org,  Stefan
>  Monnier <monnier@iro.umontreal.ca>
> Date: Sat, 03 Jun 2023 10:19:24 +0000
>
> > Won't this work:
> >
> > diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el
> > index 01826da273d..7eb185e7042 100644
> > --- a/lisp/emacs-lisp/package.el
> > +++ b/lisp/emacs-lisp/package.el
> > @@ -927,7 +927,9 @@ package--get-activatable-pkg
> >                                (package-vc-p p2)
> >                                ;; Prefer builtin packages.
> >                                (package-disabled-p p1 v1)
> > -                              (not (package-disabled-p p2 v2))))))))
> > +                              (not (package-disabled-p p2 v2))
> > +                              ;; Prever newer packages
> > +                              (version-list-< v2 v1)))))))
> >      ;; Check if PACKAGE is available in `package-alist'.
> >      (while
> >          (when pkg-descs
>
> Ping?

If there's no response, and you think this is the right fix, we can
simply install it, I guess.


--
__________________________

С уважением,
Бойков Евгений Алексеевич
сот. 8-924-202-25-65
e-mail: artscan@list.ru


--
__________________________

С уважением,
Бойков Евгений Алексеевич
сот. 8-924-202-25-65
e-mail: artscan@list.ru