• Welcome to Jose's Read Only Forum 2023.

Add Brace Highlighting To CSED (updated)

Started by Nick Melnick, January 02, 2015, 09:02:28 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Nick Melnick

This is useful for locating faulty brace (paren, etc) placement when writing code.
When a brace is encountered, and it has a match, the brace(s) will be enclosed in
green colored boxes. If there is no matching brace, the offending brace will be
enclosed in a red box. The code responds to: () [] {} <>.

First, paste the following block of code in
just above the * EXIT FUNCTION * statement:

            ' Add Brace Highlighting Functionality:
            ' Refer to: CSED_SCI.INC, sub: CSED_ShowLinCol
            ' First, we set the style of the indicator number we want to use to the Box style
            SendMessage hEdit, %SCI_INDICSETSTYLE, 8, %INDIC_BOX
            ' Then, we make that indicator the current one
            SendMessage hEdit, %SCI_SETINDICATORCURRENT, 8, 0
            ' Lastly, we apply the indicator (in this case), to a single char
            SendMessage hEdit, %SCI_BRACEHIGHLIGHTINDICATOR, 1, 8 ' use indicator for SCI_BRACEHIGHLIGHTINDICATOR...

Then, paste the following block of code in
CSED_SCI.INC, sub: CSED_ShowLinCol
just above the * END SUB * statement:

   '  Refer to CSED.BAS, function: CSED_MDIWindowProc, CASE %WM_CREATE
   SELECT CASE SendMessage(pSed.hEdit, %SCI_GETCHARAT, curPos, 0)
   CASE 40, 41, 60, 62, 91, 93, 123, 125  ' () <> [] {}
      endPos = SendMessage(pSed.hEdit, %SCI_BRACEMATCH, curPos, 0)
      IF endPos < 0 THEN   ' No match
         SendMessage pSed.hEdit, %SCI_INDICSETFORE, 8, %RED
         SendMessage pSed.hEdit, %SCI_BRACEBADLIGHT, curPos, 0
      ELSE                 ' Have match
         SendMessage pSed.hEdit, %SCI_INDICSETFORE, 8, %GREEN
         SendMessage pSed.hEdit, %SCI_BRACEHIGHLIGHT, curPos, endPos
      END IF
   CASE ELSE   ' Clear any Brace Highlighting
      SendMessage pSed.hEdit, %SCI_BRACEHIGHLIGHT, %FALSE, %FALSE

You may want to consider adding this as an option in a future release of CSED, Jose.
Some fixes/enhancements.
An annoying green rectangle would appear at line 0, position 0 in the document.
In the 2nd block of code -
Replace: SendMessage pSed.hEdit, %SCI_BRACEHIGHLIGHT, %FALSE, %FALSE

The markers were difficult to see. In the 1st block of code-
Replace: SendMessage hEdit, %SCI_INDICSETSTYLE, 8, %INDIC_BOX

Add these two lines of code after the last line:
SendMessage hEdit, %SCI_INDICSETOUTLINEALPHA, 8, 255 ' transparency of outline
SendMessage hEdit, %SCI_INDICSETALPHA, 8, 127        ' transparency of interior

Adjust the values to your liking.

José Roca

I don't have plans of releasing new versions of the editor because I haven't done any programming, except updating the Windows API headers, since Bob's death.

But you can make your own version and add all the features you like.

Permission is granted to develop new versions of the editor as long as the source code is made freely available in this forum or elsewhere.

Nick Melnick

>I don't have plans of releasing new versions of the editor...

I'm sorry to hear that Jose, since much of your code postings have been
useful and educational.