SynEdit

From Free Pascal wiki
Jump to navigationJump to search

Deutsch (de) English (en) español (es) français (fr) 日本語 (ja) polski (pl) русский (ru) 中文(中国大陆)‎ (zh_CN)

General

Synedit is a syntax highlighting edit control with support for many languages/syntaxes.

The SynEdit contained in Lazarus is based on on SynEdit 1.0.3 [[1]], and was adapted and extended quite a lot. For example UTF-8 support and code folding were added.

The package contains a source editor component named TSynEdit, several syntax highlighters and other components used for source editing.

It is licensed under the same terms as the original SynEdit (MPL or GPL)

Synedit 2.0.5 port

An alternate port of the current version of the original SynEdit :

http://wiki.lazarus.freepascal.org/SynEdit/port

code: https://github.com/rnapoles/

SynEdit in the IDE

The SynEdit in Lazarus is a built-in package, because the IDE uses it itself. Therefore the package can not be removed from the installation list. To remove the entries from the component palette, the SynEditDsgn package can be removed from installation.

Using SynEdit

Highlighting

(Auto-)Completion

There are 3 completion plug-ins for SynEdit:

  • TSynCompletion
    • Offers a list of words in a drop-down.
    • Used in the IDE for identifier completion.
    • Included in examples.
    • Only available in the component palette since 0.9.31
  • TSynAutoComplete
    • Replaces the current token (if known) with a piece of text. Not interactive. No drop-down
    • Included in examples.
    • Available in the component palette.
  • TSynEditAutoComplete
    • Basic template module. No drop-down.
    • Used by the IDE for code-templates. The IDE contains additional code extending the features. (drop-down and syncro macros are added by IDE only)
    • Not Included in examples.

See examples for more info.

Todo: The differences between 2nd and 3pd need to be documented. Maybe they can be merged

Change text from code

Text can be accessed via SynEdit.Lines. Changing text via the Lines property does not work with undo/redo

Use TextBetweenPoints and TextBetweenPointsEx to change text, if you want undo/redo do work.

BookMarks

Please see the following topic in the forum: http://forum.lazarus.freepascal.org/index.php/topic,14948.msg79794.html

Examples

Examples can be found in the folder lazarus/examples/synedit

How to add support to Copy, Paste, Cut, Undo, Redo, etc

These features can be implemented by using SynEdit commands.

uses
  ...
  SynEdit, SynEditKeyCmds;

procedure TfrmPrincipal.HandleCodigoKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  if (Shift = [ssCtrl]) then
  begin
    case Key of
    VK_C: synCodigo.CommandProcessor(TSynEditorCommand(ecCopy), ' ', nil);
    VK_V: synCodigo.CommandProcessor(TSynEditorCommand(ecPaste), ' ', nil);
    VK_X: synCodigo.CommandProcessor(TSynEditorCommand(ecCut), ' ', nil);
    end;
  end;
end;

Further development, discussions

  • RTL (right-to-left): started by Mazen
  • automatic monospace font selection: At the moment SynEdit starts with a font 'courier'. December 2012/BigChimp: but Courier *is* monospace!!?!? But it would be better, if SynEdit would start with a monospace font (meaning: every character has the same width). At the moment the LCL TFont does not provide such a property. At the moment the user has to choose the right font.
  • automatic UTF-8 font selection: Same as above monospace, but also with an UTF-8 font, so that for example umlaute are shown correctly. At the moment the user has to choose the right font.
  • Dead keys. Most keyboards support typing two or more keys to create one special character (like accented or umlaut characters).
  • Redesign of the SynEdit component. The primary goal is more reliable display and navigation in the text. A more modular approach also allows for better integration of extensions, and for specialized controls, for use outside of Lazarus.

See also