Difference between revisions of "Editor Macros PascalScript"

From Lazarus wiki
Jump to navigationJump to search
m (Added property LinesCount info.)
 
(22 intermediate revisions by 7 users not shown)
Line 1: Line 1:
= General =
+
{{Editor Macros PascalScript}}
  
The PascalScript macro functionality is available in Lazarus 1.1 and later. To use the feature you have to install the package EditorMacroScript, which includes the PascalScript package. PascalScript is provided by REM Objects. A minimum package is provided with the Lazarus 1.1 distribution.
+
== General ==
  
See also [[IDE_Window:_Editor_Macros]]
+
The [[PascalScript]] macro functionality is available in Lazarus 1.1 and later. To use the feature you have to install the package EditorMacroScript, which includes the [[Pascal Script]] package. Pascal Script is provided by REM Objects. A minimum package is provided with the Lazarus 1.1 distribution.
  
= Simple actions =
+
== Availability ==
 +
 
 +
This functionality is only available on selected platforms/architectures:
 +
 
 +
*Windows
 +
** 32/64bit Intel/AMD
 +
*Linux
 +
** 32/64bit Intel/AMD
 +
*Mac
 +
** 32(/maybe 64)bit Intel/AMD
 +
** 32bit PPC
 +
 
 +
== Simple actions ==
  
 
All simple Keyboard actions are represented as follows:
 
All simple Keyboard actions are represented as follows:
Line 11: Line 23:
 
;ecChar('a');: Inserts an 'a'
 
;ecChar('a');: Inserts an 'a'
  
See the unit SynEditKeyCmds in package SynEdit, and IDECommands in IDEIntf for a full list. Or use the Recorder to get the names of actions.
+
See the unit SynEditKeyCmds in package [[SynEdit]], and IDECommands in IDEIntf for a full list. Or use the Recorder to get the names of actions.
  
= Functions =
+
== Functions ==
    Function MessageDlg( const Msg : string; DlgType : TMsgDlgType; Buttons : TMsgDlgButtons; HelpCtx : Longint) : Integer');
 
    Function MessageDlgPos( const Msg : string; DlgType : TMsgDlgType; Buttons : TMsgDlgButtons; HelpCtx : Longint; X, Y : Integer) : Integer');
 
    Function MessageDlgPosHelp( const Msg : string; DlgType : TMsgDlgType; Buttons : TMsgDlgButtons; HelpCtx : Longint; X, Y : Integer; const HelpFileName : string) : Integer');
 
    Procedure ShowMessage( const Msg : string);
 
    Procedure ShowMessagePos( const Msg : string; X, Y : Integer)');
 
    Function InputBox( const ACaption, APrompt, ADefault : string) : string');
 
    Function InputQuery( const ACaption, APrompt : string; var Value : string) : Boolean');
 
  
= Objects provided =
+
<syntaxhighlight lang=pascal>
 +
    Function MessageDlg( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint ): Integer;
 +
    Function MessageDlgPos( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
 +
    Function MessageDlgPosHelp( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer;
 +
    Procedure ShowMessage( const Msg: string );
 +
    Procedure ShowMessagePos( const Msg: string; X, Y  Integer );
 +
    Function InputBox( const ACaption, APrompt, ADefault: string): string;
 +
    Function InputQuery( const ACaption, APrompt: string; var Value: string): Boolean;
 +
</syntaxhighlight>
 +
 
 +
== Objects provided ==
  
 
Scripts can refer to the invoking SynEdit via the identifier "Caller".
 
Scripts can refer to the invoking SynEdit via the identifier "Caller".
  
== Caller: TSynEdit ==
+
=== Caller: TSynEdit ===
  
 
The following methods and properties are available:
 
The following methods and properties are available:
  
 
;Caret:  
 
;Caret:  
 +
<syntaxhighlight lang=pascal>
 
     property CaretX: Integer;
 
     property CaretX: Integer;
 
     property CaretY: Integer;
 
     property CaretY: Integer;
 
     property CaretXY: TPoint;
 
     property CaretXY: TPoint;
 
     property LogicalCaretXY: TPoint;
 
     property LogicalCaretXY: TPoint;
     property LogicalCaretX: TPoint;
+
     property LogicalCaretX: Integer;
 
     procedure MoveCaretIgnoreEOL(const NewCaret: TPoint);
 
     procedure MoveCaretIgnoreEOL(const NewCaret: TPoint);
 
     procedure MoveLogicalCaretIgnoreEOL(const NewLogCaret: TPoint);
 
     procedure MoveLogicalCaretIgnoreEOL(const NewLogCaret: TPoint);
 +
</syntaxhighlight>
  
 
;Selection:
 
;Selection:
 +
<syntaxhighlight lang=pascal>
 
     property BlockBegin: TPoint;
 
     property BlockBegin: TPoint;
 
     property BlockEnd: TPoint;
 
     property BlockEnd: TPoint;
Line 51: Line 69:
 
     procedure SelectLine(WithLeadSpaces: Boolean);
 
     procedure SelectLine(WithLeadSpaces: Boolean);
 
     procedure SelectParagraph;
 
     procedure SelectParagraph;
 
+
</syntaxhighlight>
  
 
;Search/Replace:
 
;Search/Replace:
 +
<syntaxhighlight lang=pascal>
 
     function SearchReplace(const ASearch, AReplace: string; AOptions: TSynSearchOptions): integer;
 
     function SearchReplace(const ASearch, AReplace: string; AOptions: TSynSearchOptions): integer;
 
     function SearchReplaceEx(const ASearch, AReplace: string; AOptions: TSynSearchOptions; AStart: TPoint): integer;
 
     function SearchReplaceEx(const ASearch, AReplace: string; AOptions: TSynSearchOptions; AStart: TPoint): integer;
Line 68: Line 87:
 
                                         // (before if ssoBackward) // Default is to start at caret (Only SearchReplace / SearchReplaceEx has start/end param)
 
                                         // (before if ssoBackward) // Default is to start at caret (Only SearchReplace / SearchReplaceEx has start/end param)
 
     );
 
     );
 +
</syntaxhighlight>
  
 
Returns the number of replacements done. When Searching, returns 1 if found, 0 if not found. If found the match will be selected (use BlockBegin/End).
 
Returns the number of replacements done. When Searching, returns 1 if found, 0 if not found. If found the match will be selected (use BlockBegin/End).
  
 +
<syntaxhighlight lang=pascal>
 
   if Caller.SearchReplace('FindMe', ' ', []) > 0 then begin
 
   if Caller.SearchReplace('FindMe', ' ', []) > 0 then begin
 
     // Selection is set to the first occurrence of FindMe (searched from position of caret)
 
     // Selection is set to the first occurrence of FindMe (searched from position of caret)
 
   end;
 
   end;
 +
</syntaxhighlight>
  
 
;Text:
 
;Text:
 +
<syntaxhighlight lang=pascal>
 
     property Lines[Index: Integer]: string; // read only
 
     property Lines[Index: Integer]: string; // read only
 +
    property LinesCount: integer; // read only  (new for Lazarus 2.2)
 
     property LineAtCaret: string;  // read only
 
     property LineAtCaret: string;  // read only
 
     procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
 
     procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
Line 87: Line 111:
 
                                   aSelectionMode: TSynSelectionMode
 
                                   aSelectionMode: TSynSelectionMode
 
                                   );
 
                                   );
 +
</syntaxhighlight>
  
 
;Clipboard:
 
;Clipboard:
 +
<syntaxhighlight lang=pascal>
 
     procedure CopyToClipboard;
 
     procedure CopyToClipboard;
 
     procedure CutToClipboard;
 
     procedure CutToClipboard;
 
     procedure PasteFromClipboard;
 
     procedure PasteFromClipboard;
 
     property CanPaste: Boolean    // read only
 
     property CanPaste: Boolean    // read only
 +
</syntaxhighlight>
  
 
;Logical / Physical:
 
;Logical / Physical:
 +
<syntaxhighlight lang=pascal>
 
     function LogicalToPhysicalPos(const p: TPoint): TPoint;
 
     function LogicalToPhysicalPos(const p: TPoint): TPoint;
 
     function LogicalToPhysicalCol(const Line: String; Index, LogicalPos
 
     function LogicalToPhysicalCol(const Line: String; Index, LogicalPos
Line 102: Line 130:
 
                                   Index, PhysicalPos: integer): integer;
 
                                   Index, PhysicalPos: integer): integer;
 
     function PhysicalLineLength(Line: String; Index: integer): integer;
 
     function PhysicalLineLength(Line: String; Index: integer): integer;
 +
