Sign in Join
Wiki copytemporary

Editor Macro Column Align Source: what changed

Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-Please see [[Editor Macros PascalScript]] for info how to use PascalScript Macros in the IDE Source editor.
1+Please see [[Editor Macros PascalScript]] for info how to use PascalScript Macros in the IDE Source editor.
22
3-The macro shown below aligns selected code to a specific token. It looks for a specific token in each selected line, and aligns each occurrence of it.
3+The macro shown below aligns selected code to a specific token. It looks for a specific token in each selected line, and aligns each occurrence of it.
44
5-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)
6-```
7-text: string;
8- a: Integer;
9- foo: boolean
10-```
5+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)
116
12-The macro:
7+``` pascal
8+ text: string;
9+ a: Integer;
10+ foo: boolean
1311```
12+
13+The macro:
14+
15+``` pascal
1416function IsIdent(c: Char): Boolean;
15- begin
16- Result := ((c >= 'a') and (c <= 'z')) or
17- ((c >= 'A') and (c <= 'Z')) or
18- ((c >= '0') and (c <= '9')) or
19- (c = '_');
20- end;
21-
22- var
23- p1, p2: TPoint;
24- s1, s2: string;
25- i, j, k: Integer;
26- begin
27- if not Caller.SelAvail then exit;
28- p1 := Caller.BlockBegin;
29- p2 := Caller.BlockEnd;
30- if (p1.y > p2.y) or ((p1.y = p2.y) and (p1.x > p2.x)) then begin
31- p1 := Caller.BlockEnd;
32- p2 := Caller.BlockBegin;
33- end;
34- s1 := Caller.Lines[p1.y - 1];
35- s2 := '';
36- i := p1.x
37- while (i <= length(s1)) and (s1[i] in [#9, ' ']) do inc(i);
38- j := i;
39- if i <= length(s1) then begin
40- if IsIdent(s1[i]) then // pascal identifier
41- while (i <= length(s1)) and IsIdent(s1[i]) do inc(i)
42- else
43- while (i <= length(s1)) and not(IsIdent(s1[i]) or (s1[i] in [#9, ' '])) do inc(i);
44- end;
45- if i > j then s2 := copy(s1, j, i-j);
46-
47- if not InputQuery( 'Align', 'Token', s2) then exit;
48-
49- j := 0;
50- for i := p1.y to p2.y do begin
51- s1 := Caller.Lines[i - 1];
52- k := pos(s2, s1);
53- if (k > j) then j := k;
54- end;
55- if j < 1 then exit;
56-
57- for i := p1.y to p2.y do begin
58- s1 := Caller.Lines[i - 1];
59- k := pos(s2, s1);
60- if (k > 0) and (k < j) then begin
61- Caller.LogicalCaretXY := Point(k, i);
62- while k < j do begin
63- ecChar(' ');
64- inc(k);
65- end;
66- end;
17+begin
18+ Result := ((c >= 'a') and (c <= 'z')) or
19+ ((c >= 'A') and (c <= 'Z')) or
20+ ((c >= '0') and (c <= '9')) or
21+ (c = '_');
22+end;
23+
24+var
25+ p1, p2: TPoint;
26+ s1, s2: string;
27+ i, j, k: Integer;
28+begin
29+ if not Caller.SelAvail then exit;
30+ p1 := Caller.BlockBegin;
31+ p2 := Caller.BlockEnd;
32+ if (p1.y > p2.y) or ((p1.y = p2.y) and (p1.x > p2.x)) then begin
33+ p1 := Caller.BlockEnd;
34+ p2 := Caller.BlockBegin;
35+ end;
36+ s1 := Caller.Lines[p1.y - 1];
37+ s2 := '';
38+ i := p1.x
39+ while (i <= length(s1)) and (s1[i] in [#9, ' ']) do inc(i);
40+ j := i;
41+ if i <= length(s1) then begin
42+ if IsIdent(s1[i]) then // pascal identifier
43+ while (i <= length(s1)) and IsIdent(s1[i]) do inc(i)
44+ else
45+ while (i <= length(s1)) and not(IsIdent(s1[i]) or (s1[i] in [#9, ' '])) do inc(i);
46+ end;
47+ if i > j then s2 := copy(s1, j, i-j);
48+
49+ if not InputQuery( 'Align', 'Token', s2) then exit;
50+
51+ j := 0;
52+ for i := p1.y to p2.y do begin
53+ s1 := Caller.Lines[i - 1];
54+ k := pos(s2, s1);
55+ if (k > j) then j := k;
56+ end;
57+ if j < 1 then exit;
58+
59+ for i := p1.y to p2.y do begin
60+ s1 := Caller.Lines[i - 1];
61+ k := pos(s2, s1);
62+ if (k > 0) and (k < j) then begin
63+ Caller.LogicalCaretXY := Point(k, i);
64+ while k < j do begin
65+ ecChar(' ');
66+ inc(k);
6767 end;
68-
69- end.
68+ end;
69+ end;
70+
71+end.
7072```
7173
7274## See also
7375
74- * [[Editor Macros PascalScript]]
75- * [[IDE Window: Editor Macros]]
76+- [[Editor Macros PascalScript]]
77+- [[IDE Window: Editor Macros]]
7678
7779---
78-*From the Free Pascal wiki, page "Editor Macro Column Align Source", as the Internet Archive kept it on 2023-09-24. 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).*
80+*From the Free Pascal wiki, page "Editor Macro Column Align Source", as it stood on 2020-09-21 after a change by Trev, 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).*
81+Category: IDE Macros
82+Category: Lazarus
83+Category: Pascal Script
84+Category: PascalScript

Back to history