Recent

Author Topic: Documentation for SynEdit (La biblia del SynEdit)  (Read 28226 times)

Edson

  • Hero Member
  • *****
  • Posts: 1301
Documentation for SynEdit (La biblia del SynEdit)
« on: October 12, 2013, 07:26:50 pm »
I have written a document about highlighter before: 
http://forum.lazarus.freepascal.org/index.php/topic,21952.0.html

Now I have a new document that includes the before, and covers the SynEdit component.
Well this is not so complete document but it's my humble contribution:

It's in spansih again, but I hope someone can translate.

EDITED: Link deleted. New links in the next posts.
« Last Edit: November 13, 2013, 10:18:37 pm by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #1 on: October 12, 2013, 07:50:48 pm »
Well I don't speak Spanish, but I had a look at it (just the top few pages), and it looks great (I can recognise some of the content.

as for logical versus physical, I can only judge the picture (top of page 12)

The picture (a table) has 2 rows: bytes and characters.

However the 2nd row should be "position/cell in display grid".

If you look at the tab: It is ONE SINGLE CHAR. But it takes several positions in the grid.
Btw so does the Chinese "あ". The "あ" takes 2 places in the grid. It is a so-called "full width" glyph. While latin a-z are half width glyphs. So yes, even in a strictly monospaced font, there are 2 sizes.

It is important to distinguish between:
- byte (logical)
- utf8 codepoint
- char
- glyph (not really important in this context)
- display-grid-cells (physical)



Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #2 on: October 12, 2013, 07:58:00 pm »
Quote
SynEdit1.ExecuteCommand(ecChar,'x',nil);

There is a better way:
Code: [Select]
    procedure ClearAll;
    procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode = scamEnd);

    property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String              // Logical Points
      read GetTextBetweenPoints write SetTextBetweenPointsSimple;
    property TextBetweenPointsEx[aStartPoint, aEndPoint: TPoint; CaretMode: TSynCaretAdjustMode]: String
      write SetTextBetweenPointsEx;
    procedure SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
                                   const AValue: String;
                                   aFlags: TSynEditTextFlags = [];
                                   aCaretMode: TSynCaretAdjustMode = scamIgnore;
                                   aMarksMode: TSynMarksAdjustMode = smaMoveUp;
                                   aSelectionMode: TSynSelectionMode = smNormal
                                  );

Code: [Select]
SynEdit.InsertTextAtCaret('A');
or to delete/replace text
Code: [Select]
var p1,p2: TPoint;
begin
  p1 := SynEdit.LogicalCaretXY;
  p2 := SynEdit.LogicalCaretXY;
  p2.x := p2.x + UTF8CharacterLength(@SynEdit.LineText[p2.x]); // byte len of char AFTER current caret
  SynEdit.TextBetweenPoints[p1,p2] := '';

** EDIT: I see you did cover that later
« Last Edit: October 12, 2013, 08:13:39 pm by Martin_fr »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #3 on: October 12, 2013, 08:23:45 pm »
Thanks Martin for the observations.

I will correct and complete the document in the next revision.  But InsertTextAtCaret() and TextBetweenPoints() are explained in the document. Maybe not so explained.

I don't have information about "full width" glyph. That's why I haven't included.

Do you know where can I find that information?
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #4 on: October 12, 2013, 08:35:50 pm »
As I mentioned in my "Edit", I saw to late that you included InsertTextAtCaret

"full width" is a term you can google in te context of monospaced fonts. But you do not need to explain it.

I only gave it as example that tab #9 is not the only char that takes more than one cell.

You should make a difference between "character" and "display-grid-cell"

In your table the 2nd row is called character, but tab occupies 4 places. That is wrong: tab is one char. But 4 cells in the display grid.

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #5 on: October 12, 2013, 09:30:38 pm »
Is this image better?
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 9791
  • Debugger - SynEdit - and more
    • wiki
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #6 on: October 12, 2013, 10:01:51 pm »
Yes.
The layout of the image is fine in the new and the old.  What matters is that now (in the new) it is "cells".


I guess your text mentions somewhere that #$C3#$BA is one char?

UNRELATED:
I do not know, if you point people towards the Utf8 routines (like Utf8Length, Utf8Pos, ....). If you do, you should mention, that they do NOT really work on chars, but on codepoints.


BlueIcaro

  • Hero Member
  • *****
  • Posts: 792
    • Blog personal
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #7 on: October 12, 2013, 10:59:38 pm »
Thanks for share this doc.
Also it's wrote in spanish!! (in my language!!!). Some times I'm playing with some control, and I missed a complete documentation, but now with TSynedit you did a very good documentation

Gracias, hace algo de tiempo empecé a investigar sobre Synedit, pero con tu documento me has ahorrado mucho tiempo, y enseñas cosas que habría pasado por alto. Poir cierto, el título le viene como anillo al dedo, pero podrías añadir algo así: "Todo lo que quisiste saber sobre TSynedit y nunca te atreviste a preguntar."

@Martin_Fr, I take a fast look to the documentation, and I think it's very complete, I saw the answers to the comun question that you usually post in the forum.

/BlueIcaro

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #8 on: October 12, 2013, 11:29:13 pm »
Included the observations of Martin, here the Revision 2:

BlueIcaro:
En realidad le iba a poner de título algo como "El kamasutra del SynEdit", pero podrían tomarlo como poco serio.

EDITED: Link deleted. New links in the next posts.
« Last Edit: November 13, 2013, 10:19:25 pm by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

eldonfsr

  • Sr. Member
  • ****
  • Posts: 446
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #9 on: October 13, 2013, 04:11:17 am »
Great job edson thanks a lot.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #10 on: October 13, 2013, 12:11:05 pm »
Thanks for this hard work, Edson! Here's hoping some enterprising soul will translate it for the Lazarus wiki.

En realidad le iba a poner de título algo como "El kamasutra del SynEdit", pero podrían tomarlo como poco serio.
:)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #11 on: October 20, 2013, 04:28:51 am »
Here, the last revision of "The Bible of SynEdit". I have added more information about MarkUps and about Highlighter's algorithms.

"Aquí está la nueva revisión de "La Biblia del SynEdit". He agregado más información sobre marcadores de texto y sobre los algoritmos usados en los resaltadores."

http://blog.pucp.edu.pe/media/4946/20131019-la_biblia_del_synedit_-_rev3.pdf

I'm updating the wiki on spanish, but cannot update the english version. Sorry, my English is not so good.
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #12 on: October 20, 2013, 10:09:26 am »
I'm updating the wiki on spanish, but cannot update the english version. Sorry, my English is not so good.
No problem, thanks a lot for your work! It's easier to translate something than to figure things out, do all the work to write the documentation etc.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

Morton

  • Full Member
  • ***
  • Posts: 111
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #13 on: October 20, 2013, 01:50:48 pm »
http://blog.pucp.edu.pe/media/4946/20131019-la_biblia_del_synedit_-_rev3.pdf

"De acuerdo a la comparación hecha, NO SE RECOMIENDA, de ninguna forma, implementar resaltadores de sintaxis con el algoritmo de funciones Hash"

Statement is much to broad to be generaly true.
Even your first character preselection is a hash.
A hash is simply  a kind of sieve, a preselection to avoid many comparisons.
Which sieve is the cheapest in computing time depends on the string keys to process
and may vary a lot not only by implementation, but also from compiler to compiler.

Of course if I had designed the highlighters for FPC I would have used something else,
but I would never have used your first character preselection.

BTW on an ideal machine with unlimited resources.
An algorithm using character selection for every character of the string keys would be the fastest possible  as it reduces the needed comparisons to zero.

Initializing boolean tables for every sieve level needed to process a given keylist
and store them in a level table to access them by a given level is feasible on todays PCs.
Zero comparisons needed.
« Last Edit: October 20, 2013, 03:32:53 pm by Morton »

Edson

  • Hero Member
  • *****
  • Posts: 1301
Re: Documentation for SynEdit (La biblia del SynEdit)
« Reply #14 on: October 20, 2013, 05:32:22 pm »
Quote
Even your first character preselection is a hash.

OK. But it is more a tree prefix than a hash.

The suggestion I do about the hash algortithm, is not based only on the speed. (I indicate that the first-char prefix is almost, not always, faster).

I consider several criterias:

* Speed
* Size of code, memory used
* Optimizable
* Readable
* Maintaining
* Posibility of using external file for sintax.

In all of these, the hash lose.

« Last Edit: October 20, 2013, 05:33:53 pm by Edson »
Lazarus 2.2.6 - FPC 3.2.2 - x86_64-win64 on Windows 10

 

TinyPortal © 2005-2018