Module:core.hooks
Hooks for IPython.
In Python, it is possible to overwrite any method of any object if you reallywant to. But IPython exposes a few ‘hooks’, methods which aredesigned tobe overwritten by users for customization purposes. This module defines thedefault versions of all such hooks, which get used by IPython if notoverridden by the user.
Hooks are simple functions, but they should be declared withself as theirfirst argument, because when activated they are registered into IPython asinstance methods. The self argument will be the IPython running instanceitself, so hooks have full access to the entire IPython object.
If you wish to define a new hook and activate it, you can make anextension or astartup script. Forexample, you could use a startup file like this:
importosdefcalljed(self,filename,linenum):"My editor hook calls the jed editor directly."print("Calling my own editor, jed ...")ifos.system('jed +%d%s'%(linenum,filename))!=0:raiseTryNext()defload_ipython_extension(ip):ip.set_hook('editor',calljed)
1 Class
- classIPython.core.hooks.CommandChainDispatcher(commands=None)
Bases:
objectDispatch calls to a chain of commands until some func can handle it
Usage: instantiate, execute “add” to add commands (with optionalpriority), execute normally via f() calling mechanism.
- __init__(commands=None)
- add(func,priority=0)
Add a func to the cmd chain with given priority
4 Functions
- IPython.core.hooks.editor(self,filename,linenum=None,wait=True)
Open the default editor at the given filename and linenumber.
This is IPython’s default editor hook, you can use it as an example towrite your own modified one. To set your own editor function as thenew editor hook, call ip.set_hook(‘editor’,yourfunc).
- IPython.core.hooks.synchronize_with_editor(self,filename,linenum,column)
- IPython.core.hooks.show_in_pager(self,data,start,screen_lines)
Run a string through pager
- IPython.core.hooks.clipboard_get(self)
Get text from the clipboard.