Added :wq
This commit is contained in:
parent
209c19b9db
commit
4adc1c168a
2 changed files with 52 additions and 5 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
## next - C-C-C-Combo Edition
|
## next - C-C-C-Combo Edition
|
||||||
* Alert on unknown command
|
* Alert on unknown command
|
||||||
|
* Added `:wq`
|
||||||
|
|
||||||
## 0.3.0 - Extrovert Edition
|
## 0.3.0 - Extrovert Edition
|
||||||
* Register new commands from the outside world
|
* Register new commands from the outside world
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,28 @@
|
||||||
path = require 'path'
|
path = require 'path'
|
||||||
|
|
||||||
|
trySave = (func) ->
|
||||||
|
deferred = Promise.defer()
|
||||||
|
|
||||||
|
try
|
||||||
|
func()
|
||||||
|
deferred.resolve()
|
||||||
|
catch error
|
||||||
|
if error.message.endsWith('is a directory')
|
||||||
|
atom.notifications.addWarning("Unable to save file: #{error.message}")
|
||||||
|
else if error.code is 'EACCES' and error.path?
|
||||||
|
atom.notifications.addWarning("Unable to save file: Permission denied '#{error.path}'")
|
||||||
|
else if error.code in ['EPERM', 'EBUSY', 'UNKNOWN', 'EEXIST'] and error.path?
|
||||||
|
atom.notifications.addWarning("Unable to save file '#{error.path}'", detail: error.message)
|
||||||
|
else if error.code is 'EROFS' and error.path?
|
||||||
|
atom.notifications.addWarning("Unable to save file: Read-only file system '#{error.path}'")
|
||||||
|
else if errorMatch = /ENOTDIR, not a directory '([^']+)'/.exec(error.message)
|
||||||
|
fileName = errorMatch[1]
|
||||||
|
atom.notifications.addWarning("Unable to save file: A directory in the path '#{fileName}' could not be written to")
|
||||||
|
else
|
||||||
|
throw error
|
||||||
|
|
||||||
|
deferred.promise
|
||||||
|
|
||||||
class Ex
|
class Ex
|
||||||
@singleton: =>
|
@singleton: =>
|
||||||
@ex ||= new Ex
|
@ex ||= new Ex
|
||||||
|
|
@ -47,23 +70,46 @@ class Ex
|
||||||
enew: => @edit()
|
enew: => @edit()
|
||||||
|
|
||||||
write: (filePath) ->
|
write: (filePath) ->
|
||||||
|
deferred = Promise.defer()
|
||||||
|
|
||||||
projectPath = atom.project.getPath()
|
projectPath = atom.project.getPath()
|
||||||
pane = atom.workspace.getActivePane()
|
pane = atom.workspace.getActivePane()
|
||||||
editor = atom.workspace.getActiveEditor()
|
editor = atom.workspace.getActiveEditor()
|
||||||
if atom.workspace.getActiveTextEditor().getPath() isnt undefined
|
if atom.workspace.getActiveTextEditor().getPath() isnt undefined
|
||||||
if filePath?
|
if filePath?
|
||||||
editorPath = editor.getPath()
|
editorPath = editor.getPath()
|
||||||
editor.saveAs(path.join(projectPath, filePath))
|
fullPath = if path.isAbsolute(filePath)
|
||||||
|
filePath
|
||||||
|
else
|
||||||
|
path.join(projectPath, filePath)
|
||||||
|
trySave(-> editor.saveAs(fullPath))
|
||||||
|
.then ->
|
||||||
|
deferred.resolve()
|
||||||
editor.buffer.setPath(editorPath)
|
editor.buffer.setPath(editorPath)
|
||||||
else
|
else
|
||||||
editor.save()
|
trySave(-> editor.save())
|
||||||
|
.then deferred.resolve
|
||||||
else
|
else
|
||||||
if filePath?
|
if filePath?
|
||||||
editor.saveAs(path.join(projectPath, filePath))
|
fullPath = if path.isAbsolute(filePath)
|
||||||
|
filePath
|
||||||
else
|
else
|
||||||
pane.saveActiveItemAs()
|
path.join(projectPath, filePath)
|
||||||
|
trySave(-> editor.saveAs(fullPath))
|
||||||
|
.then deferred.resolve
|
||||||
|
else
|
||||||
|
fullPath = atom.showSaveDialogSync()
|
||||||
|
if fullPath?
|
||||||
|
trySave(-> editor.saveAs(fullPath))
|
||||||
|
.then deferred.resolve
|
||||||
|
|
||||||
w: (filePath) => @write(filePath)
|
deferred.promise
|
||||||
|
|
||||||
|
w: (filePath) =>
|
||||||
|
@write(filePath)
|
||||||
|
|
||||||
|
wq: (filePath) =>
|
||||||
|
@write(filePath).then => @quit()
|
||||||
|
|
||||||
wa: ->
|
wa: ->
|
||||||
atom.workspace.saveAll()
|
atom.workspace.saveAll()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue