Is it possible to configure formatter to preserve empty lines and line comments? e.g. -------------- myMethod someCode. < empty line that I would like to preserve > moreCode. ---------------
the formatter also automatically puts comments on the end of the previous statement. e.g.
------ someCode. "a comment" moreCode.
---- ends up as ---- someCode. "a comment"
moreCode. ----- Both those behaviors seems odd to me. I've seen empty newlines and line comments in Pharo code... so either I missed some setting or people just don't use the formatter? Thanks, Peter |
Hi peter
I do not know :) But I think that should be customizable.
If I recall, the problem is that comments are not a node but an attribute of a node. We should try to fix that. It is not clear where you always want to put them. I use the formatter and I would like to use it much more systemaitcally.
|
Ah! RBConfigurableFormatter class>>settingsOn: is missing one setting ---- (aBuilder setting: #retainBlankLinesBetweenStatements) label: 'Retain blank lines between statements'.
---- As for the comments, I looked at RBConfigurableFormatter>>formatStatementCommentsFor: one idea might be to look at the space between end of the statement and beginning of the comment and if there is newline present then preserve it.
something like -------------------------- formatStatementCommentsFor: aStatementNode originalSource isNil ifTrue: [ ^ self ].
FormatCommentWithStatements ifFalse: [ ^ self ]. aStatementNode statementComments
do: [ :each | (self newLinesBeforeStartingAt: each first) > 0 ifTrue: [ self newLine ]
ifFalse: [ codeStream tab ]. codeStream nextPutAll: (originalSource copyFrom: each first to: each last) ]
--------------------------- There should be also an accompanying setting #retainBlankLineBeforeComments. Peter
On Wed, Aug 20, 2014 at 7:45 PM, stepharo <[hidden email]> wrote:
|
actually it should be: ------------- formatStatementCommentsFor: aStatementNode originalSource isNil ifTrue: [ ^ self ].
FormatCommentWithStatements ifFalse: [ ^ self ]. aStatementNode statementComments
do: [ :each | | count | count := self newLinesBeforeStartingAt: each first.
(count) > 0 ifTrue: [ self newLines: count ] ifFalse: [ codeStream tab ].
codeStream nextPutAll: (originalSource copyFrom: each first to: each last) ] -------------- to allow having comments on top of sections of code.
On Wed, Aug 20, 2014 at 10:20 PM, Peter Uhnák <[hidden email]> wrote:
|
In reply to this post by Peter Uhnak
Thanks Peter, really useful for readability
Davide |
In reply to this post by Peter Uhnak
Thanks Peter, really useful for readability
Davide -- View this message in context: http://forum.world.st/Code-formatting-preserving-newlines-and-comments-tp4773967p4815079.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. |
Free forum by Nabble | Edit this page |