Feature request: Optional support for end ; syntax, as in ALGOL 68 lazarus / 62-General ---------------------------------------------------------------------- darknatter · 2026-01-30 12:11 Lazarus has a nice feature that when you hover over an 'end' statement it highlights the beginning and end of a block, but if the block is larger than one screen height, this is of no use. I have on more than one occasion had to find a bug where an "end" got missed, or an extra one got added, code that looks like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           end;        end;        astatement;      end;    end;  somestatement;  end;end;  Stuff like this happens if I forgot a 'begin' somewhere, or accidentally confused the alignment when I had a long code line, and similar. What I would like is to have support for optionally making the end statement explicit, like this: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           end if;        end if;        astatement;      end for;    end if;  somestatement;  end for;end function;   This way I would get a compiler error "found 'end if' when 'end for' expected" - leading me straight to the source of the problem. Right now I do this manually using a comment, but compiler support would make it much more efficient. If it does not work in Delphi or Turbo Pascal compatibility mode, so be it. The idea is far from new, and many verbose non-brace languages support it. I apologize if this has already been discussed, I was not able to find it in a forum search. ---------------------------------------------------------------------- cdbc · 2026-01-30 12:27 Hi Well, the recommendation is to split those 'Way Too Long' func/methods/procs up into smaller building-blocks, i.e.: separate functions/procedures, so that you have methods with, say, max 20 lines in them (Nb.: Linus Torvalds  says around 7 lines) Just use the "Divide and Conquer" principle...  If push comes to shove, make the editor full-screen, while you're /wrestling/ the longest method and then back to normal, when you're done. Just my 2 cents worth. Regards Benny ---------------------------------------------------------------------- wp · 2026-01-30 12:35 Not an answer to your question, but a great help for finding unpaired "end" statements: "Editor options" > "Pairs/Matches and structure" > "Outline (global)" (Laz/main), or "Editor options" > "Display" > "Markup and Matches" > "Outline (global)" (Laz 4.4 and earlier). When this checkbox is checked the begin and end of a block are colored in the same color: when the "end" of procedure is not colored in red, you know that you are missing an "end" along the way. It took some time to get accustomed to the colorful screen, but now I won't miss this feature. ---------------------------------------------------------------------- 440bx · 2026-01-30 12:40 The suggestion/request is reasonable but, its implementation is far from problem free as it introduces ambiguities in the Pascal grammar. Effectively, your suggestion would almost certainly require changing the semicolon from a statement separator to a statement terminator otherwise, constructions such as "end for" would either be ambiguous or require a grammar that is no longer LL(1). One "hack" that comes to mind to avoid the problem is to have new keywords such as "end_for", "end_if", etc.  Those would function just like "end" would but would provide the additional information needed to implement the begin/end matching you'd like to have.   The downsides of something like that is the need for new keywords which have the potential to collide with existing identifiers, e.g, variable names, in already existing code.  Another potential problem is: what would a stand alone block be ended with ?  that is, a "begin" < bunch of statements here> "end" <--- should this last end be "end_begin" ? (sounds weird) I've run into the problem you've mentioned and so far the most practical solution I've seen is Lazarus "outline" feature which matches "begin" and "end" which makes it fairly easy to find (and correct) the mismatches. Quote from: cdbc on January 30, 2026, 01:27:16 pmHi Well, the recommendation is to split those 'Way Too Long' func/methods/procs up into smaller building-blocks, i.e.: separate functions/procedures, so that you have methods with, say, max 20 lines in them (Nb.: Linus Torvalds  says around 7 lines) I consider that really bad advice.  The result is code broken into umpteen little pieces that the programmer has to mentally re- assemble.  Programming isn't (or shouldn't be) the creation of jigsaw puzzles. @darkmattter, Follow @wp's recommendation.  That's what I do when I end up with mimatch begin/end pairs. OTH, I don't leave the matching enabled.  Too much clutter for my taste. ---------------------------------------------------------------------- Martin_fr · 2026-01-30 13:18 Another "not an answer but". Lazarus has various tools, that you can use/combine. 1) "Find Start of code block" / "Find other end of code block" to jump between matching begin/end 2) the highlight when the caret is on either the end/begin 3) the before mention (by WP) outline   (not only are begin/end colored, but the for/if to which they belong get the same color too. So if the "if" is e.g. blue, then you are looking for a blue end) 4) Folding and follow folding lines in the gutter    (includes special color for the innermost fold-line / which will be the one if your are right in front of the end) As for "big amount of lines". - You can fold/collapse contained blocks, to have a better overview of the "big block". - You can fold arbitrary lines (select lines, and fold/hide selection) Additionally, you can always Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i for i := 0 to c -1 do begin  //...end; // for i := 0 to c - 1 Then if there is some missing end somewhere, you still know what the "end" originally was for. Folding "known good parts" with those methods, will allow to identify the correct matches. ---------------------------------------------------------------------- marcov · 2026-01-30 13:25 Quote from: darknatter on January 30, 2026, 01:11:19 pmI apologize if this has already been discussed, I was not able to find it in a forum search. Modula2 has a similar feature, and in those threads the block system in general has been discussed, and the general opinion is that it is better to leave it alone, than have another detail dialect feature that partitions the FPC/Lazarus source code into the have and have nots. In my own opinion, we need to reduce redundant features more than adding more. ---------------------------------------------------------------------- PascalDragon · 2026-02-01 20:09 Quote from: darknatter on January 30, 2026, 01:11:19 pmI apologize if this has already been discussed, I was not able to find it in a forum search. Don't know if it has already been discussed, but I see no sense in that. Pascal is without such block end markers. ---------------------------------------------------------------------- avra · 2026-02-02 12:40 Quote from: darknatter on January 30, 2026, 01:11:19 pm...I would get a compiler error "found 'end if' when 'end for' expected"... You can use something like this (put it into customend.inc file and include it in all of your units): Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$macro on} {$define end_if := end}{$define end_for := end}{$define end_func := end}  It will change nothing for compiler, but will help your need for visual distinction. ---------------------------------------------------------------------- H₂SO₄ · 2026-02-02 13:25 Quote from: darknatter on January 30, 2026, 01:11:19 pmCode: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i           end;        end;        astatement;      end;    end;  somestatement;  end;end;  I agree with Benny; if your functions become so long and deeply nested that the block structure becomes hard to conceptualize at a glance, it's time to refactor the code. Note that this doesn't necessarily mean extracting code into new functions; a classic example would be changing nested  if  statements into early returns: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if ConditionOne then begin  if ConditionTwo then begin    if ConditionThree then begin      DoSomething();    end;  end;end; Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i if not ConditionOne then Exit();if not ConditionTwo then Exit();if not ConditionThree then Exit();DoSomething(); ---------------------------------------------------------------------- TBMan · 2026-02-02 19:26 Quote from: wp on January 30, 2026, 01:35:49 pmNot an answer to your question, but a great help for finding unpaired "end" statements: "Editor options" > "Pairs/Matches and structure" > "Outline (global)" (Laz/main), or "Editor options" > "Display" > "Markup and Matches" > "Outline (global)" (Laz 4.4 and earlier). When this checkbox is checked the begin and end of a block are colored in the same color: when the "end" of procedure is not colored in red, you know that you are missing an "end" along the way. It took some time to get accustomed to the colorful screen, but now I won't miss this feature. I use this feature too. It saves a lot of time, especially when you are coding fast and want to get it down while it is fresh in your mind's eye. The "ends" get automatically placed as well.