Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2018-01

Can the Lazarus IDE match parentheses and begin/ends?

12 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bo Berglund

I wonder if it is possible (and if so how) to enable the Lazarus code editor to match the open/close parenthesis and begin/end block delimiters?
I find that I often have trouble finding which level of these I am at...

I am currently using Lazarus 1.8.0 with FPC 3.0.4 on a Windows 7 X64 laptop.

Bo Berglund Developer in Sweden

Reply by email

Mattias Gaertner
to Bo Berglund: I wonder if it is possible (and if so how) to enable the Lazarus code editor to match the…
I wonder if it is possible (and if so how) to enable the Lazarus code editor to match the open/close parenthesis

Since a long time. It is enabled by default.
http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Options_Markup#Bracket_Highlight

and begin/end block delimiters?

Same:
http://wiki.lazarus.freepascal.org/IDE_Window:_Editor_Options_Markup#Current_Word

Full colors came with 1.8:
http://wiki.lazarus.freepascal.org/Lazarus_IDE_Tools#Outline

Mattias

Reply by email

Martin Frb
to Bo Berglund: I wonder if it is possible (and if so how) to enable the Lazarus code editor to match the…
Bo Berglund wrote
I wonder if it is possible (and if so how) to enable the Lazarus code editor to match the open/close parenthesis and begin/end block delimiters?

brackets are already answered in the other mails.

begin/end is not on the wiki (yet), but it is in the Options dialog under > Editor > Display > Markup and Matches

It is called "Word Brackets on caret"

There is a listbox with: "Procedure","Begin/end", "repeat" ..... you can select each entry and check "Markup (on caret), to get the highlight

eg
*  "Procedure" will highlight 3 keyword: Procedure, begin, end,
* "Begin/end (procedure)" highlights only the begin and end of a procedure block

You can choose the kind of highlight (eg change back color, instead of frame) in the "Colors" page of the option dialog.

Reply by email

Martin Frb
to Martin Frb
Martin Frb wrote 5 lines
eg *  "Procedure" will highlight 3 keyword: Procedure, begin, end, * "Begin/end (procedure)" highlights only the begin and end of a procedure block

My mistake
"Procedure"  is just Procedure ...end

And both of the above, will highlight all three together.

Reply by email

Bo Berglund
to Martin Frb: brackets are already answered in the other mails. begin/end is not on the wiki (yet), but…
Martin Frb wrote
On 05/01/18 12:41, Bo Berglund via Lazarus wrote: > I wonder if it is possible (and if so how) to enable the Lazarus code > editor to match the open/close parenthesis and begin/end block > delimiters?

Martin, thanks for your detailed description! It made it possible for me to at least partially solve the problem!

brackets are already answered in the other mails.

But the links in these replies go to a webpage that says a bit down:

"Bracket Highlight

If the cursor is behind or in front of a bracket, highlight matching bracket"

And that is all. No description on *how* to actually activate this function, which was clearly not working in my Lazarus... Also the definition of a "bracket" is a bit muddy. Does it refer to square parenthesis [ ] or normal ( ) or begin end or all of these?

Furthermore the webpage directs me to the "Automatic feature" page of the editor option, which in fact does not exist in my Lazarus. Under Editor there are 8 subpages, none named "Automatic feature". If one expands the Display node there are Colors, Markup and Matches, User defined markup. So the wiki page is misleading.

Show quoted text 7 lines
begin/end is not on the wiki (yet), but it is in the Options dialog under > Editor > Display > Markup and Matches It is called "Word Brackets on caret" There is a listbox with: "Procedure","Begin/end", "repeat" ..... you can select each entry and check "Markup (on caret), to get the highlight

In my case these are all checked except for the last 4 boxes. Additionally the checkbox to the right "Markup (on caret)" is checked as is the top "Word Brackets on caret" and yet I did not see anything in the IDE...
Do I have to use some kind of hot key to make it display?

Well, it seems to be a mis-match in the default settings where the feature is enabled by default but the colors are set by default to completely hide the highlight....
Seems like a strange way to set the defaults.

Show quoted text 7 lines
eg *  "Procedure" will highlight 3 keyword: Procedure, begin, end, * "Begin/end (procedure)" highlights only the begin and end of a procedure block You can choose the kind of highlight (eg change back color, instead of frame) in the "Colors" page of the option dialog.

After a lot of fiddling I managed to get the following working:

begin-end: A red box pink background via "Word-brackets" color [ ]: basically the same, but via "Brackets highlights" color if-then-else: same via "Word-brackets" color

Not working:
( ): Controlled by what?
And this is what I originally was looking for because I frequently make ( ) errors....

Bo Berglund Developer in Sweden

Reply by email

Martin Frb
to Bo Berglund
Bo Berglund wrote 9 lines
On Fri, 5 Jan 2018 14:12:59 +0100, Martin Frb via Lazarus wrote: > On 05/01/18 12:41, Bo Berglund via Lazarus wrote: >> I wonder if it is possible (and if so how) to enable the Lazarus code >> editor to match the open/close parenthesis and begin/end block >> delimiters? Martin, thanks for your detailed description! It made it possible for me to at least partially solve the problem!

which part (about begin/end) is NOT solved? (Or does "partly" refer to brackets?)

Show quoted text 10 lines
> brackets are already answered in the other mails. But the links in these replies go to a webpage that says a bit down: "Bracket Highlight If the cursor is behind or in front of a bracket, highlight matching bracket" And that is all. No description on *how* to actually activate this function, which was clearly not working in my Lazarus...

Same options dialog/page as above "Markup and Matches"

There is a dropdown "Bracket highlight" (below the 1st divider / unamed divider)
 with options such as "on both sides", "Left of cursor", .... "no highlight"

I am not sure, it may require that the text has some highlighter active (but pascal sources always have this).
If you load plain text, then it may not work on that file...

It matches (), {}, [], and single quotes. It toggles between bold and not bold, and applies a frame (at least for me, I may have changed settings) But again in color options you can change what highlight to apply: Editor > Display > Colors:
   Entry "Bracket Highlights" (1st in section "Text").

Show quoted text 5 lines
Furthermore the webpage directs me to the "Automatic feature" page of the editor option, which in fact does not exist in my Lazarus. Under Editor there are 8 subpages, none named "Automatic feature". If one expands the Display node there are Colors, Markup and Matches, User defined markup. So the wiki page is misleading.

The wiki is indeed outdated. (If anyone has time...) "Automatic ..." was probably the name of a sub page in an older Lazarus version.

Show quoted text 15 lines
> begin/end is not on the wiki (yet), but it is in the Options dialog > under > Editor > Display > Markup and Matches > > It is called "Word Brackets on caret" > > There is a listbox with: "Procedure","Begin/end", "repeat" ..... > you can select each entry and check "Markup (on caret), to get the highlight In my case these are all checked except for the last 4 boxes. Additionally the checkbox to the right "Markup (on caret)" is checked as is the top "Word Brackets on caret" and yet I did not see anything in the IDE... Do I have to use some kind of hot key to make it display? Well, it seems to be a mis-match in the default settings where the feature is enabled by default but the colors are set by default to completely hide the highlight....

Which color profile are you using? (Default, Delphi, Ocean....) In the Default it should have a red frame (for begin/end pairs)

You can always check the default by deleting (BACK UP !) your editor_options.xml
This is in the primary config path (View Menu > Ide Internals > About IDE

Show quoted text 8 lines
After a lot of fiddling I managed to get the following working: begin-end: A red box pink background via "Word-brackets" color [ ]: basically the same, but via "Brackets highlights" color if-then-else: same via "Word-brackets" color Not working: ( ): Controlled by what?

Should be the same as ()

Just remember, I think there is a bug in 1.8 (already fixed for the not yet released 1.8.2)

brackets only work if they are surrounded by spaces (or maybe it was NOT surrounded...)
https://bugs.freepascal.org/view.php?id=32803

svn rev 56695

rebuild ide with this patch

Index: components/synedit/synedit.pp
===================================================================
--- components/synedit/synedit.pp    (revision 56694)
+++ components/synedit/synedit.pp    (revision 56695)
@@ -8945,7 +8945,7 @@
        while not Highlighter.GetEol do begin
          Start := Highlighter.GetTokenPos + 1;
          Token := Highlighter.GetToken;
-        if (PosX >= Start) and (PosX <= Start + Length(Token)) then begin
+        if (PosX >= Start) and (PosX < Start + Length(Token)) then begin
            Attri := Highlighter.GetTokenAttribute;
            TokenType := Highlighter.GetTokenKind;
            exit(True);
@@ -8990,7 +8990,7 @@
          //TokenType := Highlighter.GetTokenKind;
          Attri := Highlighter.GetTokenAttribute;
          //DebugLn(['  TCustomSynEdit.CaretAtIdentOrString: Start=',
Start, ', Token=', Token]);
-        if (PosX >= Start) and (PosX <= Start + Length(Token)) then
+        if (PosX >= Start) and (PosX < Start + Length(Token)) then
          begin
            AtIdent := Attri = Highlighter.IdentifierAttribute;
            NearString := (Attri = Highlighter.StringAttribute)

