The ToolsAPI of Delphi 13 (checked in 13.2, not present in 12) has an interface for adding a code formatter to the IDE: a plugin implements IOTACodeFormatter and registers it with IOTACodeFormatterServices.AddFormatter.
The GExperts code formatter could use it in Delphi 13 and later instead of only its own shortcut. That would give:
CanFormatOnSave)SupportsOffsetRemapping with GetStoredOffsetsForFormatter / SetStoredOffsetsForFormatter)The IDE passes the source as UTF8String and positions as byte offsets, so the formatter would have to map those and report how they move.
Still to be checked: whether the IDE actually provides the service at run time, which IDE commands call a registered formatter, and how this interacts with the IDE's own formatter.
Tested with a small test package in the 32-bit IDE of Delphi 13.2:
IOTACodeFormatterServicesis available. Before the test formatter was registered,CanHandleFile('x.pas')returned False: Delphi 13 no longer has a code formatter of its own.actFormatSource) calls the registered formatter:HandleFile,GetConfirmDlg,SupportsOffsetRemapping, thenFormatFile. The result replaces the editor text. Format Document (EditFormatDocument) does not call it.FormatSelected. The IDE replaces the whole file with whatFormatSelectedreturns, so it must return the complete file with only the selection formatted.CanFormatOnSaveand, if that returns True,FormatFile, without asking.FormatLine,CanFormatLineandAutoFormatLinewere not called; typing in the editor was not tested.Implemented in revision #5857. The option is on the Misc. tab of the Code Formatter configuration: "Register as the IDE's code formatter (Format Source command)". It only takes effect while the Code Formatter expert is enabled.