mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Store foldEndPattern in syntax global's scoped properties
There's a slight wrinkle in this commit… TextMate grammars sometimes store the `foldStopMarker` directly in the grammar, rather than storing it in a separate scoped preferences file like the other settings. So we have to scan through grammars looking for those that have the fold end marker and make a scoped property for that grammar's scope.
This commit is contained in:
@@ -2,14 +2,6 @@ fs = require('fs')
|
||||
TextMateBundle = require 'text-mate-bundle'
|
||||
|
||||
describe "TextMateBundle", ->
|
||||
describe ".getPreferenceInScope(scope, preferenceName)", ->
|
||||
it "returns the preference by the given name in the given scope or undefined if there isn't one", ->
|
||||
expect(TextMateBundle.getPreferenceInScope('source.coffee', 'decreaseIndentPattern')).toBe '^\\s*(\\}|\\]|else|catch|finally)$'
|
||||
expect(TextMateBundle.getPreferenceInScope('source.coffee', 'shellVariables')).toBeDefined()
|
||||
|
||||
it "returns the preference by the given name in the given scope for a scope registered via a comma-separated list of scopes", ->
|
||||
expect(TextMateBundle.getPreferenceInScope('source.objc++', 'shellVariables')).toBeDefined()
|
||||
|
||||
describe ".getPreferencesByScopeSelector()", ->
|
||||
it "logs warning, but does not raise errors if a preference can't be parsed", ->
|
||||
bundlePath = fs.join(require.resolve('fixtures'), "test.tmbundle")
|
||||
|
||||
@@ -119,7 +119,7 @@ class LanguageMode
|
||||
continue if @editSession.isBufferRowBlank(row)
|
||||
indentation = @editSession.indentationForBufferRow(row)
|
||||
if indentation <= startIndentLevel
|
||||
includeRowInFold = indentation == startIndentLevel and TextMateBundle.foldEndRegexForScope(@grammar, scopes[0]).search(@editSession.lineForBufferRow(row))
|
||||
includeRowInFold = indentation == startIndentLevel and @foldEndRegexForScopes(scopes).search(@editSession.lineForBufferRow(row))
|
||||
foldEndRow = row if includeRowInFold
|
||||
break
|
||||
|
||||
@@ -196,3 +196,7 @@ class LanguageMode
|
||||
decreaseIndentRegexForScopes: (scopes) ->
|
||||
if decreaseIndentPattern = syntax.getProperty(scopes, 'editor.decreaseIndentPattern')
|
||||
new OnigRegExp(decreaseIndentPattern)
|
||||
|
||||
foldEndRegexForScopes: (scopes) ->
|
||||
if foldEndPattern = syntax.getProperty(scopes, 'editor.foldEndPattern')
|
||||
new OnigRegExp(foldEndPattern)
|
||||
|
||||
@@ -27,6 +27,8 @@ class TextMateBundle
|
||||
@grammarsByFileType[fileType] = grammar
|
||||
@grammarsByScopeName[grammar.scopeName] = grammar
|
||||
|
||||
bundle
|
||||
|
||||
@grammarForFilePath: (filePath) ->
|
||||
return @grammarsByFileType["txt"] unless filePath
|
||||
|
||||
@@ -51,20 +53,6 @@ class TextMateBundle
|
||||
@grammarForScopeName: (scopeName) ->
|
||||
@grammarsByScopeName[scopeName]
|
||||
|
||||
@getPreferenceInScope: (scopeSelector, preferenceName) ->
|
||||
@preferencesByScopeSelector[scopeSelector]?[preferenceName]
|
||||
|
||||
@getPreferenceValueInScope: (scope, preferenceName, valueName) ->
|
||||
values = @getPreferenceInScope(scope, preferenceName)
|
||||
(_.find values, ({name}) -> name is valueName)?['value']
|
||||
|
||||
@foldEndRegexForScope: (grammar, scope) ->
|
||||
marker = @getPreferenceInScope(scope, 'foldingStopMarker')
|
||||
if marker
|
||||
new OnigRegExp(marker)
|
||||
else
|
||||
new OnigRegExp(grammar.foldingStopMarker)
|
||||
|
||||
grammars: null
|
||||
|
||||
constructor: (@path) ->
|
||||
|
||||
@@ -19,7 +19,8 @@ class TextMatePackage extends Package
|
||||
).join(', ')
|
||||
|
||||
load: ->
|
||||
TextMateBundle.load(@name)
|
||||
@bundle = TextMateBundle.load(@name)
|
||||
@grammars = @bundle.grammars
|
||||
super
|
||||
|
||||
constructor: ->
|
||||
@@ -29,6 +30,12 @@ class TextMatePackage extends Package
|
||||
|
||||
getScopedProperties: ->
|
||||
scopedProperties = []
|
||||
|
||||
for grammar in @grammars when grammar.foldingStopMarker
|
||||
scopedProperties.push
|
||||
selector: TextMatePackage.cssSelectorForScopeSelector(grammar.scopeName)
|
||||
properties: { editor: { foldEndPattern: grammar.foldingStopMarker } }
|
||||
|
||||
if fs.exists(@preferencesPath)
|
||||
for preferencePath in fs.list(@preferencesPath)
|
||||
plist.parseString fs.read(preferencePath), (e, data) =>
|
||||
@@ -53,5 +60,6 @@ class TextMatePackage extends Package
|
||||
commentEnd: _.valueForKeyPath(textMateSettings, 'shellVariables.TM_COMMENT_END')
|
||||
increaseIndentPattern: textMateSettings.increaseIndentPattern
|
||||
decreaseIndentPattern: textMateSettings.decreaseIndentPattern
|
||||
foldEndPattern: textMateSettings.foldingStopMarker
|
||||
)
|
||||
{ editor: editorProperties } if _.size(editorProperties) > 0
|
||||
|
||||
Reference in New Issue
Block a user