summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:52:10 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:52:10 +0200
commit54cd5c95d9af7037e1b96a726506ceb5df4f43a5 (patch)
tree9052ea14cdc262b7e1866578a95fe58f9752e554 /sqlparse
parent0269aced73a295dea0a57c49dd77ff73031fcdd0 (diff)
downloadsqlparse-54cd5c95d9af7037e1b96a726506ceb5df4f43a5.tar.gz
Add tabs correctly on identifiers offset
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters.py18
1 files changed, 15 insertions, 3 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 3bd492b..401c436 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -475,9 +475,21 @@ class ReindentFilter:
ignore = False
for token in identifiers:
if not ignore and not token.ttype:
- ws = self._gentabs(offset)
- tlist.insert_before(token, sql.Token(T.Whitespace,
- ws))
+ prev = tlist.token_prev(token, False)
+ if prev and prev.ttype == T.Whitespace:
+ value = prev.value
+
+ spaces = 0
+ while value and value[-1] == ' ':
+ value = value[:-1]
+ spaces += 1
+
+ value += self._gentabs(spaces + offset)
+ prev.value = value
+ else:
+ ws = sql.Token(T.Whitespace,
+ self._gentabs(offset))
+ tlist.insert_before(token, ws)
ignore = token.ttype
# Decrease offset the size of the first token