Leave Markdown files alone

This commit is contained in:
Garen Torikian 2013-04-22 16:13:11 -07:00
parent 1ccf026a83
commit 4fc7e1a9d5
2 changed files with 27 additions and 1 deletions

View File

@ -4,13 +4,14 @@ module.exports =
configDefaults:
ensureSingleTrailingNewline: true
ignoredGrammars: ["GitHub Markdown"]
whitespaceBeforeSave: (editSession) ->
buffer = editSession.buffer
buffer.on 'will-be-saved', ->
return if editSession.getGrammar().name in config.get("whitespace.ignoredGrammars")
buffer.transact ->
buffer.scan /[ \t]+$/g, ({replace}) -> replace('')
if config.get('whitespace.ensureSingleTrailingNewline')
if buffer.getLastLine() is ''
row = buffer.getLastRow() - 1

View File

@ -86,3 +86,28 @@ describe "Whitespace", ->
editor.getBuffer().save()
expect(editor.getText()).toBe "foo\n"
expect(editor.getCursorBufferPosition()).toEqual([0,3])
describe "whitespace.ensureSingleTrailingNewline config", ->
[originalConfigValue] = []
grammar = null
beforeEach ->
originalConfigValue = config.get("whitespace.ignoredGrammars")
expect(originalConfigValue).toEqual ["GitHub Markdown"]
spyOn(syntax, "addGrammar").andCallThrough()
atom.activatePackage("gfm")
expect(syntax.addGrammar).toHaveBeenCalled()
grammar = syntax.addGrammar.argsForCall[0][0]
afterEach ->
config.set("whitespace.ignoredGrammars", originalConfigValue)
config.update()
it "parses the grammar", ->
expect(grammar).toBeDefined()
expect(grammar.scopeName).toBe "source.gfm"
it "leaves Markdown files alone", ->
editor.insertText "foo \nline break!"
editor.getBuffer().save()
expect(editor.getText()).toBe "foo \nline break!"