#extends phd_site
#implements respond
#attr $Title = "pdbrc.py"
#attr $Copyright = 2003
#attr $First = "init.py.html"
#attr $Prev = "pdbrc.html"
#attr $Last = "pdbrc.py.html"
#attr $alternates = (("Plain text version", "text/plain", "pdbrc.py.txt"),)
#def body_html
#raw
<pre>
<font color="#0000ff"># This is startup file for interactive python debugger.
#
# Text version <a href="pdbrc.py.txt">here</a>
#
# Generated by <a href="../vimrc.html">gvim</a> :runtime syntax/2html.vim
#
</font>
</pre>

<style type="text/css">
<!--
pre { white-space: pre-wrap; font-family: monospace; color: #000000; background-color: #ffffff; }
body { font-family: monospace; color: #000000; background-color: #ffffff; }
* { font-size: 1em; }
.PreProc { color: #a020f0; }
.pythonBuiltin { color: #0000ff; font-weight: bold; }
.pythonExceptions { color: #8b0000; }
.Identifier { color: #00ff00; }
.Statement { color: #000000; font-weight: bold; }
.Comment { color: #bebebe; }
.Special { color: #6a5acd; }
-->
</style>
<!--

-->
</script>
</head>
<body>
<pre id='vimCodeElement'>
<span class="Comment"># This is startup file for interactive python debugger pdb.</span>
<span class="Comment"># Use it like this in ~/.pdbrc:</span>
<span class="Comment"># import os</span>
<span class="Comment"># x = execfile(&quot;pdbrc.py&quot;)</span>
<span class="Comment"># See <a href="http://wiki.python.org/moin/PdbRcIdea">http://wiki.python.org/moin/PdbRcIdea</a></span>

<span class="Statement">def</span> <span class="Identifier">init</span>():
    <span class="PreProc">import</span> atexit
    <span class="PreProc">import</span> os
    <span class="PreProc">import</span> sys
    <span class="PreProc">import</span> readline

    <span class="Comment"># Command line history:</span>
    histfile = os.path.expanduser(&quot;~/.pdb_history&quot;)

    <span class="Statement">try</span>:
        readline.read_history_file(histfile)
    <span class="Statement">except</span> <span class="pythonExceptions">IOError</span>:
        <span class="Statement">pass</span>


    <span class="Statement">def</span> <span class="Identifier">savehist</span>(histfile=histfile):
        <span class="PreProc">import</span> os
        <span class="PreProc">import</span> readline

        histfilesize = os.environ.get('HISTFILESIZE') <span class="Special">\</span>
            <span class="Statement">or</span> os.environ.get('HISTSIZE')
        <span class="Statement">if</span> histfilesize:
            <span class="Statement">try</span>:
                histfilesize = <span class="pythonBuiltin">int</span>(histfilesize)
            <span class="Statement">except</span> <span class="pythonExceptions">ValueError</span>:
                <span class="Statement">pass</span>
            <span class="Statement">else</span>:
                readline.set_history_length(histfilesize)
        readline.write_history_file(histfile)

    atexit.register(savehist)


    <span class="Statement">def</span> <span class="Identifier">info</span>(<span class="pythonBuiltin">type</span>, value, tb):
        <span class="Comment"># return to debugger after fatal exception (Python cookbook 14.5):</span>
        <span class="PreProc">import</span> pdb
        <span class="PreProc">import</span> sys
        <span class="PreProc">import</span> traceback

        <span class="Statement">if</span> <span class="pythonBuiltin">hasattr</span>(sys, 'ps1') <span class="Statement">or</span> <span class="Statement">not</span> sys.stderr.isatty():
            sys.__excepthook__(<span class="pythonBuiltin">type</span>, value, tb)
        traceback.print_exception(<span class="pythonBuiltin">type</span>, value, tb)
        <span class="pythonBuiltin">print</span>
        pdb.pm()

    sys.excepthook = info

init()

<span class="Comment"># <a href="https://github.com/giampaolo/sysconf/blob/master/home/.pdbrc.py">https://github.com/giampaolo/sysconf/blob/master/home/.pdbrc.py</a></span>
<span class="PreProc">import</span> pdb
<span class="PreProc">import</span> rlcompleter
<span class="Comment">#pdb.Pdb.complete = rlcompleter.Completer(locals()).complete</span>

<span class="Comment"># <a href="http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182">http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182</a></span>
<span class="Statement">def</span> <span class="Identifier">complete</span>(self, text, state, rlcompleter=rlcompleter):
    &quot;&quot;&quot;return the next possible completion for text, using the current frame's
       local namespace

       This is called successively with state == 0, 1, 2, ... until it
       returns None.  The completion should begin with 'text'.
    &quot;&quot;&quot;
    <span class="Comment"># keep a completer class, and make sure that it uses the current local scope </span>
    <span class="Statement">if</span> <span class="Statement">not</span> <span class="pythonBuiltin">hasattr</span>(self, 'completer'):
        self.completer = rlcompleter.Completer(self.curframe.f_locals)
    <span class="Statement">else</span>:
        self.completer.namespace = self.curframe.f_locals
    <span class="Statement">return</span> self.completer.complete(text, state)

<span class="Comment"># Cleanup any variables that could otherwise clutter up the namespace.</span>
<span class="Statement">del</span> pdb, rlcompleter
</pre>
<!-- vim: set foldmethod=manual : -->
#end raw
#end def
$phd_site.respond(self)
