Skip to content

Add name defined in readline to completion key bindings C-i C-p C-n - #698

Merged
ima1zumi merged 1 commit into
ruby:masterfrom
tompng:hardcoded_complete_key_to_method
May 5, 2024
Merged

ima1zumi merged 1 commit into
ruby:masterfrom
tompng:hardcoded_complete_key_to_method

Conversation

@tompng

@tompng tompng commented May 3, 2024 •

Copy link
Copy Markdown
Member

This pull request moves hardcoded \C-i \C-p \C-n to line_editor's method. Just like we did it to completion_journey_up.

vi: \C-n is menu-complete. moves completion even if autocomplete is off.
vi: \C-p is menu-complete-backward. moves completion backward even if autocomplete is off.
\C-i is complete. when autocomplete is enabled, it is menu-complete. unless, it is tab complete
shift-tab is completion-journey-up, a bit different from menu-complete-backward (disabled when autocomplete is off)

Naming

Readline can configure complete, menu-complete and menu-complete-backward. Uses the same name to make it configurable in irbrc. The old complete method is renamed to perform_completion.

@tompng tompng added the enhancement New feature or request label May 3, 2024
Comment thread lib/reline/line_editor.rb
@vi_waiting_operator_arg = nil
@completion_journey_state = nil
@completion_state = CompletionState::NORMAL
@completion_occurs = 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.

Why is this instance variable initialization no longer necessary?

@tompng tompng May 5, 2024 •

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.

The actual scope of @completion_occurs is very narrow. Removing this initialization will represent the narrow scope clearer.

def input_key(key)
  @completion_occurs = false # initialize here
  calls process_key() or normal_key() # completion might occur
  do_something unless @completion_occurs # use it here

  # after here, @completion_occurs is no longer necessary.
  # maybe we can remove instance variable, but I think it's too much
end

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.

I see. Thanks!

Comment thread lib/reline/line_editor.rb
end
elsif Symbol === key.char and respond_to?(key.char, true)

if key.char.is_a?(Symbol)

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.

✨✨✨

@ima1zumi
ima1zumi merged commit 1314787 into ruby:master May 5, 2024
matzbot pushed a commit to ruby/ruby that referenced this pull request May 5, 2024
@tompng
tompng deleted the hardcoded_complete_key_to_method branch May 5, 2024 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants