diff --git a/components/codetools/codetoolmanager.pas b/components/codetools/codetoolmanager.pas index 58cb29e4a4..4e808519b1 100644 --- a/components/codetools/codetoolmanager.pas +++ b/components/codetools/codetoolmanager.pas @@ -341,15 +341,15 @@ type // blocks (e.g. begin..end, case..end, try..finally..end, repeat..until) function FindBlockCounterPart(Code: TCodeBuffer; X,Y: integer; - var NewCode: TCodeBuffer; - var NewX, NewY, NewTopLine: integer): boolean; + out NewCode: TCodeBuffer; + out NewX, NewY, NewTopLine: integer): boolean; function FindBlockStart(Code: TCodeBuffer; X,Y: integer; - var NewCode: TCodeBuffer; - var NewX, NewY, NewTopLine: integer): boolean; + out NewCode: TCodeBuffer; + out NewX, NewY, NewTopLine: integer): boolean; function GuessUnclosedBlock(Code: TCodeBuffer; X,Y: integer; - var NewCode: TCodeBuffer; - var NewX, NewY, NewTopLine: integer): boolean; - + out NewCode: TCodeBuffer; + out NewX, NewY, NewTopLine: integer): boolean; + // method jumping function JumpToMethod(Code: TCodeBuffer; X,Y: integer; var NewCode: TCodeBuffer; @@ -2756,7 +2756,7 @@ begin end; function TCodeToolManager.FindBlockCounterPart(Code: TCodeBuffer; - X, Y: integer; var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer + X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer ): boolean; var CursorPos: TCodeXYPosition; @@ -2789,7 +2789,7 @@ begin end; function TCodeToolManager.FindBlockStart(Code: TCodeBuffer; - X, Y: integer; var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer + X, Y: integer; out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer ): boolean; var CursorPos: TCodeXYPosition; @@ -2822,7 +2822,7 @@ begin end; function TCodeToolManager.GuessUnclosedBlock(Code: TCodeBuffer; X, Y: integer; - var NewCode: TCodeBuffer; var NewX, NewY, NewTopLine: integer): boolean; + out NewCode: TCodeBuffer; out NewX, NewY, NewTopLine: integer): boolean; var CursorPos: TCodeXYPosition; NewPos: TCodeXYPosition; diff --git a/components/codetools/stdcodetools.pas b/components/codetools/stdcodetools.pas index 34c3af3a30..fd5b49a34f 100644 --- a/components/codetools/stdcodetools.pas +++ b/components/codetools/stdcodetools.pas @@ -202,7 +202,7 @@ type function GuessUnclosedBlock(const CursorPos: TCodeXYPosition; out NewPos: TCodeXYPosition; out NewTopLine: integer): boolean; function FindBlockCleanBounds(const CursorPos: TCodeXYPosition; - var BlockCleanStart, BlockCleanEnd: integer): boolean; + out BlockCleanStart, BlockCleanEnd: integer): boolean; // compiler directives function GuessMisplacedIfdefEndif(const CursorPos: TCodeXYPosition; @@ -4523,13 +4523,15 @@ begin end; function TStandardCodeTool.FindBlockCleanBounds( - const CursorPos: TCodeXYPosition; var BlockCleanStart, BlockCleanEnd: integer + const CursorPos: TCodeXYPosition; out BlockCleanStart, BlockCleanEnd: integer ): boolean; var CleanCursorPos: integer; BlockStartFound: Boolean; begin Result:=false; + BlockCleanStart:=0; + BlockCleanEnd:=0; // scan code BeginParsingAndGetCleanPos(true,false,CursorPos,CleanCursorPos); // read word at cursor diff --git a/ide/codetemplatesdlg.pas b/ide/codetemplatesdlg.pas index 46ce99fc83..e5ada787b6 100644 --- a/ide/codetemplatesdlg.pas +++ b/ide/codetemplatesdlg.pas @@ -33,9 +33,14 @@ interface uses Classes, SysUtils, LCLProc, LResources, Forms, Controls, Graphics, Dialogs, ClipBrd, StdCtrls, Buttons, ExtCtrls, Menus, FileUtil, - SynEdit, SynHighlighterPas, SynEditAutoComplete, CodeToolManager, CodeCache, - KeywordFuncLists, BasicCodeTools, PascalParserTool, + // synedit + SynEdit, SynHighlighterPas, SynEditAutoComplete, + // codetools + CodeToolManager, CodeAtom, CodeCache, KeywordFuncLists, BasicCodeTools, + PascalParserTool, + // IDEIntf IDECommands, TextTools, SrcEditorIntf, MenuIntf, IDEWindowIntf, LazIDEIntf, + // IDE IDEProcs, InputHistory, LazarusIDEStrConsts, EditorOptions, CodeMacroSelect; type @@ -405,18 +410,39 @@ end; function CodeMacroAddMissingEnd(const Parameter: string; InteractiveValue: TPersistent; SrcEdit: TSourceEditorInterface; var Value, ErrorMsg: string): boolean; +{ checks if at current position a block end should be inserted + Examples: + + No block end required: + begin| + end + + repeat| + until + + begin| + repeat + + Block end required: + begin + begin| + end; +} var Line: String; p: TPoint; - CodeBuf: TCodeBuffer; + CodeXYPos: TCodeXYPosition; begin Result:=true; Value:=''; Line:=SrcEdit.CurrentLineText; p:=SrcEdit.CursorTextXY; if p.y<1 then exit; - CodeBuf:=SrcEdit.CodeToolsBuffer as TCodeBuffer; - if CodeBuf=nil then exit; + CodeXYPos.X:=p.x; + CodeXYPos.Y:=p.y; + CodeXYPos.Code:=SrcEdit.CodeToolsBuffer as TCodeBuffer; + if CodeXYPos.Code=nil then exit; + // ToDo while (p.y<=SrcEdit.LineCount) do begin