aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkristoffer.lunden <kristoffer.lunden@dd23f896-6e2b-0410-bc3e-d184d5eb269a>2010-07-01 23:47:59 (GMT)
committerkristoffer.lunden <kristoffer.lunden@dd23f896-6e2b-0410-bc3e-d184d5eb269a>2010-07-01 23:47:59 (GMT)
commit1cd43551d2cce626927ff95f799b0d9e564de800 (patch)
treea9ef38e0c9b13266954b905c2737c80844f5d7e8
parent74cc1b2753b685d3aecb25f6c4e5af6d6cf3f6ee (diff)
downloadgedit-autotab-1cd43551d2cce626927ff95f799b0d9e564de800.zip
gedit-autotab-1cd43551d2cce626927ff95f799b0d9e564de800.tar.gz
gedit-autotab-1cd43551d2cce626927ff95f799b0d9e564de800.tar.bz2
actually try to guess at tabs or spaces for the file
git-svn-id: http://gedit-autotab.googlecode.com/svn/trunk@24 dd23f896-6e2b-0410-bc3e-d184d5eb269a
-rw-r--r--autotab.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/autotab.py b/autotab.py
index d45fbce..516641f 100644
--- a/autotab.py
+++ b/autotab.py
@@ -151,7 +151,8 @@ class AutoTab(gedit.Plugin):
indent_count = {'tabs':0, 2:0, 3:0, 4:0, 8:0}
last_indent = 0
last_indent_spaces = None
- seen_tab = False
+ seen_tabs = 0
+ seen_spaces = 0
for line in text.splitlines():
if len(line) == 0 or not line[0].isspace():
continue
@@ -159,8 +160,10 @@ class AutoTab(gedit.Plugin):
if line[0] == '\t':
indent_count['tabs'] += 1
last_indent_spaces = None
- seen_tab = True
+ seen_tabs += 1
continue
+ elif line[0] == ' ':
+ seen_spaces += 1
indent = 0
while line.startswith(' '):
@@ -180,9 +183,13 @@ class AutoTab(gedit.Plugin):
# no indentations, leave old values
if sum(indent_count.values()) == 0:
- # default to tabs if we've seen one, otherwise spaces
+ # if we've seen tabs or spaces, default to those
# can't guess at size, so using default
- self.update_tabs(self.tabs_width, not seen_tab)
+ if seen_tabs or seen_spaces:
+ if seen_tabs > seen_spaces:
+ self.update_tabs(self.tabs_width, False)
+ else:
+ self.update_tabs(self.tabs_width, True)
return
winner = max(indent_count, key=indent_count.get)