Page 1 of 1

Perfectionist: Can you indent multi-line variables without including spaces?

Posted: 07 Oct 2022, 08:07
by sashaatx
how can I write multi-line variables (I find them ultra convenient) but its obviously taking in spaces to the variable. Understandably.


I would like the long way around to prettyvariable() below, I want to be able to format properly but delete the space before each line in the variable.

Im thinking of a loop-trim? Id like to get the subs input.

​

Code: Select all

Class var
{
    prettyvariable() {
        necessary= 
        (
        unrelatedcode:="here"
        ;notes here, unrelated            
        )
    }
    
    uglyvariable() {
        necessary= 
(
unrelatedcode:="here"
;notes here, unrelated            

)
    }
}

Image

Re: Perfectionist: Can you indent multi-line variables without including spaces?

Posted: 07 Oct 2022, 08:33
by sashaatx
solution

Code: Select all




var:=var.prettyvariable()
var=
(
            %var%
        %var%
    %var%
          %var%
)

msgbox before: `n%var%

Loop, parse, var, `n
{
  newvar .= LTrim(A_LoopField," ")
  newvar .= "`n"
} 

msgbox after: `n%newvar%

Class var
{
    prettyvariable() {
        necessary= 
        (
        unrelatedcode:="here"
        ;notes here, unrelated            
        )
        return necessary
    }
}

Re: Perfectionist: Can you indent multi-line variables without including spaces?

Posted: 07 Oct 2022, 10:37
by Xtra

Code: Select all

var:=var.prettyvariable()
var=
(ltrim
            %var%
        %var%
    %var%
          %var%
)

msgbox result: `n%var%
ExitApp

Class var
{
    prettyvariable() {
        necessary= 
        (ltrim
        unrelatedcode:="here"
        ;notes here, unrelated            
        )
        return necessary
    }
}