-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
50 keep new lines in arrays #85
base: master
Are you sure you want to change the base?
Changes from 31 commits
14d9dd5
8823659
41e8dfb
1702f70
841d0b7
cf3584b
834a155
eea78cd
7484b2d
05a1d4a
b1fb128
0fd3a77
6703f51
ac96454
e2bd936
737e1ed
6060712
d2401f9
0c7f83b
3748fbb
b3bb208
97265b4
e02476f
7b3036d
8144bc4
d378314
ef21ccd
60d211c
ba45be4
88a5b9a
074110c
7d3bc56
4e8907c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
helper | ||
braceNodeHasMultiLineParts: aNode | ||
|
||
^ (aNode elements anySatisfy: [:node | | ||
(self willBeMultiLine: node) or: (self isTypeOfNewLineMarker: node)]) or: [self isCaseOf: (self parentFor: aNode)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing square brackets around the or: |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
helper | ||
evaluateBraceStatements: aNode multiLine: multiLine | ||
Yannis-Hofmann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
aNode elements do: [:element | | isLast | | ||
isLast := element = aNode elements last. | ||
((self isOptionalNewLineMarker: element) and: [multiLine]) ifFalse: [ | ||
((self isEmptyLineMarker: element) or: [self isOptionalEmptyLineMarker: element]) | ||
ifTrue: [self newLine] | ||
ifFalse: [ | ||
(self isOptionalNewLineMarker: element) ifFalse: [ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could be that I'm reading this wrong, but isn't this always false because if it were true, control flow would have gone into the upper ifTrue branch? One suggestion, to help clarify the method, could be to create a separate |
||
self visitNode: element. | ||
isLast ifFalse: [ | ||
config spaceBeforePointInArray ifTrue: [stream space]. | ||
self stream nextPut: $.]]. | ||
|
||
isLast ifFalse: [multiLine ifTrue: [self newLine] ifFalse: [self stream space]]]]] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
helper | ||
getBraceNodeLength: aNode | ||
|
||
^ aNode elements | ||
inject: 0 | ||
into: [:sum :node | sum + (self preFormat: node) size] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
helper | ||
isOptionalEmptyLineMarker: aNode | ||
|
||
^ aNode isLiteralNode and: [aNode key = #ppOptionalEmptyLine] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
helper | ||
isOptionalNewLineMarker: aNode | ||
|
||
^ aNode isLiteralNode and: [aNode key = #ppOptionalNewLine] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
helper | ||
isTypeOfNewLineMarker: aNode | ||
|
||
^ ((self isOptionalEmptyLineMarker: aNode) or: (self isOptionalNewLineMarker: aNode) or: (self isEmptyLineMarker: aNode)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing square brackets around or |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
formatToMaxLineWidth: aBoolean | ||
|
||
formatToMaxLineWidth := aBoolean |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
formatToMaxLineWidth | ||
|
||
^ formatToMaxLineWidth ifNil: [formatToMaxLineWidth := false] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
maxLineWidth: anInteger | ||
|
||
maxLineWidth := anInteger |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
maxLineWidth | ||
|
||
^ maxLineWidth ifNil: [maxLineWidth := 83] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
charAt: aNumber | ||
|
||
^ string at: aNumber |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
accessing | ||
charAtIndex | ||
|
||
^ self charAt: index |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
helper | ||
countTabs | ||
|
||
| i | | ||
i := index + 1. | ||
tabCount := 0. | ||
|
||
[i <= string size and: [(self charAt: i) = Character tab]] whileTrue: [ | ||
tabCount := tabCount + 1. | ||
i := i + 1] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
formatting | ||
format: aString withWindowWidth: aNumber | ||
|
||
aString isEmpty ifTrue: [^ aString]. | ||
|
||
string := aString. | ||
maxWidth := aNumber. | ||
self reset. | ||
|
||
[index <= string size] whileTrue: [ | seperator | | ||
seperator := self charAtIndex. | ||
self getNextWord. | ||
|
||
seperator = Character cr ifTrue: [self putNewlineAndCountTabs] ifFalse: [ | ||
wordWidth + lineWidth + 1 > maxWidth | ||
ifTrue: [self putIndentedNewlineAndWord] | ||
ifFalse: [self putSeperatorAndWord]]]. | ||
|
||
^ resultStream contents |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
helper | ||
getNextWord | ||
|
||
| i | | ||
i := index + 1. | ||
wordWidth := 0. | ||
wordStream reset. | ||
|
||
[i <= string size and: [inString or: [(seperators occurrencesOf: (self charAt: i)) = 0]]] whileTrue: [ | ||
wordStream nextPut: (self charAt: i). | ||
(self charAt: i) = $' ifTrue: [inString := inString not]. | ||
wordWidth := wordWidth + 1. | ||
i := i + 1] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
put | ||
putIndentedNewlineAndWord | ||
|
||
resultStream nextPut: Character cr; | ||
next: tabCount + 1 put: Character tab; | ||
nextPutAll: wordStream contents. | ||
lineWidth := tabCount + 1 + wordWidth. | ||
index := index + wordWidth + 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
put | ||
putNewlineAndCountTabs | ||
|
||
self countTabs. | ||
|
||
resultStream nextPut: Character cr; | ||
next: tabCount put: Character tab. | ||
tabCount = 0 | ||
ifTrue: [ | ||
resultStream nextPutAll: wordStream contents. | ||
index := index + wordWidth + 1] | ||
ifFalse: [ | ||
index := index + tabCount. | ||
self getNextWord. | ||
resultStream nextPutAll: wordStream contents. | ||
index := index + wordWidth + 1]. | ||
lineWidth := tabCount + wordWidth |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
put | ||
putSeperatorAndWord | ||
|
||
resultStream nextPut: self charAtIndex; | ||
nextPutAll: wordStream contents. | ||
lineWidth := lineWidth + wordWidth + 1. | ||
index := index + wordWidth + 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
initialize | ||
reset | ||
|
||
seperators := { Character cr. Character tab. Character space}. | ||
resultStream := '' writeStream. | ||
wordStream := '' writeStream. | ||
lineWidth := 0. | ||
wordWidth := 0. | ||
tabCount := 0. | ||
index := 1. | ||
inString := false. | ||
|
||
self skipToEndOfFirstWord |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
initialize | ||
skipToEndOfFirstWord | ||
|
||
[index <= string size and: [inString or: [(seperators occurrencesOf: self charAtIndex) = 0]]] whileTrue: [ | ||
resultStream nextPut: self charAtIndex. | ||
self charAtIndex = $' ifTrue: [inString := inString not]. | ||
lineWidth := lineWidth + 1. | ||
index := index + 1] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"class" : { | ||
}, | ||
"instance" : { | ||
"charAt:" : "JW 5/31/2022 11:05", | ||
"charAtIndex" : "JW 5/31/2022 11:05", | ||
"countTabs" : "JW 5/31/2022 11:12", | ||
"format:withWindowWidth:" : "JW 6/1/2022 20:52", | ||
"getNextWord" : "JW 6/1/2022 20:09", | ||
"putIndentedNewlineAndWord" : "JW 6/23/2022 11:45", | ||
"putNewlineAndCountTabs" : "JW 6/23/2022 11:46", | ||
"putSeperatorAndWord" : "JW 6/23/2022 11:47", | ||
"reset" : "JW 6/1/2022 20:05", | ||
"skipToEndOfFirstWord" : "JW 6/1/2022 20:10" } } |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"category" : "PoppyPrint-Core", | ||
"classinstvars" : [ | ||
], | ||
"classvars" : [ | ||
], | ||
"commentStamp" : "", | ||
"instvars" : [ | ||
"string", | ||
"resultStream", | ||
"wordStream", | ||
"seperators", | ||
"lineWidth", | ||
"wordWidth", | ||
"tabCount", | ||
"index", | ||
"maxWidth", | ||
"inString" ], | ||
"name" : "PPWindowFormatter", | ||
"pools" : [ | ||
], | ||
"super" : "Object", | ||
"type" : "normal" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this was used during debugging only? or is there a reason to keep the temp var around?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, this is actually needed for the LineWidth