…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.
This ensures the most recent history items appears first on the suggestions list.
We can't recover the current build directory when the user invokes M-i so let's track it in a variable. The user still has to delete the extra verbiage but at least won't be surprised about where the command is run.
How important is it to stat each file only once? If the answer is "not very", I think we can further simplify as follows:
diff --git a/counsel.el b/counsel.el index 86e5264..339eb51 100644 --- a/counsel.el +++ b/counsel.el @@ -5425,15 +5425,14 @@ counsel--get-build-subdirs "Return all subdirs under BLDDIR sorted by modification time. If there are non-directory files in BLDDIR, include BLDDIR in the list as it may also be a build directory." - (let* ((files (directory-files-and-attributes + (let* ((files (directory-files blddir t directory-files-no-dot-files-regexp t)) - (dirs (cl-remove-if-not #'cl-second files))) + (dirs (cl-remove-if-not #'file-directory-p files))) ;; Any non-dir files? (when (< (length dirs) (length files)) - (push (cons blddir (file-attributes blddir)) dirs)) - (mapcar #'car (sort dirs (lambda (x y) - (time-less-p (nth 6 y) (nth 6 x))))))) + (push blddir dirs)) + (sort dirs #'file-newer-than-file-p))) (defun counsel-compile-get-build-directories (&optional dir) "Return a list of potential build directories."
astoff added a commit to astoff/swiper that referenced this issue
Jan 1, 2021
We can't recover the current build directory when the user invokes M-i so let's track it in a variable. The user still has to delete the extra verbiage but at least won't be surprised about where the command is run. Fixes abo-abo#2077
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments.