admin管理员组文章数量:1355648
I am working with Pascal/Delphi code and need to format a selection of code with custom indentation rules (e.g. 4 spaces for indentation). I want to apply these formatting rules to the selected code without affecting the entire document.
For example, I have this unformatted code:
procedure MyProcedure;
begin
if SomeCondition then
begin
DoSomething;
for i := 0 to 10 do
begin
DoSomethingElse;
end;
end;
end;
I want to quickly apply 4 spaces for indentation to the selected portion, including the begin
and end
of the loop, so the code becomes properly indented like this:
procedure MyProcedure;
begin
if SomeCondition then
begin
DoSomething;
for i := 0 to 10 do
begin
DoSomethingElse;
end;
end;
end;
I am working with Pascal/Delphi code and need to format a selection of code with custom indentation rules (e.g. 4 spaces for indentation). I want to apply these formatting rules to the selected code without affecting the entire document.
For example, I have this unformatted code:
procedure MyProcedure;
begin
if SomeCondition then
begin
DoSomething;
for i := 0 to 10 do
begin
DoSomethingElse;
end;
end;
end;
I want to quickly apply 4 spaces for indentation to the selected portion, including the begin
and end
of the loop, so the code becomes properly indented like this:
procedure MyProcedure;
begin
if SomeCondition then
begin
DoSomething;
for i := 0 to 10 do
begin
DoSomethingElse;
end;
end;
end;
Share
Improve this question
edited Mar 28 at 13:26
AmigoJack
6,1852 gold badges19 silver badges34 bronze badges
asked Mar 28 at 5:45
user5005768-hduser5005768-hd
1,4593 gold badges30 silver badges66 bronze badges
6
|
Show 1 more comment
2 Answers
Reset to default 3Tested using the built-in code formatter in Delphi 12.3:
Make sure you have Modeling installed in Tools|Manage Features.
Set the Block Indent to
4
spaces. (Tools|Editor|Language and select Delphi).In the Delphi formatter (Tools|Language|Formatter|Delphi|Indentation), set the following:
- Indent Begin and End keywords:
True
- Indent blocks between Begin and End:
False
- Indent Function Bodies:
True
- Indent Begin and End keywords:
Use Ctrl+D to format the code. If a block is selected, just that block will be formatted. Otherwise, the entire unit will be formatted.
Formatter options can be found here.
Tools/Options.../Editor/Language/(Language Delphi)/Block Indent: set to
4
, click Save.Select a piece of code (the finished fragment), press Ctrl+D.
If the formatter didn't work, copy the piece of code to another page of the editor and repeat formatting there.
Additional formatting options can be found in: Tools/Options.../Language/Formatter/Delphi.
版权声明:本文标题:How to easily and quickly apply custom indentation format rule to selected PascalDelphi code? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744054421a2583012.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
begin
being also indented, so everything within it is on the same level). And you should tell us which IDE you're using, since Pascal/Delphi is unbound to the IDE strictly speaking - nobody can know if you use Lazarus, Delphi or even something else. – AmigoJack Commented Mar 28 at 13:29