diff --git a/bpython.py b/bpython.py index 1ed6303..54234d0 100644 --- a/bpython.py +++ b/bpython.py @@ -45,24 +45,27 @@ import string import shlex import pydoc -class Dummy( object ): - pass -OPTS = Dummy() - -OPTS.auto_display_list = True - +# These are used for syntax hilighting. from pygments import highlight from pygments.lexers import PythonLexer from bpython.formatter import BPythonFormatter -OPTS.syntax = True +# And these are used for argspec. from pyparsing import Forward, Suppress, QuotedString, dblQuotedString, \ Group, OneOrMore, ZeroOrMore, Literal, Optional, Word, \ alphas, alphanums, printables, ParseException -OPTS.arg_spec = True +class Dummy( object ): + pass +OPTS = Dummy() DO_RESIZE = False +# Set default values. (Overridden by loadrc()) +OPTS.tab_length = 4 +OPTS.auto_display_list = True +OPTS.syntax = True +OPTS.arg_spec = True + # TODO: # # C-l doesn't repaint the screen yet. @@ -199,7 +202,6 @@ class Repl( object ): self.f_string = '' self.matches = [] self.argspec = None - self.tablen = None self.s = '' self.list_win_visible = False self._C = {} @@ -920,12 +922,12 @@ class Repl( object ): x = gethw()[1] if not self.cpos: # I know the nested if blocks look nasty. :( - if self.s[-1] == '\t': - n = self.tablen - if len(self.s) > 1: - n = n * 2 + if self.atbol(): + n = len(self.s) % OPTS.tab_length + if not n: + n = OPTS.tab_length - self.s = self.s[ : -1 ] + self.s = self.s[ : -n ] else: self.s = self.s[ : -self.cpos-1 ] + self.s[ -self.cpos : ] @@ -1027,14 +1029,14 @@ class Repl( object ): otherwise attempt to autocomplete to the best match of possible choices in the match list.""" - if self.tablen is None: - x = self.scr.getyx()[1] - if self.atbol(): - self.addstr( self.c ) + x_pos = len(self.s) - self.cpos + num_spaces = x_pos % OPTS.tab_length + if not num_spaces: + num_spaces = OPTS.tab_length + + self.addstr( ' ' * num_spaces) self.print_line( self.s ) - if self.tablen is None: - self.tablen = self.scr.getyx()[1] - x return True if not OPTS.auto_display_list and not self.list_win_visible: @@ -1445,8 +1447,6 @@ def loadrc(): if hasattr( OPTS, k ): setattr( OPTS, k, v ) - if not "pyparsing" in sys.modules: - OPTS.arg_spec = False stdscr = None diff --git a/doc/bpython.1 b/doc/bpython.1 index 80a568f..2bccc3b 100644 --- a/doc/bpython.1 +++ b/doc/bpython.1 @@ -26,7 +26,7 @@ in\-line, much like modern IDEs, but in a simple, lightweight package that can be run in a terminal window. -.B * In\-line syntax highlighting. (available with Pygments) +.B * In\-line syntax highlighting. .RS Hilights commands as you type! .RE @@ -34,7 +34,7 @@ Hilights commands as you type! .RS Press tab to complete expressions when there's only one suggestion. .RE -.B * Expected parameter list. (available with pyparsing) +.B * Expected parameter list. .RS This displays a list of parameters for any function you call. It uses the inspect module, then tries pydoc. .RE diff --git a/doc/bpythonrc.5 b/doc/bpythonrc.5 index 21fed5a..421c9c4 100644 --- a/doc/bpythonrc.5 +++ b/doc/bpythonrc.5 @@ -55,6 +55,13 @@ Syntax highlighting as you type. Display the arg spec (list of arguments) for callables, when possible. .RE +.B tab_length +.BI integer +(default: 4) +.RS +The number of spaces a soft tab equals. +.RE + .SH SEE ALSO .BR bpython (1).