Recent

Author Topic: Adding new highlighter  (Read 13038 times)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Adding new highlighter
« on: August 05, 2011, 09:18:53 am »
I need to have CSS highlighting in the source editor, what files must be modified and what are the modifications?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #1 on: August 05, 2011, 12:22:40 pm »
Isn't there one already? I did at least see the name, but I do not know how good it is.

There are more highlighters,: http://bugs.freepascal.org/view.php?id=18248

To write your own: http://wiki.lazarus.freepascal.org/SynEdit_Highlighter

Also some-one (search the mailinglist) recently ported something called "SynWeb" very impressive. (In March: "Synedit and SynWeb port"
You may get in contact.

Chronos

  • Full Member
  • ***
  • Posts: 240
    • PascalClassLibrary
Re: Adding new highlighter
« Reply #2 on: August 05, 2011, 07:14:35 pm »
CSS highlighting would be appreciated. What about TSynCssSyn component in SynEdit group in component pallete?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #3 on: August 05, 2011, 11:51:27 pm »
Quote
Isn't there one already?
Yep, but it's meant to be used by applications, it's not available in the source editor.
Quote
CSS highlighting would be appreciated. What about TSynCssSyn component in SynEdit group in component pallete?
The other highlighters are also taken from there. I've tried modifying editoroptions.pp by:
  • adding SynHighlighterCSS to the uses clause
  • adding lshCSS to TLazSyntaxHighlighter
  • adding corresponding entry in EditorOptionsDividerDefaults, EditorOptionsFoldDefaults, DefaultCommentTypes, LazSyntaxHighlighterNames and CompatibleLazSyntaxHilighter
  • adding TSynCSSSyn to LazSyntaxHighlighterClasses
The popup entry appears, but selecting it doesn't highlight the current source as CSS. Did I miss something?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #4 on: August 06, 2011, 12:11:26 am »
Ahm long time I looked at that...

Quick look I had:
   constructor TEditOptLangList.Create;
probably needs an entry.

Look at
Revision: 24622
Date: 21:03:17, 14 April 2010
SynEdit: added Diff Highlighter

It contains the changes I made for the diff highlighter.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #5 on: August 06, 2011, 12:14:44 am »
Btw, it will be ok for the css, because it is anyway already compiled in the IDE (so it works in the designer)


But looking at all the other highlighters that were contributed:
I want to put them in a package of their own, so the compilation of the IDE does not automatically include them.
And also have 2 packages for registration: "Component palette" and "use in sourceedit"
The latter requiring to change the EditorOptions to provide an interface....
(well having said that => not any-time soon)

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #6 on: August 06, 2011, 05:37:10 am »
Quote
Quick look I had:
   constructor TEditOptLangList.Create;
probably needs an entry.
Aha! This is maybe the missing link. Thanks, man.

EDIT:
I added
Code: [Select]
NewInfo := TEditOptLanguageInfo.Create;
with NewInfo do
begin
  TheType := lshCSS;
  DefaultCommentType := DefaultCommentTypes[TheType];
  SynClass := LazSyntaxHighlighterClasses[TheType];
  SetBothFilextensions('css');
  SampleSource :=
    'div.menu {'#13#10+
    '  color: yellow;'#13#10+
    '  background-color: blue;'#13#10+
    '  left-margin: 10px;'#13#10+
    '  right-margin: 10px;'#13#10+
    '  padding: 0px;'#13#10+
    '}';
  MappedAttributes := TStringList.Create;
  //with MappedAttributes do
  //begin
  //  Add('Comment=Comment');
  //  Add('String=String');
  //  Add('Key=Key');
  //  Add('Number=Number');
  //  Add('Space=Space');
  //end;
  CaretXY := Point(1,1);
end;
Add(NewInfo);
yet the editor still can't highlight any css file...
Quote
The latter requiring to change the EditorOptions to provide an interface....
You mean the entry in environment options?
« Last Edit: August 06, 2011, 06:04:27 am by Leledumbo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #7 on: August 06, 2011, 12:31:53 pm »
yet the editor still can't highlight any css file...
Can you send as a patch? Then I can try myself.

Quote
Quote
The latter requiring to change the EditorOptions to provide an interface....
You mean the entry in environment options?
That's not related to your case. That's an idea, of allowing additional HL optional through packages to be registered.

Current HL are in SynEdit package => the IDE always includes this, so it isn't optional.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #8 on: August 07, 2011, 12:30:19 am »
Quote
Can you send as a patch? Then I can try myself.
In the attachment

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #9 on: August 07, 2011, 02:10:17 am »
BTW, which version of Lazarus do you have?

I am asking because:
1) You seem to have a pretty up-to-date version, the patch applied flawlessly => and it didn't even have context.
2) it removed ComCtrl from uses, which meant it didn't compile (and comctrls must have been there for a while (afaik)


