Recent

Author Topic: user defined markup and token type (string/comment)  (Read 6453 times)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
user defined markup and token type (string/comment)
« on: April 08, 2015, 01:22:42 pm »
Follow up to http://forum.lazarus.freepascal.org/index.php/topic,27985.msg173857.html#msg173857

Yes you are right, I did not check before I posted.
The base colors do not have a priority.

You can add a feature request, but it will be awhile before I get to it.

It doesn't have to be a feature request. The syntax highlighting engine would only need to switch into string mode once it encounters an opening quote (as it does for the color), disabling any keyword checking until the closing quote.

Well even this kind of "disabling" would need to bi implemented. So it is a feature request.

But it is not at all that easy.

The markup, and the highlight are done in 2 independent modules. That is because the markup works with any highlighter, and even without highlighter.

The markup would need to enquire with the highlighter (if any highlighter is used), what token type is present at a certain location. Strings can start with different chars in different languages. In some languages string may be multi line)

And (example for pascal) this would include handling search terms like
Code: [Select]
:= 'abcwhich are part string (so it is not enough to check at the begin of the token)

In the IDE the search engine does not provide reg ex for this, but some of the related classes can be used with reg-ex. So matching part string would not always be that obvious.

It also needs to detect, if text changes between string, and none string (multiline string / change of hl). Or (in pascal) with comments, that could be at any line in the text (string becomes comment and vice versa), since there are multi line comments.

The fact that strings can change over many lines, of which only the first was edited, means that the current concept of finding the correct range to rescan for matches must be changed too. IIRC Currently only edited lines are re-searched (if they are visible on the screen)

All in all, it is not a simple as it sounds.


I would probably first work on providing this via priorities (not hand to do, but I still need to find the time, there are other things I want to finish first).
Priorities will solve many cases.

Priorities do not have the issues with what needs to be searched. The found results do not change. priorities simply decide, at the time of actual painting the text to the canvas, if a color is applied or not.

Adding dedicated search in/outside string options would probably be much later.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: user defined markup and token type (string/comment)
« Reply #1 on: April 08, 2015, 01:45:01 pm »
OK, I understand. Thanks for your explanation Martin.
keep it simple

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: user defined markup and token type (string/comment)
« Reply #2 on: April 08, 2015, 01:50:54 pm »
I suggest you make she change to the highlighter
Try in components\synedit\synhighlighterpas.pp
line 2345
Code: [Select]
  fStringAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrString, SYNS_XML_AttrString);
instead of TSynHighlighterAttributes.Create

And the same for comments. Then you can set their priority.
User defined colors also have a priority (edit on the user defined page).

That will get you immediately what you need.

When I have time, I probably merge the 2 classes (assuming all checks pass / e.g. need to check, if alpha works in that case).

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: user defined markup and token type (string/comment)
« Reply #3 on: April 08, 2015, 02:33:31 pm »
Still doesn't work. But it is only an annoyance not worth all the effort right now. I tested 1.4RC2 extensively while porting a realstudio project to freepascal. It worked great. Now I test 1.4RC3...
keep it simple

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: user defined markup and token type (string/comment)
« Reply #4 on: April 08, 2015, 02:56:49 pm »
It did work for me when I tested.
What exactly do you highlight?

Though it can only do color. Underline and italics do have prioritise, but they are not available in the IDE options dialog.

I have highlights for "debugln" and "assert" (font color)

The user defined font color has a priority of 3500 (afaik default)

Assuming that string does have a color assigned for its font/foreground color,
if I set the string font color priority to 3501, then that worked.

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: user defined markup and token type (string/comment)
« Reply #5 on: April 08, 2015, 05:20:19 pm »
I still do not get priority settings next to the colour settings when I select string or comment.

In synhighlighterpas.pp fIDEDirectiveAttri and fCaseLabelAttri are also instantiated from AttributeModifier.Create but both can only change alpha settings in IDE Options (with AND without a selected foreground colour).
« Last Edit: April 08, 2015, 05:30:06 pm by Artie »
keep it simple

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9754
  • Debugger - SynEdit - and more
    • wiki
Re: user defined markup and token type (string/comment)
« Reply #6 on: April 08, 2015, 05:30:25 pm »
After I replaced, and recompiled.

IF you mark your string with say a background color, then you must set the foreground color to the same value as default text, and set the checkbox.

If the checkbox is not set. then the priority is not listed.

If you want do keep he backcolor, then you must set the backcolors checkbox (and ensure priority is less than selection)

The image is, before I increased the priority

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: user defined markup and token type (string/comment)
« Reply #7 on: April 08, 2015, 08:26:15 pm »
Thanks Martin, yes I got it working.

I only need to uncheck BOLD for custom words (and consequently for reserved words), otherwise they would still raise to bold in string texts. But you mentioned this before, so this was to be expected. Thanks again!
keep it simple

munair

  • Hero Member
  • *****
  • Posts: 798
  • compiler developer @SharpBASIC
    • SharpBASIC
Re: user defined markup and token type (string/comment)
« Reply #8 on: November 11, 2016, 11:32:52 am »
With version 1.6 this hack no longer seems to work. I changed synhighlighterpas.pp as suggested:
Code: Pascal  [Select][+][-]
  1. // fCommentAttri := TSynHighlighterAttributes.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
  2. fCommentAttri := TSynHighlighterAttributesModifier.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
  3. fCommentAttri.Style:= [fsItalic];
  4. AddAttribute(fCommentAttri);
  5. FCurCommentAttri := TSynSelectedColorMergeResult.Create(@SYNS_AttrComment, SYNS_XML_AttrComment);
Did the same for fStringAttri. I recompiled the IDE with and without the FCur<>Attri line but it makes no difference. With the foreground color selected alpha and priority settings do not show up. Is there another hack I should be aware of?
keep it simple

 

TinyPortal © 2005-2018