[Top][All Lists]

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

[elpa] externals/vertico bf727c2: vertico--recompute-candidates: Extract

From: ELPA Syncer
Subject: [elpa] externals/vertico bf727c2: vertico--recompute-candidates: Extract vertico--filter-files
Date: Wed, 14 Jul 2021 17:57:22 -0400 (EDT)

branch: externals/vertico
commit bf727c25a7f069f8c6167d45c9c88f16f9c6b9e9
Author: Daniel Mendler <mail@daniel-mendler.de>
Commit: Daniel Mendler <mail@daniel-mendler.de>

    vertico--recompute-candidates: Extract vertico--filter-files
    Show hidden files only when all other files have been filtered out.
    This is the behavior of the `completion-pcm--filename-try-filter`.
 vertico.el | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/vertico.el b/vertico.el
index 7464f9e..9213f4c 100644
--- a/vertico.el
+++ b/vertico.el
@@ -34,8 +34,9 @@
 ;;; Code:
 (require 'seq)
-(require 'cl-lib)
-(eval-when-compile (require 'subr-x))
+  (require 'cl-lib)
+  (require 'subr-x))
 (defgroup vertico nil
   "VERTical Interactive COmpletion."
@@ -295,6 +296,13 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
   "Return the sorting function given the completion METADATA."
   (or (completion-metadata-get metadata 'display-sort-function) 
+(defun vertico--filter-files (files)
+  "Filter FILES by `completion-ignored-extensions'."
+  (let ((re (concat "\\(?:\\(?:\\`\\|/\\)\\.\\.?/\\|"
+                    (regexp-opt completion-ignored-extensions)
+                    "\\)\\'")))
+    (or (seq-remove (lambda (x) (string-match-p re x)) files) files)))
 (defun vertico--recompute-candidates (pt content bounds metadata)
   "Recompute candidates given PT, CONTENT, BOUNDS and METADATA."
   (pcase-let* ((field (substring content (car bounds) (+ pt (cdr bounds))))
@@ -312,10 +320,7 @@ The function is configured by BY, BSIZE, BINDEX, BPRED and 
     ;; since this breaks the special casing in the 
`completion-file-name-table' for `file-exists-p'
     ;; and `file-directory-p'.
     (when completing-file
-      (let ((ignore (concat "\\(?:\\`\\|/\\)\\.?\\./\\'"
-                            (and completion-ignored-extensions
-                                 (concat "\\|" (regexp-opt 
completion-ignored-extensions) "\\'")))))
-        (setq all (cl-delete-if (lambda (x) (string-match-p ignore x)) all))))
+      (setq all (vertico--filter-files all)))
     ;; Sort using the `display-sort-function' or the Vertico sort functions
     (unless (memq sort '(nil identity))
       (vertico--update-history-hash (substring content 0 base))

reply via email to

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