| 1 | 1 | | ## General |
| 2 | 2 | | |
| 3 | 3 | | 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. |
| 4 | 4 | | |
| 5 | 5 | | ## Availability |
| 6 | 6 | | |
| 7 | 7 | | This functionality is only available on selected platforms/architectures: |
| 8 | 8 | | |
| 9 | 9 | | - Windows |
| 10 | 10 | | - 32/64bit Intel/AMD |
| 11 | 11 | | - Linux |
| 12 | 12 | | - 32/64bit Intel/AMD |
| 13 | 13 | | - Mac |
| 14 | 14 | | - 32(/maybe 64)bit Intel/AMD |
| 15 | 15 | | - 32bit PPC |
| 16 | 16 | | |
| 17 | 17 | | ## Simple actions |
| 18 | 18 | | |
| 19 | 19 | | All simple Keyboard actions are represented as follows: |
| 20 | 20 | | |
| 21 | 21 | | ecLeft; |
| 22 | 22 | | Move Caret one to the left (in the editor that invoked the macro) |
| 23 | 23 | | |
| 24 | 24 | | ecChar('a'); |
| 25 | 25 | | Inserts an 'a' |
| 26 | 26 | | |
| 27 | 27 | | 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. |
| 28 | 28 | | |
| 29 | 29 | | ## Functions |
| 30 | 30 | | |
| 31 | 31 | | ``` pascal |
| 32 | 32 | | Function MessageDlg( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint ): Integer; |
| 33 | 33 | | Function MessageDlgPos( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer): Integer; |
| 34 | 34 | | Function MessageDlgPosHelp( const Msg: string; DlgType: TMsgDlgType; Buttons: TMsgDlgButtons; HelpCtx: Longint; X, Y: Integer; const HelpFileName: string): Integer; |
| 35 | 35 | | Procedure ShowMessage( const Msg: string ); |
| 36 | 36 | | Procedure ShowMessagePos( const Msg: string; X, Y Integer ); |
| 37 | 37 | | Function InputBox( const ACaption, APrompt, ADefault: string): string; |
| 38 | 38 | | Function InputQuery( const ACaption, APrompt: string; var Value: string): Boolean; |
| 39 | 39 | | ``` |
| 40 | 40 | | |
| 41 | 41 | | ## Objects provided |
| 42 | 42 | | |
| 43 | 43 | | Scripts can refer to the invoking SynEdit via the identifier "Caller". |
| 44 | 44 | | |
| 45 | 45 | | ### Caller: TSynEdit |
| 46 | 46 | | |
| 47 | 47 | | The following methods and properties are available: |
| 48 | 48 | | |
| 49 | 49 | | Caret |
| 50 | 50 | | |
| 51 | 51 | | ``` pascal |
| 52 | 52 | | property CaretX: Integer; |
| 53 | 53 | | property CaretY: Integer; |
| 54 | 54 | | property CaretXY: TPoint; |
| 55 | 55 | | property LogicalCaretXY: TPoint; |
| 56 | 56 | | property LogicalCaretX: Integer; |
| 57 | 57 | | procedure MoveCaretIgnoreEOL(const NewCaret: TPoint); |
| 58 | 58 | | procedure MoveLogicalCaretIgnoreEOL(const NewLogCaret: TPoint); |
| 59 | 59 | | ``` |
| 60 | 60 | | |
| 61 | 61 | | Selection |
| 62 | 62 | | |
| 63 | 63 | | ``` pascal |
| 64 | 64 | | property BlockBegin: TPoint; |
| 65 | 65 | | property BlockEnd: TPoint; |
| 66 | 66 | | property SelAvail: Boolean; // read only |
| 67 | 67 | | property SelText: string; |
| 68 | 68 | | property SelectionMode: TSynSelectionMode; |
| 69 | 69 | | procedure ClearSelection; |
| 70 | 70 | | procedure SelectAll; |
| 71 | 71 | | procedure SelectToBrace; |
| 72 | 72 | | procedure SelectWord; |
| 73 | 73 | | procedure SelectLine(WithLeadSpaces: Boolean); |
| 74 | 74 | | procedure SelectParagraph; |
| 75 | 75 | | ``` |
| 76 | 76 | | |
| 77 | 77 | | Search/Replace |
| 78 | 78 | | |
| 79 | 79 | | ``` pascal |
| 80 | 80 | | function SearchReplace(const ASearch, AReplace: string; AOptions: TSynSearchOptions): integer; |
| 81 | 81 | | function SearchReplaceEx(const ASearch, AReplace: string; AOptions: TSynSearchOptions; AStart: TPoint): integer; |
| 82 | 82 | | |
| 83 | 83 | | TSynSearchOptions = set of |
| 84 | 84 | | ( ssoMatchCase, ssoWholeWord, |
| 85 | 85 | | ssoBackwards, |
| 86 | 86 | | ssoEntireScope, ssoSelectedOnly, // Default is From Caret to End-of-text (or begin-of-text if backward) |
| 87 | 87 | | ssoReplace, ssoReplaceAll, // Otherwise the function does a search only |
| 88 | 88 | | ssoPrompt, // Show the prompt before replacing |
| 89 | 89 | | ssoSearchInReplacement, // continue search-replace in replacement (with ssoReplaceAll) // replace recursive |
| 90 | 90 | | ssoRegExpr, ssoRegExprMultiLine, |
| 91 | 91 | | ssoFindContinue // Assume the current selection is the last match, and start search behind selection |
| 92 | 92 | | // (before if ssoBackward) // Default is to start at caret (Only SearchReplace / SearchReplaceEx has start/end param) |
| 93 | 93 | | ); |
| 94 | 94 | | ``` |
| 95 | 95 | | |
| 96 | 96 | | 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). |
| 97 | 97 | | |
| 98 | 98 | | ``` pascal |
| 99 | 99 | | if Caller.SearchReplace('FindMe', ' ', []) > 0 then begin |
| 100 | 100 | | // Selection is set to the first occurrence of FindMe (searched from position of caret) |
| 101 | 101 | | end; |
| 102 | 102 | | ``` |
| 103 | 103 | | |
| 104 | 104 | | Text |
| 105 | 105 | | |
| 106 | 106 | | ``` pascal |
| 107 | 107 | | property Lines[Index: Integer]: string; // read only |
| 108 | 108 | | property LinesCount: integer; // read only (new for Lazarus 2.2) |
| 109 | 109 | | property LineAtCaret: string; // read only |
| 110 | 110 | | procedure InsertTextAtCaret(aText: String; aCaretMode : TSynCaretAdjustMode); |
| 111 | 111 | | property TextBetweenPoints[aStartPoint, aEndPoint: TPoint]: String // Logical Points |
| 112 | 112 | | procedure SetTextBetweenPoints(aStartPoint, aEndPoint: TPoint; |
| 113 | 113 | | const AValue: String; |
| 114 | 114 | | aFlags: TSynEditTextFlags = []; |
| 115 | 115 | | aCaretMode: TSynCaretAdjustMode; |
| 116 | 116 | | aMarksMode: TSynMarksAdjustMode; |
| 117 | 117 | | aSelectionMode: TSynSelectionMode |
| 118 | 118 | | ); |
| 119 | 119 | | ``` |
| 120 | 120 | | |
| 121 | 121 | | Clipboard |
| 122 | 122 | | |
| 123 | 123 | | ``` pascal |
| 124 | 124 | | procedure CopyToClipboard; |
| 125 | 125 | | procedure CutToClipboard; |
| 126 | 126 | | procedure PasteFromClipboard; |
| 127 | 127 | | property CanPaste: Boolean // read only |
| 128 | 128 | | ``` |
| 129 | 129 | | |
| 130 | 130 | | Logical / Physical |
| 131 | 131 | | |
| 132 | 132 | | ``` pascal |
| 133 | 133 | | function LogicalToPhysicalPos(const p: TPoint): TPoint; |
| 134 | 134 | | function LogicalToPhysicalCol(const Line: String; Index, LogicalPos |
| 135 | 135 | | : integer): integer; |
| 136 | 136 | | function PhysicalToLogicalPos(const p: TPoint): TPoint; |
| 137 | 137 | | function PhysicalToLogicalCol(const Line: string; |
| 138 | 138 | | Index, PhysicalPos: integer): integer; |
| 139 | 139 | | function PhysicalLineLength(Line: String; Index: integer): integer; |
| 140 | 140 | | ``` |
| 141 | 141 | | |
| 142 | 142 | | ### ClipBoard: TClipBoard |
| 143 | 143 | | |
| 144 | 144 | | ``` pascal |
| 145 | 145 | | property AsText: String; |
| 146 | 146 | | ``` |
| 147 | 147 | | |
| 148 | 148 | | ## Available Macros / Downloads |
| 149 | 149 | | |
| 150 | | - | <table> |
| 151 | | - | <caption>Editor macros</caption> |
| 152 | | - | <tbody> |
| 153 | | - | <tr> |
| 154 | | - | <td><p><strong>Description</strong></p></td> |
| 155 | | - | <td><p><strong>Link</strong></p></td> |
| 156 | | - | </tr> |
| 157 | | - | <tr> |
| 158 | | - | <td><p><strong>Column Align Source code</strong></p> |
| 159 | | - | <p>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.</p> |
| 160 | | - | <p>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)</p> |
| 161 | | - | <p>You can vertically align things like := or // or (</p> |
| 162 | | - | <table> |
| 163 | | - | <tbody> |
| 164 | | - | <tr> |
| 165 | | - | <td><div class="sourceCode" id="cb1"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a> foo := <span class="dv">1</span>;</span> |
| 166 | | - | <span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a> something := <span class="dv">2</span>;</span> |
| 167 | | - | <span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a> x := -<span class="dv">3</span>;</span></code></pre></div></td> |
| 168 | | - | <td><div class="sourceCode" id="cb2"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a> foo := <span class="dv">1</span>;</span> |
| 169 | | - | <span id="cb2-2"><a href="#cb2-2" aria-hidden="true" tabindex="-1"></a> something := <span class="dv">2</span>;</span> |
| 170 | | - | <span id="cb2-3"><a href="#cb2-3" aria-hidden="true" tabindex="-1"></a> x := -<span class="dv">3</span>;</span></code></pre></div></td> |
| 171 | | - | </tr> |
| 172 | | - | </tbody> |
| 173 | | - | </table></td> |
| 174 | | - | <td><p>[[Editor Macro Column Align Source]]</p></td> |
| 175 | | - | </tr> |
| 176 | | - | <tr> |
| 177 | | - | <td><p><strong>Count array elements</strong></p> |
| 178 | | - | <p>A macro to count the boundaries in an array constant.</p> |
| 179 | | - | <table> |
| 180 | | - | <tbody> |
| 181 | | - | <tr> |
| 182 | | - | <td><div class="sourceCode" id="cb3"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> foo: <span class="kw">array</span> [<span class="dv">0.</span>.] <span class="kw">of</span> <span class="dt">integer</span> = (</span> |
| 183 | | - | <span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>,</span> |
| 184 | | - | <span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a> <span class="dv">4</span></span> |
| 185 | | - | <span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a> );</span></code></pre></div></td> |
| 186 | | - | <td><div class="sourceCode" id="cb4"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">const</span> foo: <span class="kw">array</span> [<span class="dv">0..3</span>] <span class="kw">of</span> <span class="dt">integer</span> = (</span> |
| 187 | | - | <span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a> <span class="dv">1</span>, <span class="dv">2</span>, <span class="dv">3</span>,</span> |
| 188 | | - | <span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a> <span class="dv">4</span></span> |
| 189 | | - | <span id="cb4-4"><a href="#cb4-4" aria-hidden="true" tabindex="-1"></a> );</span></code></pre></div></td> |
| 190 | | - | </tr> |
| 191 | | - | </tbody> |
| 192 | | - | </table></td> |
| 193 | | - | <td><p>See <a href="http://forum.lazarus.freepascal.org/index.php/topic,27186.msg167883.html#msg167883">http://forum.lazarus.freepascal.org/index.php/topic,27186.msg167883.html#msg167883</a> for counting array elements.</p></td> |
| 194 | | - | </tr> |
| 195 | | - | <tr> |
| 196 | | - | <td><p><strong>Add PasDoc for function declaration</strong></p> |
| 197 | | - | <p>Comments a procedure/function in <a href="https://github.com/pasdoc/pasdoc/wiki">PasDoc</a> format</p> |
| 198 | | - | <p>Example: Executing the macro with the caret in the line of function declaration will insert the comment before.</p> |
| 199 | | - | <table> |
| 200 | | - | <tbody> |
| 201 | | - | <tr> |
| 202 | | - | <td><div class="sourceCode" id="cb5"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> AddRadioButton(<span class="kw">const</span> aCaption: <span class="dt">string</span>; aChecked: <span class="dt">boolean</span> = <span class="kw">False</span>): TCheckBox;</span></code></pre></div></td> |
| 203 | | - | <td><div class="sourceCode" id="cb6"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="co">{ Description</span></span> |
| 204 | | - | <span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a><span class="co"> @param(aCaption description )</span></span> |
| 205 | | - | <span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a><span class="co"> @param(aChecked description )</span></span> |
| 206 | | - | <span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="co"> @returns( description )</span></span> |
| 207 | | - | <span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a><span class="co"> @raises( none )</span></span> |
| 208 | | - | <span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a><span class="co">}</span></span> |
| 209 | | - | <span id="cb6-7"><a href="#cb6-7" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> AddRadioButton(<span class="kw">const</span> aCaption: <span class="dt">string</span>; aChecked: <span class="dt">boolean</span> = <span class="kw">False</span>): TRadioButton;</span></code></pre></div></td> |
| 210 | | - | </tr> |
| 211 | | - | </tbody> |
| 212 | | - | </table> |
| 213 | | - | <p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc"><span>https://github.com/DomingoGP/LazarusMacroPasDoc</span></a></p></td> |
| 214 | | - | <td><p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroPasDocLazarus.txt">MacroPasDocLazarus.txt</a></p></td> |
| 215 | | - | </tr> |
| 216 | | - | <tr> |
| 217 | | - | <td><p><strong>Sort selected lines</strong></p> |
| 218 | | - | <p>There are two macros, one with the normal alphabetical order and another that orders by type</p> |
| 219 | | - | <table> |
| 220 | | - | <tbody> |
| 221 | | - | <tr> |
| 222 | | - | <td><div class="sourceCode" id="cb7"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a> c:<span class="dt">integer</span>;</span> |
| 223 | | - | <span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a> b:<span class="dt">integer</span>;</span> |
| 224 | | - | <span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a> d:<span class="dt">boolean</span>;</span> |
| 225 | | - | <span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a> a:<span class="dt">boolean</span>;</span></code></pre></div></td> |
| 226 | | - | <td><div class="sourceCode" id="cb8"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a> <span class="co">//normal sorting</span></span> |
| 227 | | - | <span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> a:<span class="dt">boolean</span>;</span> |
| 228 | | - | <span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> b:<span class="dt">integer</span>;</span> |
| 229 | | - | <span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> c:<span class="dt">integer</span>;</span> |
| 230 | | - | <span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> d:<span class="dt">boolean</span>;</span></code></pre></div></td> |
| 231 | | - | <td><div class="sourceCode" id="cb9"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a> <span class="co">//sorting by type</span></span> |
| 232 | | - | <span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> d:<span class="dt">boolean</span>;</span> |
| 233 | | - | <span id="cb9-3"><a href="#cb9-3" aria-hidden="true" tabindex="-1"></a> a:<span class="dt">boolean</span>;</span> |
| 234 | | - | <span id="cb9-4"><a href="#cb9-4" aria-hidden="true" tabindex="-1"></a> c:<span class="dt">integer</span>;</span> |
| 235 | | - | <span id="cb9-5"><a href="#cb9-5" aria-hidden="true" tabindex="-1"></a> b:<span class="dt">integer</span>; </span></code></pre></div></td> |
| 236 | | - | </tr> |
| 237 | | - | </tbody> |
| 238 | | - | </table></td> |
| 239 | | - | <td><p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortLinesLazarus.txt">MacroSortLinesLazarus.txt</a></p> |
| 240 | | - | <p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortByTypeLazarus.txt">MacroSortByTypeLazarus.txt</a></p></td> |
| 241 | | - | </tr> |
| 242 | | - | <tr> |
| 243 | | - | <td></td> |
| 244 | | - | <td></td> |
| 245 | | - | </tr> |
| 246 | | - | <tr> |
| 247 | | - | <td><p><strong>Column Align by procedure/function name the selected lines</strong></p> |
| 248 | | - | <table> |
| 249 | | - | <tbody> |
| 250 | | - | <tr> |
| 251 | | - | <td><div class="sourceCode" id="cb10"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span> Create;</span> |
| 252 | | - | <span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">destructor</span> Destroy; <span class="kw">override</span>;</span> |
| 253 | | - | <span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Load(<span class="kw">const</span> aFileName:TFileName):<span class="dt">boolean</span>;</span> |
| 254 | | - | <span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">procedure</span> Save(<span class="kw">const</span> aFileName:TFileName); </span> |
| 255 | | - | <span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Size:<span class="dt">integer</span>; </span></code></pre></div></td> |
| 256 | | - | <td><div class="sourceCode" id="cb11"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span> Create;</span> |
| 257 | | - | <span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">destructor</span> Destroy; <span class="kw">override</span></span> |
| 258 | | - | <span id="cb11-3"><a href="#cb11-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Load(<span class="kw">const</span> aFileName:TFileName):<span class="dt">boolean</span>;</span> |
| 259 | | - | <span id="cb11-4"><a href="#cb11-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">procedure</span> Save(<span class="kw">const</span> aFileName:TFileName); </span> |
| 260 | | - | <span id="cb11-5"><a href="#cb11-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Size:<span class="dt">integer</span>;</span></code></pre></div></td> |
| 261 | | - | </tr> |
| 262 | | - | </tbody> |
| 263 | | - | </table></td> |
| 264 | | - | <td><p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroAlignFunctionProcedureNamesLazarus.txt">MacroAlignFunctionProcedureNamesLazarus.txt</a></p></td> |
| 265 | | - | </tr> |
| 266 | | - | <tr> |
| 267 | | - | <td></td> |
| 268 | | - | <td></td> |
| 269 | | - | </tr> |
| 270 | | - | <tr> |
| 271 | | - | <td><p><strong>Sort selected function/procedures declarations by Name, keeps the comments before the function/procedure</strong></p> |
| 272 | | - | <table> |
| 273 | | - | <tbody> |
| 274 | | - | <tr> |
| 275 | | - | <td><div class="sourceCode" id="cb12"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb12-1"><a href="#cb12-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">destructor</span> Destroy; <span class="kw">override</span>;</span> |
| 276 | | - | <span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span> Create;</span> |
| 277 | | - | <span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a> <span class="kw">procedure</span> Save(<span class="kw">const</span> aFileName:TFileName);</span> |
| 278 | | - | <span id="cb12-4"><a href="#cb12-4" aria-hidden="true" tabindex="-1"></a> <span class="co">{ Load the aFileName }</span></span> |
| 279 | | - | <span id="cb12-5"><a href="#cb12-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Load(<span class="kw">const</span> aFileName:TFileName):<span class="dt">boolean</span>;</span> |
| 280 | | - | <span id="cb12-6"><a href="#cb12-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Size:<span class="dt">integer</span>; </span></code></pre></div></td> |
| 281 | | - | <td><div class="sourceCode" id="cb13"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">constructor</span> Create;</span> |
| 282 | | - | <span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="kw">destructor</span> Destroy; <span class="kw">override</span>;</span> |
| 283 | | - | <span id="cb13-3"><a href="#cb13-3" aria-hidden="true" tabindex="-1"></a> <span class="co">{ Load the aFileName }</span></span> |
| 284 | | - | <span id="cb13-4"><a href="#cb13-4" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Load(<span class="kw">const</span> aFileName:TFileName):<span class="dt">boolean</span>;</span> |
| 285 | | - | <span id="cb13-5"><a href="#cb13-5" aria-hidden="true" tabindex="-1"></a> <span class="kw">procedure</span> Save(<span class="kw">const</span> aFileName:TFileName);</span> |
| 286 | | - | <span id="cb13-6"><a href="#cb13-6" aria-hidden="true" tabindex="-1"></a> <span class="kw">function</span> Size:<span class="dt">integer</span>; </span></code></pre></div></td> |
| 287 | | - | </tr> |
| 288 | | - | </tbody> |
| 289 | | - | </table></td> |
| 290 | | - | <td><p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortFuncProcLazarus.txt">MacroSortFuncProcLazarus.txt</a></p></td> |
| 291 | | - | </tr> |
| 292 | | - | <tr> |
| 293 | | - | <td></td> |
| 294 | | - | <td></td> |
| 295 | | - | </tr> |
| 296 | | - | <tr> |
| 297 | | - | <td></td> |
| 298 | | - | <td></td> |
| 299 | | - | </tr> |
| 300 | | - | <tr> |
| 301 | | - | <td><p><strong>Sort selected units in the uses clause</strong></p> |
| 302 | | - | <table> |
| 303 | | - | <tbody> |
| 304 | | - | <tr> |
| 305 | | - | <td><div class="sourceCode" id="cb14"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb14-1"><a href="#cb14-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">uses</span></span> |
| 306 | | - | <span id="cb14-2"><a href="#cb14-2" aria-hidden="true" tabindex="-1"></a> Classes, SysUtils, Forms, Controls, Graphics, Dialogs; </span></code></pre></div></td> |
| 307 | | - | <td><div class="sourceCode" id="cb15"><pre class="sourceCode pascal"><code class="sourceCode pascal"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a> <span class="kw">uses</span></span> |
| 308 | | - | <span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> Classes, Controls, Dialogs, Forms, Graphics, SysUtils;</span></code></pre></div></td> |
| 309 | | - | </tr> |
| 310 | | - | </tbody> |
| 311 | | - | </table></td> |
| 312 | | - | <td><p><a href="https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortUsesLazarus.txt">MacroSortUsesLazarus.txt</a></p></td> |
| 313 | | - | </tr> |
| 314 | | - | <tr> |
| 315 | | - | <td></td> |
| 316 | | - | <td></td> |
| 317 | | - | </tr> |
| 318 | | - | </tbody> |
| 319 | | - | </table> |
| 150 | + | Editor macros |
| 151 | + | |
| 152 | + | **Description** |
| 153 | + | |
| 154 | + | **Link** |
| 155 | + | |
| 156 | + | **Column Align Source code** |
| 157 | + | |
| 158 | + | 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. |
| 159 | + | |
| 160 | + | 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) |
| 161 | + | |
| 162 | + | You can vertically align things like := or // or ( |
| 163 | + | |
| 164 | + | ``` pascal |
| 165 | + | foo := 1; |
| 166 | + | something := 2; |
| 167 | + | x := -3; |
| 168 | + | ``` |
| 169 | + | |
| 170 | + | ``` pascal |
| 171 | + | foo := 1; |
| 172 | + | something := 2; |
| 173 | + | x := -3; |
| 174 | + | ``` |
| 175 | + | |
| 176 | + | [[Editor Macro Column Align Source]] |
| 177 | + | |
| 178 | + | **Count array elements** |
| 179 | + | |
| 180 | + | A macro to count the boundaries in an array constant. |
| 181 | + | |
| 182 | + | ``` pascal |
| 183 | + | const foo: array [0..] of integer = ( |
| 184 | + | 1, 2, 3, |
| 185 | + | 4 |
| 186 | + | ); |
| 187 | + | ``` |
| 188 | + | |
| 189 | + | ``` pascal |
| 190 | + | const foo: array [0..3] of integer = ( |
| 191 | + | 1, 2, 3, |
| 192 | + | 4 |
| 193 | + | ); |
| 194 | + | ``` |
| 195 | + | |
| 196 | + | See <http://forum.lazarus.freepascal.org/index.php/topic,27186.msg167883.html#msg167883> for counting array elements. |
| 197 | + | |
| 198 | + | **Add PasDoc for function declaration** |
| 199 | + | |
| 200 | + | Comments a procedure/function in [PasDoc](https://github.com/pasdoc/pasdoc/wiki) format |
| 201 | + | |
| 202 | + | Example: Executing the macro with the caret in the line of function declaration will insert the comment before. |
| 203 | + | |
| 204 | + | ``` pascal |
| 205 | + | function AddRadioButton(const aCaption: string; aChecked: boolean = False): TCheckBox; |
| 206 | + | ``` |
| 207 | + | |
| 208 | + | ``` pascal |
| 209 | + | { Description |
| 210 | + | @param(aCaption description ) |
| 211 | + | @param(aChecked description ) |
| 212 | + | @returns( description ) |
| 213 | + | @raises( none ) |
| 214 | + | } |
| 215 | + | function AddRadioButton(const aCaption: string; aChecked: boolean = False): TRadioButton; |
| 216 | + | ``` |
| 217 | + | |
| 218 | + | [<https://github.com/DomingoGP/LazarusMacroPasDoc>](https://github.com/DomingoGP/LazarusMacroPasDoc) |
| 219 | + | |
| 220 | + | [MacroPasDocLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroPasDocLazarus.txt) |
| 221 | + | |
| 222 | + | **Sort selected lines** |
| 223 | + | |
| 224 | + | There are two macros, one with the normal alphabetical order and another that orders by type |
| 225 | + | |
| 226 | + | ``` pascal |
| 227 | + | c:integer; |
| 228 | + | b:integer; |
| 229 | + | d:boolean; |
| 230 | + | a:boolean; |
| 231 | + | ``` |
| 232 | + | |
| 233 | + | ``` pascal |
| 234 | + | //normal sorting |
| 235 | + | a:boolean; |
| 236 | + | b:integer; |
| 237 | + | c:integer; |
| 238 | + | d:boolean; |
| 239 | + | ``` |
| 240 | + | |
| 241 | + | ``` pascal |
| 242 | + | //sorting by type |
| 243 | + | d:boolean; |
| 244 | + | a:boolean; |
| 245 | + | c:integer; |
| 246 | + | b:integer; |
| 247 | + | ``` |
| 248 | + | |
| 249 | + | [MacroSortLinesLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortLinesLazarus.txt) |
| 250 | + | |
| 251 | + | [MacroSortByTypeLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortByTypeLazarus.txt) |
| 252 | + | |
| 253 | + | **Column Align by procedure/function name the selected lines** |
| 254 | + | |
| 255 | + | ``` pascal |
| 256 | + | constructor Create; |
| 257 | + | destructor Destroy; override; |
| 258 | + | function Load(const aFileName:TFileName):boolean; |
| 259 | + | procedure Save(const aFileName:TFileName); |
| 260 | + | function Size:integer; |
| 261 | + | ``` |
| 262 | + | |
| 263 | + | ``` pascal |
| 264 | + | constructor Create; |
| 265 | + | destructor Destroy; override |
| 266 | + | function Load(const aFileName:TFileName):boolean; |
| 267 | + | procedure Save(const aFileName:TFileName); |
| 268 | + | function Size:integer; |
| 269 | + | ``` |
| 270 | + | |
| 271 | + | [MacroAlignFunctionProcedureNamesLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroAlignFunctionProcedureNamesLazarus.txt) |
| 272 | + | |
| 273 | + | **Sort selected function/procedures declarations by Name, keeps the comments before the function/procedure** |
| 274 | + | |
| 275 | + | ``` pascal |
| 276 | + | destructor Destroy; override; |
| 277 | + | constructor Create; |
| 278 | + | procedure Save(const aFileName:TFileName); |
| 279 | + | { Load the aFileName } |
| 280 | + | function Load(const aFileName:TFileName):boolean; |
| 281 | + | function Size:integer; |
| 282 | + | ``` |
| 283 | + | |
| 284 | + | ``` pascal |
| 285 | + | constructor Create; |
| 286 | + | destructor Destroy; override; |
| 287 | + | { Load the aFileName } |
| 288 | + | function Load(const aFileName:TFileName):boolean; |
| 289 | + | procedure Save(const aFileName:TFileName); |
| 290 | + | function Size:integer; |
| 291 | + | ``` |
| 292 | + | |
| 293 | + | [MacroSortFuncProcLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortFuncProcLazarus.txt) |
| 294 | + | |
| 295 | + | **Sort selected units in the uses clause** |
| 296 | + | |
| 297 | + | ``` pascal |
| 298 | + | uses |
| 299 | + | Classes, SysUtils, Forms, Controls, Graphics, Dialogs; |
| 300 | + | ``` |
| 301 | + | |
| 302 | + | ``` pascal |
| 303 | + | uses |
| 304 | + | Classes, Controls, Dialogs, Forms, Graphics, SysUtils; |
| 305 | + | ``` |
| 306 | + | |
| 307 | + | [MacroSortUsesLazarus.txt](https://github.com/DomingoGP/LazarusMacroPasDoc/blob/master/MacroSortUsesLazarus.txt) |
| 320 | 308 | | |
| 321 | 309 | | ## See also |
| 322 | 310 | | |
| 323 | 311 | | - [[IDE Window: Editor Macros]] |
| 324 | 312 | | - [[Editor Macro Column Align Source]] - macro to align selected code to a specific token. |
| 325 | 313 | | |
| 326 | 314 | | --- |
| 327 | 315 | | *From the Free Pascal wiki, page "Editor Macros PascalScript", as it stood on 2022-01-23 after a change by DomingoGP, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |