Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tab completion appending quote #782

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented Nov 25, 2024

Fixes #444

When complecion candidates are %w[foo bar baz]

input before tab complete master this pull request readline-ext
x = "f█ x = "f"█ x = "foo"█ same
x = 'f█ x = 'f'█ x = 'foo'█ same
x = "b█ x = "b"█ x = "ba█ same
["a", "f█ ["a", "f"█ ["a", "foo"█ same
["a"b", "f█ ["a"b", "f█ ["a"b", "foo█ ["a"b", "foo"█
["a\"b", "f█ ["a\"b", "f"█ ["a\"b", "foo"█ same
x = "f█ bar baz x = "f"█ bar baz x = "foo█ bar baz same
require 'readline'
Readline.completion_proc = proc { |word,preposing|
  %w[foo bar baz].select { |w| w.start_with?(word) }
}
Readline.readline('> ')

Copy link
Member

@ima1zumi ima1zumi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@ima1zumi ima1zumi merged commit cbf2132 into ruby:master Nov 25, 2024
44 of 46 checks passed
@tompng tompng deleted the fix_quoted_tab_complete branch November 25, 2024 17:39
@@ -578,8 +578,9 @@ def context
@context
end

def retrieve_completion_block(set_completion_quote_character = false)
@line_editor.retrieve_completion_block(set_completion_quote_character)
def retrieve_completion_block(_unused = false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we ever use its argument?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left the parameter because this is exposed to DialogProcScope like this.

# This is possible
Reline.add_dialog_proc(:dialogname, ->{
  p retrieve_completion_block(true)
  nil
})

But code searching in github, it looks like this method is not used yet. I think we can remove the parameter.

I didn't confirm yet, but this method itself might be useful to use from IRB to reduce this hack
https://github.com/ruby/irb/blob/84366b8cdd7ac4c200a03405a07ed074aff5ae23/lib/irb/input-method.rb#L302-L305
Hack that stores @completion_params in completion_proc and read it from dialog_proc

@ima1zumi ima1zumi added the bug Something isn't working label Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Development

Successfully merging this pull request may close these issues.

Cannot tab-complete quoted words
3 participants