--- a/gsf/src/org/netbeans/modules/gsf/GsfDocument.java Tue Apr 08 22:53:16 2008 +0400 +++ a/gsf/src/org/netbeans/modules/gsf/GsfDocument.java Tue Apr 08 12:13:27 2008 -0700 @@ -86,6 +86,7 @@ } /** Get the formatter for this document. */ + @Override public Formatter getFormatter() { if (formatter == null) { // NbDocument will go looking in the settings map for a formatter - let's make @@ -103,7 +104,10 @@ public int getShiftWidth() { org.netbeans.modules.gsf.api.Formatter f = language.getFormatter(); if (f != null) { - return f.indentSize(); + int shiftWidth = f.indentSize(); + if (shiftWidth > 0) { + return shiftWidth; + } } return super.getShiftWidth(); } --- a/javascript.editing/src/org/netbeans/modules/javascript/editing/CodeStyle.java Tue Apr 08 22:53:16 2008 +0400 +++ a/javascript.editing/src/org/netbeans/modules/javascript/editing/CodeStyle.java Tue Apr 08 12:13:27 2008 -0700 @@ -54,7 +54,7 @@ * * @author Dusan Balek */ -public final class CodeStyle { +public /*final*/ class CodeStyle { private static CodeStyle INSTANCE; @@ -64,7 +64,7 @@ private Preferences preferences; - private CodeStyle(Preferences preferences) { + protected CodeStyle(Preferences preferences) { this.preferences = preferences; } --- a/javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java Tue Apr 08 22:53:16 2008 +0400 +++ a/javascript.editing/src/org/netbeans/modules/javascript/editing/JsFormatter.java Tue Apr 08 12:13:27 2008 -0700 @@ -47,12 +47,18 @@ import java.util.Stack; import javax.swing.text.BadLocationException; import javax.swing.text.Document; +import javax.swing.text.EditorKit; +import org.netbeans.api.editor.mimelookup.MimeLookup; +import org.netbeans.api.editor.mimelookup.MimePath; import org.netbeans.api.lexer.Token; import org.netbeans.api.lexer.TokenHierarchy; import org.netbeans.api.lexer.TokenId; import org.netbeans.api.lexer.TokenSequence; import org.netbeans.editor.BaseDocument; +import org.netbeans.editor.Settings; +import org.netbeans.editor.SettingsNames; import org.netbeans.editor.Utilities; +import org.netbeans.modules.editor.options.BaseOptions; import org.netbeans.modules.gsf.api.CompilationInfo; import org.netbeans.modules.gsf.api.OffsetRange; import org.netbeans.modules.javascript.editing.lexer.LexUtilities; @@ -98,7 +104,7 @@ private Stack stack = new Stack(); public JsFormatter() { - this.codeStyle = CodeStyle.getDefault(null); + this.codeStyle = new DocSyncedCodeStyle(); } public JsFormatter(CodeStyle codeStyle, int rightMarginOverride) { @@ -119,11 +125,11 @@ } public int indentSize() { - return codeStyle.getIndentSize(); + return -1; // Use IDE defaults } public int hangingIndentSize() { - return codeStyle.getContinuationIndentSize(); + return -1; // Use IDE defaults } /** Compute the initial balance of brackets at the given offset. */ @@ -849,9 +855,69 @@ * those settings */ private static void syncOptions(BaseDocument doc, CodeStyle style) { - org.netbeans.editor.Formatter formatter = doc.getFormatter(); - if (formatter.getSpacesPerTab() != style.getIndentSize()) { - formatter.setSpacesPerTab(style.getIndentSize()); + if (style instanceof DocSyncedCodeStyle) { + ((DocSyncedCodeStyle)style).syncToDocument(doc); + } + } + + private static final class DocSyncedCodeStyle extends CodeStyle { + private DocSyncedCodeStyle() { + super(null); + } + + private int indentSize = 4; + private int continuationIndentSize = 4; + private int rightMargin = 80; + private EditorKit kit; + + // Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel + private EditorKit getEditorKit() { + if(kit == null) + kit = MimeLookup.getLookup(MimePath.parse("text/xml")).lookup(EditorKit.class); // NOI18N + return kit; + } + + // Copied from option.editor's org.netbeans.modules.options.indentation.IndentationModel + private Integer getSpacesPerTab() { + Integer sp = + (Integer) Settings.getValue(getEditorKit().getClass(), SettingsNames.SPACES_PER_TAB); + return sp; + } + + public void syncToDocument(BaseDocument doc) { + Integer sp = getSpacesPerTab(); + int indent = sp.intValue(); + if (indent <= 0) { + indent = 4; + } + indentSize = continuationIndentSize = indent; + } + + @Override + public int getIndentSize() { + return indentSize; + } + + @Override + public int getContinuationIndentSize() { + return continuationIndentSize; + } + + @Override + public boolean reformatComments() { + // This isn't used in JavaScript yet + return false; + } + + @Override + public boolean indentHtml() { + // This isn't used in JavaScript yet + return false; + } + + @Override + public int getRightMargin() { + return rightMargin; } }