Recent

Author Topic: Sourcecodeeditor typecolor customization  (Read 1191 times)

Shpend

  • Jr. Member
  • **
  • Posts: 93
Sourcecodeeditor typecolor customization
« on: November 18, 2019, 04:48:44 pm »
Hi folks,

I desperately want lazarus to be able to color in a predefined way, everything like this:

Code: Pascal  [Select][+][-]
  1.   type
  2.     TMyCustomColorForThisType1 = 0..100; //just some random code
  3.     TMyCustomColorForThisType2 = 0..100; //just some random code
  4.     TMyCustomColorForThisType3 = 0..100; //just some random code
  5.     TMyCustomColorForThisType4 = 0..100; //just some random code
  6.     TMyCustomColorForThisType5 = 0..100; //just some random code
  7.  

So in my fantasy, lazarus should color the "TMyCustomColorForThisType1..5" into a color i set up in the opensource lazarus editor.pas file.

But I would like to hear from you guys, which part of the lazarus package is the part where I can make this change happen via code.

I mean, feel free to also maybe implement this, since its a very nice feature to have, which all modern IDE's have, since mostly its more visually nicer code, atleast for me and a bunch of ppl :-D

Anyway, I would be super glad to hear from you guys about this!

Best regards

Shpend

winni

  • Hero Member
  • *****
  • Posts: 1437
Re: Sourcecodeeditor typecolor customization
« Reply #1 on: November 18, 2019, 05:14:03 pm »
Hi!

Have a look at this page to see how the color settings for the editor are done:

https://wiki.lazarus.freepascal.org/UserSuppliedSchemeSettings

If you click on one of the links in the first row of the table then you can see the related XML-File.

Winni

JanRoza

  • Hero Member
  • *****
  • Posts: 574
    • http://www.silentwings.nl
Re: Sourcecodeeditor typecolor customization
« Reply #2 on: November 18, 2019, 05:16:58 pm »
Have you looked at the Lazarus Tools/options menu (Display-Colors)?
Almost anything in the Editor can be colorized to your personal taste there.
Ah, I see Winni was quicker than me.  :D
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.8 FPC 3.0.4
       Lazarus 2.1.0 FPC 3.3.1
       CodeTyphon 7.2 FPC 3.3.1

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #3 on: November 18, 2019, 05:22:12 pm »
hi thx for the fast response, but sadly my point got missunderstood, np!

I would like to have a dynamic color cusomization, since i am not willing of adding like 100 datatypes for each winapi and my own one, (medium size project)

So I would basically like telling lazarus editor, that, whenever he sees :

"type
   TypeA = Byte;
   TypeB = Char;
"
he shall color TypeA and TypeB into a predefined color, so spoken in algorithms, whenever he detects the "type" keyword and next a "=" sign, color all strings between these 2 parts.

Where can I do this, i sadly have no clue where in the open source code of lazarus i can make this happen :/

JanRoza

  • Hero Member
  • *****
  • Posts: 574
    • http://www.silentwings.nl
Re: Sourcecodeeditor typecolor customization
« Reply #4 on: November 18, 2019, 05:29:58 pm »
I don't think it is wise to change the source of Lazarus, each new release of Lazarus will overwrite your changes.
No idea if many people have a need for what you want, I for one don't and have enough with the options Lazarus has now.
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.8 FPC 3.0.4
       Lazarus 2.1.0 FPC 3.3.1
       CodeTyphon 7.2 FPC 3.3.1

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #5 on: November 18, 2019, 05:30:32 pm »
Or actually, can u tell me where can I find the sourcecode of this
 "Tools-->--Settings-->Editor-->Displays-->Colors"

then I can look to create a new elementattribute which is called "types" and is distinguished from  (variable,  procedure, function) and you can then color these by your own :-)

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #6 on: November 18, 2019, 05:31:59 pm »
@JanRoza
this feature u dont need, is built-in  in any ususal IDE u know of any language, so there is a big need for it ;-)

and i want it for myself too, if u dont want it, ok, but i didnt ask who likes it and who not, i asked where can I find a solution to this

JanRoza

  • Hero Member
  • *****
  • Posts: 574
    • http://www.silentwings.nl
Re: Sourcecodeeditor typecolor customization
« Reply #7 on: November 18, 2019, 05:41:23 pm »
Sorry for giving my personal opinion!  >:(
OS: Windows 10 (64 bit) / Linux Mint (64 bit)
Laz: Lazarus 2.0.8 FPC 3.0.4
       Lazarus 2.1.0 FPC 3.3.1
       CodeTyphon 7.2 FPC 3.3.1

winni

  • Hero Member
  • *****
  • Posts: 1437
Re: Sourcecodeeditor typecolor customization
« Reply #8 on: November 18, 2019, 05:43:33 pm »
Hi!

Look at the directory lazarus/components/synedit .
There are around 25 file that start with synhighlighter

But you cannot decide the type of a variable just by one line of text:

126 can be a shortint, a smallint, a longint or an int64. OR: a byte, a word, a DWord or a Qword.
Similar with the char.

So you need a minimal parser to do your job.
That's using a sledgehammer to crack a nut.

Think about your plans.

Winni

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #9 on: November 18, 2019, 06:02:03 pm »
Hi winni!,

thx for this response, but what u mentioned is not an issue, since i want to collor (ALL) basic types as custom types, which are defined ofc as "type  TBlah = <Any Type here>" and i wanna color <Any type here> so it doesnt matter what 126 is, i just color all of them, and the base types I have already colored within the editorsettinfs in lazarus, so only the custom ones are missing, which i will color via code, so any new custom type will get colored in a specific color :)

