t-edson / SynFacilSyn

Scriptable Highlighter for the SynEdit Component of Lazarus
GNU General Public License v2.0
34 stars 16 forks source link

Facil for atSynEdit #18

Closed Alexey-T closed 9 years ago

Alexey-T commented 9 years ago

Feel free to ask more:if wiki misses txt, I write more or tell here...

t-edson commented 9 years ago

OK, it could be. I don't understand yet, how one adapter works.

t-edson commented 9 years ago

Now I'm updating the SynFacilSyn with some patchs and documentation, before to take the AtSynEdit version.

Alexey-T commented 9 years ago

adapter: don't do adapter. First do OnCalcHilite event. If u ll do it--I ll help to make adapter

t-edson commented 9 years ago

I've checking the OnCalcHilite event on the \app\demo_editor. And can see that the key for highlighting, is to fill the AParts[] table with information about the tokens. The questions are:

  1. Why you use copy in Str:= Copy(ed.Strings.Lines[ALineIndex], ACharIndex, ALineLen) ? Wouldn't be the same to do Str:= ed.Strings.Lines[ALineIndex]?
  2. How do you implement highlighting for multi-line tokens like Comments? I only see a process "by line" without any reference to previous line.
t-edson commented 9 years ago

I think the information on the Wiki for highlighting must be clarified:

== How to highlight syntax? == Ther are two ways: === Using Adpter === ... === Using the event OnCalcHilite === ...

Alexey-T commented 9 years ago

