Code template with parameters lazarus / 6-IDE-CodeTools ---------------------------------------------------------------------- Leledumbo · 2009-01-05 07:27 Example: Code: [Select]cls(TMyClass)| expands to: Code: [Select]TMyClass = class private   | public end; with template source: Code: [Select]$Param(1) = class private   | public end; Is it supported (with different way perhaps)? If not, which sources need changes? ---------------------------------------------------------------------- Vincent Snijders · 2009-01-05 09:35 Something like parameters exists, but maybe not as you want. Play with "Enable Macro" and "Insert Macro". A Macro can have parameters. Maybe a general Macro that just echoes the passed parameter needs to be added. ---------------------------------------------------------------------- Leledumbo · 2009-01-05 10:38 QuoteMaybe a general Macro that just echoes the passed parameter needs to be added.I guess so as I don't seem to find a way out from available ones ---------------------------------------------------------------------- jctaborda · 2009-01-05 10:53 Using "Enable Macros" and inserting the paste macro, you can write the name of the class, then cut it to the clipboard and use "cls + Ctrl+J" to complete the code. $Paste() = class(TtiObject) private protected   function    GetOwner: $Paste()List; reintroduce;   procedure   SetOwner(const Value: $Paste()List); reintroduce;   function    GetCaption: string; override; public   property    Owner: $Paste()List read GetOwner write SetOwner;   constructor Create; override;   destructor  Destroy; override;   procedure   Save; override;   function    IsValid(const AErrors: TtiObjectErrors): boolean; override; published end; ---------------------------------------------------------------------- cd · 2009-03-28 19:47 i introduced additional macro $PrevWord(param) here is a description of how it works line Code: [Select]i 0 count-1 forb| with code template "forb" being Code: [Select]for $PrevWord(1) := $PrevWord(2) to $PrevWord(3) do // template:$PrevWord(0) begin   | end;$PrevWord(-1) is expanded to Code: [Select]for i := 0 to count-1 do // template:forb begin   | end; $PrevWord(index) is for the indexth word - from left to right, index=1 is for the first word, index=0 is for the name of template, "forb" for example; $PrevWord(-1) expands to empty string and is used at the end of template to delete words in the beginning of the line and bring it to the state as if there were no parameters before template name $PrevWord(index) is expanded to | (cursor location) if corresponding word is empty (thus there may be several cursor locations, see below); if we invoke the same template for just Code: [Select]i forb| it expands to Code: [Select]for i := | to  do // template:forb begin end; note | at the first empty parameter this is rather useful especially for for-loops where one has to type in 3 parameters; if i use a "for"-template without parameters i still have to interrupt normal characters input flow and use cursor or mouse to position cursor to the parameters placesholders. It is even more convenient if template is called upon "space-pressed". here is another exapmle, Code: [Select]i 1 length(memo1.lines[0])div(3)-1 forb| is transformed by Code: [Select]for $PrevWord(1) := $PrevWord(2) to $PrevWord(3) do begin   | end;$PrevWord(-1) to Code: [Select]for i:=1 to length(memo1.lines[0])div(3)-1 do begin   | end; and one more Code: [Select]st:tstringlist trycf| is transformed by Code: [Select]$PrevWord(1) := $PrevWord(2).Create; try   | finally   $PrevWord(1).Free; end;$PrevWord(-1) to Code: [Select]st := tstringlist.Create; try   | finally   st.Free; end; the only inconvenience is "length(memo1.lines[0])div(3)-1" - words- parameters cannot contain spaces, but can contain "[]()^@." if some words-parameters are empty then after having applied macros the template will contain several | cursor positions - to deal with the situation ExecuteCodeTemplate also needs tiny changes to make it take the first | only and wipe out all that follow. for those who have interest i attached source code for both of changed files from /ide/ subfolder the initial version of ide was 0.9.26.2 beta (SVN 18980) - codetemplatesdlg.pas and codemacroprompt.pas. ---------------------------------------------------------------------- Leledumbo · 2009-03-30 04:48 Haven't tried but looks lovely. I'll try it at home. ---------------------------------------------------------------------- Leledumbo · 2009-03-31 11:26 Umm... why I got: Code: [Select]i 0 count-1 for i := 0 to count-1 do // template:forb begin   | end; instead of: Code: [Select]for i := 0 to count-1 do // template:forb begin   | end; ? ---------------------------------------------------------------------- cd · 2009-03-31 15:22 hm $PrevWord(-1) at the end of the template should perform cleanup. ---------------------------------------------------------------------- Leledumbo · 2009-04-01 03:08 Oops! I should've read more carefully