THX in advance

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6368
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #10 on: November 18, 2019, 06:40:42 pm »
I am still not sure what exactly you want....

Quote
Code: Pascal  [Select][+][-]
  1.  TMyCustomColorForThisType1 = 0..100;

1) You want the literal typename "TMyCustomColorForThisType1" to be colored?
So in
Code: Pascal  [Select][+][-]
  1. var Foo: TMyCustomColorForThisType1;
Code: Pascal  [Select][+][-]
  1. a := TMyCustomColorForThisType1(b);
The word TMyCustomColorForThisType1 will be colored?

1b)
You want type-names (e.g. TMyCustomColorForThisType1) colored ONLY within the "type" block in which they are defined?
(And maybe when they are used as type in "var" blocks)
But not in code (begin..end) blocks

2) You want any number from 0..100 to be colored? (never mind what type the number really is, but just because it potentially might be of a custom type)?



As for 1, you may want to look at https://wiki.lazarus.freepascal.org/IDE_Window:_Editor_User_Defined_Words
This will not automatically detect the type names though. You need to add each of them by hand.

1b could be done in a highlighter (though currently not implemented).

As for 2 - no luck.

Generally the HL is based on the current file, without knowing any other file  (the exception is IFDEF lowlight, which is driven by codetools).
So if file A contains "type TMyCustomColorForThisType1 = 0..100;" and file B contains "5" then the editor does not know about file A.
But even within the same file, that would need a complete rewrite of the way highlighting works.

« Last Edit: November 18, 2019, 06:42:49 pm by Martin_fr »

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #11 on: November 18, 2019, 07:26:07 pm »
Based on n your response: I want 1) and 1b)

So this "TMyCustomColorForThisType1 " shall be now colored ANYWHERE its used!

for 2) no, this i dont want.

"1b could be done in a highlighter (though currently not implemented)."

I hope so, but I dont know yet which highlighter would this be, since there are tons of files sadly which start with the work "synchighlighter"

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6368
    • wiki
Re: Sourcecodeeditor typecolor customization
« Reply #12 on: November 18, 2019, 07:50:48 pm »
It is SynHighlighterPas.pp

The highlighter does not make a list of known types. (So it does not have a list of all the names)

In type/var blocks (an it alreadyknows if it is in such a block), it could determine the type-names lexically.
- In a type block, anything before "=" is a type.
   Also anything after a = can be a type, if it is not an inline declaration "record ... end", "(enum)", "0..9", ... then it is a typename and should be highlighted.
   e.g. type TFoo = OtherUnit.TheFooType;
- In a var/const block it is similar but after the colon.
- Same in function parameter lists (declaration).


Now in code it is way more complex.
  A := THis.Meth();
THis could be a class (type). Or it could be a variable (object).
  B := Foo(1);
Function or typecast?

Not only does one need to know if there is a type THis or Foo. It is needed to know if this identifier is a type in this scope.
Code: Pascal  [Select][+][-]
  1. type Foo = Byte;
  2. procedure Bar;
  3.   procedure Foo(a: integer); begin end;
  4. begin
  5.   x := Foo(1);
  6. end;
There is a type Foo. But above code refers to the function.

Yes all this can be determined. In fact codetools already do this.
The best way to go about this would be a TSynEditMarkup module.





In the HL look at
 TSynPasSyn.IdentKind
TSynPasSyn.NExt

and
cfbtVarType, cfbtLocalVarType

as well as
    rsAfterEqualOrColon,   // very first word after "=" or ":"
    rsAfterEqual,          // between "=" and ";" (or block end) // a ^ means ctrl-char, not pointer to type


An ident after a equal or colon, if inside a vartype block.....


I need to spent a bit more time for more info.

Also not sure, if it should at all go into the HL (it can for a personal mod). Because for future extension it may be better as a markup module. (But that needs a lot more explanation than I could write up right now)




Btw to understand how HL do work, read https://wiki.lazarus.freepascal.org/SynEdit_Highlighter
« Last Edit: November 18, 2019, 07:56:03 pm by Martin_fr »

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #13 on: November 18, 2019, 08:09:20 pm »
Quote
Now in code it is way more complex.
  A := THis.Meth();
THis could be a class (type). Or it could be a variable (object).
  B := Foo(1);
Function or typecast?

Thx first of all, for the huge interest in my issue :)

2.) But I really need to rely on lazarus/FPC naming convinctions (any type has a "T" prefix) so if you have code like: "Foo(x)" I will treat it as ur fault, if you dont mark it as TFoo (as it should be) and if its an external class, u can make it urself (but i saw like 90%code is reliant on the type convections, so no worries about this)
Same goes for "THis.Meth(), i need to rely on the naming convections, like variables never should be declared with an uppercase, so i will assume any variable is written in lowercase, so with this assumption it can work well and to be fair, i dont make excusive-assumptions here but anythign else is generally bad code desing, in tgerms of names, so I will like color the usual and good naming rules :-D

Whats ur opinion on it Martin

Shpend

  • Jr. Member
  • **
  • Posts: 93
Re: Sourcecodeeditor typecolor customization
« Reply #14 on: November 18, 2019, 08:14:19 pm »
Ahhh and btw thx for the link to understand the ighlighter  :D :P


 

TinyPortal © 2005-2018