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

Provide option for tab to apply completion #390

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mskar
Copy link

@mskar mskar commented Oct 4, 2020

In #387, I requested a feature that adds parentheses after functions completed with Tab or Enter.
This pull request implements the feature I requested (function completion with added parentheses), but also strives to make autocompletion work like in the VSCode Python extension and PyCharm. In VSCode and PyCharm, Tab applies completion instead of cycling through completion options, like in bash or zsh.

TLDR:

previous behavior:

  • Tab cycles completion
  • function completion does not add parentheses

proposed behavior:

  • Tab applies completion
  • function completion adds parentheses

Currently, this feature is enabled by default, but it can be disabled using by adding

repl.tab_apply_completion = False

to config.py.

For more information, please take a look at this comment in #387.

To install ptpython with the tab_apply_completion feature, run

python -m pip install git+https://github.com/mskar/ptpython.git@tab_apply_completion

Changes:

Changed: when triggering completion with Tab, insert text that all options have in common
Changed: use Tab to accept only option or accept selected
Changed: do not move through options with not Tab and Shift-Tab
Unchanged: use Enter to accept if completion menu is showing
Unchanged: move through options with c-n and c-p
Unchanged: cancel completion with c-g

@mskar mskar force-pushed the tab_apply_completion branch 7 times, most recently from c3b2aee to 1b4fc38 Compare October 7, 2020 04:06
@mskar mskar force-pushed the tab_apply_completion branch 3 times, most recently from 6afc560 to f1721f4 Compare October 10, 2020 21:28
@mskar mskar force-pushed the tab_apply_completion branch 4 times, most recently from e8c3bf3 to 7dd79e0 Compare October 17, 2020 22:52
improve completion when completion menu is not showing

improve apply completion with enter

improve completion with enter in ptpython
@mskar
Copy link
Author

mskar commented Oct 18, 2020

I split the original feature into 5 independent features.
Each feature has its own setting (disabled by default) to allow for granular control of completion behavior:

  1. enable_auto_complete_function_parentheses:
  • Tab: Unchanged unless combined with one of the settings that end in _option_on_tab.
  • Enter: Accepts selected completion and add parentheses to functions
  1. enable_auto_complete_selected_option_on_tab:
  • Tab: Accepts the selected completion option if an option is selected
  • Enter: Unchanged
  1. enable_auto_complete_top_option_on_enter:
  • Tab: Unchanged
  • Enter: Accepts the first completion option if the completion menu is showing
  1. enable_auto_complete_top_option_on_tab:
  • Tab: Accepts the first completion option if the completion menu is showing and no option is selected
  • Enter: Unchanged
  1. enable_auto_complete_only_option_on_tab:
  • Tab: Accepts completion if there is only one completion option or starts completion if there are multiple options
  • Enter: Unchanged

These features can be combined.
Enabling all of the features makes completion behave like in PyCharm and VSCode.

Is 5 settings too many?
Would it be a good idea to add another setting that combined 2-5 (enable_auto_complete_[selected,top,only]_option_on_[tab,enter])?

Please let me know if any of the settings should be renamed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants