File: SetSpaces.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (247 lines) | stat: -rw-r--r-- 10,675 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
{(*}
(*------------------------------------------------------------------------------
 Delphi Code formatter source code 

The Original Code is SetSpaces.pas, released February 2001.
The Initial Developer of the Original Code is Anthony Steele.
Portions created by Anthony Steele are Copyright (C) 1999-2008 Anthony Steele.
All Rights Reserved.
Contributor(s): Anthony Steele. 

The contents of this file are subject to the Mozilla Public License Version 1.1
(the "License"). you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.mozilla.org/NPL/

Software distributed under the License is distributed on an "AS IS" basis,
WITHOUT WARRANTY OF ANY KIND, either express or implied.
See the License for the specific language governing rights and limitations 
under the License.

Alternatively, the contents of this file may be used under the terms of
the GNU General Public License Version 2 or later (the "GPL") 
See http://www.gnu.org/licenses/gpl.html
------------------------------------------------------------------------------*)
{*)}

{ mostly spacing and line breaking +options }

unit SetSpaces;

{$I JcfGlobal.inc}

interface

uses JcfSetBase, SettingsStream, SettingsTypes;

type

  TSetSpaces = class(TSetBase)
  private
    fbTabsToSpaces: boolean;
    fbSpacesToTabs: boolean;
    fiSpacesForTab: integer;
    fiSpacesPerTab: integer;

    fbFixSpacing: boolean;
    fbSpaceBeforeClassHeritage: boolean;

    fiSpacesBeforeColonVar: integer;
    fiSpacesBeforeColonConst: integer;
    fiSpacesBeforeColonParam: integer;
    fiSpacesBeforeColonFn: integer;
    fiSpacesBeforeColonClassVar: integer;
    fiSpacesBeforeColonRecordField: integer;
    fiSpacesBeforeColonCaseLabel: integer;
    fiSpacesBeforeColonLabel: integer;
    fiSpacesBeforeColonInGeneric: integer;

    fiMaxSpacesInCode: integer;
    fbUseMaxSpacesInCode: boolean;

    // add spaces
    fbSpaceBeforeOpenBracketsInFunctionDeclaration: boolean;
    fbSpaceBeforeOpenBracketsInFunctionCall: boolean;
    fbSpaceBeforeOpenSquareBracketsInExpression: boolean;

    fbSpaceAfterOpenBrackets: boolean;
    fbSpaceBeforeCloseBrackets: boolean;
    fbMoveSpaceToBeforeColon: boolean;

    feSpaceForOperator: TTriOptionStyle;

  protected
  public
    constructor Create;

    procedure WriteToStream(const pcOut: TSettingsOutput); override;
    procedure ReadFromStream(const pcStream: TSettingsInput); override;

    property TabsToSpaces: boolean read fbTabsToSpaces write fbTabsToSpaces;
    property SpacesToTabs: boolean read fbSpacesToTabs write fbSpacesToTabs;

    property SpacesPerTab: integer read fiSpacesPerTab write fiSpacesPerTab;
    property SpacesForTab: integer read fiSpacesForTab write fiSpacesForTab;

    property FixSpacing: boolean read fbFixSpacing write fbFixSpacing;

    property SpaceBeforeClassHeritage: boolean
      read fbSpaceBeforeClassHeritage write fbSpaceBeforeClassHeritage;

    property SpacesBeforeColonVar: integer read fiSpacesBeforeColonVar
      write fiSpacesBeforeColonVar;
    property SpacesBeforeColonConst: integer
      read fiSpacesBeforeColonConst write fiSpacesBeforeColonConst;
    property SpacesBeforeColonParam: integer
      read fiSpacesBeforeColonParam write fiSpacesBeforeColonParam;
    property SpacesBeforeColonFn: integer read fiSpacesBeforeColonFn
      write fiSpacesBeforeColonFn;
    property SpacesBeforeColonClassVar: integer
      read fiSpacesBeforeColonClassVar write fiSpacesBeforeColonClassVar;
    property SpacesBeforeColonRecordField: integer
      read fiSpacesBeforeColonRecordField write fiSpacesBeforeColonRecordField;
    property SpacesBeforeColonCaseLabel: integer
      read fiSpacesBeforeColonCaseLabel write fiSpacesBeforeColonCaseLabel;
    property SpacesBeforeColonLabel: integer
      read fiSpacesBeforeColonLabel write fiSpacesBeforeColonLabel;
    property SpacesBeforeColonInGeneric: integer
      read fiSpacesBeforeColonInGeneric write fiSpacesBeforeColonInGeneric;

    property MaxSpacesInCode: integer read fiMaxSpacesInCode write fiMaxSpacesInCode;
    property UseMaxSpacesInCode: boolean read fbUseMaxSpacesInCode write fbUseMaxSpacesInCode;

    property SpaceForOperator: TTriOptionStyle read feSpaceForOperator write feSpaceForOperator;

    property SpaceBeforeOpenBracketsInFunctionDeclaration: boolean
      read fbSpaceBeforeOpenBracketsInFunctionDeclaration write fbSpaceBeforeOpenBracketsInFunctionDeclaration;
    property SpaceBeforeOpenBracketsInFunctionCall: boolean read fbSpaceBeforeOpenBracketsInFunctionCall write fbSpaceBeforeOpenBracketsInFunctionCall;
    property SpaceBeforeOpenSquareBracketsInExpression: boolean
      read fbSpaceBeforeOpenSquareBracketsInExpression write fbSpaceBeforeOpenSquareBracketsInExpression;

    property SpaceAfterOpenBrackets: boolean read fbSpaceAfterOpenBrackets write fbSpaceAfterOpenBrackets;
    property SpaceBeforeCloseBrackets: boolean read fbSpaceBeforeCloseBrackets write fbSpaceBeforeCloseBrackets;
    property MoveSpaceToBeforeColon: boolean read fbMoveSpaceToBeforeColon write fbMoveSpaceToBeforeColon;

  end;

implementation

const
  SET_TABS_TO_SPACES = 'TabsToSpaces';
  SET_SPACES_TO_TABS = 'SpacesToTabs';
  SET_SPACES_PER_TAB = 'SpacesPerTab';
  SET_SPACES_FOR_TAB = 'SpacesForTab';

  SET_FIX_SPACING = 'FixSpacing';

  SET_SPACE_BEFORE_CLASS_HERITAGE = 'SpaceBeforeClassHeritage';

  SET_SPACES_BEFORE_COLON_VAR   = 'SpacesBeforeColonVar';
  SET_SPACES_BEFORE_COLON_CONST = 'SpacesBeforeColonConst';
  SET_SPACES_BEFORE_COLON_PARAM = 'SpacesBeforeColonParam';
  SET_SPACES_BEFORE_COLON_FN    = 'SpacesBeforeColonFn';
  SET_SPACES_BEFORE_COLON_CLASS_VAR = 'SpacesBeforeColonClassVar';
  SET_SPACES_BEFORE_COLON_RECORD_FIELD = 'SpacesBeforeColonRecordField';
  SET_SPACES_BEFORE_COLON_CASE_LABEL = 'SpacesBeforeColonCaseLabel';
  SET_SPACES_BEFORE_COLON_LABEL = 'SpacesBeforeColonLabel';
  SET_SPACES_BEFORE_COLON_IN_GENERIC = 'SpacesBeforeColonInGeneric';

  SET_MAX_SPACES_IN_CODE     = 'MaxSpacesInCode';
  SET_USE_MAX_SPACES_IN_CODE = 'UseMaxSpacesInCode';

  SET_SPACE_FOR_OPERATOR = 'SpaceForOperator';

  SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_DECLARATION = 'SpaceBeforeOpenBracketsInFunctionDeclaration';
  SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_CALL = 'SpaceBeforeOpenBracketsInFunctionCall';
  SET_SPACE_BEFORE_OPEN_SQUARE_BRACKETS_IN_EXPRESSION = 'SpaceBeforeOpenSquareBracketsInExpression';

  SET_SPACE_AFTER_OPEN_BRACKETS = 'SpaceAfterOpenBrackets';
  SET_SPACE_BEFORE_CLOSE_BRACKETS = 'SpaceBeforeCloseBrackets';
  SET_MOVE_SPACE_TO_BEFORE_COLON = 'MoveSpaceToBeforeColon';


constructor TSetSpaces.Create;
begin
  inherited;
  SetSection('Spaces');
end;

