Skip to content
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

49 set row length to standard browser window #81

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
format
formatString: aString class: aClass noPattern: aBoolean notifying: anObject with: aPPFormatterConfig

| formatter methodNode |
| formatter methodNode result |
self
example: 'string test'
receiver: [PPFormatter]
Expand All @@ -19,4 +19,10 @@ formatString: aString class: aClass noPattern: aBoolean notifying: anObject with
initForNode: methodNode;
config: aPPFormatterConfig.
methodNode accept: formatter.
^ aBoolean ifTrue: [self stripMethodPattern: formatter contents] ifFalse: [formatter contents]

result := aBoolean
ifTrue: [self stripMethodPattern: formatter contents]
ifFalse: [formatter contents].
aPPFormatterConfig formatToMaxLineWidth ifTrue: [result := PPWindowFormatter new format: result withWindowWidth: aPPFormatterConfig maxLineWidth].

^ result
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"format:in:notifying:decorated:" : "tobe 3/10/2021 15:45",
"formatCategory:" : "tobe 3/10/2021 14:59",
"formatClass:" : "tobe 3/10/2021 14:59",
"formatMethod:" : "tobe 3/10/2021 13:32",
"formatMethod:" : "JW 6/1/2022 19:34",
"formatPackage:" : "tobe 3/10/2021 14:59",
"formatString:class:noPattern:" : "tobe 3/10/2021 15:47",
"formatString:class:noPattern:notifying:" : "KD 6/15/2022 16:11",
Expand Down Expand Up @@ -60,7 +60,7 @@
"visitLiteralNode:" : "tobe 3/11/2021 09:09",
"visitLiteralVariableNode:" : "tobe 3/10/2021 14:58",
"visitMessageNode:" : "KD 6/15/2022 16:11",
"visitMethodNode:" : "tobe 3/11/2021 11:38",
"visitMethodNode:" : "JW 6/1/2022 20:51",
"visitNode:" : "tobe 3/11/2021 10:00",
"visitReturnNode:" : "KD 6/15/2022 16:05",
"visitTempVariableNode:" : "tobe 3/10/2021 14:58",
Expand Down
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
Expand Up @@ -2,6 +2,10 @@
"class" : {
"default" : "KD 6/15/2022 16:11" },
"instance" : {
"formatToMaxLineWidth" : "JW 6/1/2022 20:57",
"formatToMaxLineWidth:" : "JW 6/23/2022 10:53",
"maxLineWidth" : "JW 6/1/2022 19:28",
"maxLineWidth:" : "JW 6/23/2022 10:52",
"spaceBeforeComma" : "KD 6/15/2022 16:07",
"spaceBeforeComma:" : "YH 6/2/2022 14:16",
"spaceBeforePointInArray" : "Alexander Ungefug 6/1/2022 15:59",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"commentStamp" : "",
"instvars" : [
"spaceBeforeComma",
"spaceBeforePointInArray" ],
"spaceBeforePointInArray",
"formatToMaxLineWidth",
"maxLineWidth" ],
"name" : "PPFormatterConfig",
"pools" : [
],
Expand Down
Empty file.
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" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
getConfigWindowWidth: aNumber

^ PPFormatterConfig default formatToMaxLineWidth: true; maxLineWidth: aNumber.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests - WindowWidth
testSmallWindowWidth1

self canFormat:
'test

aaa aa aa aaa'
as:
'test

aaa aa aa
aaa'
with: (self getConfigWindowWidth: 10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests - WindowWidth
testSmallWindowWidth2

self canFormat:
'test

aaa aa aaa aaa'
as:
'test

aaa aa
aaa aaa'
with: (self getConfigWindowWidth: 10)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
tests - WindowWidth
testSmallWindowWidth3

self canFormat:
'test

''aaa aa aaa aaa'''
as:
'test

''aaa aa aaa aaa'''
with: (self getConfigWindowWidth: 10)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"exampleMorphDoLayoutIn" : "tobe 3/11/2021 09:00",
"getConfigSpacesBeforeComma" : "YH 6/2/2022 10:20",
"getConfigSpacesBeforePointInArray" : "KD 6/15/2022 15:56",
"getConfigWindowWidth:" : "JW 6/15/2022 15:47",
"testAllMethods" : "KD 6/15/2022 16:11",
"testBinaryMessageChain" : "tobe 3/11/2021 10:58",
"testBinaryMessageChainWithParenthesis" : "tobe 3/11/2021 13:33",
Expand Down Expand Up @@ -43,6 +44,9 @@
"testReindentMultilineComment" : "tobe 3/11/2021 10:08",
"testShortArray" : "tobe 3/11/2021 10:41",
"testShortCaseOf" : "tobe 3/11/2021 10:40",
"testSmallWindowWidth1" : "JW 6/23/2022 10:56",
"testSmallWindowWidth2" : "JW 6/23/2022 10:56",
"testSmallWindowWidth3" : "JW 6/23/2022 10:57",
"testSpaceBeforeComma" : "YH 6/2/2022 10:46",
"testSpaceBeforePointInArray" : "KD 6/15/2022 15:57",
"testSubexpressionComment" : "tobe 3/11/2021 10:08",
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
canFormat: aString toDefaultWindowWidth: anotherString

self assert: anotherString equals: (PPWindowFormatter new format: aString withWindowWidth: 83)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
helper
canFormat: aString toZeroWindowWidth: anotherString

self assert: anotherString equals: (PPWindowFormatter new format: aString withWindowWidth: 0)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
tests
testFormattingToDefaultWindowWidth1

self canFormat:
'test
ertad aweasd wed
asdasd
asdasd asdasd asd asd as dd'
toDefaultWindowWidth:
'test
ertad aweasd wed
asdasd
asdasd asdasd asd asd as dd'
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
tests
testFormattingToDefaultWindowWidth2

self canFormat:
'test
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc'
toDefaultWindowWidth:
'test
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
tests
testFormattingToDefaultWindowWidth3

self canFormat:
'test
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc'
toDefaultWindowWidth:
'test
abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc abc
abc'
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
tests
testFormattingToZeroWidth1

self canFormat:
'test
ertad aweasd wed
asdasd
asdasd asdasd asd asd as dd'
toZeroWindowWidth:
'test
ertad
aweasd
wed
asdasd
asdasd
asdasd
asd
asd
as
dd'
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"class" : {
},
"instance" : {
"canFormat:toDefaultWindowWidth:" : "JW 6/23/2022 11:49",
"canFormat:toZeroWindowWidth:" : "JW 6/23/2022 11:49",
"testFormattingToDefaultWindowWidth1" : "JW 6/23/2022 11:49",
"testFormattingToDefaultWindowWidth2" : "JW 6/23/2022 11:49",
"testFormattingToDefaultWindowWidth3" : "JW 6/23/2022 11:49",
"testFormattingToZeroWidth1" : "JW 6/23/2022 11:50" } }
Loading