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

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

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

Post by sashaatx » 07 Oct 2022, 08:07

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

sashaatx
Posts: 333
Joined: 27 May 2021, 08:27
Contact:

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

Post by sashaatx » 07 Oct 2022, 08:33

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
    }
}
https://github.com/samfisherirl
? /Easy-Auto-GUI-for-AHK-v2 ? /Useful-AHK-v2-Libraries-and-Classes : /Pulovers-Macro-Creator-for-AHKv2 :

User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

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

Post by Xtra » 07 Oct 2022, 10:37

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
    }
}

Post Reply

Return to “Ask for Help (v1)”