Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341060 - [formatter] Allow to disable autoformat locally
Summary: [formatter] Allow to disable autoformat locally
Status: RESOLVED FIXED
Alias: None
Product: TMF
Classification: Modeling
Component: Xtext Backlog (show other bugs)
Version: 2.0.0   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-27 13:53 EDT by Karsten Thoms CLA
Modified: 2016-07-21 05:13 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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