Skip to content

Commit

Permalink
Separate calling completion proc with checking args
Browse files Browse the repository at this point in the history
  • Loading branch information
aycabta committed Aug 15, 2021
1 parent d18d86b commit 3203cb9
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/reline/line_editor.rb
Expand Up @@ -1165,7 +1165,13 @@ def input_key(key)

def call_completion_proc
result = retrieve_completion_block(true)
preposing, target, postposing = result
pre, target, post = result
result = call_completion_proc_with_checking_args(pre, target, post)
Reline.core.instance_variable_set(:@completion_quote_character, nil)
result
end

private def call_completion_proc_with_checking_args(pre, target, post)
if @completion_proc and target
argnum = @completion_proc.parameters.inject(0) { |result, item|
case item.first
Expand All @@ -1179,12 +1185,11 @@ def call_completion_proc
when 1
result = @completion_proc.(target)
when 2
result = @completion_proc.(target, preposing)
result = @completion_proc.(target, pre)
when 3..Float::INFINITY
result = @completion_proc.(target, preposing, postposing)
result = @completion_proc.(target, pre, post)
end
end
Reline.core.instance_variable_set(:@completion_quote_character, nil)
result
end

Expand Down

0 comments on commit 3203cb9

Please sign in to comment.