From 235864a1fcc5d871d584dcd8eeeeaded4f6572c9 Mon Sep 17 00:00:00 2001 From: Andi Albrecht Date: Sun, 3 May 2009 21:56:03 +0200 Subject: Avoid duplicate linebreaks when reformatting (targets issue3). --- sqlparse/filters.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'sqlparse') diff --git a/sqlparse/filters.py b/sqlparse/filters.py index 695b298..91258ff 100644 --- a/sqlparse/filters.py +++ b/sqlparse/filters.py @@ -171,8 +171,12 @@ class ReindentFilter(Filter): if prev and prev.is_whitespace(): tlist.tokens.pop(tlist.token_index(prev)) offset += 1 - nl = self.nl() - tlist.insert_before(token, nl) + if prev and (str(prev).endswith('\n') + or str(prev).endswith('\r')): + nl = tlist.token_next(token) + else: + nl = self.nl() + tlist.insert_before(token, nl) token = tlist.token_next_match(tlist.token_index(nl)+offset, T.Keyword, split_words, regex=True) -- cgit v1.2.1