summaryrefslogtreecommitdiff
path: root/sqlparse
diff options
context:
space:
mode:
authorPatrick Schemitz <patrick.schemitz@digitalbriefkasten.de>2018-03-03 15:13:18 +0100
committerPatrick Schemitz <patrick.schemitz@digitalbriefkasten.de>2018-03-03 15:13:18 +0100
commit6dac1d9c98742e5e7df1281d09d33db67fdde9a6 (patch)
tree1fd4ed745b5e977bf068e5fc3868efa77215e79f /sqlparse
parent9cf45ebf8c9d59442e4739befeac968002510699 (diff)
downloadsqlparse-6dac1d9c98742e5e7df1281d09d33db67fdde9a6.tar.gz
indent all identifiers, including the first one, by width instead of keyword length
Diffstat (limited to 'sqlparse')
-rw-r--r--sqlparse/filters/reindent.py12
-rw-r--r--sqlparse/formatter.py9
2 files changed, 18 insertions, 3 deletions
diff --git a/sqlparse/filters/reindent.py b/sqlparse/filters/reindent.py
index 792133f..49c7807 100644
--- a/sqlparse/filters/reindent.py
+++ b/sqlparse/filters/reindent.py
@@ -12,7 +12,8 @@ from sqlparse.utils import offset, indent
class ReindentFilter(object):
def __init__(self, width=2, char=' ', wrap_after=0, n='\n',
- comma_first=False, indent_after_first=False):
+ comma_first=False, indent_after_first=False,
+ indent_columns=False):
self.n = n
self.width = width
self.char = char
@@ -20,6 +21,7 @@ class ReindentFilter(object):
self.offset = 0
self.wrap_after = wrap_after
self.comma_first = comma_first
+ self.indent_columns = indent_columns
self._curr_stmt = None
self._last_stmt = None
@@ -118,8 +120,12 @@ class ReindentFilter(object):
def _process_identifierlist(self, tlist):
identifiers = list(tlist.get_identifiers())
- first = next(identifiers.pop(0).flatten())
- num_offset = 1 if self.char == '\t' else self._get_offset(first)
+ if self.indent_columns:
+ first = next(identifiers[0].flatten())
+ num_offset = 1 if self.char == '\t' else self.width
+ else:
+ first = next(identifiers.pop(0).flatten())
+ num_offset = 1 if self.char == '\t' else self._get_offset(first)
if not tlist.within(sql.Function):
with offset(self, num_offset):
position = 0
diff --git a/sqlparse/formatter.py b/sqlparse/formatter.py
index 6bd8033..ecb1e2f 100644
--- a/sqlparse/formatter.py
+++ b/sqlparse/formatter.py
@@ -56,6 +56,14 @@ def validate_options(options):
options['truncate_strings'] = truncate_strings
options['truncate_char'] = options.get('truncate_char', '[...]')
+ indent_columns = options.get('indent_columns', False)
+ if indent_columns not in [True, False]:
+ raise SQLParseError('Invalid value for indent_columns: '
+ '{0!r}'.format(indent_columns))
+ elif indent_columns:
+ options['reindent'] = True # enforce reindent
+ options['indent_columns'] = indent_columns
+
reindent = options.get('reindent', False)
if reindent not in [True, False]:
raise SQLParseError('Invalid value for reindent: '
@@ -161,6 +169,7 @@ def build_filter_stack(stack, options):
char=options['indent_char'],
width=options['indent_width'],
indent_after_first=options['indent_after_first'],
+ indent_columns=options['indent_columns'],
wrap_after=options['wrap_after'],
comma_first=options['comma_first']))