hi.. --The questions are:1. Why you use copy in Str:= Copy(ed.Strings. Becaus Line can be 300 chars, and you need to get only ~~80 from it (wordwrap On)

--How do you implement highlighting for multi-line tokens As always for all lines. OnCalcHilite must work for all lines. if comment is 3 lines, OnCalchilite must give hilite for each of 3 lines

Alexey-T commented 9 years ago

information on the Wiki changed: thankx..

Alexey-T commented 9 years ago

Logic of OnCalchilite isnot simple. then.

t-edson commented 9 years ago

Good. But on multiline tokens, it's needed to know the state of the previous lines, for to work. One way would be to create an special structure for to save the state of every line. But I'm not sure it's the best way. Questions:

  1. Is there some way for to save adiitonal data for each line in ATSynEdit, like it's done in SynEdit?
  2. How is the order in wich OnCalchilite() is called in a common edition task? I guess it's not always sequencial.
Alexey-T commented 9 years ago

Q1.: what data? TATStrings cannot have more data Q2. from top line to bottom skipped fully folded lines

t-edson commented 9 years ago

So I need to create my own structure for to save the state of the edit. I don't know how EControl works.

I wanted to include this data (state of the scanner for to highlight) on ATSynEdit, like SynEdit do, using the Object part of TSTrings.

"from top line to bottom" I don't think so. I don't think that for every key pressed, all the text is scanned.

Alexey-T commented 9 years ago

U have file 200 lines. top scroll pos is 10, height 30 lines. u get indexes from 10 to 10+30..31

Alexey-T commented 9 years ago

--own structure for to save the state Yes (don't see EControl- no need)

t-edson commented 9 years ago

Let me know if I understand: "For every time you press a key (no control key), ATSynEdit call OnCalchilite, for every visible line on the editor".

Alexey-T commented 9 years ago

Yes

t-edson commented 9 years ago

OK. A simple, an efective way to refresh. Questions: Why you make this verification: if npart>High(AParts) then exit; ? Is the size of AParts limited? How many "parts" can a I use?

Alexey-T commented 9 years ago

yep: limited; it is array! High(var) gets last index. Low()=0

t-edson commented 9 years ago

I know it's an array. I will change the question: In which situations I would have npart>High(AParts)?

Alexey-T commented 9 years ago

in case I set loo small AParts len in my code. and editor line has many tokens.

t-edson commented 9 years ago

There is a first test of using SynFacilSyn here: https://github.com/t-edson/SynFacilSyn/tree/1.11/_demoSynFacilonATSynEdit Like it's expected, It cann't process mutil-line tokens, because have non information of previous lines. There is a dependency of the packet SynEdit.

Alexey-T commented 9 years ago

good. WIll test!

Alexey-T commented 9 years ago

good:keywords, comments ok hilited. :) not others. My notes.

need/ changed to

function GetTokenKind: PtrInt; reintroduce;    
Alexey-T commented 9 years ago

btw. EControl has all parse-ressults in memory. adapter calls it to get tokens multiline. U need to save results. And call em later..

t-edson commented 9 years ago

The demo is only a simple test. I will check the case of the paths, but I work on windows.

t-edson commented 9 years ago

GetTokenKind is a virtual method defined on the Base class. Using casting for to obtain th attribute is not the best way. I will consider to include a special function for to do it.

Alexey-T commented 9 years ago

==special function for to do it.= Ok english "function to do it", no "for"

t-edson commented 9 years ago

Thank for the english correction. I was thinking, It would be better to have a space into ATSynEdit, for to storage the highlighting information. Have an external structure could be slower.

Alexey-T commented 9 years ago

"for to storage" again. (Wrong lang.) I don't get an idea. what storage..

t-edson commented 9 years ago

You know highlighter needs to have information of the state of previous line to right proccess the multiline tokens. This needs to have some structure (like an array) to save the state of every line. And I said ATSynEdit would have this structure.

t-edson commented 9 years ago

Having an external structure would make necessary to synchronize the size, every time the editor adds or removes lines. This is totally possible, but could be slower than have the storage internally in ATSynEdit.

Alexey-T commented 9 years ago

hm. atSynEdit also needs to remake structure on each change. And sync its size. no? it ll be same slower. Why i dont like idea? because much work for me. And u didn't say what struct- Pointer for each line?

i try to have small ATStrings. some users tell Cudatext gets 300Mb on big 10M file. Reason: many items in TATStrings

t-edson commented 9 years ago

300Mb for a 10M file? You really have a design problem. That's not efficient. Maybe you need to redesign.

t-edson commented 9 years ago

For highlighting, it's only necessary a pointer for each line. Do you maintain an array (TATLineParts) for each line? Using an array of static data for highlighting, is bad for memory.

Alexey-T commented 9 years ago

200M for 10M file maybe or 150M. I have record: see

TATStringItem = class
public
ItemString: atString;
ItemEnd: TATLineEnds;
ItemState: TATLineState;
ItemSeparator: TATLineSeparator;
ItemHidden: array[0..cMaxStringsClients-1] of smallint;
  //0: line visible,
  //-1: line hidden,
  //>0: line hidden from this char-pos
ItemBm: byte;
ItemBmColor: TColor;
t-edson commented 9 years ago

Sorry. I don't understand what you say. I said I prefer ATSynEdit have an internal storage for highlighters.

Alexey-T commented 9 years ago

Why i donot want Pointer for each ATStrings line: it is 4 byte per line, 100000lines- 400K memory. 400K memory which not needed for almost all apps. can you make your 'storage'?

t-edson commented 9 years ago

It will be probably slower, but it's possible. I need you to give me a detail of events to catch, in order to have a synchronized list with the size of the total editor lines.

Alexey-T commented 9 years ago

Okey:event is procedure

TATAdapterHilite = class(TComponent)
public
  procedure OnEditorChange(Sender: TObject); virtual;

can you make adapter from OnCalcHilite? if yes, add to adapter this procedure

procedure OnEditorChange(Sender: TObject); override;

if no, I make adapter

t-edson commented 9 years ago

I guess you are saying: "No. There is not events defined to capture changes on the editor. You need to use adapters for that." This confused me. "can you make adapter from OnCalcHilite?" I don't know exactly, how an adapter works. Do you have an basic sample of that? What is the relation between adapters and OnCalcHilite?

Alexey-T commented 9 years ago

hm, wait a patch from me. i try making adapter

t-edson commented 9 years ago

Accepted, but the directories was reordered. I'm still waiting the responses to my questions:

  1. "No. There is not events defined to capture changes on the editor. You need to use adapters for that.". Is it OK?
  2. What is the relation between adapters and OnCalcHilite?
ghost commented 9 years ago

responces 1.U can use both adapter and nonadapter. In adapter use procedure-i added 'showmessage'. in non adapter use OnChange(OnChanged?) 1b.Cannot detect which lines changed 2.ATsynedit first calls Adapter if it assigned, then calls OnCalcHilite if assigned

t-edson commented 9 years ago

I see you have the type TATLineParts as a fixed Array, until 1000 elements. How many instances of TATLineParts do you have normally in ATSynEdit?

ghost commented 9 years ago

IMO, one instance if i correct

t-edson commented 9 years ago

IMHO, that array is information of the highlighter too, it must not be stored at the editor. It seems to me your design doesn't separate well the function of the highlighter and the editor.

ghost commented 9 years ago

I dont say it is stored. It is calced, then ed painted, then array deleted (array here only when needed)

t-edson commented 9 years ago

How do I know the index of the first line of TATSynEdit.Strings, that is visible on the screen? And the the last line?

t-edson commented 9 years ago

Is it possible to know the first and the last line modified, after an operation like "Paste text" or a multi-line edition?

Alexey-T commented 9 years ago

index of the first line: prop LineTop, visible at btm: LineBottom. NN lines may be hidden in range (folded)

Alexey-T commented 9 years ago

ATStrings- property ListUpdates: TList, has indexes of lines chged. Maybe list clears before u get OnChange? need check..