Allow skipping completion suggestions when buffer matches a pattern

Set ZSH_AUTOSUGGEST_COMPLETION_IGNORE to a glob pattern to have the
completion suggestion strategy never make suggestions when the buffer
matches the pattern.

This can be helpful when some completion routines you have are
particularly expensive and you want to prevent them from running
automatically on every keystroke.

See GitHub issue #463.
This commit is contained in:
Eric Freese
2019-12-15 08:07:59 -07:00
parent bdbe43e667
commit 7afb7364f1
4 changed files with 42 additions and 1 deletions

View File

@@ -5,7 +5,9 @@ describe 'the `completion` suggestion strategy' do
session.
run_command('autoload compinit && compinit').
run_command('_foo() { compadd bar; compadd bat }').
run_command('compdef _foo baz')
run_command('_num() { compadd two; compadd three }').
run_command('compdef _foo baz').
run_command('compdef _num one')
end
end
@@ -37,6 +39,21 @@ describe 'the `completion` suggestion strategy' do
end
end
context 'when ZSH_AUTOSUGGEST_COMPLETION_IGNORE is set to a pattern' do
let(:options) { ['ZSH_AUTOSUGGEST_STRATEGY=completion', 'ZSH_AUTOSUGGEST_COMPLETION_IGNORE="one *"'] }
it 'makes suggestions when the buffer does not match the pattern' do
session.send_string('baz ')
wait_for { session.content }.to eq('baz bar')
end
it 'does not make suggestions when the buffer matches the pattern' do
session.send_string('one t')
sleep 1
expect(session.content).to eq('one t')
end
end
context 'when async mode is enabled' do
let(:options) { ['ZSH_AUTOSUGGEST_USE_ASYNC=true', 'ZSH_AUTOSUGGEST_STRATEGY=completion'] }