Skip to content

Commit

Permalink
Added support to do semantic line wrapping at and keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
evandrocoan committed May 1, 2019
1 parent 2757482 commit c762da0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions wrap_plus.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ def CONCAT(*args):

next_word_pattern = re.compile(r'\s+[^ ]+', re.MULTILINE)
whitespace_character = (" ", "\t")
list_separator_characters = ( ",", ";" )
list_separator_characters = ( ",", ";", 'e', 'and')
word_separator_characters = ( ".", "?", "!", ":" ) + list_separator_characters
phrase_separator_characters = set( word_separator_characters ) - set( list_separator_characters )

Expand Down Expand Up @@ -1123,6 +1123,7 @@ def semantic_line_wrap(self, paragraph_lines, initial_indent, subsequent_indent,
if not balance_characters_between_line_wraps:
new_text.append( initial_indent )

is_word_backboundary = False
is_allowed_to_wrap = False
is_possible_space = False
is_flushing_comma_list = False
Expand Down Expand Up @@ -1155,6 +1156,9 @@ def force_flush_accumulated_line():
accumulated_line_length = len( accumulated_line )
next_word_length = self.peek_next_word_length( index, text )

previous_character = text[index-1]
is_word_backboundary = previous_character in whitespace_character

if is_possible_space and character in whitespace_character:
continue

Expand Down Expand Up @@ -1203,7 +1207,7 @@ def force_flush_accumulated_line():
force_flush_accumulated_line()

if accumulated_line_length > minimum_line_size:
is_allowed_to_wrap = True
is_allowed_to_wrap = is_word_backboundary and character.isalpha() or not is_word_backboundary and not character.isalpha()

if character in word_separator_characters and is_allowed_to_wrap \
or is_flushing_accumalated_line:
Expand Down Expand Up @@ -1305,9 +1309,14 @@ def is_comma_separated_list(self, text, index):

is_character_whitespace = character in whitespace_character

previous_character = text[index-1]
is_word_backboundary = previous_character in whitespace_character

if index < text_length:
is_word_separator_character = character in list_separator_characters and (
is_word_backboundary and character.isalpha() or not is_word_backboundary and not character.isalpha() )

next_character = text[index+1]
is_word_separator_character = character in list_separator_characters
is_next_character_whitepace = next_character in whitespace_character

else:
Expand Down

0 comments on commit c762da0

Please sign in to comment.