mirror of
https://github.com/atom/atom.git
synced 2026-04-28 03:01:47 -04:00
WIP: Loading TextMate Bundle preferences globally
This commit is contained in:
8
spec/app/text-mate-bundle-spec.coffee
Normal file
8
spec/app/text-mate-bundle-spec.coffee
Normal 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()
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user