From 9b231e8c4e4acaaff8c176b006aa42b1127d838d Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Mon, 25 Feb 2013 08:58:47 -0800 Subject: [PATCH] Add increase indent pattern for GFM scope --- spec/fixtures/gfm.md | 1 + src/app/text-mate-package.coffee | 16 ++++++++++++++-- .../gfm.tmbundle/Preferences/indent.cson | 4 ++++ src/packages/gfm.tmbundle/spec/gfm-spec.coffee | 7 +++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 spec/fixtures/gfm.md create mode 100644 src/packages/gfm.tmbundle/Preferences/indent.cson diff --git a/spec/fixtures/gfm.md b/spec/fixtures/gfm.md new file mode 100644 index 000000000..9d1859f8d --- /dev/null +++ b/spec/fixtures/gfm.md @@ -0,0 +1 @@ + * First list item diff --git a/src/app/text-mate-package.coffee b/src/app/text-mate-package.coffee index 2a54d12fe..c4901cc02 100644 --- a/src/app/text-mate-package.coffee +++ b/src/app/text-mate-package.coffee @@ -73,15 +73,27 @@ class TextMatePackage extends Package scopedProperties + readObjectFromPath: (path, callback) -> + object = null + error = null + if fs.isObjectPath(path) + object = fs.readObject(path) + else + plist.parseString fs.read(path), (e, data) -> + error = e + object = data[0] + error = throw new Error("Failed to load object at path `#{path}`") unless object + callback(error, object) + getTextMatePreferenceObjects: -> preferenceObjects = [] if fs.exists(@preferencesPath) for preferencePath in fs.list(@preferencesPath) - plist.parseString fs.read(preferencePath), (e, data) => + @readObjectFromPath preferencePath, (e, object) => if e console.warn "Failed to parse preference at path '#{preferencePath}'", e.stack else - preferenceObjects.push(data[0]) + preferenceObjects.push(object) preferenceObjects propertiesFromTextMateSettings: (textMateSettings) -> diff --git a/src/packages/gfm.tmbundle/Preferences/indent.cson b/src/packages/gfm.tmbundle/Preferences/indent.cson new file mode 100644 index 000000000..113cdcb96 --- /dev/null +++ b/src/packages/gfm.tmbundle/Preferences/indent.cson @@ -0,0 +1,4 @@ +'name': 'Indent' +'scope': 'source.gfm' +'settings': + 'increaseIndentPattern': '^\\s*([\\*\\+-])[ \\t]+' diff --git a/src/packages/gfm.tmbundle/spec/gfm-spec.coffee b/src/packages/gfm.tmbundle/spec/gfm-spec.coffee index 42b739832..db307ab65 100644 --- a/src/packages/gfm.tmbundle/spec/gfm-spec.coffee +++ b/src/packages/gfm.tmbundle/spec/gfm-spec.coffee @@ -132,3 +132,10 @@ describe "GitHub Flavored Markdown grammar", -> {tokens} = grammar.tokenizeLine("> Quotation") expect(tokens[0]).toEqual value: ">", scopes: ["source.gfm", "support.quote.gfm"] expect(tokens[1]).toEqual value: " Quotation", scopes: ["source.gfm", "comment.quote.gfm"] + + describe "auto indent", -> + it "indents newlines entered after list lines", -> + config.set('editor.autoIndent', true) + editSession = fixturesProject.buildEditSessionForPath('gfm.md') + editSession.insertNewlineBelow() + expect(editSession.buffer.lineForRow(1)).toBe ' '