cp-find-file, cp: New custom variable cp-find-file-more-chars

Fixes #151
This commit is contained in:
Eric Danan 2020-10-13 16:17:47 +01:00
parent bd30664bd6
commit dafa9bfeb8
2 changed files with 18 additions and 3 deletions

View file

@ -319,7 +319,9 @@ If you want some initial input to be inserted in the minibuffer every time you c
## Matcher for `counsel-projectile-find-file`
By default, the command `counsel-projectile-find-file` relies on the the matcher of the command `counsel-find-file` to display files matching minibuffer input, allowing to ignore some files based on the variable `counsel-find-file-ignore-regexp`. It is possible to use another matcher by setting the variable `counsel-projectile-find-file-matcher`. Some choices are proposed if you use the Customize interface, in particular the `counsel-projectile-find-file-matcher-basename` matcher which is provided by counsel-projectile and only displays files whose basename matches the minibuffer input (if there is none, it shows all matching files).
The matcher specified by `counsel-find-file-ignore-regexp` is also used by `counsel-projectile` to match files.
Independently of the chosen matcher, it is possible to specifying a minimum number of characters to input before the matching project files are shown through the variable `counsel-projectile-find-file-more-chars`. The default value is `0`, but a strictly positive value can improve performance in large projects.
The values of `counsel-projectile-find-file-matcher` and `counsel-projectile-find-file-more-chars` are also used by `counsel-projectile` to match files.
## Sorting candidates
The following commands allow to modify the way candidates are sorted:
- `cousnel-projectile-switch-project`

View file

@ -283,6 +283,13 @@ It is also possible to use a custom matcher. It must be a function taking two a
(function :tag "Custom function"))
:group 'counsel-projectile)
(defcustom counsel-projectile-find-file-more-chars 0
"Number of characters to input before matching project files are shown.
Setting it to a strictly positive value can improve performance in large projects."
:type 'integer
:group 'counsel-projectile)
(counsel-projectile--defcustom-action
'counsel-projectile-find-file
'(1
@ -302,6 +309,12 @@ It is also possible to use a custom matcher. It must be a function taking two a
"switch project"))
'counsel-projectile)
(defun counsel-projectile--find-file-matcher (regexp candidates)
(let ((ivy-more-chars-alist
`((t . ,counsel-projectile-find-file-more-chars))))
(or (ivy-more-chars)
(funcall counsel-projectile-find-file-matcher regexp candidates))))
(defun counsel-projectile-find-file-matcher-basename (regexp candidates)
"Return the list of CANDIDATES whose basename matches REGEXP,
or if there is none the list of all CANDIDATES matching REGEXP.
@ -393,7 +406,7 @@ non-nil, use completion based on context."
(files (and dwim (projectile-select-files project-files))))
(ivy-read (projectile-prepend-project-name "Find file: ")
(or files project-files)
:matcher counsel-projectile-find-file-matcher
:matcher #'counsel-projectile--find-file-matcher
:require-match t
:sort counsel-projectile-sort-files
:action counsel-projectile-find-file-action
@ -1476,7 +1489,7 @@ Relies on `ivy--switch-buffer-matcher' for buffers and the
matcher specified in `counsel-projectile-find-file-matcher' for
files."
(append (ivy--switch-buffer-matcher regexp counsel-projectile--buffers)
(funcall counsel-projectile-find-file-matcher regexp counsel-projectile--non-visited-files)))
(counsel-projectile--find-file-matcher regexp counsel-projectile--non-visited-files)))
(defun counsel-projectile-action (name)
"Switch to buffer or find file named NAME."