[Top][All Lists]

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

[elpa] master 4898a5e 272/399: counsel.el (counsel-compile): better hand

From: Oleh Krehel
Subject: [elpa] master 4898a5e 272/399: counsel.el (counsel-compile): better handling for counsel--get-build-subdirs
Date: Sat, 20 Jul 2019 14:57:38 -0400 (EDT)

branch: master
commit 4898a5e5b89d69ae1ecc5202771ba36fd32c08f6
Author: Alex Bennée <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-compile): better handling for counsel--get-build-subdirs
    It is possible the user might actually just have a single build
    directory rather than a hierarchy. We can handle this case by simply
    adding the probed directory to the list if we detect any non-directory
    files in the directory. While we are at it we shouldn't be returning
    any non-directories so filter those out.
 counsel.el | 22 +++++++++++++++++-----
 1 file changed, 17 insertions(+), 5 deletions(-)

diff --git a/counsel.el b/counsel.el
index 660a749..4f81731 100644
--- a/counsel.el
+++ b/counsel.el
@@ -5418,11 +5418,23 @@ subdirectories that builds may be invoked in."
 (defun counsel--get-build-subdirs (blddir)
-  "Return all subdirs of BLDDIR sorted by modification time."
-  (mapcar #'car (sort (directory-files-and-attributes
-                       blddir t directory-files-no-dot-files-regexp t)
-                      (lambda (x y)
-                        (time-less-p (nth 6 y) (nth 6 x))))))
+  "Return all subdirs under BLDDIR sorted by modification time.
+If there are non-directory files in BLDDIR we also return BLDDIR in
+  the list as it may also be a build directory."
+  (let* ((files (directory-files-and-attributes
+                 blddir t directory-files-no-dot-files-regexp t))
+         (filtered-files (cl-remove-if
+                          (lambda (f) (not (nth 1 f)))
+                          files)))
+    ;; any non-dir files?
+    (when (< (length filtered-files)
+             (length files))
+      (push (cons blddir (file-attributes blddir))
+            filtered-files))
+    (mapcar #'car
+            (sort filtered-files
+                  (lambda (x y)
+                    (time-less-p (nth 6 y) (nth 6 x)))))))
 (defun counsel-compile-get-build-directories (&optional dir)
   "Return a list of potential build directories."

reply via email to

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