7

I would like to be able to keep Delphi from formatting a specific block of text because it is much easier to read when formatted in a specific way, but pressing Ctrl+D will make it much harder to read.

  • Is there a conditional directive that may be used to instruct Delphi to skip a block of text when reformatting the source code?
  • If not, is there at least a way to prevent Delphi to put a line break after the colon : in case statements?
3
  • Unfortunately, I don't know the answer but I vote for the question because it is important to make the code styles adjustable, for automatic formatting and the like. Those line breaks where you don't want them are so annoying. Customised code formatting works well for Visual Studio and Visual Studio Code (which I sometimes use for Free Pascal development instead of its native IDE). Commented Jan 26 at 15:02
  • 1
    Boys - just select the lines if you want only those reformatted. Also please use question marks when formulating questions! Ironically for a question about formatting it lacks just that. And a proper tag. Commented Jan 26 at 15:53
  • 4
    You can use GExperts or CNPack formatters that have options to skip blocks of code Commented Jan 26 at 17:42

2 Answers 2

6

is there at least a way to prevent Delphi to put a line break after the colon : in case statements?

The formatter has an option Line break after label to control that.

Sign up to request clarification or add additional context in comments.

1 Comment

Again learnd something new. Thanks. Most of the Time I decide if I want to have a Line break or not by placing an Empty Comment behind my line. Something like lstr := 'Test123' +// '456' Most of the TIme it helps, but like Uwe said for the case Statement change the Setting Line break after label.
1

There is no conditional direction that would affect how certain code parts are formatted in Delphi.

As for controlling code formatting go to Tools > Options > Language > Formatter. There you can find most option that control code formatting.

5 Comments

There is no formatter option to control line breaks after colons in case statements.
Actually, there is! It is called Line break after label.
Hmm. When I think "label", I don't think of an item of a case statement, but an actual goto label. But, I guess a case is like a conditional goto so the items could be considered as labels.
@RemyLebeau, while they have distinct options for indent labels and indent case labels, they probably missed to separate that for the line break options. On the other hand: How many label declarations and goto statements may even exist in more recent code?
@UweRaabe Granted, modern code should avoid goto, but it is still valid code, and sometimes people do want a line break on a goto label but not on a case label. I have opened a ticket: RSS-2789: Add Formatter option for inserting "Line break after case label"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.