##// END OF EJS Templates
completers for %clear magic, add shadow history deletion
vivainio -
Show More
@@ -1,47 +1,56 b''
1 1 # -*- coding: utf-8 -*-
2 2 """ IPython extension: add %clear magic """
3 3
4 4 import IPython.ipapi
5 5 import gc
6 6 ip = IPython.ipapi.get()
7 7
8 8
9 9 def clear_f(self,arg):
10 10 """ Clear various data (e.g. stored history data)
11 11
12 12 %clear out - clear output history
13 13 %clear in - clear input history
14 14 """
15 15
16 16 api = self.getapi()
17 17 for target in arg.split():
18 18 if target == 'out':
19 19 print "Flushing output cache (%d entries)" % len(api.user_ns['_oh'])
20 20 self.outputcache.flush()
21 21 elif target == 'in':
22 22 print "Flushing input history"
23 23 from IPython import iplib
24 24 del self.input_hist[:]
25 25 del self.input_hist_raw[:]
26 26 for n in range(1,self.outputcache.prompt_count + 1):
27 27 key = '_i'+`n`
28 28 try:
29 29 del self.user_ns[key]
30 30 except: pass
31 31 elif target == 'array':
32 32 try:
33 33 pylab=ip.IP.pylab
34 34 for x in self.user_ns.keys():
35 35 if isinstance(self.user_ns[x],pylab.arraytype):
36 36 del self.user_ns[x]
37 37 except AttributeError:
38 38 print "Clear array only available in -pylab mode"
39 39 gc.collect()
40 elif target == 'shadow':
40
41 elif target == 'shadow_compress':
42 print "Compressing shadow history"
41 43 api.db.hcompress('shadowhist')
42 44
45 elif target == 'shadow_nuke':
46 print "Erased all keys from shadow history "
47 for k in ip.db.keys('shadowhist/*'):
48 del ip.db[k]
49
43 50 ip.expose_magic("clear",clear_f)
51 import ipy_completers
52 ipy_completers.quick_completer('clear','in out shadow_nuke shadow_compress')
44 53
45 54
46 55
47 56
General Comments 0
You need to be logged in to leave comments. Login now