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