[Gambas-user] 2. Fwd: while working on PrettyPrinter, changes for the IDE Editor

Charlie karl.reinl at ...9...
Mon Aug 16 22:30:29 CEST 2004


Benoit Minisini schrieb:

>On Monday 16 August 2004 00:26, Charlie Reinl wrote:
>  
>
>>Sorry guys,
>>
>>seams that I'm to hurry to day
>>
>>But has to be tested !!!!
>>
>>Amicalement
>>    
>>
Salut Benoît,

>Hi, Charlie.
>
>See my comments below.
>  
>
>I could add an event in the GambasEditor that will be raised just after a line 
>was colorized, so that you can pretty print it.
>
This is NOT PrettyPrinting is the sence how I understand PrettyPrinting 
and the work the PrettyPrinter should do.
Include PrettyPrinting automaticaly in an editor reacting line by line, 
I know 2 reasons to not to do it:
    1. PrettyPrinting is something not all coders like
    2. and main intervention, to PrettyPrint needs closed structures, to 
to well the job.

But that event would be nice for all those line analysing jobs, like 
correcting future Errors like in i=i+1 or for variables are written in 
the same way as in his declaration line ( ni will become nI while Dim nI 
as ...) and so on.
But that event should be fired
    when leaving the line or editor lose focus (my be thats what you 
mean, talking colorized)  but also when I still stay on that line and 
push a Button on the Toolbar or press F5/F8 ( and all the other cases 
where editing is finished).

>  
>
>This is faster:
>
>sLeftBlank = String$(len(sLine) - len(ltrim(sLine)), " ")
>  
>
Thank, yes it is, if it is not faster, but it is shorter, so it is better.

>  
>
>>            CASE 6 ' Number
>>                IF nI > 0 THEN
>>                    SELECT CASE iPart [nI - 1 ]
>>    
>>
>
>Why the following case ?
>  
>
May be I haven't all understood, I thougth may be I will decover other 
cases, so I started a 'Select Case'.
And even for an other reason, at my Clipper time we used to use 'Select 
Case', because while debugging, after the Select Case,
It was jumping direct to the valid Case.

>  
>
>>                        CASE 5 ' Symbol
>>                            sOut = sOut & sBlank & Left (sPart [nI ], 1 )&
>>" " & Mid (sPart [nI ], 2 )
>>                        CASE ELSE
>>                            sOut = sOut & sBlank & sPart [nI ]
>>                    END SELECT
>>                ELSE
>>                    sOut = sOut & sBlank & sPart [nI ]
>>                ENDIF
>>            CASE ELSE
>>                sOut = sOut & sBlank & sPart [nI ]
>>        END SELECT
>>       ' PRINT sPart [nI ], iPart [nI ], GetColorsName (iPart [nI ])
>>    
>>
>If the previous code was pretty printed, then the result is strange: spaces 
>before ']', ')', '[', '.'...
>  
>
My name is not 'Porte(s)', so it is a Bug not a Feature.
I looked to the closing Symbols outside, where I looked to the starting 
Symbols, and I looked for to muche

Here are the update:
    Thanks for testing:

Amicalement
Charlie

PUBLIC SUB edtEditor_Cursor()
    IF edtEditor.Line <> $iLastLine THEN
'       changings charlie
        IF Left(Trim(edtEditor.Lines[$iLastLine]) , 1) <> "'" AND Trim(edtEditor.Lines[$iLastLine]) <> "" THEN
            edtEditor.Lines[$iLastLine ]= LineAnalyze(edtEditor.Lines[$iLastLine])
        ENDIF
'       end changings charlie
        $iLastLine = edtEditor.Line
        HideCompletion
        HideSignature
        IF IsModified() THEN Scan = NULL
    ELSE IF $bCheckSignature OR frmSignature.Visible THEN
        $bCheckSignature = FALSE
        CheckSignature
    ENDIF
    DrawTitle
'   TRY PRINT Editor.Analyze(Editor.Lines[Editor.Line]).Join(",")
END
'-------------
PUBLIC SUB edtEditor_LostFocus()
    IF Left(Trim(edtEditor.Lines[$iLastLine]) , 1) <> "'" AND Trim(edtEditor.Lines[$iLastLine]) <> "" THEN
        edtEditor.Lines[$iLastLine ]= LineAnalyze(edtEditor.Lines[$iLastLine])
    ENDIF
END
'-------------
PRIVATE FUNCTION LineAnalyze(sLine AS String) AS String
DIM nI AS Integer
DIM sOut AS String
DIM sPart AS String[]
DIM iPart AS Integer[]
DIM aSPart AS Object
DIM sLeftBlanks AS String
DIM sBlank AS String
    IF IsProc(Trim(sLine)) THEN RETURN sLine
    IF Upper(Trim(sLine) )= "END" THEN RETURN sLine
'   looking for leading Blanks
    sLeftBlanks = String$(Len(sLine) - Len(LTrim(sLine)) , " ")
    ' analiesing Line
    edtEditor.Analyze(sLine)
    sPart = GambasEditor.Symbols
    iPart = GambasEditor.Types
    sBlank = " "
    ' set the sBlank
    FOR nI = 0 TO sPart.Count - 1
        SELECT CASE sPart[nI]
            CASE "." , "(" , ")" , "[" , "]"
                sBlank = ""
            CASE ELSE
                IF nI > 0 THEN
                    SELECT CASE sPart[nI - 1]
                        CASE "." , "(" , "["
                            sBlank = ""
                        CASE ELSE
                            sBlank = " "
                    END SELECT
                ELSE
                    sBlank = " "
                ENDIF
        END SELECT
        SELECT CASE iPart[nI]
            CASE 5 ' Symbol
'           here you can look up if this Symbol is written as declaret
                sOut = sOut & sBlank & sPart[nI]
            CASE 6 ' Number
                IF nI > 0 THEN
                    SELECT CASE iPart[nI - 1]
                        CASE 5 ' Symbol
                            sOut = sOut & sBlank & Left(sPart[nI] , 1 )& " " & Mid(sPart[nI] , 2)
                        CASE ELSE
                            sOut = sOut & sBlank & sPart[nI]
                    END SELECT
                ELSE
                    sOut = sOut & sBlank & sPart[nI]
                ENDIF
            CASE ELSE
                sOut = sOut & sBlank & sPart[nI]
        END SELECT
        PRINT sPart[nI] , iPart[nI] , GetColorsName(iPart[nI])
    NEXT
    sOut = sLeftBlanks & Trim(sOut)
    RETURN sOut
END
'-------------
FUNCTION GetColorsName(iType AS Integer) AS String
DIM sOut AS String
    SELECT CASE iType
        CASE edtEditor.Colors.Background
            sOut = "Background"
        CASE edtEditor.Colors.Breakpoint
            sOut = "Breakpoint"
        CASE edtEditor.Colors.Comment
            sOut = "Comment"
        CASE edtEditor.Colors.Current
            sOut = "Current"
        CASE edtEditor.Colors.DataType
            sOut = "DataType"
        CASE edtEditor.Colors.Function
            sOut = "Function"
        CASE edtEditor.Colors.Keyword
            sOut = "Keyword"
        CASE edtEditor.Colors.Normal
            sOut = "Normal"
        CASE edtEditor.Colors.Number
            sOut = "Number"
        CASE edtEditor.Colors.Operator
            sOut = "Operator"
        CASE edtEditor.Colors.String
            sOut = "String"
        CASE edtEditor.Colors.Symbol
            sOut = "Symbol"
        CASE ELSE
            sOut = "??"
    END SELECT
    RETURN sOut
END

'-------------







More information about the User mailing list