From 2416ff19a409f1bea44c58b3d3cf8c619bf7dbb6 Mon Sep 17 00:00:00 2001 From: Nathan Sobo Date: Wed, 20 Mar 2013 19:38:37 -0600 Subject: [PATCH] Add NullGrammar to obviate synchronous load of text grammar on start It's also an extremely simple grammar, so we'll do less work to initially tokenize open buffers before loading their real grammars. --- src/app/atom.coffee | 6 ------ src/app/null-grammar.coffee | 9 +++++++++ src/app/syntax.coffee | 6 ++++-- src/app/window.coffee | 1 - 4 files changed, 13 insertions(+), 9 deletions(-) create mode 100644 src/app/null-grammar.coffee diff --git a/src/app/atom.coffee b/src/app/atom.coffee index 581cbff63..5a784ea5f 100644 --- a/src/app/atom.coffee +++ b/src/app/atom.coffee @@ -41,12 +41,6 @@ _.extend atom, packageStates[pack.name] = @atomPackageStates[pack.name] packageStates - loadTextPackage: -> - textPackagePath = _.find @getPackagePaths(), (path) -> fs.base(path) is 'text.tmbundle' - pack = Package.build(textPackagePath) - @loadedPackages.push(pack) - pack.load(sync: true) - loadPackages: -> textMatePackages = [] paths = @getPackagePaths().filter (path) -> fs.base(path) isnt 'text.tmbundle' diff --git a/src/app/null-grammar.coffee b/src/app/null-grammar.coffee new file mode 100644 index 000000000..8806e4972 --- /dev/null +++ b/src/app/null-grammar.coffee @@ -0,0 +1,9 @@ +Token = require 'token' + +module.exports = +class NullGrammar + name: "Null Grammar" + scopeName: 'text.plain.null-grammar' + + tokenizeLine: (line) -> + { tokens: [new Token(value: line, scopes: ['null-grammar.text.plain'])] } diff --git a/src/app/syntax.coffee b/src/app/syntax.coffee index 0ab0e3a8a..90c040429 100644 --- a/src/app/syntax.coffee +++ b/src/app/syntax.coffee @@ -4,6 +4,7 @@ Specificity = require 'specificity' {$$} = require 'space-pen' fs = require 'fs-utils' EventEmitter = require 'event-emitter' +NullGrammar = require 'null-grammar' module.exports = class Syntax @@ -14,6 +15,7 @@ class Syntax @globalProperties = {} @scopedPropertiesIndex = 0 @scopedProperties = [] + @nullGrammar = new NullGrammar addGrammar: (grammar) -> @grammars.push(grammar) @@ -22,7 +24,7 @@ class Syntax @grammarsByScopeName[grammar.scopeName] = grammar selectGrammar: (filePath, fileContents) -> - return @grammarsByFileType["txt"] unless filePath + return @grammarsByFileType["txt"] ? @nullGrammar unless filePath extension = fs.extension(filePath)?[1..] if filePath and extension.length == 0 @@ -31,7 +33,7 @@ class Syntax @grammarByFirstLineRegex(filePath, fileContents) or @grammarsByFileType[extension] or @grammarByFileTypeSuffix(filePath) or - @grammarsByFileType["txt"] + @grammarsByFileType["txt"] ? @nullGrammar grammarByFileTypeSuffix: (filePath) -> for fileType, grammar of @grammarsByFileType diff --git a/src/app/window.coffee b/src/app/window.coffee index 21e61fdb1..58a0dd922 100644 --- a/src/app/window.coffee +++ b/src/app/window.coffee @@ -52,7 +52,6 @@ window.startup = -> handleWindowEvents() config.load() - atom.loadTextPackage() keymap.loadBundledKeymaps() atom.loadThemes() atom.loadPackages()