Page 11 of 20

Re: GoScintilla - 2.0 (beta 4)

Posted: Sun Jun 13, 2010 1:33 pm
by ts-soft
Feature Request :D

If i create a new goscintilla i have always to add many of keyword, the same for all goscintilla.
This is a bit slow :roll:
Can you add a function like copy keywordlist from control to control or using the same keywordmemory?

greetings

Thomas with extraordinary wishes

Re: GoScintilla - 2.0 (beta 4)

Posted: Sun Jun 13, 2010 1:54 pm
by srod
ts-soft wrote:Feature Request :D

If i create a new goscintilla i have always to add many of keyword, the same for all goscintilla.
This is a bit slow :roll:
Can you add a function like copy keywordlist from control to control or using the same keywordmemory?

greetings

Thomas with extraordinary wishes
lol. :lol:

I was just adding a facility to clone a control's lexer so that it can be used in multiple controls (with or without modifications), but have run up against a bug with PB 4.5 : http://www.purebasic.fr/english/viewtop ... =4&t=42570

The fact is that this is a simple addition under PB 4.5 (at least it will be when the bug is fixed!) but a hugely complex one without the new facilities which come with PB 4.5.

We'll have to await a bug fix Thomas.

By the way, you can of course just use a single Scintilla control and just switch the text etc. You will of course already have considered this though! :wink:

Re: GoScintilla - 2.0 (beta 4)

Posted: Sun Jun 13, 2010 2:16 pm
by ts-soft
srod wrote:By the way, you can of course just use a single Scintilla control and just switch the text etc. You will of course already have considered this though! :wink:
This is not a good idea, i have some small changes on each control (folding on of, bookmarks on of and so on),
but i can wait :wink:

thx for your reply
Thomas

Re: GoScintilla - 2.0 (beta 4)

Posted: Sat Jun 19, 2010 12:26 am
by ts-soft
Next problem :wink:

I require this: http://www.purebasic.fr/english/viewtop ... 23#p324323
and as addition the blockcomment in your c example /* bla blub blub */
If i mix this, nothing is working :oops:

greetings
Thomas

Re: GoScintilla - 2.0 (beta 4)

Posted: Sat Jun 19, 2010 11:08 am
by srod
Sorry Thomas, this is not a GoScintilla problem, but one with your own coding. :wink:

If I have time later on (unlikely) then I will take a look. Afraid that I cannot sit at the computer for very long at the moment due to a neck injury.

Re: GoScintilla - 2.0 (beta 4)

Posted: Sat Jun 19, 2010 11:32 am
by srod
Okay, this should get you started. All I have time for right now.

Code: Select all

IncludePath "..\..\..\"
XIncludeFile "GoScintilla.pbi"


Declare.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
Declare.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)


;Initialise the Scintilla library for Windows.
  CompilerIf  #PB_Compiler_OS = #PB_OS_Windows 
    InitScintilla()
  CompilerEndIf

