You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
As described in #172 -- which is essentially the dual of this issue -- queries can't (AFAIK) be written that perform different actions in different contexts. The aforementioned issue discusses a situation where syntactic elements are added in multi-line contexts only; this issue is for inserting elements in single-line contexts only.
Consider the following, in Bash:
{
foo
bar
quux
}
which is equivalent to:
{ foo; bar; quux; }
It's quite straightforward to write queries to format these compound statements:
However, this will fail -- that is, "format unexpectedly" -- if the input is syntactically invalid. For example, a single-line input of {foo;bar;quux} (note the missing trailing semi-colon) will be formatted as:
{
foo;
bar;
quux }
We could add ; delimiters in both single and multi-line contexts -- that would be valid -- but they'd be redundant in multi-line contexts.
(Aside: If redundant semi-colons exist in the original, multi-line input, they won't be removed by Topiary either.)
Describe the solution you'd like
Two new capture names: @{append,prepend}_delimited_softline.
To act as a generalisation of @{append,prepend}_spaced_softline, taking into account the local (#delimiter!) directive, in much the same way as @{append,prepend}_delimiter is a generalisation of @{append,prepend}_space.
Describe alternatives you've considered
Do nothing. That is, assume the input source is syntactically correct and format it appropriately. If the writer of the code has made mistakes, it's not Topiary's job to fix them.
TBH, I think "doing nothing" is probably the right thing to do in the example given. (In {foo;bar;quux}, the trailing semi-colon is considered an argument to quux; while unusual and bad style, that may be what's intended and it's no business of Topiary's to assume otherwise.)
Thus I'm posting this issue only to spur discussion, in case there are genuine uses for @{append,prepend}_delimited_softline.
The text was updated successfully, but these errors were encountered:
Redundant is fine, in general. For in languages that permit it, we tend to add trailing delimiters. The motivation for trailing delimiters is that they reduce the size of diffs if we add a line later.
That being said, I have to admit that in the case of Bash, having semicolon line terminators is pretty unidiomatic. So we should avoid this. And having no semicolons in the multiline case has the same diff-minimising property. So it does sound quite reasonable.
#205 introduces a predicate that is quite similar, in the sense that it outputs the #delimiter! only if the context is multiline. Here we would like the reverse, if I understand correctly.
We could summarize all of those use-cases with a single @XXXpend_context_delimiter which would take two predicates, like #delimiter_if_single_line! and #delimiter_if_multi_line!, and expand according to the context.
Maybe it's over-engineered for the moment, though.
Is your feature request related to a problem? Please describe.
As described in #172 -- which is essentially the dual of this issue -- queries can't (AFAIK) be written that perform different actions in different contexts. The aforementioned issue discusses a situation where syntactic elements are added in multi-line contexts only; this issue is for inserting elements in single-line contexts only.
Consider the following, in Bash:
which is equivalent to:
It's quite straightforward to write queries to format these compound statements:
However, this will fail -- that is, "format unexpectedly" -- if the input is syntactically invalid. For example, a single-line input of
{foo;bar;quux}
(note the missing trailing semi-colon) will be formatted as:We could add
;
delimiters in both single and multi-line contexts -- that would be valid -- but they'd be redundant in multi-line contexts.(Aside: If redundant semi-colons exist in the original, multi-line input, they won't be removed by Topiary either.)
Describe the solution you'd like
Two new capture names:
@{append,prepend}_delimited_softline
.To act as a generalisation of
@{append,prepend}_spaced_softline
, taking into account the local(#delimiter!)
directive, in much the same way as@{append,prepend}_delimiter
is a generalisation of@{append,prepend}_space
.Describe alternatives you've considered
Do nothing. That is, assume the input source is syntactically correct and format it appropriately. If the writer of the code has made mistakes, it's not Topiary's job to fix them.
TBH, I think "doing nothing" is probably the right thing to do in the example given. (In
{foo;bar;quux}
, the trailing semi-colon is considered an argument toquux
; while unusual and bad style, that may be what's intended and it's no business of Topiary's to assume otherwise.)Thus I'm posting this issue only to spur discussion, in case there are genuine uses for
@{append,prepend}_delimited_softline
.The text was updated successfully, but these errors were encountered: