Repository navigation
Conversation
Ctrlp accepts an override to its built-in match func. It would be nice if custom matchers could conditionally fall back to the built-in search. It would allow for smaller, cleaner matchers that only run in some cases. As a concrete example: I'm in a monorepo with ~200k+ files. I'd like to register a matcher that uses [fzy](https://github.com/Prajjwal/ctrlp.vim.git), but only in `path` mode because that is where the fzy algorithm shines. For other modes, it should fall back to ctrlp's built-in. **Implementation:** Supply an optional `match_if` predicate, which ctrlp uses at runtime to decide whether the matcher should run. For backwards compatibility, the matcher runs unconditionally if the predicate is absent. ```vimscript fu! MatchFzy(items, str, limit, mmode, ispath, crfile, regex) return systemlist("fzy -e '" . a:str . "' | head -n " . a:limit, a:items) endfu fu! ShouldMatchFzy(items, str, limit, mmode, ispath, crfile, regex) return a:mmode == "full-line" endfu let g:ctrlp_match_func = { 'match': 'MatchFzy', 'match_if': 'ShouldMatchFzy' } ``` **Other considerations:** An alternative approach would be to have the custom matcher return a sentinel value (as opposed to a list) that functions as a `skip` signal to ctrlp. I did not go that route because it seems like poor design, but I'm open to input. The rest of the plugin is currently unaware of this, and relies on a bunch of manual checks of the form `s:matcher == {}` throughout. That's a slightly larger refactor, though, and I'll wait until there's interest in merging this before implementing.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ctrlp accepts an override to its built-in match func. It would be nice if custom matchers could conditionally fall back to the built-in search. It would allow for smaller, cleaner matchers that only run in some cases.
As a concrete example:
I'm in a monorepo with ~200k+ files. I'd like to register a matcher that uses fzy, but only in
pathmode because that is where the fzy algorithm shines. For other modes, it should fall back to ctrlp's built-in.Implementation:
Supply an optional
match_ifpredicate, which ctrlp uses at runtime to decide whether the matcher should run. For backwards compatibility, the matcher runs unconditionally if the predicate is absent.Other considerations:
An alternative approach would be to have the custom matcher return a sentinel value (as opposed to a list) that functions as a
skipsignal to ctrlp. I did not go that route because it seems like poor design, but I'm open to input.The rest of the plugin is currently unaware of this, and relies on a bunch of manual checks of the form
s:matcher == {}throughout. That's a larger refactor, though, and I'll wait until there's interest in merging this before implementing.TODO: