8000 Allow ~\d in backward history search to show the full session by Carreau · Pull Request #14619 · ipython/ipython · GitHub
[go: up one dir, main page]

Skip to content

Allow ~\d in backward history search to show the full session #14619

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

8000
Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions IPython/core/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,9 @@ def extract_hist_ranges(ranges_str: str) -> Iterable[Tuple[int, int, Optional[in
return

for range_str in ranges_str.split():
if re.match(r'~\d+', range_str):
yield (int(range_str.replace("~", "-")), 1, None)
continue
rmatch = range_re.match(range_str)
if not rmatch:
continue
Expand Down
26 changes: 16 additions & 10 deletions IPython/core/tests/test_history.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from tempfile import TemporaryDirectory
# our own packages
from traitlets.config.loader import Config
import pytest

from IPython.core.history import HistoryAccessor, HistoryManager, extract_hist_ranges

Expand Down Expand Up @@ -152,16 +153,21 @@ def test_history():
ip.history_manager = hist_manager_ori


def test_extract_hist_ranges():
instr = "1 2/3 ~4/5-6 ~4/7-~4/9 ~9/2-~7/5 ~10/"
expected = [(0, 1, 2), # 0 == current session
(2, 3, 4),
(-4, 5, 7),
(-4, 7, 10),
(-9, 2, None), # None == to end
(-8, 1, None),
(-7, 1, 6),
(-10, 1, None)]


@pytest.mark.parametrize(
"instr, expected",
[
("1", [(0, 1, 2)]),
("2/3", [(2, 3, 4)]),
("~4/5-6", [(-4, 5, 7)]),
("~4/7-~4/9", [(-4, 7, 10)]),
("~9/2-~7/5", [(-9, 2, None)]),
("~10/", [(-10, 1, None)]),
("~4", [(-4, 1, None)]),
],
)
def test_extract_hist_ranges(instr, expected):
actual = list(extract_hist_ranges(instr))
assert actual == expected

Expand Down
Loading
0