emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master 62bf0b7a571: Merge commit 'new-fix-for-bug-60819'


From: Stefan Monnier
Subject: master 62bf0b7a571: Merge commit 'new-fix-for-bug-60819'
Date: Wed, 20 Dec 2023 18:38:14 -0500 (EST)

branch: master
commit 62bf0b7a571fd8ccf179d2594adf9b61727a7aea
Merge: 7275cecdf95 6cc1418fc3e
Author: Stefan Monnier <monnier@iro.umontreal.ca>
Commit: Stefan Monnier <monnier@iro.umontreal.ca>

    Merge commit 'new-fix-for-bug-60819'
---
 lisp/files.el            | 55 +++++++++++++++++++++++++++---------------------
 lisp/ls-lisp.el          | 16 +-------------
 test/lisp/files-tests.el |  4 ++++
 3 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 21f3376016c..cc15f50103f 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -7547,35 +7547,42 @@ default directory.  However, if FULL is non-nil, they 
are absolute."
           ;; if DIRPART contains wildcards.
           (dirs (if (and dirpart
                          (string-match "[[*?]" (file-local-name dirpart)))
-                    (mapcar 'file-name-as-directory
+                    (mapcar #'file-name-as-directory
                             (file-expand-wildcards
                               (directory-file-name dirpart) nil regexp))
                   (list dirpart)))
           contents)
-      (dolist (dir dirs)
+      (dolist (dir (nreverse dirs))
        (when (or (null dir)    ; Possible if DIRPART is not wild.
                  (file-accessible-directory-p dir))
-         (let ((this-dir-contents
-                ;; Filter out "." and ".."
-                (delq nil
-                       (mapcar (lambda (name)
-                                 (unless (string-match "\\`\\.\\.?\\'"
-                                                       (file-name-nondirectory 
name))
-                                   name))
-                              (directory-files
-                                (or dir ".") full
-                                (if regexp
-                                    ;; We're matching each file name
-                                    ;; element separately.
-                                    (concat "\\`" nondir "\\'")
-                                 (wildcard-to-regexp nondir)))))))
-           (setq contents
-                 (nconc
-                  (if (and dir (not full))
-                       (mapcar (lambda (name) (concat dir name))
-                              this-dir-contents)
-                    this-dir-contents)
-                  contents)))))
+          (if (equal "" nondir)
+              ;; `nondir' is "" when the pattern ends in "/".  Basically ""
+              ;; refers to the directory itself, like ".", but it's not
+              ;; among the names returned by `directory-files', so we have
+              ;; to special-case it.
+              (push (or dir nondir) contents)
+           (let ((this-dir-contents
+                  ;; Filter out "." and ".."
+                  (delq nil
+                         (mapcar (lambda (name)
+                                   (unless (string-match "\\`\\.\\.?\\'"
+                                                         
(file-name-nondirectory
+                                                          name))
+                                     name))
+                                (directory-files
+                                  (or dir ".") full
+                                  (if regexp
+                                      ;; We're matching each file name
+                                      ;; element separately.
+                                      (concat "\\`" nondir "\\'")
+                                  (wildcard-to-regexp nondir)))))))
+             (setq contents
+                   (nconc
+                    (if (and dir (not full))
+                        (mapcar (lambda (name) (concat dir name))
+                                this-dir-contents)
+                      this-dir-contents)
+                    contents))))))
       contents)))
 
 (defcustom find-sibling-rules nil
@@ -7765,7 +7772,7 @@ need to be passed verbatim to shell commands."
     (purecopy "ls"))
   "Absolute or relative name of the `ls'-like program.
 This is used by `insert-directory' and `dired-insert-directory'
-(thus, also by `dired').  For Dired, this should ideally point to
+\(thus, also by `dired').  For Dired, this should ideally point to
 GNU ls, or another version of ls that supports the \"--dired\"
 flag.  See `dired-use-ls-dired'.
 
diff --git a/lisp/ls-lisp.el b/lisp/ls-lisp.el
index c576819c5d0..1066f38c050 100644
--- a/lisp/ls-lisp.el
+++ b/lisp/ls-lisp.el
@@ -483,22 +483,8 @@ not contain `d', so that a full listing is expected."
       (if (not dir-wildcard)
           (funcall orig-fun dir-or-list switches)
         (let* ((default-directory (car dir-wildcard))
-               (wildcard (cdr dir-wildcard))
-               (files (file-expand-wildcards wildcard))
+               (files (file-expand-wildcards (cdr dir-wildcard)))
                (dir (car dir-wildcard)))
-          ;; When the wildcard ends in a slash, file-expand-wildcards
-          ;; returns nil; fix that by treating the wildcards as
-          ;; specifying only directories whose names match the
-          ;; widlcard.
-          (if (and (null files)
-                   (directory-name-p wildcard))
-              (setq files
-                    (delq nil
-                          (mapcar (lambda (fname)
-                                   (if (file-accessible-directory-p fname)
-                                        fname))
-                                 (file-expand-wildcards
-                                   (directory-file-name wildcard))))))
           (if files
               (let ((inhibit-read-only t)
                     (buf
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 3e499fff468..24b144c4247 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -2101,5 +2101,9 @@ Prompt users for any modified buffer with 
`buffer-offer-save' non-nil."
       (should (documentation 'bar))
       (should (documentation 'zot)))))
 
+(ert-deftest files-tests--expand-wildcards ()
+  (should (file-expand-wildcards
+           (concat (directory-file-name default-directory) "*/"))))
+
 (provide 'files-tests)
 ;;; files-tests.el ends here



reply via email to

[Prev in Thread] Current Thread [Next in Thread]