From bb4f3c4efa81533a6fe45d3fabb3b0076193f69f Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Fri, 28 Dec 2012 14:46:39 -0600 Subject: [PATCH] Store foldEndPattern in `syntax` global's scoped properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- spec/app/text-mate-bundle-spec.coffee | 8 -------- src/app/language-mode.coffee | 6 +++++- src/app/text-mate-bundle.coffee | 16 ++-------------- src/app/text-mate-package.coffee | 10 +++++++++- 4 files changed, 16 insertions(+), 24 deletions(-) diff --git a/spec/app/text-mate-bundle-spec.coffee b/spec/app/text-mate-bundle-spec.coffee index 663db783f..c67bc50cc 100644 --- a/spec/app/text-mate-bundle-spec.coffee +++ b/spec/app/text-mate-bundle-spec.coffee @@ -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") diff --git a/src/app/language-mode.coffee b/src/app/language-mode.coffee index 095773d37..53fcfada7 100644 --- a/src/app/language-mode.coffee +++ b/src/app/language-mode.coffee @@ -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) diff --git a/src/app/text-mate-bundle.coffee b/src/app/text-mate-bundle.coffee index fa9c5f9d1..5d31499eb 100644 --- a/src/app/text-mate-bundle.coffee +++ b/src/app/text-mate-bundle.coffee @@ -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) -> diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index dee6bf382..8dafabbdd 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -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