Recent

Author Topic: Adding custom syntax highlighter to Lazarus IDE?  (Read 1905 times)

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Adding custom syntax highlighter to Lazarus IDE?
« on: April 08, 2021, 10:56:19 am »
Background: I've got an IDE package for Lazarus that allows to build InnoSetup (NSIS, WiX) installers, e.g. on successful compile, or manually triggered, for any installer source file that's part of the project. It cooperates with my codesigning package, allowing everything up to the finished installer to be created from the IDE.

One downside is that editing a .iss is not as comfortable as in e.g. Inno Script Studio. I don't need all the fancy stuff, but highlighting would be nice! I tried to update the settings to include ISS in the INI extensions, but in my trunk, the change simple resets.

While looking for a way to add additional highlighters, I found EditorOpts in ide/editoroptions.pp. How can I access and change this from my package (to add the additional file extension to the ini highlighter as a first step, maybe to add some keywords to the ini highlighter, and in the future add custom innosetup/nsis/wix highlighters)?

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #1 on: April 08, 2021, 11:03:29 am »
xref this recent thread https://forum.lazarus.freepascal.org/index.php/topic,54000.0.html

I'm not saying all the answers are there, but apart from anything else there's a few useful links.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #2 on: April 08, 2021, 11:24:26 am »
Thank you!

My problem is not highlighters - I've worked with them for years, been using them in many projects, creating some for inhouse formats...

What I need is access to the IDE settings for highlighters from a Lazarus package. Once I know how to get there, everything else would be "easy" :)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #3 on: April 08, 2021, 11:45:01 am »
There is no general configurable highlighter. The settings configure language specific highlighters.

To write your own highlighter, see MarkMLI's post.

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #4 on: April 08, 2021, 12:12:55 pm »
@marcow: Again, I'm not asking for highlighters, I'm asking for access to the settings of the existing highlighters.

I want to update the INI highlighter to also highlight .iss instead of just .ini for example (because InnoSetup scripts are based on ini files). And the XML highlighter to also highlight .wxs (because WiX scripts are XML files).

I want to call
Code: Pascal  [Select][+][-]
  1. EditorOpts.HighlighterList.GetInfoByType(lshIni).SetBothFilextensions('ini;iss')

Well, actually update the setting instead of hard-overwriting it, but the above shows in a single line what would be a good first step. I now did this by editing EditorOptions.pp to add the additional extension, but of course this will be gone once I update my trunk build.

And as a future step, I could always add my own TEditOptLanguageInfo to the HighlighterList to try out adding a new highlighter.

But again, my question is where EditorOpts might be made available to packages. Anything from there, I can try on my own :)
« Last Edit: April 08, 2021, 12:15:48 pm by CCRDude »

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #5 on: April 08, 2021, 12:21:31 pm »
editors->display->colors

Then near the top, change objectpascal to ini, and in the edit box next to it, you can add ; separated extensions

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #6 on: April 08, 2021, 12:26:09 pm »
Yes, I know that. See my first post.
Quote
I tried to update the settings to include ISS in the INI extensions, but in my trunk, the change simple resets.
So, two things:

  • The manual option to access this in the IDE is broken, it does not save this setting. The next time I open it, it's defaults again.
  • I want to change this by code from my package, not mouse!

PS: https://gitlab.com/ccrdude/lazinstallerhelper - this is the package I'm speaking about.
« Last Edit: April 08, 2021, 12:31:27 pm by CCRDude »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #7 on: April 08, 2021, 01:00:35 pm »
Those settings are managed in unit ide/EditorOptions.pp. (and the frame for editing is in ide/frames/editor......)
However that unit is not accessible from your package.

You would need to check, if the package IdeIntf provides any access to those settings. I do not know. (But I wouldn't have high hopes...)
« Last Edit: April 08, 2021, 01:05:01 pm by Martin_fr »

CCRDude

  • Hero Member
  • *****
  • Posts: 600
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #8 on: April 08, 2021, 01:36:28 pm »
Thank you for pointing me in the right direction :)

In fact, using IDEOptEditorIntf.pas, I can access IDEEditorOptions of type TIDEEditorOptions, which holds the EditorOpts instance (assigned in Main.pas). The problem is that it does not publish TEditorOptions from EditorOptions.pas, so I can't access HighlighterList (as you expected).

And while it mentions "feel free to extend when needed", this would either be a small fix just for this single purpose, or heavy work / refactoring to new or other units since it refers to classes currently not available in the Intf units.

Not sure if I'll create a patch or simply solve the bug that prevents saving the additional extension through the UI ;)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9867
  • Debugger - SynEdit - and more
    • wiki
Re: Adding custom syntax highlighter to Lazarus IDE?
« Reply #9 on: April 08, 2021, 02:59:10 pm »
About the bug: It would be good to report it on mantis (if it isn't there yet). A patch would still be welcome. :)


About the IdeIntf. When you patch it keep in mind that the code in the IDE is GPL, while IdeIntf is LGPL(+linking). So only interface (abstract / or empty body) should be moved.

Moving every single method, is probably overkill....

Also I am not sure what is more suitable for you:
- Modify the EditorOptions, and with that modify/overwrite the settings a user may have made (and those may be changed in the user editoroptions.xml).
- Apply your own settings to one (or some) instance(s) of the SourceEditor. For that there is SourceEditorIntf (in IdeIntf). But it probably does not yet support HL settings.
- Or maybe hook the code that translates the file extension into a highlighter. (Not sure were that code resides, probably SourceEditor[Manage] or main.pas, or project....)

About the last one:
ExtensionToLazSyntaxHighlighter is in the EditorOptsIntf. But there is no callback to hook it. (Please no OnSomething, but RegisterHandlerSomething / so more than one handler can be registered).
Also this would not just affect the editors, but also other forms (diff form / something in delphi converter / ....)

------
One more note:
IdeIntf, is to provide a LGPL interface.
The IDE code itself is GPL (and that is intended).

However, if your package is GPL, then from a license view you could use IDE code.
And afaik there is no objection to that. Only no one has bothered to add the technical ability.
IMHO breaking the IDE into packages (GPL, and in the IDE folder / clearly marked as "part of the IDE") is a good idea. Not just for access. It would also help to recompile the IDE faster.
But that is a different topic, and would require some planing.
« Last Edit: April 08, 2021, 03:04:21 pm by Martin_fr »

 

TinyPortal © 2005-2018