emacs-elpa-diffs
[Top][All Lists]
Advanced

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

[elpa] master 4d533b2 178/184: counsel.el (counsel-dired): Filter to dir


From: Oleh Krehel
Subject: [elpa] master 4d533b2 178/184: counsel.el (counsel-dired): Filter to directories only
Date: Wed, 16 Oct 2019 13:15:18 -0400 (EDT)

branch: master
commit 4d533b25bdb7e8335ce47e64c4c357957317e1a1
Author: Hong Xu <address@hidden>
Commit: Oleh Krehel <address@hidden>

    counsel.el (counsel-dired): Filter to directories only
    
    Allow `counsel-find-file' to accept a file with its type limited to
    regular files or directories.
    
    It also enables more features in ivy in a directory selector in the
    future than `read-directory-name' (e.g., #1646).
    
    Fixes #2275
---
 counsel.el | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/counsel.el b/counsel.el
index efac1ee..8f92523 100644
--- a/counsel.el
+++ b/counsel.el
@@ -1880,6 +1880,9 @@ but the leading dot is a lot faster."
                  ,(regexp-opt completion-ignored-extensions))
           (regexp :tag "Regex")))
 
+(defvar counsel--find-file-predicate nil
+  "When non-nil, `counsel--find-file-matcher' will use this predicate.")
+
 (defun counsel--find-file-matcher (regexp candidates)
   "Return REGEXP matching CANDIDATES.
 Skip some dotfiles unless `ivy-text' requires them."
@@ -1889,6 +1892,9 @@ Skip some dotfiles unless `ivy-text' requires them."
           (lambda (re-str)
             (lambda (x)
               (string-match re-str (directory-file-name x)))))))
+    (when counsel--find-file-predicate
+      (let ((default-directory ivy--directory))
+        (setq res (cl-remove-if-not counsel--find-file-predicate res))))
     (if (or (null ivy-use-ignore)
             (null counsel-find-file-ignore-regexp)
             (string-match-p "\\`\\." ivy-text))
@@ -2183,10 +2189,11 @@ result as a URL."
   "Forward to `dired'.
 When INITIAL-INPUT is non-nil, use it in the minibuffer during completion."
   (interactive)
-  (counsel--find-file-1
-   "Dired (directory): " initial-input
-   (lambda (d) (dired (expand-file-name d)))
-   'counsel-dired))
+  (let ((counsel--find-file-predicate #'file-directory-p))
+    (counsel--find-file-1
+     "Dired (directory): " initial-input
+     (lambda (d) (dired (expand-file-name d)))
+     'counsel-dired)))
 
 (ivy-configure 'counsel-dired
   :display-transformer-fn #'ivy-read-file-transformer)



reply via email to

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