From cd8e6a7f20dc9a866eeddccba45f4b05012a6505 Mon Sep 17 00:00:00 2001 From: Corey Johnson Date: Thu, 9 Aug 2012 16:04:23 -0700 Subject: [PATCH] Don't auto-indent ff a grammar doesn't have an indent/outdent regex --- src/app/language-mode.coffee | 9 ++++++--- src/app/project.coffee | 2 +- src/app/text-mate-bundle.coffee | 11 +++++++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 4abc027b9..1ab2f5653 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -95,7 +95,8 @@ class LanguageMode precedingLine = @editSession.lineForBufferRow(precedingRow) scopes = @tokenizedBuffer.scopesForPosition([precedingRow, Infinity]) - increaseIndentPattern = new OnigRegExp(TextMateBundle.getPreferenceInScope(scopes[0], 'increaseIndentPattern')) + increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0]) + return unless increaseIndentPattern currentIndentation = @buffer.indentationForRow(bufferRow) desiredIndentation = @buffer.indentationForRow(precedingRow) @@ -105,8 +106,10 @@ class LanguageMode autoDecreaseIndentForBufferRow: (bufferRow) -> scopes = @tokenizedBuffer.scopesForPosition([bufferRow, 0]) - increaseIndentPattern = new OnigRegExp(TextMateBundle.getPreferenceInScope(scopes[0], 'increaseIndentPattern')) - decreaseIndentPattern = new OnigRegExp(TextMateBundle.getPreferenceInScope(scopes[0], 'decreaseIndentPattern')) + increaseIndentPattern = TextMateBundle.indentRegexForScope(scopes[0]) + decreaseIndentPattern = TextMateBundle.outdentRegexForScope(scopes[0]) + return unless increaseIndentPattern and decreaseIndentPattern + line = @buffer.lineForRow(bufferRow) return unless decreaseIndentPattern.test(line) diff --git a/src/app/project.coffee b/src/app/project.coffee index 4d8a27e22..442e7df18 100644 --- a/src/app/project.coffee +++ b/src/app/project.coffee @@ -11,7 +11,7 @@ ChildProcess = require 'child-process' module.exports = class Project tabText: ' ' - autoIndent: false + autoIndent: true softTabs: true softWrap: false rootDirectory: null diff --git a/src/app/text-mate-bundle.coffee b/src/app/text-mate-bundle.coffee index a42c60297..3e0780c49 100644 --- a/src/app/text-mate-bundle.coffee +++ b/src/app/text-mate-bundle.coffee @@ -4,7 +4,6 @@ plist = require 'plist' TextMateGrammar = require 'text-mate-grammar' - module.exports = class TextMateBundle @grammarsByFileType: {} @@ -30,12 +29,20 @@ class TextMateBundle @grammarsByFileType[extension] or @grammarsByFileType["txt"] @getPreferenceInScope: (scopeSelector, preferenceName) -> - @preferencesByScopeSelector[scopeSelector][preferenceName] + @preferencesByScopeSelector[scopeSelector]?[preferenceName] @lineCommentStringForScope: (scope) -> shellVariables = @getPreferenceInScope(scope, 'shellVariables') lineComment = (_.find shellVariables, ({name}) -> name == "TM_COMMENT_START")['value'] + @indentRegexForScope: (scope) -> + if source = @getPreferenceInScope(scope, 'increaseIndentPattern') + new OnigRegExp(source) + + @outdentRegexForScope: (scope) -> + if source = @getPreferenceInScope(scope, 'decreaseIndentPattern') + new OnigRegExp(source) + grammars: null constructor: (@path) ->