Reply by email

Bo Berglund
to Martin Frb: which part (about begin/end) is NOT solved? (Or does "partly" refer to brackets?) Same…
Martin Frb wrote 13 lines
On 06/01/18 10:25, Bo Berglund via Lazarus wrote: > Not working: > ( ): Controlled by what? Should be the same as () Just remember, I think there is a bug in 1.8 (already fixed for the not yet released 1.8.2) brackets only work if they are surrounded by spaces (or maybe it was NOT surrounded...) https://bugs.freepascal.org/view.php?id=32803

OK, I see....
There are strange highlighting going on, example:
Parms.Add(IntToStr(Rev));
Here if I put the cursor left of the ; I get hightlight properly. But any place before or after any other ( or ) no highlight!

In another code line if I do the same and put the cursorat the end ); between the last chars, then the highlight comes on and boxes the last ) paired with a ( on 7 lines above when there are a lot of both ( and ) inbetween....
Clearly an erroneous highlight.

Well, the other highlightings seem to
Bo Berglund
Developer in Sweden

Reply by email

Martin Frb
to Bo Berglund
Bo Berglund wrote 5 lines
In another code line if I do the same and put the cursorat the end ); between the last chars, then the highlight comes on and boxes the last ) paired with a ( on 7 lines above when there are a lot of both ( and ) inbetween.... Clearly an erroneous highlight.

Please check this kind of errors, with 1.8.2 (once released) or the bug fix patch applied.
If an incorrect bracket is highlighted with the fix, then please report it.

Note that, brackets in strings or comments, will/should not be matched with brackets in code.

    if (a = '(' ) then // (
         a := ')';  // )

should match
- the 2 brackets in code
- AND the 2 brackets inside the 2 strings
- AND the 2 brackets inside the 2 comments

It should also match the correct quotes '.

Bracket matching only ever looks at one kind of brackets. When matching (), it will totally ignore any [].
So erroneous code like
  if (a[1]] = 2) then
will match the ().
As well as the [] directly around the 1.
And the extra ] will not match anything.

Reply by email

Bo Berglund
to Martin Frb
Martin Frb wrote
Please check this kind of errors, with 1.8.2 (once released) or the bug fix patch applied.

I guess I will have to get around to learning how to build fpc and lazarus on Windows then...
On my Linux boxes it is a simple matter of svn update (or co) and then make clean, make bigide and make install (with some parameters). I have written an installation script for this and it works everytime on my Linux boxes (RPi mostly).

But on Windows I am lost, so I have used the binary installer, which makes my installation a lot harder to modify for various configurations...

Bo Berglund Developer in Sweden

Reply by email

Martin Frb
to Bo Berglund
Bo Berglund wrote 7 lines
On Sun, 7 Jan 2018 22:45:09 +0100, Martin Frb via Lazarus wrote: > Please check this kind of errors, with 1.8.2 (once released) or the bug > fix patch applied. I guess I will have to get around to learning how to build fpc and lazarus on Windows then...

Install fpc from the fpc installer. Or keep the fpc as installed by the lazarus installer. (If you move the directory, you need to edit fpc.cfg)

Keep a lazarus.exe

Get the lazarus source (svn or otherwise; or patch the existing one).

- Copy the lazarus.exe into the top level of your source folder.
- Optional: create a lazarus.cfg file with the primary conf path http://wiki.freepascal.org/Multiple_Lazarus#Using_lazarus.cfg_file
- Run it (make sure all pathes are correct in Tools Options / or run with --setup)
- choose menu Tools > build lazarus

Open and build the ide/startlazarus project.

Reply by email