Proposal to introduce "completion_filter_proc" configuration option#883
Open
amatsuda wants to merge 1 commit intoruby:masterfrom
Open
Proposal to introduce "completion_filter_proc" configuration option#883amatsuda wants to merge 1 commit intoruby:masterfrom
amatsuda wants to merge 1 commit intoruby:masterfrom
Conversation
which allows users to customize how completion candidates are filtered.
Problem it solves:
Currently, Reline hardcodes prefix matching for completion filtering -
candidates must start with the typed text. This patch makes the
filtering logic configurable, enabling alternative matching strategies
like fuzzy matching (where "fb" can match "foo_bar").
Default behavior:
When no custom proc is set, it falls back to prefix matching
(respecting completion_ignore_case) for backward compatibility.
Example usage for fuzzy matching:
Reline.completion_filter_proc = ->(target, candidate) {
idx = 0
target.each_char.all? { |c| (idx = candidate.index(c, idx)) && (idx += 1) }
}
This checks if each character in target appears in candidate in order
(but not necessarily contiguously), enabling peco/fzf-style fuzzy matching.
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.
which allows users to customize how completion candidates are filtered.
Problem it solves
Currently, Reline hardcodes prefix matching for completion filtering - candidates must start with the typed text. And that behavior cannot be changed even by specifying
completion_proc. This patch makes the filtering logic configurable, enabling alternative matching strategies like fuzzy matching (where "fb" can match "foo_bar").Default behavior
When no custom proc is set, it falls back to the current prefix matching (respecting completion_ignore_case) for backward compatibility.
Example usage for fuzzy matching
This checks if each character in target appears in candidate in order (but not necessarily contiguously), enabling peco/fzf-style fuzzy matching.
To actually play with this example feature, for instance put something like this in the command line
ruby -Ilib -rreline -e "Reline.autocompletion = true; Reline.completion_proc = ->(_) { String.instance_methods(false).sort.map(&:to_s) }; Reline.completion_filter_proc = ->(target, candidate) { idx = 0; target.each_char.all? { |c| (idx = candidate.index(c, idx)) && (idx += 1) } }; puts Reline.readline('> ')"and you can get "each_grapheme_cluster" by typing "egc". Enjoy!