mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 01:52:56 +01:00
process-text-files.py mk-indent: Add support for left-pad-match
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
7ac9cd7a69
commit
109179b55e
1 changed files with 20 additions and 1 deletions
|
|
@ -40,6 +40,7 @@ class Cmd(jwutils.Cmd):
|
||||||
require_lhs_pattern = None
|
require_lhs_pattern = None
|
||||||
skip_short = None
|
skip_short = None
|
||||||
min_assignments = None
|
min_assignments = None
|
||||||
|
left_pad_match = 1
|
||||||
if context is not None:
|
if context is not None:
|
||||||
if 'indent' in context:
|
if 'indent' in context:
|
||||||
indent = context['indent']
|
indent = context['indent']
|
||||||
|
|
@ -47,6 +48,8 @@ class Cmd(jwutils.Cmd):
|
||||||
pattern = context['pattern']
|
pattern = context['pattern']
|
||||||
if 'right-align-match' in context:
|
if 'right-align-match' in context:
|
||||||
right_align_match = context['right-align-match']
|
right_align_match = context['right-align-match']
|
||||||
|
if 'left-pad-match' in context:
|
||||||
|
left_pad_match = context['left-pad-match']
|
||||||
if 'skip-lhs-pattern' in context:
|
if 'skip-lhs-pattern' in context:
|
||||||
skip_lhs_pattern = context['skip-lhs-pattern']
|
skip_lhs_pattern = context['skip-lhs-pattern']
|
||||||
if 'require-lhs-pattern' in context:
|
if 'require-lhs-pattern' in context:
|
||||||
|
|
@ -73,11 +76,25 @@ class Cmd(jwutils.Cmd):
|
||||||
#slog(NOTICE, "split into", parts)
|
#slog(NOTICE, "split into", parts)
|
||||||
if right_align_match > 0:
|
if right_align_match > 0:
|
||||||
parts[1] = parts[1].rjust(right_align_match)
|
parts[1] = parts[1].rjust(right_align_match)
|
||||||
|
lhs = parts[0].rstrip().ljust(indent)
|
||||||
if len(parts) > 2:
|
if len(parts) > 2:
|
||||||
p2_stripped = parts[2].strip()
|
p2_stripped = parts[2].strip()
|
||||||
if len(p2_stripped) or len(parts) > 3:
|
if len(p2_stripped) or len(parts) > 3:
|
||||||
parts[2] = ' ' + p2_stripped
|
parts[2] = ' ' + p2_stripped
|
||||||
r += parts[0].rstrip().ljust(indent) + ''.join(parts[1:]) + '\n'
|
if left_pad_match > 0:
|
||||||
|
pad = ''
|
||||||
|
#slog(NOTICE, "working off {} >{}<".format(left_pad_match, lhs[-left_pad_match:]))
|
||||||
|
for c in lhs[-left_pad_match:]:
|
||||||
|
if c != ' ':
|
||||||
|
pad += ' '
|
||||||
|
for c in parts[1]:
|
||||||
|
if c != ' ':
|
||||||
|
break
|
||||||
|
if len(pad):
|
||||||
|
pad = pad[:-1]
|
||||||
|
#slog(NOTICE, " pad for {}=>{}<".format(line, pad))
|
||||||
|
lhs += pad
|
||||||
|
r += lhs + ''.join(parts[1:]) + '\n'
|
||||||
assignments += 1
|
assignments += 1
|
||||||
if min_assignments is not None and assignments < min_assignments:
|
if min_assignments is not None and assignments < min_assignments:
|
||||||
return data
|
return data
|
||||||
|
|
@ -398,9 +415,11 @@ class CmdMkIndentEquals(Cmd):
|
||||||
slog(NOTICE, "Beautifying", len(files), "makefiles:")
|
slog(NOTICE, "Beautifying", len(files), "makefiles:")
|
||||||
context = dict()
|
context = dict()
|
||||||
right_align_match = 2
|
right_align_match = 2
|
||||||
|
left_pad_match = 1
|
||||||
context["indent"] = args.equal_pos - right_align_match
|
context["indent"] = args.equal_pos - right_align_match
|
||||||
context["pattern"] = "([?+:]*=|::=)"
|
context["pattern"] = "([?+:]*=|::=)"
|
||||||
context["right-align-match"] = right_align_match
|
context["right-align-match"] = right_align_match
|
||||||
|
context["left-pad-match"] = left_pad_match
|
||||||
context["skip-lhs-pattern"] = "[^A-Za-z0-9_# ]"
|
context["skip-lhs-pattern"] = "[^A-Za-z0-9_# ]"
|
||||||
context["require-lhs-pattern"] = "^[ #]*[A-Za-z0-9_]"
|
context["require-lhs-pattern"] = "^[ #]*[A-Za-z0-9_]"
|
||||||
context["skip-short"] = args.skip_short
|
context["skip-short"] = args.skip_short
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue