diff --git a/spec/app/text-mate-grammar-spec.coffee b/spec/app/text-mate-grammar-spec.coffee
index 3dae2764a..51ca1c483 100644
--- a/spec/app/text-mate-grammar-spec.coffee
+++ b/spec/app/text-mate-grammar-spec.coffee
@@ -242,6 +242,23 @@ describe "TextMateGrammar", ->
expect(tokens[21]).toEqual value: 'div', scopes: ["text.html.ruby","meta.tag.block.any.html","entity.name.tag.block.any.html"]
expect(tokens[22]).toEqual value: '>', scopes: ["text.html.ruby","meta.tag.block.any.html","punctuation.definition.tag.end.html"]
+ it "updates the grammar if the included grammar is updated later", ->
+ atom.activatePackage('html.tmbundle', sync: true)
+ atom.activatePackage('ruby-on-rails-tmbundle', sync: true)
+
+ grammar = syntax.selectGrammar('foo.html.erb')
+ grammarUpdatedHandler = jasmine.createSpy("grammarUpdatedHandler")
+ grammar.on 'grammar-updated', grammarUpdatedHandler
+
+ {tokens} = grammar.tokenizeLine("
<% <<-SQL select * from users;")
+ expect(tokens[12].value).toBe " select * from users;"
+
+ atom.activatePackage('sql.tmbundle', sync: true)
+ expect(grammarUpdatedHandler).toHaveBeenCalled()
+ {tokens} = grammar.tokenizeLine("
<% <<-SQL select * from users;")
+ expect(tokens[12].value).toBe " "
+ expect(tokens[13].value).toBe "select"
+
describe "when a grammar matching the desired scope is unavailable", ->
it "updates the grammar if a matching grammar is added later", ->
atom.deactivatePackage('html.tmbundle')
diff --git a/src/app/null-grammar.coffee b/src/app/null-grammar.coffee
index 6dadc599a..8d7079d55 100644
--- a/src/app/null-grammar.coffee
+++ b/src/app/null-grammar.coffee
@@ -15,6 +15,6 @@ class NullGrammar
tokenizeLine: (line) ->
{ tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] }
- grammarAddedOrRemoved: -> # no op
+ grammarUpdated: -> # noop
_.extend NullGrammar.prototype, EventEmitter
diff --git a/src/app/syntax.coffee b/src/app/syntax.coffee
index db48ad045..c5ffd1f58 100644
--- a/src/app/syntax.coffee
+++ b/src/app/syntax.coffee
@@ -34,16 +34,17 @@ class Syntax
previousGrammars = new Array(@grammars...)
@grammars.push(grammar)
@grammarsByScopeName[grammar.scopeName] = grammar
- @notifyOtherGrammars(previousGrammars, grammar.scopeName)
+ @grammarUpdated(grammar.scopeName)
@trigger 'grammar-added', grammar
removeGrammar: (grammar) ->
_.remove(@grammars, grammar)
delete @grammarsByScopeName[grammar.scopeName]
- @notifyOtherGrammars(@grammars, grammar.scopeName)
+ @grammarUpdated(grammar.scopeName)
- notifyOtherGrammars: (grammars, scopeName) ->
- grammar.grammarAddedOrRemoved(scopeName) for grammar in grammars
+ grammarUpdated: (scopeName) ->
+ for grammar in @grammars when grammar.scopeName isnt scopeName
+ grammar.grammarUpdated(scopeName)
setGrammarOverrideForPath: (path, scopeName) ->
@grammarOverridesByPath[path] = scopeName
diff --git a/src/app/text-mate-grammar.coffee b/src/app/text-mate-grammar.coffee
index a38cb1074..56d168c2b 100644
--- a/src/app/text-mate-grammar.coffee
+++ b/src/app/text-mate-grammar.coffee
@@ -64,9 +64,10 @@ class TextMateGrammar
addIncludedGrammarScope: (scope) ->
@includedGrammarScopes.push(scope) unless _.include(@includedGrammarScopes, scope)
- grammarAddedOrRemoved: (scopeName) =>
+ grammarUpdated: (scopeName) =>
return unless _.include(@includedGrammarScopes, scopeName)
@clearRules()
+ syntax.grammarUpdated(@scopeName)
@trigger 'grammar-updated'
getScore: (path, contents) ->