Skip to content

Commit

Permalink
Merge pull request #8 from jwhonce/formatter
Browse files Browse the repository at this point in the history
Turn on/off formatting
  • Loading branch information
lovesegfault authored Jun 13, 2017
2 parents 066a467 + 4669c03 commit 9f9623b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ x23LimitStringx23

fi
```

Special comments '@formatter:off' and '@formatter:on' can be used to disable formatting around a block of statements.

```shell
# @formatter:off
command \
--option1 \
--option2 \
--option3 \
# @formatter:on

This is modeled after the Eclipse feature.
________________________________________________________________________________

Originally written by [Paul Lutus](http://arachnoid.com/python/beautify_bash_program.html)
11 changes: 10 additions & 1 deletion beautysh/beautysh.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def beautify_string(self, data, path=''):
here_string = ''
output = []
line = 1
formatter = True
for record in re.split('\n', data):
record = record.rstrip()
stripped_record = record.strip()
Expand Down Expand Up @@ -87,10 +88,18 @@ def beautify_string(self, data, path=''):
test_record = re.sub(
'(.*)%s.*' % ext_quote_string, '\\1',
test_record, 1)
if(in_ext_quote):
if(in_ext_quote or not formatter):
# pass on unchanged
output.append(record)
if(re.search(r'#\s*@formatter:on', stripped_record)):
formatter = True
continue
else: # not in ext quote
if(re.search(r'#\s*@formatter:off', stripped_record)):
formatter = False
output.append(record)
continue

inc = len(re.findall(
'(\s|\A|;)(case|then|do)(;|\Z|\s)', test_record))
inc += len(re.findall('(\{|\(|\[)', test_record))
Expand Down

0 comments on commit 9f9623b

Please sign in to comment.