1
# -*- coding: utf-8 -*-
2
""" IPython extension: add %clear magic """
6
ip = IPython.ipapi.get()
10
""" Clear various data (e.g. stored history data)
12
%clear out - clear output history
13
%clear in - clear input history
14
%clear shadow_compress - Compresses shadow history (to speed up ipython)
15
%clear shadow_nuke - permanently erase all entries in shadow history
16
%clear dhist - clear dir history
20
for target in arg.split():
22
print "Flushing output cache (%d entries)" % len(api.user_ns['_oh'])
23
self.outputcache.flush()
25
print "Flushing input history"
26
from IPython import iplib
27
pc = self.outputcache.prompt_count + 1
28
for n in range(1, pc):
33
# must be done in-place
34
self.input_hist[:] = ['\n'] * pc
35
self.input_hist_raw[:] = ['\n'] * pc
36
elif target == 'array':
39
for x in self.user_ns.keys():
40
if isinstance(self.user_ns[x],pylab.arraytype):
42
except AttributeError:
43
print "Clear array only available in -pylab mode"
46
elif target == 'shadow_compress':
47
print "Compressing shadow history"
48
api.db.hcompress('shadowhist')
50
elif target == 'shadow_nuke':
51
print "Erased all keys from shadow history "
52
for k in ip.db.keys('shadowhist/*'):
54
elif target == 'dhist':
55
print "Clearing directory history"
56
del ip.user_ns['_dh'][:]
59
ip.expose_magic("clear",clear_f)
61
ipy_completers.quick_completer(
62
'%clear','in out shadow_nuke shadow_compress dhist')