[IPython-user] How to set a default completer

Fernando Perez fperez.net@gmail....
Fri Mar 26 21:01:22 CDT 2010


Hey Chris,

On Thu, Mar 25, 2010 at 2:11 PM, Christopher Burns <cburns@berkeley.edu> wrote:
> I just discovered the traits_completer in IPython Extensions:
>
> import ipy_traits_completer
> ipy_traits_completer.activate()
>
> documented here:
> http://ipython.scipy.org/doc/stable/html/interactive/extension_api.html#provided-extensions
>
> This works great!  How would I go about deactivating this completer or
> restoring the default behavior?  (Short of restarting ipython)
>
> Can I unassign the hook or reset it to a default similar to this:
> ip.set_hook('complete_command', trait_completer, re_key = '.*')
>
> Ideally I'd like to create a magic command that would allow me to
> toggle the completer.

Hackish, but works:


from ipy_traits_completer import activate as traits_comp_activate

def traits_comp_deactivate():
    """Turn traits completer off"""
    import IPython.ipapi
    from IPython.strdispatch import StrDispatch

    ip = IPython.ipapi.get()
    sdisp = StrDispatch()
    ip.IP.strdispatchers['complete_command'] = sdisp
    ip.IP.Completer.custom_completers = sdisp


Then, you can call

traits_comp_activate()

to get traits-aware completion, or

traits_comp_deactivate()

to go back to normal.

Funny, I'd written that code years ago (the traits completer) and
forgotten about it when you asked me :)

Cheers,

f


More information about the IPython-user mailing list