##// END OF EJS Templates
Fix %history to stop printing last line....
Fernando Perez -
Show More
@@ -85,22 +85,22 b" def magic_history(self, parameter_s = ''):"
85 if 'g' in opts:
85 if 'g' in opts:
86 init = 1
86 init = 1
87 final = len(input_hist)
87 final = len(input_hist)
88 parts = parameter_s.split(None,1)
88 parts = parameter_s.split(None, 1)
89 if len(parts) == 1:
89 if len(parts) == 1:
90 parts += '*'
90 parts += '*'
91 head, pattern = parts
91 head, pattern = parts
92 pattern = "*" + pattern + "*"
92 pattern = "*" + pattern + "*"
93 elif len(args) == 0:
93 elif len(args) == 0:
94 final = len(input_hist)
94 final = len(input_hist)-1
95 init = max(1,final-default_length)
95 init = max(1,final-default_length)
96 elif len(args) == 1:
96 elif len(args) == 1:
97 final = len(input_hist)
97 final = len(input_hist)
98 init = max(1,final-int(args[0]))
98 init = max(1, final-int(args[0]))
99 elif len(args) == 2:
99 elif len(args) == 2:
100 init,final = map(int,args)
100 init, final = map(int, args)
101 else:
101 else:
102 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
102 warn('%hist takes 0, 1 or 2 arguments separated by spaces.')
103 print self.magic_hist.__doc__
103 print >> Term.cout, self.magic_hist.__doc__
104 return
104 return
105
105
106 width = len(str(final))
106 width = len(str(final))
@@ -114,13 +114,14 b" def magic_history(self, parameter_s = ''):"
114 sh = self.shadowhist.all()
114 sh = self.shadowhist.all()
115 for idx, s in sh:
115 for idx, s in sh:
116 if fnmatch.fnmatch(s, pattern):
116 if fnmatch.fnmatch(s, pattern):
117 print "0%d: %s" %(idx, s)
117 print >> outfile, "0%d: %s" %(idx, s)
118 found = True
118 found = True
119
119
120 if found:
120 if found:
121 print "==="
121 print >> outfile, "==="
122 print "shadow history ends, fetch by %rep <number> (must start with 0)"
122 print >> outfile, \
123 print "=== start of normal history ==="
123 "shadow history ends, fetch by %rep <number> (must start with 0)"
124 print >> outfile, "=== start of normal history ==="
124
125
125 for in_num in range(init,final):
126 for in_num in range(init,final):
126 inline = input_hist[in_num]
127 inline = input_hist[in_num]
@@ -130,7 +131,7 b" def magic_history(self, parameter_s = ''):"
130 multiline = int(inline.count('\n') > 1)
131 multiline = int(inline.count('\n') > 1)
131 if print_nums:
132 if print_nums:
132 print >> outfile, \
133 print >> outfile, \
133 '%s:%s' % (str(in_num).ljust(width),line_sep[multiline]),
134 '%s:%s' % (str(in_num).ljust(width), line_sep[multiline]),
134 if pyprompts:
135 if pyprompts:
135 print >> outfile, '>>>',
136 print >> outfile, '>>>',
136 if multiline:
137 if multiline:
@@ -141,9 +142,10 b" def magic_history(self, parameter_s = ''):"
141 print >> outfile, inline,
142 print >> outfile, inline,
142 else:
143 else:
143 print >> outfile, inline,
144 print >> outfile, inline,
144 output = self.shell.user_ns['Out'].get(in_num)
145 if print_outputs:
145 if output is not None:
146 output = self.shell.user_ns['Out'].get(in_num)
146 print repr(output)
147 if output is not None:
148 print >> outfile, repr(output)
147
149
148 if close_at_end:
150 if close_at_end:
149 outfile.close()
151 outfile.close()
@@ -153,7 +153,6 b' def doctest_hist_op():'
153 >>> ss
153 >>> ss
154 <...s instance at ...>
154 <...s instance at ...>
155 >>>
155 >>>
156 >>> get_ipython().magic("hist -op")
157 """
156 """
158
157
159 def test_shist():
158 def test_shist():
General Comments 0
You need to be logged in to leave comments. Login now