Don't auto-indent ff a grammar doesn't have an indent/outdent regex

This commit is contained in:
Corey Johnson
2012-08-09 16:04:23 -07:00
parent 956cffe225
commit cd8e6a7f20
3 changed files with 16 additions and 6 deletions

View File

@@ -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)

View File

@@ -11,7 +11,7 @@ ChildProcess = require 'child-process'
module.exports =
class Project
tabText: ' '
autoIndent: false
autoIndent: true
softTabs: true
softWrap: false
rootDirectory: null

View File

@@ -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) ->