IDE: code templates: added macro AddSemicolon

git-svn-id: trunk@53110 -
This commit is contained in:
mattias 2016-10-14 17:27:18 +00:00
parent 8a18022cc5
commit 9dbd2f1f15
2 changed files with 33 additions and 0 deletions

View File

@ -169,6 +169,10 @@ function CodeMacroAddMissingEnd(const {%H-}Parameter: string;
{%H-}InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, {%H-}ErrorMsg: string): boolean;
function CodeMacroAddSemicolon(const {%H-}Parameter: string;
{%H-}InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, {%H-}ErrorMsg: string): boolean;
function CodeMacroOfAll(const {%H-}Parameter: string; {%H-}InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface;
var Value, ErrorMsg: string): boolean;
@ -481,6 +485,29 @@ begin
end;
end;
function CodeMacroAddSemicolon(const Parameter: string;
InteractiveValue: TPersistent; SrcEdit: TSourceEditorInterface; var Value,
ErrorMsg: string): boolean;
var
XY: TPoint;
Code: TCodeBuffer;
p, AtomStart: integer;
Src, Token: String;
begin
Result:=true;
Value:='';
XY:=SrcEdit.CursorTextXY;
if XY.y<1 then exit;
Code:=SrcEdit.CodeToolsBuffer as TCodeBuffer;
Code.LineColToPosition(XY.y,XY.x,p);
Src:=Code.Source;
ReadRawNextPascalAtom(Src,p,AtomStart,true,true);
Token:=lowercase(copy(Src,AtomStart,p-AtomStart));
if (Token='else') or (Token='do') or (Token=';') or (Token=')') or (Token=']') then
exit;
Value:=';';
end;
function CodeMacroOfAll(const Parameter: string; InteractiveValue: TPersistent;
SrcEdit: TSourceEditorInterface; var Value, ErrorMsg: string): boolean;
// completes
@ -772,6 +799,9 @@ begin
RegisterCodeMacro('AddMissingEnd', lisInsertEndIfNeeded,
lisCheckIfTheNextTokenInSourceIsAnEndAndIfNotReturnsL,
@CodeMacroAddMissingEnd,nil);
RegisterCodeMacro('AddSemicolon', lisInsertSemicolonIfNeeded,
lisCheckTheNextTokenInSourceAndAddsASemicolonIfNeeded,
@CodeMacroAddSemicolon,nil);
RegisterCodeMacro('OfAll', lisListOfAllCaseValues,
lisReturnsListOfAllValuesOfCaseVariableInFrontOfVaria,
@CodeMacroOfAll,nil);

View File

@ -5637,6 +5637,9 @@ resourcestring
lisInsertEndIfNeeded = 'insert end if needed';
lisCheckIfTheNextTokenInSourceIsAnEndAndIfNotReturnsL = 'Check if the next '
+'token in source is an "end" and if not return "LineEnding + end; + LineEnding".';
lisInsertSemicolonIfNeeded = 'Insert semicolon if needed';
lisCheckTheNextTokenInSourceAndAddsASemicolonIfNeeded = 'Check the next '
+'token in source and adds a semicolon if needed';
lisListOfAllCaseValues = 'list of all case values';
lisReturnsListOfAllValuesOfCaseVariableInFrontOfVaria = 'Return the list of '
+'all values of case variable in front of variable.'#13