</syntaxhighlight>
  
== ClipBoard: TClipBoard ==
+
=== ClipBoard: TClipBoard ===
  
 +
<syntaxhighlight lang=pascal>
 
     property AsText: String;
 
     property AsText: String;
 +
</syntaxhighlight>
 +
 +
== Available Macros / Downloads ==
 +
  
= Example =
+
{| class="wikitable"
 +
|+Editor macros
 +
|-
 +
|'''Description'''
 +
|'''Link'''
 +
|- style="vertical-align:top;"
 +
|
 +
'''Column Align Source code'''
  
The macro shown below aligns selected code to a specific token. It looks for a specific token in each selected line, and aligns each occurrence of it.
+
A macro that aligns selected code to a specific token. It looks for a specific token in each selected line, and aligns each occurrence of it.
  
 
Select the 3 lines. If the selection starts right before the ":" then the ":" will be detected. A prompt will ask you to confirm the ":". Then all ":" will be aligned. (If you use a word for alignment, please note, that it will be matched regardless of word boundaries)
 
Select the 3 lines. If the selection starts right before the ":" then the ":" will be detected. A prompt will ask you to confirm the ":". Then all ":" will be aligned. (If you use a word for alignment, please note, that it will be matched regardless of word boundaries)
  
<syntaxhighlight>
+
You can vertically align things like :=  or // or (
   text: string;
+
 
   a: Integer;
+
{| class="wikitable"
   foo: boolean
+
|
 +
<syntaxhighlight lang=pascal>
 +
  foo := 1;
 +
  something := 2;
 +
  x := -3;
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
   foo      := 1;
 +
  something := 2;
 +
  x        := -3;
 +
</syntaxhighlight>
 +
|}
 +
 
 +
|
 +
[[Editor Macro Column Align Source]]
 +
 
 +
 
 +
|- style="vertical-align:top;"
 +
|
 +
'''Count array elements'''
 +
 
 +
A macro to count the boundaries in an array constant.
 +
 
 +
 
 +
{| class="wikitable"
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  const foo: array [0..] of integer = (
 +
    1, 2, 3,
 +
    4
 +
  );
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  const foo: array [0..3] of integer = (
 +
    1, 2, 3,
 +
    4
 +
  );
 +
</syntaxhighlight>
 +
|}
 +
 
 +
|
 +
See http://forum.lazarus.freepascal.org/index.php/topic,27186.msg167883.html#msg167883 for counting array elements.
 +
 
 +
 
 +
|- style="vertical-align:top;"
 +
|
 +
'''Add PasDoc for function declaration'''
 +
 
 +
Comments a procedure/function in [https://github.com/pasdoc/pasdoc/wiki PasDoc] format
 +
 
 +
Example: 
 +
Executing the macro with the caret in the line of function declaration will insert the comment before.
 +
 
 +
{| class="wikitable"
 +
|
 +
<syntaxhighlight lang=pascal>
 +
function AddRadioButton(const aCaption: string; aChecked: boolean = False): TCheckBox;
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
{ Description
 +
  @param(aCaption description )
 +
  @param(aChecked description )
 +
  @returns( description )
 +
  @raises( none )
 +
}
 +
function AddRadioButton(const aCaption: string; aChecked: boolean = False): TRadioButton;
 +
 
 +
</syntaxhighlight>
 +
|}
 +
 
 +
[https://github.com/DomingoGP/LazarusMacroPasDoc https://github.com/DomingoGP/LazarusMacroPasDoc]
 +
|
 +
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroPasDocLazarus.txt MacroPasDocLazarus.txt]
 +
|- style="vertical-align:top;"
 +
|
 +
'''Sort selected lines'''
 +
 
 +
There are two macros, one with the normal alphabetical order and another that orders by type
 +
 
 +
{| class="wikitable"
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  c:integer;
 +
  b:integer;
 +
  d:boolean;
 +
  a:boolean;
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  //normal sorting
 +
   a:boolean;
 +
  b:integer;
 +
  c:integer;
 +
   d:boolean;
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  //sorting by type
 +
  d:boolean;
 +
  a:boolean;
 +
  c:integer;
 +
  b:integer; 
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The macro:
+
|}
<syntaxhighlight>
 
function IsIdent(c: Char): Boolean;
 
begin
 
  Result := ((c >= 'a') and (c <= 'z')) or
 
            ((c >= 'A') and (c <= 'Z')) or
 
            ((c >= '0') and (c <= '9')) or
 
            (c = '_');
 
end;
 
  
var
+
|
  p1, p2: TPoint;
+
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortLinesLazarus.txt MacroSortLinesLazarus.txt]
  s1, s2: string;
 
  i, j, k: Integer;
 
begin
 
  if not Caller.SelAvail then exit;
 
  p1 := Caller.BlockBegin;
 
  p2 := Caller.BlockEnd;
 
  if (p1.y > p2.y) or ((p1.y = p2.y) and (p1.x > p2.x)) then begin
 
    p1 := Caller.BlockEnd;
 
    p2 := Caller.BlockBegin;
 
  end;
 
  s1 := Caller.Lines[p1.y - 1];
 
  s2 := '';
 
  i := p1.x
 
  while (i <= length(s1)) and (s1[i] in [#9, ' ']) do inc(i);
 
  j := i;
 
  if i <= length(s1) then begin
 
    if IsIdent(s1[i]) then // pascal identifier
 
      while (i <= length(s1)) and IsIdent(s1[i]) do inc(i)
 
    else
 
      while (i <= length(s1)) and not(IsIdent(s1[i]) or (s1[i] in [#9, ' '])) do inc(i);
 
  end;
 
  if i > j then s2 := copy(s1, j, i-j);
 
  
  if not InputQuery( 'Align', 'Token', s2) then exit;
+
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortByTypeLazarus.txt MacroSortByTypeLazarus.txt]
 +
|-
 +
|- style="vertical-align:top;"
 +
|
 +
'''Column Align by procedure/function name the selected lines'''
  
   j := 0;
+
{| class="wikitable"
   for i := p1.y to p2.y do begin
+
|
    s1 := Caller.Lines[i - 1];
+
<syntaxhighlight lang=pascal>
    k := pos(s2, s1);
+
   constructor Create;
    if (k > j) then j := k;
+
  destructor Destroy; override;
   end;
+
  function Load(const aFileName:TFileName):boolean;
  if j < 1 then exit;
+
   procedure Save(const aFileName:TFileName);
 +
  function Size:integer;
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  constructor Create;
 +
  destructor  Destroy; override
 +
  function  Load(const aFileName:TFileName):boolean;
 +
  procedure Save(const aFileName:TFileName);  
 +
   function  Size:integer;
 +
</syntaxhighlight>
 +
|}
 +
|
 +
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroAlignFunctionProcedureNamesLazarus.txt MacroAlignFunctionProcedureNamesLazarus.txt]
 +
|-
 +
|- style="vertical-align:top;"
 +
|
 +
'''Sort selected function/procedures declarations by Name, keeps the comments before the function/procedure'''
  
  for i := p1.y to p2.y do begin
+
{| class="wikitable"
    s1 := Caller.Lines[i - 1];
+
|
    k := pos(s2, s1);
+
<syntaxhighlight lang=pascal>
    if (k > 0) and (k < j) then begin
+
  destructor  Destroy; override;
      Caller.LogicalCaretXY := Point(k, i);
+
  constructor Create;
      while k < j do begin
+
  procedure Save(const aFileName:TFileName);
        ecChar(' ');
+
  { Load the aFileName }
        inc(k);
+
  function  Load(const aFileName:TFileName):boolean;
      end;
+
  function  Size:integer; 
    end;
+
</syntaxhighlight>
  end;
+
|
 +
<syntaxhighlight lang=pascal>
 +
  constructor Create;
 +
  destructor  Destroy; override;
 +
  { Load the aFileName }
 +
  function  Load(const aFileName:TFileName):boolean;
 +
  procedure Save(const aFileName:TFileName);
 +
  function  Size:integer;  
 +
</syntaxhighlight>
 +
|}
 +
|
 +
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortFuncProcLazarus.txt MacroSortFuncProcLazarus.txt]
 +
|-
 +
|-
 +
|- style="vertical-align:top;"
 +
|
 +
'''Sort selected units in the uses clause'''
  
end.
+
{| class="wikitable"
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  uses
 +
    Classes, SysUtils, Forms, Controls, Graphics, Dialogs; 
 +
</syntaxhighlight>
 +
|
 +
<syntaxhighlight lang=pascal>
 +
  uses
 +
    Classes, Controls, Dialogs, Forms, Graphics, SysUtils;
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
|}
 +
|
 +
[https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortUsesLazarus.txt MacroSortUsesLazarus.txt]
 +
|-
 +
 +
|}
 +
 +
== See also ==
  
[[Category:Lazarus]]
+
* [[IDE Window: Editor Macros]]
[[Category:PascalScript]]
+
* [[Editor Macro Column Align Source]] - macro to align selected code to a specific token.
[[Category:IDE Macros]]
 

Latest revision as of 08:58, 23 January 2022

English (en) русский (ru)

General

The PascalScript macro functionality is available in Lazarus 1.1 and later. To use the feature you have to install the package EditorMacroScript, which includes the Pascal Script package. Pascal Script is provided by REM Objects. A minimum package is provided with the Lazarus 1.1 distribution.

Availability

This functionality is only available on selected platforms/architectures:

  • Windows
    • 32/64bit Intel/AMD
  • Linux
    • 32/64bit Intel/AMD
  • Mac
    • 32(/maybe 64)bit Intel/AMD
    • 32bit PPC

Simple actions

All simple Keyboard actions are represented as follows:

ecLeft;
Move Caret one to the left (in the editor that invoked the macro)
ecChar('a');
Inserts an 'a'

See the unit SynEditKeyCmds in package SynEdit, and IDECommands in IDEIntf for a full list. Or use the Recorder to get the names of actions.

Functions

    Function MessageDlg( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint ): Integer;
    Function MessageDlgPos( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer;
    Function MessageDlgPosHelp( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer;
    Procedure ShowMessage( const Msg: string );
    Procedure ShowMessagePos( const Msg: string; X, Y  Integer );
    Function InputBox( const ACaption, APrompt, ADefault: string): string;
    Function InputQuery( const ACaption, APrompt: string; var Value: string): Boolean;

Objects provided

Scripts can refer to the invoking SynEdit via the identifier "Caller".

Caller: TSynEdit

The following methods and properties are available:

Caret
    property CaretX: Integer;
    property CaretY: Integer;
    property CaretXY: TPoint;
    property LogicalCaretXY: TPoint;
    property LogicalCaretX: Integer;
    procedure MoveCaretIgnoreEOL(const NewCaret: TPoint);
    procedure MoveLogicalCaretIgnoreEOL(const NewLogCaret: TPoint);
Selection
    property BlockBegin: TPoint;
    property BlockEnd: TPoint;
    property SelAvail: Boolean; // read only
    property SelText: string;
    property SelectionMode: TSynSelectionMode;
    procedure ClearSelection;
    procedure SelectAll;
    procedure SelectToBrace;
    procedure SelectWord;
    procedure SelectLine(WithLeadSpaces: Boolean);
    procedure SelectParagraph;
Search/Replace
    function SearchReplace(const ASearch, AReplace: string; AOptions: TSynSearchOptions): integer;
    function SearchReplaceEx(const ASearch, AReplace: string; AOptions: TSynSearchOptions; AStart: TPoint): integer;

    TSynSearchOptions = set of
    ( ssoMatchCase, ssoWholeWord,
      ssoBackwards,
      ssoEntireScope, ssoSelectedOnly,  // Default is From Caret to End-of-text (or begin-of-text if backward) 
      ssoReplace, ssoReplaceAll,        // Otherwise the function does a search only
      ssoPrompt,                        // Show the prompt before replacing
      ssoSearchInReplacement,           // continue search-replace in replacement (with ssoReplaceAll) // replace recursive
      ssoRegExpr, ssoRegExprMultiLine,
      ssoFindContinue                   // Assume the current selection is the last match, and start search behind selection
                                        // (before if ssoBackward) // Default is to start at caret (Only SearchReplace / SearchReplaceEx has start/end param)
    );

Returns the number of replacements done. When Searching, returns 1 if found, 0 if not found. If found the match will be selected (use BlockBegin/End).

  if Caller.SearchReplace('FindMe', ' ', []) > 0 then begin
    // Selection is set to the first occurrence of FindMe (searched from position of caret)
  end;
Text
    property Lines[Index: Integer]: string; // read only
    property LinesCount: integer; // read only   (new for Lazarus 2.2)
    property LineAtCaret: string;  // read only
    procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode);
    property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String              // Logical Points
    procedure SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint;
                                   const AValue: String;
                                   aFlags: TSynEditTextFlags = [];
                                   aCaretMode: TSynCaretAdjustMode;
                                   aMarksMode: TSynMarksAdjustMode;
                                   aSelectionMode: TSynSelectionMode
                                  );
Clipboard
    procedure CopyToClipboard;
    procedure CutToClipboard;
    procedure PasteFromClipboard;
    property CanPaste: Boolean     // read only
Logical / Physical
    function LogicalToPhysicalPos(const p: TPoint): TPoint;
    function LogicalToPhysicalCol(const Line: String; Index, LogicalPos
                              : integer): integer;
    function PhysicalToLogicalPos(const p: TPoint): TPoint;
    function PhysicalToLogicalCol(const Line: string;
                                  Index, PhysicalPos: integer): integer;
    function PhysicalLineLength(Line: String; Index: integer): integer;

ClipBoard: TClipBoard

    property AsText: String;

Available Macros / Downloads

Editor macros
Description Link

Column Align Source code

A macro that aligns selected code to a specific token. It looks for a specific token in each selected line, and aligns each occurrence of it.

Select the 3 lines. If the selection starts right before the ":" then the ":" will be detected. A prompt will ask you to confirm the ":". Then all ":" will be aligned. (If you use a word for alignment, please note, that it will be matched regardless of word boundaries)

You can vertically align things like := or // or (

  foo := 1;
  something := 2;
  x := -3;
  foo       := 1;
  something := 2;
  x         := -3;

Editor Macro Column Align Source


Count array elements

A macro to count the boundaries in an array constant.


  const foo: array [0..] of integer = (
    1, 2, 3,
    4
  );
  const foo: array [0..3] of integer = (
    1, 2, 3,
    4
  );

See http://forum.lazarus.freepascal.org/index.php/topic,27186.msg167883.html#msg167883 for counting array elements.


Add PasDoc for function declaration

Comments a procedure/function in PasDoc format

Example: Executing the macro with the caret in the line of function declaration will insert the comment before.

function AddRadioButton(const aCaption: string; aChecked: boolean = False): TCheckBox;
{ Description
  @param(aCaption description )
  @param(aChecked description )
  @returns( description )
  @raises( none )
}
function AddRadioButton(const aCaption: string; aChecked: boolean = False): TRadioButton;

https://github.com/DomingoGP/LazarusMacroPasDoc

MacroPasDocLazarus.txt

Sort selected lines

There are two macros, one with the normal alphabetical order and another that orders by type

  c:integer;
  b:integer;
  d:boolean;
  a:boolean;
  //normal sorting
  a:boolean;
  b:integer;
  c:integer;
  d:boolean;
  //sorting by type
  d:boolean;
  a:boolean;
  c:integer;
  b:integer;

MacroSortLinesLazarus.txt

MacroSortByTypeLazarus.txt

Column Align by procedure/function name the selected lines

  constructor Create;
  destructor Destroy; override;
  function Load(const aFileName:TFileName):boolean;
  procedure Save(const aFileName:TFileName); 
  function Size:integer;
  constructor Create;
  destructor  Destroy; override
  function  Load(const aFileName:TFileName):boolean;
  procedure Save(const aFileName:TFileName);   
  function  Size:integer;

MacroAlignFunctionProcedureNamesLazarus.txt

Sort selected function/procedures declarations by Name, keeps the comments before the function/procedure

  destructor  Destroy; override;
  constructor Create;
  procedure Save(const aFileName:TFileName);
  { Load the aFileName }
  function  Load(const aFileName:TFileName):boolean;
  function  Size:integer;
  constructor Create;
  destructor  Destroy; override;
  { Load the aFileName }
  function  Load(const aFileName:TFileName):boolean;
  procedure Save(const aFileName:TFileName);
  function  Size:integer;

MacroSortFuncProcLazarus.txt

Sort selected units in the uses clause

  uses
    Classes, SysUtils, Forms, Controls, Graphics, Dialogs;
  uses
    Classes, Controls, Dialogs, Forms, Graphics, SysUtils;

MacroSortUsesLazarus.txt

See also