Recent

Author Topic: Syntax Highlightning memo component? --- SynEdit  (Read 11312 times)

Zomis

  • Jr. Member
  • **
  • Posts: 95
Syntax Highlightning memo component? --- SynEdit
« on: January 13, 2007, 09:17:13 pm »
I'm wondering if there is a component for Lazarus like Delphi's TRichEdit (although I've never learned how that works...) which can have several font colors and styles (bold, italic, etc.) so that it's possible to create some kind of syntax highlighting for the textbox.

RudieD

  • Full Member
  • ***
  • Posts: 234
The FRED Trainer. (Training FRED with Lazarus/FPC)

Zomis

  • Jr. Member
  • **
  • Posts: 95
RE: Syntax Highlightning memo component?
« Reply #2 on: January 15, 2007, 07:58:09 pm »
Thanks a lot :) But I think the SynEdit component fits me better (I wouldn't have found that if it wasn't for your link!)

However, I can't get the TSynAutoComplete to work. When I press the shortcut defined (I've tried with the shortcut Shift+Space as well as Ctrl+Space) in the SynEdit component assigned, nothing happens! Although I've defined AutoCompleteList as follows:
Code: [Select]
something
somethingelse
some3theing

theo

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1891
Re: RE: Syntax Highlightning memo component?
« Reply #3 on: January 15, 2007, 10:39:28 pm »
Quote from: "Zomis"
Thanks a lot :) I wouldn't have found that if it wasn't for your link!


Funny, because the Lazarus IDE uses this component as Editor too.
So you have it always in front of you ;-)

Quote from: "Zomis"

However, I can't get the TSynAutoComplete to work.

TSynAutoComplete does what the Lazarus Editor does when you press CTRL+J.

If you have questions about Synedit, have a look at the Synedit Webiste: http://synedit.sourceforge.net/

Zomis

  • Jr. Member
  • **
  • Posts: 95
Re: RE: Syntax Highlightning memo component?
« Reply #4 on: January 15, 2007, 10:53:02 pm »
Quote from: "theo"
Funny, because the Lazarus IDE uses this component as Editor too.
So you have it always in front of you ;-)

TSynAutoComplete does what the Lazarus Editor does when you press CTRL+J.

If you have questions about Synedit, have a look at the Synedit Webiste: http://synedit.sourceforge.net/
Yeah, I'm quite suprised myself that I haven't noticed it before. I had no idea that there was a component which had all that highlighting preconfigured, I thought I had to make that code myself :shock:

After looking a bit at the source of TSynEdit and stuff, I came to the conclusion that the TSynAutoComplete isn't exactly what I'm looking for...
I'm more looking for a Ctrl+Space function. I've taken a look at the page and I noticed that there's a SynCompletionProposal, which sounds like what I'm looking for. But there's no SynCompletionProposal component avalible in Lazarus. So I've downloaded the latest release from the Synedit Website, and I compare that download to the Lazarus SynEdit, and I see that most Lazarus files which is NEWER. But there's a lot of more files in the package I just downloaded - including a SynCompletionProposal.pas with a lot of TSynBaseCompletionProposal info and more...

So why is not that latest package included in Lazarus? Is it not compatible with FreePascal? (I haven't tried to install the package myself yet)

Roman

  • New Member
  • *
  • Posts: 17
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #5 on: May 17, 2015, 06:05:40 pm »
Hello. I would like to have the Enter key for the autocomplete shortcut, like it is in Lazarus code editor (if you type "begin" followed by Enter key, you get "end" added to "begin"). But if I change the shortcut to Enter/Return, then Enter works only after the autocomplete symbol in list (say "begin"). That means I cannot make a new line elsewhere. What am I doing wrong?

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6912
  • Debugger - SynEdit - and more
    • wiki
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #6 on: May 17, 2015, 07:05:13 pm »
http://wiki.lazarus.freepascal.org/SynEdit#Completion_plugins

and the example folder in your lazarus directory

Roman

  • New Member
  • *
  • Posts: 17
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #7 on: May 20, 2015, 06:43:51 pm »
Thank you, Martin, but in suggested link there is not enough information for me or I'am not able to find it, and in example for synedit there are two shortcuts: shift-space and ctrl-space, not enter. Still asking for help.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6912
  • Debugger - SynEdit - and more
    • wiki
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #8 on: May 20, 2015, 07:23:11 pm »
Sorry I did misread your post.

I thought you are looking for code completion, the drop down, that in the IDE proposes all matching functions and variables.

Quote
if you type "begin" followed by Enter key, you get "end" added to "begin"

This is not part of SynEdit. In the IDE this is done by codetools.

However you can almost archive it with code templates. But you need to write some handling yourself, to use return

Code: [Select]
    SynAutoComplete1: TSynAutoComplete;

//Set   SynAutoComplete1.AutoCompleteList to (TStrings) Use Append, or Add, or Text property

begin
=begin
=end



You can use any key (but just one):
Code: [Select]
  SynAutoComplete1.ShortCut := KeyToShortCut(VK_RETURN, []);
 

But that shortcut looses its normal function (so return no longer creates a new line.

So instead, you need to add an event to SynEdit.OnProcessCommand
and check if the command is ecLineBreak, then you need to check yourself, if the text before the caret needs any special handling.

For just inserting an end, the TSynAutoComplete is not needed in this case, since you can insert it yourself.


Roman

  • New Member
  • *
  • Posts: 17
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #9 on: May 20, 2015, 08:20:12 pm »
Than you again. Now I have an idea how to solve a problem.

Roman

  • New Member
  • *
  • Posts: 17
Re: Syntax Highlightning memo component? --- SynEdit
« Reply #10 on: May 20, 2015, 08:51:38 pm »
It works!
Code: [Select]
procedure TForm1.SynEdit1CommandProcessed(Sender: TObject;
  var Command: TSynEditorCommand; var AChar: TUTF8Char; Data: pointer);
var p: TPoint; X: Integer; s: string;
begin
  if Command=ecLineBreak then
  begin
    p:=SynEdit1.LogicalCaretXY; s:=SynEdit1.Lines[p.Y-2]; X:=Length(s);
    if Copy(s,X-4,MaxInt)='begin' then SynEdit1.InsertTextAtCaret('end')
  end
end;
« Last Edit: May 20, 2015, 08:53:16 pm by Roman »

 

TinyPortal © 2005-2018