This commit is contained in:
Daniel Perez 2015-11-19 21:30:40 +00:00
commit b1cb32d135

View file

@ -4,11 +4,10 @@ fs = require 'fs-plus'
VimOption = require './vim-option' VimOption = require './vim-option'
trySave = (func) -> trySave = (func) ->
deferred = Promise.defer() new Promise (resolve) ->
try try
func() func()
deferred.resolve() resolve()
catch error catch error
if error.message.endsWith('is a directory') if error.message.endsWith('is a directory')
atom.notifications.addWarning("Unable to save file: #{error.message}") atom.notifications.addWarning("Unable to save file: #{error.message}")
@ -30,7 +29,6 @@ trySave = (func) ->
else else
throw error throw error
deferred.promise
saveAs = (filePath) -> saveAs = (filePath) ->
editor = atom.workspace.getActiveTextEditor() editor = atom.workspace.getActiveTextEditor()
@ -150,7 +148,7 @@ class Ex
if filePath.indexOf(' ') isnt -1 if filePath.indexOf(' ') isnt -1
throw new CommandError('Only one file name allowed') throw new CommandError('Only one file name allowed')
deferred = Promise.defer() new Promise (resolve) ->
editor = atom.workspace.getActiveTextEditor() editor = atom.workspace.getActiveTextEditor()
saved = false saved = false
@ -158,7 +156,7 @@ class Ex
fullPath = getFullPath(filePath) fullPath = getFullPath(filePath)
if editor.getPath()? and (not fullPath? or editor.getPath() == fullPath) if editor.getPath()? and (not fullPath? or editor.getPath() == fullPath)
# Use editor.save when no path is given or the path to the file is given # Use editor.save when no path is given or the path to the file is given
trySave(-> editor.save()).then(deferred.resolve) trySave(-> editor.save()).then(resolve)
saved = true saved = true
else if not fullPath? else if not fullPath?
fullPath = atom.showSaveDialogSync() fullPath = atom.showSaveDialogSync()
@ -166,9 +164,7 @@ class Ex
if not saved and fullPath? if not saved and fullPath?
if not force and fs.existsSync(fullPath) if not force and fs.existsSync(fullPath)
throw new CommandError("File exists (add ! to override)") throw new CommandError("File exists (add ! to override)")
trySave(-> saveAs(fullPath)).then(deferred.resolve) trySave(-> saveAs(fullPath)).then(resolve)
deferred.promise
w: (args...) => w: (args...) =>
@write(args...) @write(args...)