From 5a075d515e3873ceed80cf623bba2670400d7669 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 28 Dec 2012 13:47:50 -0600 Subject: [PATCH] Retrieve indent/outdent patterns from scoped properties, not TM bundle --- src/app/language-mode.coffee | 32 ++++++++++++++++++++------------ src/app/text-mate-bundle.coffee | 8 -------- src/app/text-mate-package.coffee | 2 ++ 3 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index eb5db0e60..095773d37 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -130,7 +130,7 @@ class LanguageMode suggestedIndentForBufferRow: (bufferRow) -> currentIndentLevel = @editSession.indentationForBufferRow(bufferRow) scopes = @editSession.scopesForBufferPosition([bufferRow, 0]) - return currentIndentLevel unless increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0]) + return currentIndentLevel unless increaseIndentRegex = @increaseIndentRegexForScopes(scopes) currentLine = @buffer.lineForRow(bufferRow) precedingRow = @buffer.previousNonBlankRow(bufferRow) @@ -139,10 +139,10 @@ class LanguageMode precedingLine = @buffer.lineForRow(precedingRow) desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow) - desiredIndentLevel += 1 if increaseIndentPattern.test(precedingLine) + desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine) - return desiredIndentLevel unless decreaseIndentPattern = TextMateBundle.outdentRegexForScope(scopes[0]) - desiredIndentLevel -= 1 if decreaseIndentPattern.test(currentLine) + return desiredIndentLevel unless decreaseIndentRegex = @decreaseIndentRegexForScopes(scopes) + desiredIndentLevel -= 1 if decreaseIndentRegex.test(currentLine) Math.max(desiredIndentLevel, currentIndentLevel) @@ -159,32 +159,40 @@ class LanguageMode precedingLine = @editSession.lineForBufferRow(precedingRow) scopes = @editSession.scopesForBufferPosition([precedingRow, Infinity]) - increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0]) - return unless increaseIndentPattern + increaseIndentRegex = @increaseIndentRegexForScopes(scopes) + return unless increaseIndentRegex currentIndentLevel = @editSession.indentationForBufferRow(bufferRow) desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow) - desiredIndentLevel += 1 if increaseIndentPattern.test(precedingLine) + desiredIndentLevel += 1 if increaseIndentRegex.test(precedingLine) if desiredIndentLevel > currentIndentLevel @editSession.setIndentationForBufferRow(bufferRow, desiredIndentLevel) autoDecreaseIndentForBufferRow: (bufferRow) -> scopes = @editSession.scopesForBufferPosition([bufferRow, 0]) - increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0]) - decreaseIndentPattern = TextMateBundle.outdentRegexForScope(scopes[0]) - return unless increaseIndentPattern and decreaseIndentPattern + increaseIndentRegex = @increaseIndentRegexForScopes(scopes) + decreaseIndentRegex = @decreaseIndentRegexForScopes(scopes) + return unless increaseIndentRegex and decreaseIndentRegex line = @buffer.lineForRow(bufferRow) - return unless decreaseIndentPattern.test(line) + return unless decreaseIndentRegex.test(line) currentIndentLevel = @editSession.indentationForBufferRow(bufferRow) precedingRow = @buffer.previousNonBlankRow(bufferRow) precedingLine = @buffer.lineForRow(precedingRow) desiredIndentLevel = @editSession.indentationForBufferRow(precedingRow) - desiredIndentLevel -= 1 unless increaseIndentPattern.test(precedingLine) + desiredIndentLevel -= 1 unless increaseIndentRegex.test(precedingLine) if desiredIndentLevel < currentIndentLevel @editSession.setIndentationForBufferRow(bufferRow, desiredIndentLevel) tokenizeLine: (line, stack, firstLine) -> {tokens, stack} = @grammar.tokenizeLine(line, stack, firstLine) + + increaseIndentRegexForScopes: (scopes) -> + if increaseIndentPattern = syntax.getProperty(scopes, 'editor.increaseIndentPattern') + new OnigRegExp(increaseIndentPattern) + + decreaseIndentRegexForScopes: (scopes) -> + if decreaseIndentPattern = syntax.getProperty(scopes, 'editor.decreaseIndentPattern') + new OnigRegExp(decreaseIndentPattern) diff --git a/src/app/text-mate-bundle.coffee b/src/app/text-mate-bundle.coffee index 4be12f689..fa9c5f9d1 100644 --- a/src/app/text-mate-bundle.coffee +++ b/src/app/text-mate-bundle.coffee @@ -58,14 +58,6 @@ class TextMateBundle values = @getPreferenceInScope(scope, preferenceName) (_.find values, ({name}) -> name is valueName)?['value'] - @indentRegexForScope: (scope) -> - if source = @getPreferenceInScope(scope, 'increaseIndentPattern') - new OnigRegExp(source) - - @outdentRegexForScope: (scope) -> - if source = @getPreferenceInScope(scope, 'decreaseIndentPattern') - new OnigRegExp(source) - @foldEndRegexForScope: (grammar, scope) -> marker = @getPreferenceInScope(scope, 'foldingStopMarker') if marker diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 75e509f41..dee6bf382 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -51,5 +51,7 @@ class TextMatePackage extends Package editorProperties = _.compactObject( commentStart: _.valueForKeyPath(textMateSettings, 'shellVariables.TM_COMMENT_START') commentEnd: _.valueForKeyPath(textMateSettings, 'shellVariables.TM_COMMENT_END') + increaseIndentPattern: textMateSettings.increaseIndentPattern + decreaseIndentPattern: textMateSettings.decreaseIndentPattern ) { editor: editorProperties } if _.size(editorProperties) > 0