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

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

Merged
merged 1 commit into from
May 5, 2024

Conversation

tompng
Copy link
Member

@tompng tompng commented May 3, 2024

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
@@ -235,7 +235,6 @@ def reset_variables(prompt = '', encoding:)
@vi_waiting_operator_arg = nil
@completion_journey_state = nil
@completion_state = CompletionState::NORMAL
@completion_occurs = false
Copy link
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?

Copy link
Member Author

@tompng tompng May 5, 2024

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
Member

Choose a reason for hiding this comment

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

I see. Thanks!

end
elsif Symbol === key.char and respond_to?(key.char, true)

if key.char.is_a?(Symbol)
Copy link
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
40 checks passed
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
Development

Successfully merging this pull request may close these issues.

2 participants