diff --git a/IPython/terminal/shortcuts/__init__.py b/IPython/terminal/shortcuts/__init__.py index 09f9a15..f71ce49 100644 --- a/IPython/terminal/shortcuts/__init__.py +++ b/IPython/terminal/shortcuts/__init__.py @@ -186,12 +186,12 @@ AUTO_SUGGEST_BINDINGS = [ # 2) prompt-toolkit checks if we are at the end of text, not end of line # hence it does not work in multi-line mode of navigable provider Binding( - auto_suggest.accept_in_vi_insert_mode, + auto_suggest.accept_or_jump_to_end, ["end"], "has_suggestion & default_buffer_focused & emacs_like_insert_mode", ), Binding( - auto_suggest.accept_in_vi_insert_mode, + auto_suggest.accept_or_jump_to_end, ["c-e"], "has_suggestion & default_buffer_focused & emacs_like_insert_mode", ), diff --git a/IPython/terminal/shortcuts/auto_suggest.py b/IPython/terminal/shortcuts/auto_suggest.py index 6c2b4ff..93c1fa4 100644 --- a/IPython/terminal/shortcuts/auto_suggest.py +++ b/IPython/terminal/shortcuts/auto_suggest.py @@ -2,6 +2,7 @@ import re import tokenize from io import StringIO from typing import Callable, List, Optional, Union, Generator, Tuple +import warnings from prompt_toolkit.buffer import Buffer from prompt_toolkit.key_binding import KeyPressEvent @@ -192,7 +193,7 @@ def accept_or_jump_to_end(event: KeyPressEvent): nc.end_of_line(event) -def accept_in_vi_insert_mode(event: KeyPressEvent): +def _deprected_accept_in_vi_insert_mode(event: KeyPressEvent): """Accept autosuggestion or jump to end of line. .. deprecated:: 8.12 @@ -381,3 +382,16 @@ def swap_autosuggestion_down(event: KeyPressEvent): provider=provider, direction_method=provider.down, ) + + +def __getattr__(key): + if key == "accept_in_vi_insert_mode": + warnings.warn( + "`accept_in_vi_insert_mode` is deprecated since IPython 8.12 and " + "renamed to `accept_or_jump_to_end`. Please update your configuration " + "accordingly", + DeprecationWarning, + stacklevel=2, + ) + return _deprected_accept_in_vi_insert_mode + raise AttributeError diff --git a/IPython/terminal/tests/test_shortcuts.py b/IPython/terminal/tests/test_shortcuts.py index 18c9dab..45bb327 100644 --- a/IPython/terminal/tests/test_shortcuts.py +++ b/IPython/terminal/tests/test_shortcuts.py @@ -1,7 +1,7 @@ import pytest from IPython.terminal.shortcuts.auto_suggest import ( accept, - accept_in_vi_insert_mode, + accept_or_jump_to_end, accept_token, accept_character, accept_word, @@ -22,6 +22,13 @@ from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from unittest.mock import patch, Mock +def test_deprected(): + import IPython.terminal.shortcuts.auto_suggest as iptsa + + with pytest.warns(DeprecationWarning, match=r"8\.12.+accept_or_jump_to_end"): + iptsa.accept_in_vi_insert_mode + + def make_event(text, cursor, suggestion): event = Mock() event.current_buffer = Mock() @@ -80,7 +87,7 @@ def test_autosuggest_at_EOL(text, cursor, suggestion, called): event = make_event(text, cursor, suggestion) event.current_buffer.insert_text = Mock() - accept_in_vi_insert_mode(event) + accept_or_jump_to_end(event) if called: event.current_buffer.insert_text.assert_called() else: