Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Upcoming (TBD)
==============

Features
---------
* Let tab and control-space behaviors be configurable.


1.60.0 (2026/03/05)
==============

Expand Down
50 changes: 43 additions & 7 deletions mycli/key_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
)
from prompt_toolkit.key_binding import KeyBindings
from prompt_toolkit.key_binding.key_processor import KeyPressEvent
from prompt_toolkit.selection import SelectionType

from mycli.constants import DOCS_URL
from mycli.packages import shortcuts
Expand Down Expand Up @@ -120,13 +121,31 @@ def _(event: KeyPressEvent) -> None:

@kb.add("tab")
def _(event: KeyPressEvent) -> None:
"""Force autocompletion at cursor."""
"""Complete action at cursor."""
_logger.debug("Detected <Tab> key.")
b = event.app.current_buffer

behaviors = mycli.config['keys'].as_list('tab')

if 'toolkit_default' in behaviors:
if b.complete_state:
b.complete_next()
else:
b.start_completion(select_first=True)

if b.complete_state:
b.complete_next()
else:
if 'advance' in behaviors:
b.complete_next()
elif 'toggle' in behaviors:
b.cancel_completion()
return

if 'advancing_summon' in behaviors:
b.start_completion(select_first=True)
elif 'prefixing_summon' in behaviors:
b.start_completion(insert_common_part=True)
elif 'summon' in behaviors:
b.start_completion(select_first=False)

@kb.add("escape", eager=True, filter=in_completion)
def _(event: KeyPressEvent) -> None:
Expand All @@ -141,19 +160,36 @@ def _(event: KeyPressEvent) -> None:
@kb.add("c-space")
def _(event: KeyPressEvent) -> None:
"""
Initialize autocompletion at cursor.
Complete action at cursor.

If the autocompletion menu is not showing, display it with the
By default, if the autocompletion menu is not showing, display it with the
appropriate completions for the context.

If the menu is showing, select the next completion.
"""
_logger.debug("Detected <C-Space> key.")

b = event.app.current_buffer

behaviors = mycli.config['keys'].as_list('control_space')

if 'toolkit_default' in behaviors:
if b.text:
b.start_selection(selection_type=SelectionType.CHARACTERS)
return

if b.complete_state:
b.complete_next()
else:
if 'advance' in behaviors:
b.complete_next()
elif 'toggle' in behaviors:
b.cancel_completion()
return

if 'advancing_summon' in behaviors:
b.start_completion(select_first=True)
elif 'prefixing_summon' in behaviors:
b.start_completion(insert_common_part=True)
elif 'summon' in behaviors:
b.start_completion(select_first=False)

@kb.add("c-x", "p", filter=emacs_mode)
Expand Down
13 changes: 13 additions & 0 deletions mycli/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,19 @@ control_d = exit
# possible values: auto, fzf, reverse_isearch
control_r = auto

# comma-separated list: toolkit_default, summon, advancing_summon, prefixing_summon, advance, toggle
#
# * toolkit_default - ignore other behaviors and use prompt_toolkit's default bindings
# * summon - when completions are not visible, summon them
# * advancing_summon - when completions are not visible, summon them _and_ advance in the list
# * prefixing_summon - when completions are not visible, summon them _and_ insert the common prefix
# * advance - when completions are visible, advance in the list
# * toggle - when completions are visible, toggle the list off
control_space = summon, advance

# comma-separated list: toolkit_default, summon, advancing_summon, prefixing_summon, advance, toggle
tab = advancing_summon, advance

# Custom colors for the completion menu, toolbar, etc, with actual support
# depending on the terminal, and the property being set.
# Colors: #ffffff, bg:#ffffff, border:#ffffff.
Expand Down
13 changes: 13 additions & 0 deletions test/myclirc
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,19 @@ control_d = exit
# possible values: auto, fzf, reverse_isearch
control_r = auto

# comma-separated list: toolkit_default, summon, advancing_summon, prefixing_summon, advance, toggle
#
# * toolkit_default - ignore other behaviors and use prompt_toolkit's default bindings
# * summon - when completions are not visible, summon them
# * advancing_summon - when completions are not visible, summon them _and_ advance in the list
# * prefixing_summon - when completions are not visible, summon them _and_ insert the common prefix
# * advance - when completions are visible, advance in the list
# * toggle - when completions are visible, toggle the list off
control_space = summon, advance

# comma-separated list: toolkit_default, summon, advancing_summon, prefixing_summon, advance, toggle
tab = advancing_summon, advance

# Custom colors for the completion menu, toolbar, etc, with actual support
# depending on the terminal, and the property being set.
# Colors: #ffffff, bg:#ffffff, border:#ffffff.
Expand Down