summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:03:49 +0200
committerJesús Leganés Combarro "Piranna" <piranna@gmail.com>2012-06-10 13:03:49 +0200
commit63f6fc8fc8a2ab19f56cfc8cb8e88ec9fab7c305 (patch)
tree36084fad483edefa8701c25aede41dc7918874b1
parent1a33df8f26a6b9290f9a3e9dbe6c7c7f462088cc (diff)
downloadsqlparse-63f6fc8fc8a2ab19f56cfc8cb8e88ec9fab7c305.tar.gz
Added indent tabs on ReindentFilter.nl()
-rw-r--r--sqlparse/filters.py7
-rw-r--r--sqlparse/formatter.py8
2 files changed, 12 insertions, 3 deletions
diff --git a/sqlparse/filters.py b/sqlparse/filters.py
index 3bf46d5..b075d39 100644
--- a/sqlparse/filters.py
+++ b/sqlparse/filters.py
@@ -294,7 +294,12 @@ class ReindentFilter:
Return an indented new line token
"""
# TODO: newline character should be configurable
- ws = '\n' + self.char * (self.indent * self.width + self.offset)
+ ws = '\n'
+ offset = self.indent * self.width + self.offset
+ if self.char == '\t':
+ tabs, offset = divmod(offset, self.width)
+ ws += self.char * tabs
+ ws += ' ' * offset
return sql.Token(T.Whitespace, ws)
def _split_kwds(self, tlist):
diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py
index 7c7eaad..39e5d28 100644
--- a/sqlparse/formatter.py
+++ b/sqlparse/formatter.py
@@ -9,6 +9,9 @@ from sqlparse import SQLParseError
from sqlparse import filters
+INDENT_WIDTH = 2
+
+
def validate_options(options):
"""Validates options."""
@@ -57,7 +60,7 @@ def validate_options(options):
options['indent_char'] = ' '
# indent_width
- indent_width = options.get('indent_width', 2)
+ indent_width = options.get('indent_width', INDENT_WIDTH)
try:
indent_width = int(indent_width)
except (TypeError, ValueError):
@@ -112,7 +115,8 @@ def build_filter_stack(stack, options):
stack.enable_grouping()
stack.stmtprocess.append(
filters.ReindentFilter(char=options['indent_char'],
- width=options['indent_width']))
+ width=options['indent_width'],
+ line_width=options['right_margin']))
if options.get('right_margin', False):
stack.enable_grouping()