##// END OF EJS Templates
More code reuse between GUI-independant frontend and Wx frontend: getting...
More code reuse between GUI-independant frontend and Wx frontend: getting the current edited buffer and setting it throught properties.

File last commit:

r839:3d6c30d0
r1462:ffe71205
Show More
clearcmd.py
66 lines | 2.1 KiB | text/x-python | PythonLexer
vivainio
Jorgen's %clean array
r245 # -*- coding: utf-8 -*-
""" IPython extension: add %clear magic """
import IPython.ipapi
import gc
ip = IPython.ipapi.get()
def clear_f(self,arg):
""" Clear various data (e.g. stored history data)
%clear out - clear output history
%clear in - clear input history
vivainio
doc, changelog fixes
r791 %clear shadow_compress - Compresses shadow history (to speed up ipython)
%clear shadow_nuke - permanently erase all entries in shadow history
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 %clear dhist - clear dir history
vivainio
Jorgen's %clean array
r245 """
api = self.getapi()
for target in arg.split():
if target == 'out':
fperez
Defaults rename, clean up api to use properties or direct access rather than...
r284 print "Flushing output cache (%d entries)" % len(api.user_ns['_oh'])
vivainio
Jorgen's %clean array
r245 self.outputcache.flush()
elif target == 'in':
print "Flushing input history"
from IPython import iplib
vivainio
%clear in now properly pads the history with empty entries
r795 pc = self.outputcache.prompt_count + 1
for n in range(1, pc):
vivainio
Jorgen's %clean array
r245 key = '_i'+`n`
try:
del self.user_ns[key]
except: pass
vivainio
%clear in now properly pads the history with empty entries
r795 # must be done in-place
self.input_hist[:] = ['\n'] * pc
self.input_hist_raw[:] = ['\n'] * pc
vivainio
Jorgen's %clean array
r245 elif target == 'array':
try:
pylab=ip.IP.pylab
for x in self.user_ns.keys():
if isinstance(self.user_ns[x],pylab.arraytype):
del self.user_ns[x]
except AttributeError:
print "Clear array only available in -pylab mode"
gc.collect()
vivainio
completers for %clear magic, add shadow history deletion
r790
elif target == 'shadow_compress':
print "Compressing shadow history"
vivainio
ipy_completers.quick_completer for easy creation of custom completers
r789 api.db.hcompress('shadowhist')
vivainio
Jorgen's %clean array
r245
vivainio
completers for %clear magic, add shadow history deletion
r790 elif target == 'shadow_nuke':
print "Erased all keys from shadow history "
for k in ip.db.keys('shadowhist/*'):
del ip.db[k]
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 elif target == 'dhist':
print "Clearing directory history"
del ip.user_ns['_dh'][:]
vivainio
completers for %clear magic, add shadow history deletion
r790
vivainio
Jorgen's %clean array
r245 ip.expose_magic("clear",clear_f)
vivainio
completers for %clear magic, add shadow history deletion
r790 import ipy_completers
vivainio
cd -TAB pads zeros, %clear dhist, some doc changes
r839 ipy_completers.quick_completer(
'%clear','in out shadow_nuke shadow_compress dhist')
vivainio
Jorgen's %clean array
r245