procedure TSetSpaces.ReadFromStream(const pcStream: TSettingsInput);
begin
  Assert(pcStream <> nil);

  fbTabsToSpaces := pcStream.Read(SET_TABS_TO_SPACES, True);
  fbSpacesToTabs := pcStream.Read(SET_SPACES_TO_TABS, False);

  fiSpacesPerTab := pcStream.Read(SET_SPACES_PER_TAB, 2);
  fiSpacesForTab := pcStream.Read(SET_SPACES_FOR_TAB, 2);

  fbFixSpacing := pcStream.Read(SET_FIX_SPACING, True);

  fbSpaceBeforeClassHeritage := pcStream.Read(SET_SPACE_BEFORE_CLASS_HERITAGE, False);

  fiSpacesBeforeColonVar   := pcStream.Read(SET_SPACES_BEFORE_COLON_VAR, 0);
  fiSpacesBeforeColonConst := pcStream.Read(SET_SPACES_BEFORE_COLON_CONST, 0);
  fiSpacesBeforeColonParam := pcStream.Read(SET_SPACES_BEFORE_COLON_PARAM, 0);
  fiSpacesBeforeColonFn    := pcStream.Read(SET_SPACES_BEFORE_COLON_FN, 0);
  fiSpacesBeforeColonClassVar := pcStream.Read(SET_SPACES_BEFORE_COLON_CLASS_VAR, 0);
  fiSpacesBeforeColonRecordField := pcStream.Read(SET_SPACES_BEFORE_COLON_RECORD_FIELD, 0);

  fiSpacesBeforeColonCaseLabel := pcStream.Read(SET_SPACES_BEFORE_COLON_CASE_LABEL, 0);
  fiSpacesBeforeColonLabel     := pcStream.Read(SET_SPACES_BEFORE_COLON_LABEL, 0);
  fiSpacesBeforeColonInGeneric := pcStream.Read(SET_SPACES_BEFORE_COLON_IN_GENERIC, 0);

  fiMaxSpacesInCode    := pcStream.Read(SET_MAX_SPACES_IN_CODE, 2);
  fbUseMaxSpacesInCode := pcStream.Read(SET_USE_MAX_SPACES_IN_CODE, False);

  feSpaceForOperator := TTriOptionStyle(pcStream.Read(SET_SPACE_FOR_OPERATOR, Ord(eAlways)));

  fbSpaceBeforeOpenBracketsInFunctionDeclaration := pcStream.Read(SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_DECLARATION, False);
  fbSpaceBeforeOpenBracketsInFunctionCall := pcStream.Read(SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_CALL, False);
  fbSpaceBeforeOpenSquareBracketsInExpression := pcStream.Read(SET_SPACE_BEFORE_OPEN_SQUARE_BRACKETS_IN_EXPRESSION, False);

  fbSpaceAfterOpenBrackets := pcStream.Read(SET_SPACE_AFTER_OPEN_BRACKETS, False);
  fbSpaceBeforeCloseBrackets := pcStream.Read(SET_SPACE_BEFORE_CLOSE_BRACKETS, False);
  fbMoveSpaceToBeforeColon := pcStream.Read(SET_MOVE_SPACE_TO_BEFORE_COLON, False);
end;

procedure TSetSpaces.WriteToStream(const pcOut: TSettingsOutput);
begin
  Assert(pcOut <> nil);

  pcOut.Write(SET_TABS_TO_SPACES, fbTabsToSpaces);
  pcOut.Write(SET_SPACES_TO_TABS, fbSpacesToTabs);
  pcOut.Write(SET_SPACES_PER_TAB, fiSpacesPerTab);
  pcOut.Write(SET_SPACES_FOR_TAB, fiSpacesForTab);

  pcOut.Write(SET_FIX_SPACING, fbFixSpacing);
  pcOut.Write(SET_SPACE_BEFORE_CLASS_HERITAGE, fbSpaceBeforeClassHeritage);

  pcOut.Write(SET_SPACES_BEFORE_COLON_VAR, fiSpacesBeforeColonVar);
  pcOut.Write(SET_SPACES_BEFORE_COLON_CONST, fiSpacesBeforeColonConst);
  pcOut.Write(SET_SPACES_BEFORE_COLON_PARAM, fiSpacesBeforeColonParam);
  pcOut.Write(SET_SPACES_BEFORE_COLON_FN, fiSpacesBeforeColonFn);
  pcOut.Write(SET_SPACES_BEFORE_COLON_CLASS_VAR, fiSpacesBeforeColonClassVar);

  pcOut.Write(SET_SPACES_BEFORE_COLON_RECORD_FIELD, fiSpacesBeforeColonRecordField);

  pcOut.Write(SET_SPACES_BEFORE_COLON_CASE_LABEL, fiSpacesBeforeColonCaseLabel);
  pcOut.Write(SET_SPACES_BEFORE_COLON_LABEL, fiSpacesBeforeColonLabel);
  pcOut.Write(SET_SPACES_BEFORE_COLON_IN_GENERIC, fiSpacesBeforeColonInGeneric);

  pcOut.Write(SET_MAX_SPACES_IN_CODE, fiMaxSpacesInCode);
  pcOut.Write(SET_USE_MAX_SPACES_IN_CODE, fbUseMaxSpacesInCode);

  pcOut.Write(SET_SPACE_FOR_OPERATOR, ord(feSpaceForOperator));

  pcOut.Write(SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_DECLARATION, fbSpaceBeforeOpenBracketsInFunctionDeclaration);
  pcOut.Write(SET_SPACE_BEFORE_OPEN_BRACKETS_IN_FUNCTION_CALL, fbSpaceBeforeOpenBracketsInFunctionCall);
  pcOut.Write(SET_SPACE_BEFORE_OPEN_SQUARE_BRACKETS_IN_EXPRESSION, fbSpaceBeforeOpenSquareBracketsInExpression);

  pcOut.Write(SET_SPACE_AFTER_OPEN_BRACKETS, fbSpaceAfterOpenBrackets);
  pcOut.Write(SET_SPACE_BEFORE_CLOSE_BRACKETS, fbSpaceBeforeCloseBrackets);

  pcOut.Write(SET_MOVE_SPACE_TO_BEFORE_COLON, fbMoveSpaceToBeforeColon);
end;


end.