From: silvioprog <sil...@gm...> - 2016-09-15 05:48:36
|
On Thu, Sep 15, 2016 at 2:18 AM, Michalis Kamburelis < mic...@gm...> wrote: > 2016-09-15 6:55 GMT+02:00 silvioprog <sil...@gm...>: > > So, what do you think about removing all first white-spaces? See a > preview showing how it would be: > > > > I *extremely* agree:) It's been bothering me since some time too, but > I did not have time to deal with it. > > We should simply scan the lines of the @longCode, looking for the > longest prefix composed of whitespace (spaces, tabs). And then (if > this prefix is not empty) remove it (from all the lines). > > If you want to implement it, go very much ahead:) I did a draft, but I need to test it ASAP: procedure TDocGenerator.HandleLongCodeTag( ThisTag: TTag; var ThisTagData: TObject; EnclosingTag: TTag; var EnclosingTagData: TObject; const TagParameter: string; var ReplaceStr: string); var Source: TStrings; Code, Line: string; I, FirstPos: Integer; begin if TagParameter = '' then exit; // Trim off "marker" characters at the beginning and end of TagParameter. Code := Copy(TagParameter, 2, Length(TagParameter) - 2); FirstPos := FirstWordPos(Code); if FirstPos > 0 then begin Source := TStringList.Create; try Source.Text := Code; for I := 0 to Pred(Source.Count) do begin Line := Source[I]; // Trim all early white-spaces // Then indents the code with only two white-spaces Source[I] := Copy(Line, FirstPos, MaxInt); end; Code := TrimRight(Source.Text); finally Source.Free; end; end; // Then format pascal code. ReplaceStr := FormatPascalCode(Code); end; -- Silvio Clécio |