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 | import os |
|
16 | import os | |
17 | import sys |
|
17 | import sys | |
18 | from io import open as io_open |
|
18 | from io import open as io_open | |
|
19 | import fnmatch | |||
19 |
|
20 | |||
20 | # Our own packages |
|
21 | # Our own packages | |
21 | from IPython.core.error import StdinNotImplementedError |
|
22 | from IPython.core.error import StdinNotImplementedError | |
@@ -170,7 +171,8 b' class HistoryMagics(Magics):' | |||||
170 | pattern = None |
|
171 | pattern = None | |
171 | limit = None if args.limit is _unspecified else args.limit |
|
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 | if args.pattern: |
|
176 | if args.pattern: | |
175 | pattern = "*" + " ".join(args.pattern) + "*" |
|
177 | pattern = "*" + " ".join(args.pattern) + "*" | |
176 | else: |
|
178 | else: | |
@@ -183,6 +185,9 b' class HistoryMagics(Magics):' | |||||
183 | hist = history_manager.get_tail(n, raw=raw, output=get_output) |
|
185 | hist = history_manager.get_tail(n, raw=raw, output=get_output) | |
184 | else: |
|
186 | else: | |
185 | if args.range: # Get history by ranges |
|
187 | if args.range: # Get history by ranges | |
|
188 | if args.pattern: | |||
|
189 | range_pattern = "*" + " ".join(args.pattern) + "*" | |||
|
190 | print_nums = True | |||
186 | hist = history_manager.get_range_by_str(" ".join(args.range), |
|
191 | hist = history_manager.get_range_by_str(" ".join(args.range), | |
187 | raw, get_output) |
|
192 | raw, get_output) | |
188 | else: # Just get history for the current session |
|
193 | else: # Just get history for the current session | |
@@ -200,6 +205,9 b' class HistoryMagics(Magics):' | |||||
200 | # into an editor. |
|
205 | # into an editor. | |
201 | if get_output: |
|
206 | if get_output: | |
202 | inline, output = inline |
|
207 | inline, output = inline | |
|
208 | if range_pattern: | |||
|
209 | if not fnmatch.fnmatch(inline, range_pattern): | |||
|
210 | continue | |||
203 | inline = inline.expandtabs(4).rstrip() |
|
211 | inline = inline.expandtabs(4).rstrip() | |
204 |
|
212 | |||
205 | multiline = "\n" in inline |
|
213 | multiline = "\n" in inline |
General Comments 0
You need to be logged in to leave comments.
Login now