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

Benoit Minisini gambas at ...1...
Mon Aug 16 20:59:10 CEST 2004


On Monday 16 August 2004 22:30, Charlie wrote:
> 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.

Let's call it "Line pretty printing" :-)

>
> 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).
>

I think an event raised just before colorize the line will be sufficient, as 
colorize is a sort of "line pretty printing", and so the moments it is run 
are good moments for "line pretty printing".

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

LTrim() does not create any intermediate strings, so it IS faster: do the 
test! :-) 

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

I didn't understand what you said :-(

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

If you look carefully at the following code, provided it was "line pretty 
printed", you will see stranges spaces yet...

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

Regards,

-- 
Benoit Minisini
mailto:gambas at ...1...




More information about the User mailing list