Skip to content

Commit 22316dc

Browse files
committed
We now use configurable soft-tabs instead of literal tabs.
committer: Bob Farrell <bob@keys.(none)>
1 parent 6168b0d commit 22316dc

3 files changed

Lines changed: 31 additions & 24 deletions

File tree

bpython.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,27 @@
4545
import shlex
4646
import pydoc
4747

48-
class Dummy( object ):
49-
pass
50-
OPTS = Dummy()
51-
52-
OPTS.auto_display_list = True
53-
48+
# These are used for syntax hilighting.
5449
from pygments import highlight
5550
from pygments.lexers import PythonLexer
5651
from bpython.formatter import BPythonFormatter
57-
OPTS.syntax = True
5852

53+
# And these are used for argspec.
5954
from pyparsing import Forward, Suppress, QuotedString, dblQuotedString, \
6055
Group, OneOrMore, ZeroOrMore, Literal, Optional, Word, \
6156
alphas, alphanums, printables, ParseException
62-
OPTS.arg_spec = True
6357

58+
class Dummy( object ):
59+
pass
60+
OPTS = Dummy()
6461
DO_RESIZE = False
6562

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+
6669
# TODO:
6770
#
6871
# C-l doesn't repaint the screen yet.
@@ -199,7 +202,6 @@ def __init__( self, scr, interp, statusbar=None, idle=None):
199202
self.f_string = ''
200203
self.matches = []
201204
self.argspec = None
202-
self.tablen = None
203205
self.s = ''
204206
self.list_win_visible = False
205207
self._C = {}
@@ -920,12 +922,12 @@ def bs( self ):
920922
x = gethw()[1]
921923

922924
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
927929

928-
self.s = self.s[ : -1 ]
930+
self.s = self.s[ : -n ]
929931
else:
930932
self.s = self.s[ : -self.cpos-1 ] + self.s[ -self.cpos : ]
931933

@@ -1027,14 +1029,14 @@ def tab( self ):
10271029
otherwise attempt to autocomplete to the best match of possible
10281030
choices in the match list."""
10291031

1030-
if self.tablen is None:
1031-
x = self.scr.getyx()[1]
1032-
10331032
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)
10351039
self.print_line( self.s )
1036-
if self.tablen is None:
1037-
self.tablen = self.scr.getyx()[1] - x
10381040
return True
10391041

10401042
if not OPTS.auto_display_list and not self.list_win_visible:
@@ -1445,8 +1447,6 @@ def loadrc():
14451447
if hasattr( OPTS, k ):
14461448
setattr( OPTS, k, v )
14471449

1448-
if not "pyparsing" in sys.modules:
1449-
OPTS.arg_spec = False
14501450

14511451
stdscr = None
14521452

doc/bpython.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,15 @@ in\-line, much like modern IDEs, but in a simple,
2626
lightweight package that can be run in a terminal
2727
window.
2828

29-
.B * In\-line syntax highlighting. (available with Pygments)
29+
.B * In\-line syntax highlighting.
3030
.RS
3131
Hilights commands as you type!
3232
.RE
3333
.B * Readline\-like autocomplete with suggestions displayed as you type.
3434
.RS
3535
Press tab to complete expressions when there's only one suggestion.
3636
.RE
37-
.B * Expected parameter list. (available with pyparsing)
37+
.B * Expected parameter list.
3838
.RS
3939
This displays a list of parameters for any function you call. It uses the inspect module, then tries pydoc.
4040
.RE

doc/bpythonrc.5

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ Syntax highlighting as you type.
5555
Display the arg spec (list of arguments) for callables, when possible.
5656
.RE
5757

58+
.B tab_length
59+
.BI integer
60+
(default: 4)
61+
.RS
62+
The number of spaces a soft tab equals.
63+
.RE
64+
5865
.SH SEE ALSO
5966
.BR bpython (1).
6067

0 commit comments

Comments
 (0)