|
45 | 45 | import shlex |
46 | 46 | import pydoc |
47 | 47 |
|
48 | | -class Dummy( object ): |
49 | | - pass |
50 | | -OPTS = Dummy() |
51 | | - |
52 | | -OPTS.auto_display_list = True |
53 | | - |
| 48 | +# These are used for syntax hilighting. |
54 | 49 | from pygments import highlight |
55 | 50 | from pygments.lexers import PythonLexer |
56 | 51 | from bpython.formatter import BPythonFormatter |
57 | | -OPTS.syntax = True |
58 | 52 |
|
| 53 | +# And these are used for argspec. |
59 | 54 | from pyparsing import Forward, Suppress, QuotedString, dblQuotedString, \ |
60 | 55 | Group, OneOrMore, ZeroOrMore, Literal, Optional, Word, \ |
61 | 56 | alphas, alphanums, printables, ParseException |
62 | | -OPTS.arg_spec = True |
63 | 57 |
|
| 58 | +class Dummy( object ): |
| 59 | + pass |
| 60 | +OPTS = Dummy() |
64 | 61 | DO_RESIZE = False |
65 | 62 |
|
| 63 | +# Set default values. (Overridden by loadrc()) |
| 64 | +OPTS.tab_length = 4 |
| 65 | +OPTS.auto_display_list = True |
| 66 | +OPTS.syntax = True |
| 67 | +OPTS.arg_spec = True |
| 68 | + |
66 | 69 | # TODO: |
67 | 70 | # |
68 | 71 | # C-l doesn't repaint the screen yet. |
@@ -199,7 +202,6 @@ def __init__( self, scr, interp, statusbar=None, idle=None): |
199 | 202 | self.f_string = '' |
200 | 203 | self.matches = [] |
201 | 204 | self.argspec = None |
202 | | - self.tablen = None |
203 | 205 | self.s = '' |
204 | 206 | self.list_win_visible = False |
205 | 207 | self._C = {} |
@@ -920,12 +922,12 @@ def bs( self ): |
920 | 922 | x = gethw()[1] |
921 | 923 |
|
922 | 924 | if not self.cpos: # I know the nested if blocks look nasty. :( |
923 | | - if self.s[-1] == '\t': |
924 | | - n = self.tablen |
925 | | - if len(self.s) > 1: |
926 | | - n = n * 2 |
| 925 | + if self.atbol(): |
| 926 | + n = len(self.s) % OPTS.tab_length |
| 927 | + if not n: |
| 928 | + n = OPTS.tab_length |
927 | 929 |
|
928 | | - self.s = self.s[ : -1 ] |
| 930 | + self.s = self.s[ : -n ] |
929 | 931 | else: |
930 | 932 | self.s = self.s[ : -self.cpos-1 ] + self.s[ -self.cpos : ] |
931 | 933 |
|
@@ -1027,14 +1029,14 @@ def tab( self ): |
1027 | 1029 | otherwise attempt to autocomplete to the best match of possible |
1028 | 1030 | choices in the match list.""" |
1029 | 1031 |
|
1030 | | - if self.tablen is None: |
1031 | | - x = self.scr.getyx()[1] |
1032 | | - |
1033 | 1032 | if self.atbol(): |
1034 | | - self.addstr( self.c ) |
| 1033 | + x_pos = len(self.s) - self.cpos |
| 1034 | + num_spaces = x_pos % OPTS.tab_length |
| 1035 | + if not num_spaces: |
| 1036 | + num_spaces = OPTS.tab_length |
| 1037 | + |
| 1038 | + self.addstr( ' ' * num_spaces) |
1035 | 1039 | self.print_line( self.s ) |
1036 | | - if self.tablen is None: |
1037 | | - self.tablen = self.scr.getyx()[1] - x |
1038 | 1040 | return True |
1039 | 1041 |
|
1040 | 1042 | if not OPTS.auto_display_list and not self.list_win_visible: |
@@ -1445,8 +1447,6 @@ def loadrc(): |
1445 | 1447 | if hasattr( OPTS, k ): |
1446 | 1448 | setattr( OPTS, k, v ) |
1447 | 1449 |
|
1448 | | - if not "pyparsing" in sys.modules: |
1449 | | - OPTS.arg_spec = False |
1450 | 1450 |
|
1451 | 1451 | stdscr = None |
1452 | 1452 |
|
|
0 commit comments