If OpenWindow(0, 100, 200, 680, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) ;Required for the tab key to function correctly when the Scintilla control has the focus.

  ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla.
    GOSCI_Create(1, 10, 10, 660, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN)
  ;Set the padding added to the width of the line-number margin.
    GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10)

  ;Set folding symbols margin width.
    GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 24)

  ;Set the back color of the line containing the caret.
    GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $B4FFFF)

  ;Set font.
    GOSCI_SetFont(1, "Courier New", 10)

  ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs.
    GOSCI_SetTabs(1, 2)

  ;Set styles for our syntax highlighting.
  ;=======================================
    ;First define some constants to identify our various styles.
    ;You can name these as we wish.
      Enumeration
        #STYLES_COMMANDS = 1
        #STYLES_COMMENTS
        #STYLES_LITERALSTRINGS
        #STYLES_NUMBERS
      EndEnumeration

    ;Set individual styles for commands.
      GOSCI_SetStyleFont(1, #STYLES_COMMANDS, "", -1, #PB_Font_Bold)
      GOSCI_SetStyleColors(1, #STYLES_COMMANDS, $800000)  ;We have omitted the optional back color.

    ;Set individual styles for comments.
      GOSCI_SetStyleFont(1, #STYLES_COMMENTS, "", -1, #PB_Font_Italic)
      GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $006400)  ;We have omitted the optional back color.
      
    ;Set individual styles for literal strings.
      GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, #Gray)  ;We have omitted the optional back color.

    ;Set individual styles for numbers.
      GOSCI_SetStyleColors(1, #STYLES_NUMBERS, #Red)  ;We have omitted the optional back color.

  ;Set delimiters and keywords for our syntax highlighting.
  ;========================================================
    ;First some commands.
      GOSCI_AddKeywords(1, "Let", #STYLES_COMMANDS)
    ;Now some comments.
    ;This will need supplementing with our user-defined line styling function.
      GOSCI_AddKeywords(1, "Rem", #STYLES_COMMENTS)
    ;Now set up quotes to denote literal strings. 
      GOSCI_AddDelimiter(1, Chr(34), Chr(34), #GOSCI_DELIMITBETWEEN, #STYLES_LITERALSTRINGS)

  ;Additional lexer options.
  ;=========================
    ;The lexer needs to know what separator characters we are using.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/%()[],.") ;You would use GOSCI_AddKeywords() to set a style for some of these if required.
    ;We can also set a style for numbers.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS)

  ;Set our user-defined line styling function.
  ;===========================================
    GOSCI_SetLineStylingFunction(1, @MyLineStyler())

  ;Set some initial text.
  ;======================
    text$ = "/* - A not so simple demo utilising a user-defined line styling function." + #CRLF$
    text$ + "     Shows how to trap REM statements + block comments + additional code-folding! */" + #CRLF$ + #CRLF$
    text$ + "'{" + #CRLF$ + "REM - a simple assignment!" + #CRLF$
    text$ + "  Let x$ = " + Chr(34) + "Heyho!" + Chr(34) + #CRLF$
    text$ + "'}" + #CRLF$
    
    GOSCI_SetText(1, text$)

  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_SizeWindow
        ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
      
      Case #PB_Event_Gadget
        Select EventGadget()
        EndSelect
    EndSelect
  Until eventID = #PB_Event_CloseWindow 

  ;Free the Scintilla gadget.
  ;This needs explicitly calling in order to free resources used by GoScintilla.
    GOSCI_Free(1)
EndIf


;/////////////////////////////////////////////////////////////////////////////////
;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines.
Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, blnIsEndOfPreviousLineCommented, numBytesToStyle, numBytesStyled, *ptrAscii.ASCII
  Protected *ptrUnicode.UNICODE, symbolJustStyled$
  ;Is the end of the previous line commented? (We store a flag to indicate this in the line data.)
    If currentLine > 0
      blnIsEndOfPreviousLineCommented = GOSCI_GetLineData(id, currentLine-1)
    EndIf
  ;Need to loop through the UTF-8 buffer, alternating between styling comments and invoking GoScintilla's styling lexer as appropriate.
    While numUtf8Bytes
      If blnIsEndOfPreviousLineCommented
        numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, @blnIsEndOfPreviousLineCommented)
        numUtf8Bytes - numBytesStyled
        *utf8Buffer + numBytesStyled
      EndIf
      If numUtf8Bytes > 0
        ;We are now outside of a comment block. We now search for an opening /* comment marker on a symbol by symbol basis.
        ;All other symbols will be passed back to GoScintilla for styling.
          While numUtf8Bytes > 0
            *ptrAscii = *utf8Buffer
            If *ptrAscii\a = '/' And numUtf8Bytes > 1
              *ptrAscii + 1
              If *ptrAscii\a = '*' ;Open comment found.
                ;Apply the comment style to the /* symbol so as not to confuse our comment styler utility function below.
                  ScintillaSendMessage(id, #SCI_SETSTYLING, 2, #STYLES_COMMENTS)
                  numUtf8Bytes - 2
                  *utf8Buffer + 2
                blnIsEndOfPreviousLineCommented = #True ;Mark that, at this point, the end of the current line will be commented.
                Break
              EndIf
            EndIf
            numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)
            numUtf8Bytes - numBytesStyled
            If numBytesStyled
              symbolJustStyled$ = LCase(PeekS(*utf8Buffer, numBytesStyled, #PB_UTF8))
              If symbolJustStyled$ = "rem"
                ;We now apply the comments style to the rest of the line, excluding any #LF or #CR characters as this will
                ;cause Scintilla to force us to restyle the entire document.
                  *utf8Buffer + numBytesStyled
                  If numUtf8Bytes
                    numBytesStyled = numUtf8Bytes
                    *ptrAscii = *utf8Buffer + numUtf8Bytes - 1
                    While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
                      *ptrAscii - 1
                      numBytesStyled - 1
                    Wend
                    If numBytesStyled
                      ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
                      numUtf8Bytes - numBytesStyled
                      *utf8Buffer + numBytesStyled
                    EndIf
                  EndIf
              ElseIf numBytesStyled >=2
                *ptrUnicode = *utf8Buffer
                If *ptrUnicode\u = $7B27        ;'{
                  GOSCI_IncFoldLevel(id)
                ElseIf *ptrUnicode\u = $7D27    ;'}
                  GOSCI_DecFoldLevel(id)
                EndIf
                *utf8Buffer + numBytesStyled
              Else
                *utf8Buffer + numBytesStyled
              EndIf
            EndIf     
          Wend
      EndIf
    Wend
  ;Mark the current line as appropriate, depending upon whether it is an open ended comment.
    If GOSCI_GetLineData(id, currentLine) <> blnIsEndOfPreviousLineCommented
      GOSCI_SetLineData(id, currentLine, blnIsEndOfPreviousLineCommented)
      result = #GOSCI_STYLENEXTLINEREGARDLESS
    EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;A utility function called by our main line styler above to apply the comment style to any part of a line which is commented.
;Returns the number of bytes styled.
Procedure.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)
  Protected numBytesToStyle, *ptrAscii.ASCII
  *ptrAscii = *utf8Buffer
  While numBytesToStyle < numUtf8Bytes
    numBytesToStyle + 1
    If *ptrAscii\a = '*' And numBytesToStyle < numUtf8Bytes
      *ptrAscii + 1
      If *ptrAscii\a = '/'
        numBytesToStyle + 1
        *ptrCommented\i = #False 
        Break
      EndIf
    Else
      *ptrAscii + 1      
    EndIf
  Wend
  If numBytesToStyle
    ;Do not apply the comment style to EOL characters. This will cause Scintilla to force us to restyle the entire document.
    ;Instead we will leave myLineStyler() to invoke the GOSCI_StyleNextSymbol() function in order to apply the default style.
      *ptrAscii-1
      While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
        numBytesToStyle - 1
        *ptrAscii-1
        If numBytesToStyle = 0
          Break
        EndIf
      Wend
      If numBytesToStyle
        ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesToStyle, #STYLES_COMMENTS)
      EndIf
  EndIf
  ProcedureReturn numBytesToStyle
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////

Re: GoScintilla - 2.0 (beta 4)

Posted: Sat Jun 19, 2010 12:46 pm
by ts-soft
srod wrote:Sorry Thomas, this is not a GoScintilla problem, but one with your own coding. :wink:
you're right.

thx you again, works excellent :D

greetings
Thomas

Re: GoScintilla - 2.0 (beta 4)

Posted: Sun Jun 20, 2010 7:45 pm
by ts-soft
Next problem :oops:
I habe to add "//" (two slashes) as the same ' or REM ?

If i make any change on your myLineStyler() the code doesn't work anymore or do nothing, i'm to stupid for this :?

I hope you can help me.

Greetings
Thomas

Re: GoScintilla - 2.0 (beta 4)

Posted: Sun Jun 20, 2010 11:09 pm
by srod

Code: Select all

IncludePath "..\..\..\"
XIncludeFile "GoScintilla.pbi"

Declare.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
Declare.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)


;Initialise the Scintilla library for Windows.
  CompilerIf  #PB_Compiler_OS = #PB_OS_Windows 
    InitScintilla()
  CompilerEndIf

If OpenWindow(0, 100, 200, 680, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) ;Required for the tab key to function correctly when the Scintilla control has the focus.

  ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla.
    GOSCI_Create(1, 10, 10, 660, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN)
  ;Set the padding added to the width of the line-number margin.
    GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10)

  ;Set folding symbols margin width.
    GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 24)

  ;Set the back color of the line containing the caret.
    GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $B4FFFF)

  ;Set font.
    GOSCI_SetFont(1, "Courier New", 10)

  ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs.
    GOSCI_SetTabs(1, 2)

  ;Set styles for our syntax highlighting.
  ;=======================================
    ;First define some constants to identify our various styles.
    ;You can name these as we wish.
      Enumeration
        #STYLES_COMMANDS = 1
        #STYLES_COMMENTS
        #STYLES_LITERALSTRINGS
        #STYLES_NUMBERS
      EndEnumeration

    ;Set individual styles for commands.
      GOSCI_SetStyleFont(1, #STYLES_COMMANDS, "", -1, #PB_Font_Bold)
      GOSCI_SetStyleColors(1, #STYLES_COMMANDS, $800000)  ;We have omitted the optional back color.

    ;Set individual styles for comments.
      GOSCI_SetStyleFont(1, #STYLES_COMMENTS, "", -1, #PB_Font_Italic)
      GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $006400)  ;We have omitted the optional back color.
      
    ;Set individual styles for literal strings.
      GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, #Gray)  ;We have omitted the optional back color.

    ;Set individual styles for numbers.
      GOSCI_SetStyleColors(1, #STYLES_NUMBERS, #Red)  ;We have omitted the optional back color.

  ;Set delimiters and keywords for our syntax highlighting.
  ;========================================================
    ;First some commands.
      GOSCI_AddKeywords(1, "Let", #STYLES_COMMANDS)
    ;Now some comments.
    ;This will need supplementing with our user-defined line styling function.
      GOSCI_AddKeywords(1, "Rem", #STYLES_COMMENTS)
    ;Now set up quotes to denote literal strings. 
      GOSCI_AddDelimiter(1, Chr(34), Chr(34), #GOSCI_DELIMITBETWEEN, #STYLES_LITERALSTRINGS)

  ;Additional lexer options.
  ;=========================
    ;The lexer needs to know what separator characters we are using.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/%()[],.") ;You would use GOSCI_AddKeywords() to set a style for some of these if required.
    ;We can also set a style for numbers.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS)

  ;Set our user-defined line styling function.
  ;===========================================
    GOSCI_SetLineStylingFunction(1, @MyLineStyler())

  ;Set some initial text.
  ;======================
    text$ = "/* - A not so simple demo utilising a user-defined line styling function." + #CRLF$
    text$ + "     Shows how to trap REM statements + block comments + additional code-folding! */" + #CRLF$ + #CRLF$
    text$ + "'{" + #CRLF$ + "REM - a simple assignment!" + #CRLF$
    text$ + "// Another comment!" + #CRLF$
    text$ + "  Let x$ = " + Chr(34) + "Heyho!" + Chr(34) + #CRLF$
    text$ + "'}" + #CRLF$
    
    GOSCI_SetText(1, text$)

  Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_SizeWindow
        ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
      
      Case #PB_Event_Gadget
        Select EventGadget()
        EndSelect
    EndSelect
  Until eventID = #PB_Event_CloseWindow 

  ;Free the Scintilla gadget.
  ;This needs explicitly calling in order to free resources used by GoScintilla.
    GOSCI_Free(1)
EndIf


;/////////////////////////////////////////////////////////////////////////////////
;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines.
Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, blnIsEndOfPreviousLineCommented, numBytesToStyle, numBytesStyled, *ptrAscii.ASCII, *ptrUnicode.UNICODE
  Protected blnLastSymbolAValidStarter = #True
  ;Is the end of the previous line commented? (We store a flag to indicate this in the line data.)
    If currentLine > 0
      blnIsEndOfPreviousLineCommented = GOSCI_GetLineData(id, currentLine-1)
    EndIf
  ;Need to loop through the UTF-8 buffer, alternating between styling comments and invoking GoScintilla's styling lexer as appropriate.
    While numUtf8Bytes
      If blnIsEndOfPreviousLineCommented
        numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, @blnIsEndOfPreviousLineCommented)
        numUtf8Bytes - numBytesStyled
        *utf8Buffer + numBytesStyled
      EndIf
      blnLastSymbolAValidStarter = #True
      If numUtf8Bytes > 0
        ;We are now outside of a comment block. We now search for an opening /* comment marker on a symbol by symbol basis.
        ;All other symbols will be passed back to GoScintilla for styling.
          While numUtf8Bytes > 0
            numBytesStyled = 0
            *ptrAscii = *utf8Buffer
            If *ptrAscii\a = '/' And numUtf8Bytes > 1
              *ptrAscii + 1
              If blnLastSymbolAValidStarter And *ptrAscii\a = '/' ;We have a single line comment and so we style the remainder of this line (excluding EOL characters) appropriately.
                numBytesStyled = numUtf8Bytes
                ;Do not apply the comment style to EOL characters as this can cause problems.
                  *ptrAscii + numUtf8Bytes - 1
                  While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
                    *ptrAscii - 1
                    numBytesStyled - 1
                  Wend
                ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
              ElseIf *ptrAscii\a = '*' ;Open comment found.
                ;Apply the comment style to the /* symbol so as not to confuse our comment styler utility function below.
                  ScintillaSendMessage(id, #SCI_SETSTYLING, 2, #STYLES_COMMENTS)
                  numUtf8Bytes - 2
                  *utf8Buffer + 2
                blnIsEndOfPreviousLineCommented = #True ;Mark that, at this point, the end of the current line will be commented.
                Break
              EndIf
            EndIf
            If numBytesStyled = 0
              If *ptrAscii\a = 9 Or *ptrAscii\a = 32 Or *ptrAscii\a = ';'
                blnLastSymbolAValidStarter = #True
              Else
                blnLastSymbolAValidStarter = #False
              EndIf
              numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)    
              numUtf8Bytes - numBytesStyled
              If numBytesStyled
                symbolJustStyled$ = LCase(PeekS(*utf8Buffer, numBytesStyled, #PB_UTF8))
                If symbolJustStyled$ = "rem"
                  ;We now apply the comments style to the rest of the line, excluding any #LF or #CR characters as this will
                  ;cause Scintilla to force us to restyle the entire document.
                    *utf8Buffer + numBytesStyled
                    If numUtf8Bytes
                      numBytesStyled = numUtf8Bytes
                      *ptrAscii = *utf8Buffer + numUtf8Bytes - 1
                      While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
                        *ptrAscii - 1
                        numBytesStyled - 1
                      Wend
                      If numBytesStyled
                        ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
                        numUtf8Bytes - numBytesStyled
                        *utf8Buffer + numBytesStyled
                      EndIf
                    EndIf
                ElseIf numBytesStyled >=2
                  *ptrUnicode = *utf8Buffer
                  If *ptrUnicode\u = $7B27        ;'{
                    GOSCI_IncFoldLevel(id)
                  ElseIf *ptrUnicode\u = $7D27    ;'}
                    GOSCI_DecFoldLevel(id)
                  EndIf
                  *utf8Buffer + numBytesStyled
                Else
                  *utf8Buffer + numBytesStyled
                EndIf
              EndIf     
            Else
              numUtf8Bytes - numBytesStyled
              *utf8Buffer + numBytesStyled
            EndIf
          Wend
      EndIf
    Wend
  ;Mark the current line as appropriate, depending upon whether it is an open ended comment.
    If GOSCI_GetLineData(id, currentLine) <> blnIsEndOfPreviousLineCommented
      GOSCI_SetLineData(id, currentLine, blnIsEndOfPreviousLineCommented)
      result = #GOSCI_STYLENEXTLINEREGARDLESS
    EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;A utility function called by our main line styler above to apply the comment style to any part of a line which is commented.
;Returns the number of bytes styled.
Procedure.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER)
  Protected numBytesToStyle, *ptrAscii.ASCII
  *ptrAscii = *utf8Buffer
  While numBytesToStyle < numUtf8Bytes
    numBytesToStyle + 1
    If *ptrAscii\a = '*' And numBytesToStyle < numUtf8Bytes
      *ptrAscii + 1
      If *ptrAscii\a = '/'
        numBytesToStyle + 1
        *ptrCommented\i = #False 
        Break
      EndIf
    Else
      *ptrAscii + 1      
    EndIf
  Wend
  If numBytesToStyle
    ;Do not apply the comment style to EOL characters. This will cause Scintilla to force us to restyle the entire document.
    ;Instead we will leave myLineStyler() to invoke the GOSCI_StyleNextSymbol() function in order to apply the default style.
      *ptrAscii-1
      While *ptrAscii\a = #LF Or *ptrAscii\a = #CR
        numBytesToStyle - 1
        *ptrAscii-1
        If numBytesToStyle = 0
          Break
        EndIf
      Wend
      If numBytesToStyle
        ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesToStyle, #STYLES_COMMENTS)
      EndIf
  EndIf
  ProcedureReturn numBytesToStyle
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
This code may need some adjusting depending on how you want the // comment marker to behave. With the code as it is, it will only function if appearing at the beginning of a line or after a whitespace character. That adjustment I leave to you however.

Re: GoScintilla - 2.0 (beta 4)

Posted: Mon Jun 21, 2010 6:09 am
by ts-soft
Thx again, works fine here :D

Re: GoScintilla - 2.0 (beta 4)

Posted: Tue Jul 20, 2010 1:43 pm
by Peyman
Hi Srod, many thanks for creating GOSCI 2, you do a great job on this.
myLineStyler is very complex for me, can you explain this function for these jobs ?
i want create lua, in lua :

Code: Select all

Block comment start with --[[ and end with ]]
Line comment start with --
Block literal string start with [[ and end with ]]
Thanks,
Peyman.

Re: GoScintilla - 2.0 (beta 4)

Posted: Tue Jul 20, 2010 1:48 pm
by srod
Yes that will be a lot of work and I haven't time at the moment.

Afraid that you'll just have to wade through the advanced demos and perhaps have a look at some of the code in this thread which I posted in reply to some of ts-soft's queries.

Re: GoScintilla - 2.0 (beta 4)

Posted: Tue Jul 20, 2010 1:55 pm
by Peyman
yes i see them and change them for my job but just block string literal create me unsuccessful if you find some free time you made me very happy if help me but any way thanks.
have you any plan to add SCI_REGISTERIMAGE (image for code completion) ?

Re: GoScintilla - 2.0 (beta 4)

Posted: Tue Jul 20, 2010 2:07 pm
by srod
No plans to add such images no, but you should be able to add them quite easily.

Re: GoScintilla - 2.0 (beta 4)

Posted: Tue Jul 20, 2010 3:51 pm
by srod
Here you are then Peyman... you twisted my arm! :)

The following is a quick adjustment to the c-style block comment advanced demo and so I have not tested it a great deal. I have stripped out all syntax highlighting etc. so that you can just focus upon the block comments etc.

I have used a custom line styling function to give the following :
  • --[[ denotes a block comment which is then delimited by ]].
  • [[...]] denotes a literal string.
  • -- denotes a comment 'to the end of the line' etc.

Code: Select all

IncludePath "..\..\..\"
XIncludeFile "GoScintilla.pbi"


;First define some constants to identify our various styles.
;You can name these as we wish.
  Enumeration
    #STYLES_COMMENTS = 1
    #STYLES_LITERALSTRINGS
    #STYLES_NUMBERS
  EndEnumeration

Declare.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
Declare.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER=0, styleToUse = #STYLES_COMMENTS)


Structure _readData
  StructureUnion
    a.a
    u.u  
    l.l
  EndStructureUnion
EndStructure

;Initialise the Scintilla library for Windows.
  CompilerIf  #PB_Compiler_OS = #PB_OS_Windows 
    InitScintilla()
  CompilerEndIf

If OpenWindow(0, 100, 200, 600, 600, "GoScintilla demo!", #PB_Window_SystemMenu | #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
  RemoveKeyboardShortcut(0, #PB_Shortcut_Tab) ;Required for the tab key to function correctly when the Scintilla control has the focus.

  ;Create our Scintilla control. Note that we do not specify a callback; this is optional for GoSctintilla.
    GOSCI_Create(1, 10, 10, 580, 580, 0, #GOSCI_AUTOSIZELINENUMBERSMARGIN)
  ;Set the padding added to the width of the line-number margin.
    GOSCI_SetAttribute(1, #GOSCI_LINENUMBERAUTOSIZEPADDING, 10)

  ;Set folding symbols margin width.
    GOSCI_SetMarginWidth(1, #GOSCI_MARGINFOLDINGSYMBOLS, 24)

  ;Set the back color of the line containing the caret.
    GOSCI_SetColor(1, #GOSCI_CARETLINEBACKCOLOR, $B4FFFF)

  ;Set font.
    GOSCI_SetFont(1, "Courier New", 10)

  ;Set tabs. Here we use a 'hard' tab in which a tab character is physically inserted. Set the 3rd (optional) parameter to 1 to use soft-tabs.
    GOSCI_SetTabs(1, 2)

  ;Set styles for our syntax highlighting.
  ;=======================================
    ;Set individual styles for comments.
      GOSCI_SetStyleFont(1, #STYLES_COMMENTS, "", -1, #PB_Font_Italic)
      GOSCI_SetStyleColors(1, #STYLES_COMMENTS, $006400)  ;We have omitted the optional back color.

    ;Set individual styles for literal strings.
      GOSCI_SetStyleColors(1, #STYLES_LITERALSTRINGS, #Blue)  ;We have omitted the optional back color.

    ;Set individual styles for numbers.
      GOSCI_SetStyleColors(1, #STYLES_NUMBERS, #Red)  ;We have omitted the optional back color.

  ;Additional lexer options.
  ;=========================
    ;The lexer needs to know what separator characters we are using.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_SEPARATORSYMBOLS, @"=+-*/[]") ;You would use GOSCI_AddKeywords() to set a style for some of these if required.
    ;We can also set a style for numbers.
      GOSCI_SetLexerOption(1, #GOSCI_LEXEROPTION_NUMBERSSTYLEINDEX, #STYLES_NUMBERS)

  ;Set our user-defined line styling function.
  ;===========================================
    GOSCI_SetLineStylingFunction(1, @MyLineStyler())

  ;Set some initial text.
  ;======================
    text$ = "--[[ A simple demo utilising a user-defined line styling function." + #CRLF$
    text$ + "Shows how to trap various LUA constructs!]]" + #CRLF$ + #CRLF$
    text$ + "Let x$ = [[Heyho!]] --A simple assignment." + #CRLF$
    
    GOSCI_SetText(1, text$)
  
   Repeat
    eventID = WaitWindowEvent()
    Select eventID
      Case #PB_Event_SizeWindow
        ResizeGadget(1, #PB_Ignore, #PB_Ignore, WindowWidth(0)-20, WindowHeight(0)-20)
      
      Case #PB_Event_Gadget
        Select EventGadget()
        EndSelect
    EndSelect
  Until eventID = #PB_Event_CloseWindow 

  ;Free the Scintilla gadget.
  ;This needs explicitly calling in order to free resources used by GoScintilla.
    GOSCI_Free(1)
EndIf


;/////////////////////////////////////////////////////////////////////////////////
;The following is our user-defined line-styling function, called whenever GoScintilla is called upon to style lines.
Procedure.i myLineStyler(id, *utf8Buffer.ASCII, numUtf8Bytes, currentLine, startLine, originalEndLine)
  Protected result = #GOSCI_STYLELINESASREQUIRED, blnIsEndOfPreviousLineCommented, numBytesToStyle, numBytesStyled, *ptrAscii.ASCII
  Protected blnLastSymbolAValidStarter = #True, *ptrData._readData
  ;Is the end of the previous line commented? (We store a flag to indicate this in the line data.)
    If currentLine > 0
      blnIsEndOfPreviousLineCommented = GOSCI_GetLineData(id, currentLine-1)
    EndIf
  ;Need to loop through the UTF-8 buffer, alternating between styling comments and invoking GoScintilla's styling lexer as appropriate.
    While numUtf8Bytes
      If blnIsEndOfPreviousLineCommented
        numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, @blnIsEndOfPreviousLineCommented)
        numUtf8Bytes - numBytesStyled
        *utf8Buffer + numBytesStyled
      EndIf
      blnLastSymbolAValidStarter = #True
      If numUtf8Bytes > 0
        ;We are now outside of a comment block. We now search for an opening comment block marker on a symbol by symbol basis.
        ;All other symbols will be passed back to GoScintilla for styling.
          While numUtf8Bytes > 0
            numBytesStyled = 0
            *ptrData = *utf8Buffer
            If numUtf8Bytes >= 4 And *ptrData\l = $5B5B2D2D ;'--[['
              ;Apply the comment style to the --[[ symbol so as not to confuse our comment styler utility function below.
                ScintillaSendMessage(id, #SCI_SETSTYLING, 4, #STYLES_COMMENTS)
                numUtf8Bytes - 4
                *utf8Buffer + 4
                blnIsEndOfPreviousLineCommented = #True ;Mark that, at this point, the end of the current line will be commented.
                Break
            ElseIf numUtf8Bytes >=2
              If *ptrData\u = $2D2D ;'--'
                numBytesStyled = numUtf8Bytes
                ;Do not apply the comment style to EOL characters as this can cause problems.
                  *ptrData + numUtf8Bytes - 1
                  While *ptrData\a = #LF Or *ptrData\a = #CR
                    *ptrData - 1
                    numBytesStyled - 1
                  Wend
                  ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesStyled, #STYLES_COMMENTS)
              ElseIf *ptrData\u = $5B5B ;'[['
                numBytesStyled = myStylerUtility_StyleCommentPart(id, *utf8Buffer, numUtf8Bytes, 0, #STYLES_LITERALSTRINGS)
              EndIf
            EndIf
            If numBytesStyled = 0
              If *ptrData\a = 9 Or *ptrData\a = 32
                blnLastSymbolAValidStarter = #True
              Else
                blnLastSymbolAValidStarter = #False
              EndIf
              numBytesStyled = GOSCI_StyleNextSymbol(id, *utf8Buffer, numUtf8Bytes)    
            EndIf
            numUtf8Bytes - numBytesStyled
            *utf8Buffer + numBytesStyled
          Wend
      EndIf
    Wend
  ;Mark the current line as appropriate, depending upon whether it is an open ended comment.
    If GOSCI_GetLineData(id, currentLine) <> blnIsEndOfPreviousLineCommented
      GOSCI_SetLineData(id, currentLine, blnIsEndOfPreviousLineCommented)
      result = #GOSCI_STYLENEXTLINEREGARDLESS
    EndIf
  ProcedureReturn result
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////


;/////////////////////////////////////////////////////////////////////////////////
;A utility function called by our main line styler above to apply the comment style to any part of a line which is commented.
;Returns the number of bytes styled.
Procedure.i myStylerUtility_StyleCommentPart(id, *utf8Buffer.ASCII, numUtf8Bytes, *ptrCommented.INTEGER=0, styleToUse = #STYLES_COMMENTS)
  Protected numBytesToStyle, *ptrData._readData
  *ptrData = *utf8Buffer
  While numBytesToStyle < numUtf8Bytes
    numBytesToStyle + 1
    If numBytesToStyle < numUtf8Bytes And *ptrData\u = $5D5D ;']]'
      numBytesToStyle + 1
      If *ptrCommented
        *ptrCommented\i = #False 
      EndIf
      Break
    Else
      *ptrData + 1      
    EndIf
  Wend
  If numBytesToStyle
    ;Do not apply the comment style to EOL characters. This will cause Scintilla to force us to restyle the entire document.
    ;Instead we will leave myLineStyler() to invoke the GOSCI_StyleNextSymbol() function in order to apply the default style.
      *ptrData-1
      While *ptrData\a = #LF Or *ptrData\a = #CR
        numBytesToStyle - 1
        *ptrData-1
        If numBytesToStyle = 0
          Break
        EndIf
      Wend
      If numBytesToStyle
        ScintillaSendMessage(id, #SCI_SETSTYLING, numBytesToStyle, styleToUse)
      EndIf
  EndIf
  ProcedureReturn numBytesToStyle
EndProcedure
;/////////////////////////////////////////////////////////////////////////////////
I hope this helps?

If it does, then I charge a barrel of ale for such work! :wink: Mind you, with that measure, ts-soft should buy me a fricking brewery! :twisted: