Commit 0c5ee0e8 authored by David Gobbi's avatar David Gobbi Committed by Kitware Robot
Browse files

Merge topic 'indent-utility'

324963c2

 Also indent closing brace for K&R braces.
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Merge-request: !1650
parents 9fcbac09 324963c2
...@@ -302,9 +302,9 @@ def reindent(filename, dry_run=False): ...@@ -302,9 +302,9 @@ def reindent(filename, dry_run=False):
# save delim, row, col, and current indentation # save delim, row, col, and current indentation
stack.append((delim, i, pos, newpos)) stack.append((delim, i, pos, newpos))
elif delim == '{': elif delim == '{':
if in_assign: if in_assign or line[0:pos-1].rstrip()[-1:] == "=":
# do not adjust braces for initializer lists # do not adjust braces for initializer lists
stack.append((delim, i, pos, pos)) stack.append((delim, i, -1, pos))
elif ((in_else or in_define) and spaces.sub("", line) == "{"): elif ((in_else or in_define) and spaces.sub("", line) == "{"):
# for opening braces that might have no match # for opening braces that might have no match
indent = " "*lastpos indent = " "*lastpos
...@@ -312,7 +312,8 @@ def reindent(filename, dry_run=False): ...@@ -312,7 +312,8 @@ def reindent(filename, dry_run=False):
stack.append((delim, i, lastpos, lastpos)) stack.append((delim, i, lastpos, lastpos))
else: else:
# save delim, row, col, and previous indentation # save delim, row, col, and previous indentation
stack.append((delim, i, pos, lastpos)) stack.append((delim, i, pos, newpos))
if spaces.sub("", newlines[i][0:pos]) == "":
newpos = pos + 2 newpos = pos + 2
lastpos = newpos lastpos = newpos
continuation = False continuation = False
...@@ -322,18 +323,22 @@ def reindent(filename, dry_run=False): ...@@ -322,18 +323,22 @@ def reindent(filename, dry_run=False):
# found a ')', ']', or '}' delimiter, so pop its partner # found a ')', ']', or '}' delimiter, so pop its partner
try: try:
ldelim, j, k, newpos = stack.pop() ldelim, j, k, newpos = stack.pop()
in_assign = (k < 0)
except IndexError: except IndexError:
ldelim = "" ldelim = ""
if ldelim != {'}':'{', ')':'(', ']':'['}[delim]: if ldelim != {'}':'{', ')':'(', ']':'['}[delim]:
sys.stderr.write(filename + ":" + str(i) + ": ") sys.stderr.write(filename + ":" + str(i) + ": ")
sys.stderr.write("mismatched \'" + delim + "\'\n") sys.stderr.write("mismatched \'" + delim + "\'\n")
# adjust the indentation of matching '{', '}' # adjust the indentation of matching '{', '}'
if (ldelim == '{' and delim == '}' and if (ldelim == '{' and delim == '}' and not in_assign and
spaces.sub("", lines[i][0:pos]) == "" and spaces.sub("", line[0:pos]) == ""):
spaces.sub("", lines[j][0:k]) == ""): if spaces.sub("", newlines[j][0:k]) == "":
indent = " "*newpos indent = " "*newpos
changeline(i, spaces.sub(indent, lines[i], count=1))
changeline(j, spaces.sub(indent, lines[j], count=1)) changeline(j, spaces.sub(indent, lines[j], count=1))
changeline(i, spaces.sub(indent, lines[i], count=1))
elif i != j:
indent = " "*newpos
changeline(i, spaces.sub(indent, lines[i], count=1))
if delim == '}': if delim == '}':
continuation = False continuation = False
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment