Show More
@@ -0,0 +1,25 b'' | |||
|
1 | History Range Glob feature | |
|
2 | ========================== | |
|
3 | ||
|
4 | Previously, when using ``%history``, users could specify either | |
|
5 | a range of sessions and lines, for example: | |
|
6 | ||
|
7 | .. code-block:: python | |
|
8 | ||
|
9 | ~8/1-~6/5 # see history from the first line of 8 sessions ago, | |
|
10 | # to the fifth line of 6 sessions ago.`` | |
|
11 | ||
|
12 | Or users could specify a glob pattern: | |
|
13 | ||
|
14 | .. code-block:: python | |
|
15 | ||
|
16 | -g <pattern> # glob ALL history for the specified pattern. | |
|
17 | ||
|
18 | However users could *not* specify both. | |
|
19 | ||
|
20 | If a user *did* specify both a range and a glob pattern, | |
|
21 | then the glob pattern would be used (globbing *all* history) *and the range would be ignored*. | |
|
22 | ||
|
23 | --- | |
|
24 | ||
|
25 | With this enhancment, if a user specifies both a range and a glob pattern, then the glob pattern will be applied to the specified range of history. |
@@ -16,6 +16,7 b'' | |||
|
16 | 16 | import os |
|
17 | 17 | import sys |
|
18 | 18 | from io import open as io_open |
|
19 | import fnmatch | |
|
19 | 20 | |
|
20 | 21 | # Our own packages |
|
21 | 22 | from IPython.core.error import StdinNotImplementedError |
@@ -170,7 +171,8 b' class HistoryMagics(Magics):' | |||
|
170 | 171 | pattern = None |
|
171 | 172 | limit = None if args.limit is _unspecified else args.limit |
|
172 | 173 | |
|
173 |
|
|
|
174 | range_pattern = False | |
|
175 | if args.pattern is not None and not args.range: | |
|
174 | 176 | if args.pattern: |
|
175 | 177 | pattern = "*" + " ".join(args.pattern) + "*" |
|
176 | 178 | else: |
@@ -183,6 +185,9 b' class HistoryMagics(Magics):' | |||
|
183 | 185 | hist = history_manager.get_tail(n, raw=raw, output=get_output) |
|
184 | 186 | else: |
|
185 | 187 | if args.range: # Get history by ranges |
|
188 | if args.pattern: | |
|
189 | range_pattern = "*" + " ".join(args.pattern) + "*" | |
|
190 | print_nums = True | |
|
186 | 191 | hist = history_manager.get_range_by_str(" ".join(args.range), |
|
187 | 192 | raw, get_output) |
|
188 | 193 | else: # Just get history for the current session |
@@ -200,6 +205,9 b' class HistoryMagics(Magics):' | |||
|
200 | 205 | # into an editor. |
|
201 | 206 | if get_output: |
|
202 | 207 | inline, output = inline |
|
208 | if range_pattern: | |
|
209 | if not fnmatch.fnmatch(inline, range_pattern): | |
|
210 | continue | |
|
203 | 211 | inline = inline.expandtabs(4).rstrip() |
|
204 | 212 | |
|
205 | 213 | multiline = "\n" in inline |
General Comments 0
You need to be logged in to leave comments.
Login now