Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 341060

Summary: [formatter] Allow to disable autoformat locally
Product: [Modeling] TMF Reporter: Karsten Thoms <karsten.thoms>
Component: Xtext BacklogAssignee: Project Inbox <tmf.xtext-inbox>
Status: RESOLVED FIXED QA Contact:
Severity: enhancement    
Priority: P3 CC: boris.holzer, moritz.eysholdt
Version: 2.0.0   
Target Milestone: ---   
Hardware: PC   
OS: Mac OS X - Carbon (unsup.)   
Whiteboard:

Description Karsten Thoms CLA 2011-03-27 13:53:05 EDT
In some cases (e.g. column layouts) there is no better way of formatting then the user does himself. Thus it should be possible to explicitly ignore sections from formatting and take the original input format as output.
Comment 1 Boris holzer CLA 2011-03-30 05:24:27 EDT
I encountered the same requirement.

This Hack worked in my case:
1. Extend ...formatting.impl.FormattingConfig and introduce 
public class PreserveSpaceLocator extends SpaceLocator {}

2. Patch FormattingConfigBasedStream.line.getSpacesStr 	 
...
for (ElementLocator leadingLocator : entry.leadingLocators)
  /** PATCH - START- */
  if (leadingLocator instanceof PreserveSpaceLocator) {
	return entry.leadingWS;  
  } else
  /** PATCH - END - */
  if (leadingLocator instanceof SpaceLocator) {
...
Comment 2 Moritz Eysholdt CLA 2016-07-21 05:13:19 EDT
There is still no explicit support for this, but it's easy to implement with the new formatter:

When creating the FormattingRequest, scan the TextRegionAccess for those tokens that should enable/disable formatting and based on this configure the text ranges in 
org.eclipse.xtext.formatting2.FormatterRequest.getRegions().

I think that's good enough to close this ticket. Improved support such as dedicated API or a user interface should be treated by new tickets in https://github.com/eclipse/xtext-core/issues