Adding new highlighter lazarus / 9-Editor ---------------------------------------------------------------------- Leledumbo · 2011-08-05 07:18 I need to have CSS highlighting in the source editor, what files must be modified and what are the modifications? ---------------------------------------------------------------------- Martin_fr · 2011-08-05 10:22 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 · 2011-08-05 17:14 CSS highlighting would be appreciated. What about TSynCssSyn component in SynEdit group in component pallete? ---------------------------------------------------------------------- Leledumbo · 2011-08-05 21:51 QuoteIsn't there one already?Yep, but it's meant to be used by applications, it's not available in the source editor. QuoteCSS 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 clauseadding lshCSS to TLazSyntaxHighlighteradding corresponding entry in EditorOptionsDividerDefaults, EditorOptionsFoldDefaults, DefaultCommentTypes, LazSyntaxHighlighterNames and CompatibleLazSyntaxHilighteradding TSynCSSSyn to LazSyntaxHighlighterClassesThe popup entry appears, but selecting it doesn't highlight the current source as CSS. Did I miss something? ---------------------------------------------------------------------- Martin_fr · 2011-08-05 22:11 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 · 2011-08-05 22:14 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 · 2011-08-06 03:37 QuoteQuick 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... QuoteThe latter requiring to change the EditorOptions to provide an interface....You mean the entry in environment options? ---------------------------------------------------------------------- Martin_fr · 2011-08-06 10:31 Quote from: Leledumbo on August 06, 2011, 05:37:10 amyet the editor still can't highlight any css file... Can you send as a patch? Then I can try myself. QuoteQuoteThe 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 · 2011-08-06 22:30 QuoteCan you send as a patch? Then I can try myself.In the attachment ---------------------------------------------------------------------- Martin_fr · 2011-08-07 00:10 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.... ---------------------------------------------------------------------- Leledumbo · 2011-08-07 01:51 QuoteBTW, which version of Lazarus do you have?31419, I just diff it to head. QuoteWell 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 · 2011-08-07 09:47 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 · 2011-08-07 17:17 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 · 2011-08-07 17:28 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 · 2011-08-07 18:56 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. ---------------------------------------------------------------------- Martin_fr · 2011-08-07 19:43 If you can provide defaults for all 5 existing schemes, then I would commit the change to SVN. Css highlighter is anyway in the IDE, so it would not add much, except for a few bytes of more xml in the resource.... And since we do have an html highlighter for the source, and the ability to write web modules with fpc, it would make sense too ---------------------------------------------------------------------- Leledumbo · 2011-08-07 21:28 OK, I'll try. I'm still playing with the colors and styles.