summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorAndi Albrecht <albrecht.andi@gmail.com>2016-09-17 15:35:19 +0200
committerAndi Albrecht <albrecht.andi@gmail.com>2016-09-17 15:35:19 +0200
commitb8f73564b747cdb250fcc75fa7aa02f56d6484e0 (patch)
tree7d1d89cfa946304b6bc3c66cd96825fc6d5f7400 /sqlparse
parent4d05b441fcb801d320ac52ce90465b74d419ceac (diff)
downloadsqlparse-b8f73564b747cdb250fcc75fa7aa02f56d6484e0.tar.gz
Better formatting when using comma-first notation (issue141).
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/reindent.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 7421f6d..ab6c00f 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -43,8 +43,10 @@ class ReindentFilter(object):
# Now take current offset into account and return relative offset.
return len(line) - len(self.char * self.leading_ws)
- def nl(self):
- return sql.Token(T.Whitespace, self.n + self.char * self.leading_ws)
+ def nl(self, offset=0):
+ return sql.Token(
+ T.Whitespace,
+ self.n + self.char * max(0, self.leading_ws + offset))
def _next_token(self, tlist, idx=-1):
split_words = ('FROM', 'STRAIGHT_JOIN$', 'JOIN$', 'AND', 'OR',
@@ -125,13 +127,15 @@ class ReindentFilter(object):
# Add 1 for the "," separator
position += len(token.value) + 1
if position > (self.wrap_after - self.offset):
+ adjust = 0
if self.comma_first:
+ adjust = -2
_, comma = tlist.token_prev(
tlist.token_index(token))
if comma is None:
continue
token = comma
- tlist.insert_before(token, self.nl())
+ tlist.insert_before(token, self.nl(offset=adjust))
if self.comma_first:
_, ws = tlist.token_next(
tlist.token_index(token), skip_ws=False)