From d74bcd7b2ce6962a1d68564fbb4388c22914f3cc Mon Sep 17 00:00:00 2001 From: Philip Kaludercic Date: Wed, 26 Nov 2025 19:30:48 +0100 Subject: [PATCH] ; Fix order in which 'package-dir-info' searches files See https://mail.gnu.org/archive/html/emacs-devel/2025-11/msg00977.html. * lisp/emacs-lisp/package.el (package-dir-info): Sort files by length instead of by the default order. This aligns the intention, the implementation and the preceding comment. --- lisp/emacs-lisp/package.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lisp/emacs-lisp/package.el b/lisp/emacs-lisp/package.el index 3cc0f7699fa..aedde50d14d 100644 --- a/lisp/emacs-lisp/package.el +++ b/lisp/emacs-lisp/package.el @@ -1280,10 +1280,10 @@ The return result is a `package-desc'." (let ((files (or (and (derived-mode-p 'dired-mode) (dired-get-marked-files nil 'marked)) (directory-files default-directory t "\\.el\\'" t)))) - ;; We sort the file names in lexicographical order, to ensure - ;; that we check shorter file names first (ie. those further - ;; up in the directory structure). - (dolist (file (sort files)) + ;; We sort the file names by length, to ensure that we check + ;; shorter file names first, as these are more likely to + ;; contain the package metadata. + (dolist (file (sort files :key #'length)) ;; The file may be a link to a nonexistent file; e.g., a ;; lock file. (when (file-exists-p file)