Show More
@@ -372,6 +372,8 b' def extract_hist_ranges(ranges_str):' | |||
|
372 | 372 | """ |
|
373 | 373 | for range_str in ranges_str.split(): |
|
374 | 374 | rmatch = range_re.match(range_str) |
|
375 | if not rmatch: | |
|
376 | continue | |
|
375 | 377 | start = int(rmatch.group("start")) |
|
376 | 378 | end = rmatch.group("end") |
|
377 | 379 | end = int(end) if end else start+1 # If no end specified, get (a, a+1) |
@@ -537,11 +539,8 b" def magic_history(self, parameter_s = ''):" | |||
|
537 | 539 | if close_at_end: |
|
538 | 540 | outfile.close() |
|
539 | 541 | |
|
540 | # %hist is an alternative name | |
|
541 | magic_hist = magic_history | |
|
542 | ||
|
543 | 542 | |
|
544 |
def rep |
|
|
543 | def magic_rep(self, arg): | |
|
545 | 544 | r""" Repeat a command, or get command to input line for editing |
|
546 | 545 | |
|
547 | 546 | - %rep (no arguments): |
@@ -573,43 +572,37 b' def rep_f(self, arg):' | |||
|
573 | 572 | """ |
|
574 | 573 | |
|
575 | 574 | opts,args = self.parse_options(arg,'',mode='list') |
|
576 | if not args: | |
|
575 | if not args: # Last output | |
|
577 | 576 | self.set_next_input(str(self.shell.user_ns["_"])) |
|
578 | 577 | return |
|
579 | 578 | |
|
580 | if len(args) == 1 and not '-' in args[0]: | |
|
581 | arg = args[0] | |
|
582 | if len(arg) > 1 and arg.startswith('0'): | |
|
583 | # get from shadow hist | |
|
584 | num = int(arg[1:]) | |
|
585 | line = self.shell.shadowhist.get(num) | |
|
586 | self.set_next_input(str(line)) | |
|
587 | return | |
|
588 | try: | |
|
589 | num = int(args[0]) | |
|
590 | self.set_next_input(str(self.shell.input_hist_raw[num]).rstrip()) | |
|
591 | return | |
|
592 | except ValueError: | |
|
593 | pass | |
|
594 | ||
|
595 | for h in reversed(self.shell.input_hist_raw): | |
|
579 | arg = " ".join(args) | |
|
580 | histlines = self.history_manager.get_hist_from_rangestr(arg, raw=False) | |
|
581 | histlines = [x[2] for x in histlines] | |
|
582 | ||
|
583 | if len(histlines) > 1: # Execute immediately | |
|
584 | histlines = "\n".join(histlines) | |
|
585 | print("=== Executing: ===") | |
|
586 | print(histlines) | |
|
587 | print("=== Output: ===") | |
|
588 | self.run_source(histlines, symbol="exec") | |
|
589 | ||
|
590 | elif len(histlines) == 1: # Editable input | |
|
591 | self.set_next_input(histlines[0].rstrip()) | |
|
592 | ||
|
593 | else: # Search for term - editable input | |
|
594 | histlines = self.history_manager.get_hist_search("*"+arg+"*") | |
|
595 | for h in reversed([x[2] for x in histlines]): | |
|
596 | 596 | if 'rep' in h: |
|
597 | 597 | continue |
|
598 | if fnmatch.fnmatch(h,'*' + arg + '*'): | |
|
599 | self.set_next_input(str(h).rstrip()) | |
|
600 | return | |
|
601 | ||
|
602 | try: | |
|
603 | lines = self.extract_input_slices(args, True) | |
|
604 | print("lines", lines) | |
|
605 | self.run_cell(lines) | |
|
606 | except ValueError: | |
|
607 | print("Not found in recent history:", args) | |
|
598 | self.set_next_input(h.rstrip()) | |
|
599 | return | |
|
600 | print("Not found in history:", arg) | |
|
608 | 601 | |
|
609 | 602 | |
|
610 | 603 | def init_ipython(ip): |
|
611 |
ip.define_magic("rep",rep |
|
|
612 |
ip.define_magic("hist",magic_hist) |
|
|
604 | ip.define_magic("rep", magic_rep) | |
|
605 | ip.define_magic("hist",magic_history) # Alternative name | |
|
613 | 606 | ip.define_magic("history",magic_history) |
|
614 | 607 | |
|
615 | 608 | # XXX - ipy_completers are in quarantine, need to be updated to new apis |
General Comments 0
You need to be logged in to leave comments.
Login now