Macro for documenting procedures and functions in Pasdoc lazarus / 9-Editor ---------------------------------------------------------------------- DomingoGP · 2020-08-21 14:27 Hi, all I have created a macro that documents a procedure or function in PasDoc format. The macro will insert a comment before the procedure / function example: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i function AddRadioButton(const aCaption: string; aChecked: boolean = False): TCheckBox;  After executing the macro: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i    { Description      @param(aCaption description )      @param(aChecked description )      @returns( description )      @raises( none )    }  function AddRadioButton(const aCaption: string; aChecked: boolean = False): TRadioButton;  Create a macro https://wiki.freepascal.org/IDE_Window:_Editor_Macros in lazarus and edit inserting MacroPasDocLazarus.txt or the code below in the macro, assign a key to the macro. To create a new macro push the Record button and pulse a key (space for example) then stop recording in the lazarus editor status line. Move the new macro to the ide page and edit then macro changing the text with the contents of MacroPasDocLazarus.txt. Execute the macro with the caret in the line of the procedure function declaration. I hope someone can take advantage of it https://github.com/DomingoGP/LazarusMacroPasDoc Code of the macro Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i // Lazarus editor macro.  Template for pasdoc functions and procedures documentation// Execute with caret in the precedure/function line declaration.// Autor: Domingo Galmés  dgalmesp@gmail.com  21/08/2020// public domain.function StrTokenPos(const aStr: string; const aDelimiters: string;var aPos:integer): string;var  wI: integer;  wL: integer;  wStart: integer;begin  wL := Length(aStr);   //skip delimiters  wI := aPos;  while wI <= wL do  begin    if Pos(aStr[wI],aDelimiters) = 0 then      break;    Inc(wI);  end;  if wI > wL then // all chars are delimiters  begin    Result := '';    aPos := 0;    Exit;  end;  wStart := wI;  while wI <= wL do // while not delimiters  begin    if Pos(aStr[wI],aDelimiters) > 0 then      Break;    Inc(wI);  end;  result := Copy(aStr, wStart, wI - wStart);  Inc(wI);   //skip final delimiter (only one)  if wI<=wL then    aPos:=wI  else    aPos:=0;end; var  text:string;  start:TPoint;  declaration:string;  openParens:integer;  p:integer;  parameters:string;  l,line:integer;  inComment:boolean;  inSet:boolean;  isFunction:boolean;  parameter,parameterlower:string;begin  ecLineStart;  start:=Caller.CaretXY;  declaration:=Caller.Lines[start.Y-1];  p:=1;  text:=LowerCase(StrTokenPos(declaration,' ',p));  isFunction:=false;  if text='function' then    isFunction:=true  else if text<>'procedure' then    exit;   line:=0;  // search '(' parameters start  openParens:=0;  l:=length(declaration);  //p:=1;  while p<=l do  begin    if declaration[p]='(' then    begin      Inc(openParens);    inc(p);      break;    end;    inc(p);  end;  // seachr ')' parameters end  inComment:=false;  inSet:=false;  while p<=l do  begin    if declaration[p]=#39 then  // 'in string'.    begin      inc(p);      while (p<=l) do      begin        if declaration[p]=#39 then        begin          if (pl then    begin      inc(line);      declaration:=Caller.Lines[start.Y-1+line];      l:=length(declaration);      p:=1;    end;  end;  // separamos parameters por , o ; y despreciamos despues de :  //{parameters: aV1,aV2,aV3:integer;const aS1:string= }  //procedure Hola2(aV1,aV2,aV3:integer;const aS1:string='27');  text:='{ Description '+#10;  p:=1;  while p>0 do  begin    parameter:=StrTokenPos(parameters,',;',p);    l:=1;    parameter:=Trim(StrTokenPos(parameter,':',l));    parameterlower:=LowerCase(parameter);    l:=length(parameter);    if Pos('var',parameterlower)>0 then      parameter:=Copy(parameter,5,l-4)    else if Pos('constref',parameterlower)>0 then      parameter:=Copy(parameter,10,l-9)    else if Pos('const',parameterlower)>0 then      parameter:=Copy(parameter,7,l-6)    else if Pos('out',parameterlower)>0 then      parameter:=Copy(parameter,5,l-4);    parameter:=Trim(parameter);    text:=text+'  @param('+parameter+' description )'+#10;  end;  if isFunction then    text:=text+'  @returns( description )'+#10;  text:=text+'  @raises( none )'+#10;  text:=text+'}'+#10;  //Caller.CaretXY:=start;  Caller.insertTextAtCaret(text,scamEnd);end. ---------------------------------------------------------------------- Martin_fr · 2020-08-21 14:59 Kudos. You should edit the wiki page, and add a section "Macros for download", and then add a link to your macro. Maybe start a table, so if other add further macros, then it will be somewhat organized. ---------------------------------------------------------------------- DomingoGP · 2020-08-21 19:37 Done. I don't have experience editing the wiki. I hope the changes are correct. ---------------------------------------------------------------------- Martin_fr · 2020-08-21 19:45 I think it would be best to include the link to your repro instead of pasting the code That way people will always have the latest code. And also, if the list grows, it stays readable. Imagine scrolling through a list of 50 entries like this, just to find all the Name+ShortDescription. If you want the code on the wiki, you can add a new page for that macro. That way you have a place to link to. Also it actually needs to go on this page: https://wiki.freepascal.org/Editor_Macros_PascalScript Because that is where the PascalScript related parts are. And since we are going to start collecting samples, I should heed my own advice, and move the existing sample. Don't worry about the learning experience. ---------------------------------------------------------------------- Martin_fr · 2020-08-21 20:01 Since I had to move the existing example, I took the liberty and moved it (and replaced the source with the link). But be encouraged to contribute to the wiki. You can always ask, and it can always be amended. ---------------------------------------------------------------------- DomingoGP · 2020-08-21 20:12 You are right, I have discarded the changes made in the wiki.