Skip to content

Fix tab completion appending quote - #782

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:fix_quoted_tab_complete
Nov 25, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:fix_quoted_tab_complete

Conversation

@tompng

@tompng tompng commented Nov 25, 2024

Copy link
Copy Markdown
Member

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('> ')

@ima1zumi ima1zumi left a comment

Copy link
Copy Markdown
Member

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
@tompng
tompng deleted the fix_quoted_tab_complete branch November 25, 2024 17:39
Comment thread lib/reline/line_editor.rb

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
Copy Markdown
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
Copy Markdown
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cannot tab-complete quoted words

3 participants