Anyway, applied, fixed, compiled => works => css highlights flawlessly

Well that is, as soon as you actually set any colors.

The highlighters own default are bold for keywords, and italic for comments, and that's it.
But for some reason, they are rest => so you need to edit them yourself.

in the IDE directory are 5 (for each scheme) xml files containing hte settings for the highlighters => they need to be compiled into resources... (good question, I managed to get fpc to do it for me, by adding the correct $I => but in SVN are only the pre-compiled resources, as not everyone has windres, or whatever...
Sorry, a long time since I looked at resource


I am not sure, why in the absence of config it does not keep the current settings...
seems there simply is no check => it loops through all highlighters and initializes them...

  function ColorSchemeFactory: TColorSchemeFactory;
calls
  procedure TColorSchemeFactory.RegisterScheme(aXMLConfig: TRttiXMLConfig; AName,
which calls
  constructor TColorScheme.CreateFromXml(aXMLConfig: TRttiXMLConfig; const AName,

and that does
  for i := low(TLazSyntaxHighlighter) to high(TLazSyntaxHighlighter) do
same in
 TColorScheme.LoadFromXml

problem is that code is also used to load userschemes, and some of the code must be executed, even if there is nothing in the XML....
« Last Edit: August 07, 2011, 02:16:14 am by Martin_fr »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #10 on: August 07, 2011, 03:51:51 am »
Quote
BTW, which version of Lazarus do you have?
31419, I just diff it to head.
Quote
Well that is, as soon as you actually set any colors.

The highlighters own default are bold for keywords, and italic for comments, and that's it.
But for some reason, they are rest => so you need to edit them yourself.

in the IDE directory are 5 (for each scheme) xml files containing hte settings for the highlighters => they need to be compiled into resources...
You mean I have to add LangCSS to the XML files and set the colors, recompile the IDE, and everything should work?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #11 on: August 07, 2011, 11:47:31 am »
I just did set colors in the Option dialog.

The IDE saves them, and they are kept next time I start the IDE.

If you want the patch to go into SVN, then of course sensible defaults are required. And for defaults you need those XML files (and convert them to resource).

You can get the XML, using the export, and then merge it.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #12 on: August 07, 2011, 07:17:55 pm »
May I have your patch as well? I've got trouble finding code that connects between LangXXX in the XML and XXX that the editor understands.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9794
  • Debugger - SynEdit - and more
    • wiki
Re: Adding new highlighter
« Reply #13 on: August 07, 2011, 07:28:48 pm »
I didn't add anything to your code.

I applied your patch as it is (re-added ComCtrls to uses, but that's really the only thing) and compiled.

then I opened the options, went to Editor / Color section. Selected CSS from the drop down, and set some colors for the individual elements (keywords,numbers, constants.

That's it.
The settings are stored in your editoroptions.xml in your confi path. They will stay.

If you want to provide defaults (so that new installations of lazarus already have colors set, then edit export your editor-color-settings from the options dialog (I did not do that yet), and open the exported file.

IT has the same format and names as the xml files in the ide code (infarct the default xml files were created as export).

But once you change the xml files, you need to recompile the resource file too....

Leledumbo

  • Hero Member
  • *****
  • Posts: 8747
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Adding new highlighter
« Reply #14 on: August 07, 2011, 08:56:29 pm »
Oh, I see. The menu wasn't there for css previously. I'll define some colors, get the XML, recompile the resource, and finally rebuild the IDE. I got what I want done, thanks for helping.

 

TinyPortal © 2005-2018