Recent

Author Topic: SynEdit SynAny Comment Colors  (Read 793 times)

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
SynEdit SynAny Comment Colors
« on: March 03, 2025, 05:43:18 am »
Hello,
to use custom highlighting on SynEdit Component I have place a SynAnySyn Component on the Form.
How can I colorize the Comments that starts with:

** or &&

till the end of line ??
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11818
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit SynAny Comment Colors
« Reply #1 on: March 03, 2025, 10:00:35 am »
SynAnySyn has a few hardcoded comment. But they are not configurable (despite the name).

About the "after the end of line",  I don't think it implements that. It would need
function GetEndOfLineAttribute: TSynHighlighterAttributes;

The wiki has a tutorial on Highlighters (Search SynEdit, its linked on the main SynEdit page of the wiki). And then you can change the SynAnySyn as you need.
If you look at the source: You probably want to look at TSynAnySyn.MakeMethodTables, and what happens with SlashProc (so long as it all is single line). For multi line you need to follow TRangeState.

SynPosSyn can highlight text by position, but you need to update those yourself. And it likely also misses GetEndOfLineAttribute

Alternatively there is a TML (TextMate patterns) based Highlighter, but it misses documentation (well the TML grammar is mostly/partly documented on the net).

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
Re: SynEdit SynAny Comment Colors
« Reply #2 on: March 03, 2025, 11:32:02 am »
Update:

ChatGPT offers me MultiSyn which shall/can customize many more as AnySyn.
But this is untested by me.

Maybe it is better, to hard code the Highlighter as Sub Class...
Thank's for the Information's
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11818
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit SynAny Comment Colors
« Reply #3 on: March 03, 2025, 11:56:47 am »
The problem asking AI may be that "SynEdit" is to vague. There is more than one SynEdit.

That is, the SynEdit in Lazarus was forked of the original more than 20 years ago. It has since had many changes. If you find a 3rd party highlighter, you have to check for which variant of SynEdit it is. (though if it is for the original, it *probably* can be adapted with moderate effort)

paweld

  • Hero Member
  • *****
  • Posts: 1500
Re: SynEdit SynAny Comment Colors
« Reply #4 on: March 03, 2025, 12:04:03 pm »
As @Martin_fr wrote use TSynPositionHighlighter.
Attached is an example - it requires the trunk version because I tested line wrapping on it, but if you have an older version of lazarus just comment out line #7
Best regards / Pozdrawiam
paweld

paule32

  • Hero Member
  • *****
  • Posts: 645
  • One in all. But, not all in one.
Re: SynEdit SynAny Comment Colors
« Reply #5 on: March 03, 2025, 08:47:13 pm »
can I detect keyPress when the Cursor is within a comment ?
so, I don't force SynEdit with amount of work that only will occur outside comments...
MS-IIS - Internet Information Server, Apache, PHP/HTML/CSS, MinGW-32/64 MSys2 GNU C/C++ 13 (-stdc++20), FPC 3.2.2
A Friend in need, is a Friend indeed.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 11818
  • Debugger - SynEdit - and more
    • wiki
Re: SynEdit SynAny Comment Colors
« Reply #6 on: March 03, 2025, 09:15:13 pm »
There is only the normal OnKey events (down, press, up). They will be called independent on the highlighter context.

In fact synedit handles most keypresses without knowing if it is in comment, code, string, or whatever.

If you need to know, then you must parse the line.
If you have a highlighter that can detect the comment, then you can use that to parse the line. SynEdit does something like that for highlighting matching pairs of brackets. So a "(" in code is not matched by a ")" in a comment or string.


Edson

  • Hero Member
  • *****
  • Posts: 1325
Re: SynEdit SynAny Comment Colors
« Reply #7 on: March 04, 2025, 05:03:24 pm »
Hello,
to use custom highlighting on SynEdit Component I have place a SynAnySyn Component on the Form.
How can I colorize the Comments that starts with:

** or &&

till the end of line ??

This is something very easy if you use https://github.com/t-edson/SynFacilSyn. Just need the following syntax XML file:

Code: XML  [Select][+][-]
  1. <Language name="simple">
  2.   <Comment Start="**" ></Comment>
  3.   <Comment Start="&amp;&amp;" ></Comment>
  4. </Language>
  5.  
               
I don't know if it works in the last versions of SynEdit but it should.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018