WIP: Loading TextMate Bundle preferences globally

This commit is contained in:
Corey Johnson & Nathan Sobo
2012-08-02 13:04:43 -06:00
parent b378620c54
commit 9ca4c2c347
2 changed files with 36 additions and 4 deletions

View File

@@ -0,0 +1,8 @@
TextMateBundle = require 'text-mate-bundle'
fdescribe "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()

View File

@@ -8,6 +8,7 @@ TextMateGrammar = require 'text-mate-grammar'
module.exports =
class TextMateBundle
@grammarsByFileType: {}
@preferencesByScopeSelector: {}
@bundles: []
@loadAll: ->
@@ -17,6 +18,9 @@ class TextMateBundle
@registerBundle: (bundle)->
@bundles.push(bundle)
for scopeSelector, preferences of bundle.getPreferencesByScopeSelector()
@preferencesByScopeSelector[scopeSelector] = preferences
for grammar in bundle.grammars
for fileType in grammar.fileTypes
@grammarsByFileType[fileType] = grammar
@@ -25,13 +29,33 @@ class TextMateBundle
extension = fs.extension(fileName)[1...]
@grammarsByFileType[extension] or @grammarsByFileType["txt"]
@getPreferenceForScopeSelector: (name, scopeSelector) ->
@preferencesByScopeSelector[scopeSelector][name]
grammars: null
constructor: (bundlePath) ->
constructor: (@path) ->
@grammars = []
syntaxesPath = fs.join(bundlePath, "Syntaxes")
if fs.exists(syntaxesPath)
for syntaxPath in fs.list(syntaxesPath)
if fs.exists(@getSyntaxesPath())
for syntaxPath in fs.list(@getSyntaxesPath())
@grammars.push TextMateGrammar.loadFromPath(syntaxPath)
getPreferencesByScopeSelector: ->
return {} unless fs.exists(@getPreferencesPath())
preferencesByScopeSelector = {}
for preferencePath in fs.list(@getPreferencesPath())
plist.parseString fs.read(preferencePath), (e, data) ->
throw new Error(e) if e
{ scope, settings } = data[0]
preferencesByScopeSelector[scope] = _.extend(preferencesByScopeSelector[scope] ? {}, settings)
console.log preferencesByScopeSelector
preferencesByScopeSelector
getSyntaxesPath: ->
fs.join(@path, "Syntaxes")
getPreferencesPath: ->
fs.join(@path, "Preferences")