Update commands
This commit is contained in:
parent
8b658db090
commit
d1295587ee
1 changed files with 28 additions and 18 deletions
|
|
@ -29,6 +29,10 @@ trySave = (func) ->
|
||||||
|
|
||||||
deferred.promise
|
deferred.promise
|
||||||
|
|
||||||
|
getFullPath = (filePath) ->
|
||||||
|
return filePath if path.isAbsolute(filePath)
|
||||||
|
return path.join(atom.project.getPath(), filePath)
|
||||||
|
|
||||||
class Ex
|
class Ex
|
||||||
@singleton: =>
|
@singleton: =>
|
||||||
@ex ||= new Ex
|
@ex ||= new Ex
|
||||||
|
|
@ -42,7 +46,7 @@ class Ex
|
||||||
q: => @quit()
|
q: => @quit()
|
||||||
|
|
||||||
tabedit: (range, args) ->
|
tabedit: (range, args) ->
|
||||||
args = args.trimLeft()
|
args = args.trim()
|
||||||
filePaths = args.split(' ')
|
filePaths = args.split(' ')
|
||||||
pane = atom.workspace.getActivePane()
|
pane = atom.workspace.getActivePane()
|
||||||
if filePaths? and filePaths.length > 0
|
if filePaths? and filePaths.length > 0
|
||||||
|
|
@ -71,26 +75,32 @@ class Ex
|
||||||
|
|
||||||
tabp: => @tabprevious()
|
tabp: => @tabprevious()
|
||||||
|
|
||||||
edit: (range, filePath) => @tabedit(range, filePath) if filePath?
|
edit: (range, filePath) ->
|
||||||
|
filePath = filePath.trim()
|
||||||
|
if filePath.indexOf(' ') isnt -1
|
||||||
|
throw new CommandError('Only one file name allowed')
|
||||||
|
buffer = atom.workspace.getActiveEditor().buffer
|
||||||
|
filePath = buffer.getPath() if filePath is ''
|
||||||
|
buffer.setPath(getFullPath(filePath))
|
||||||
|
buffer.load()
|
||||||
|
|
||||||
e: (args...) => @edit(args...)
|
e: (args...) => @edit(args...)
|
||||||
|
|
||||||
enew: => @edit()
|
enew: ->
|
||||||
|
buffer = atom.workspace.getActiveEditor().buffer
|
||||||
|
buffer.setPath(undefined)
|
||||||
|
buffer.load()
|
||||||
|
|
||||||
write: (range, filePath) ->
|
write: (range, filePath) ->
|
||||||
filePath = filePath.trimLeft()
|
filePath = filePath.trim()
|
||||||
deferred = Promise.defer()
|
deferred = Promise.defer()
|
||||||
|
|
||||||
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.length > 0
|
||||||
editorPath = editor.getPath()
|
editorPath = editor.getPath()
|
||||||
fullPath = if path.isAbsolute(filePath)
|
fullPath = getFullPath(filePath)
|
||||||
filePath
|
|
||||||
else
|
|
||||||
path.join(projectPath, filePath)
|
|
||||||
trySave(-> editor.saveAs(fullPath))
|
trySave(-> editor.saveAs(fullPath))
|
||||||
.then ->
|
.then ->
|
||||||
deferred.resolve()
|
deferred.resolve()
|
||||||
|
|
@ -99,11 +109,8 @@ class Ex
|
||||||
trySave(-> editor.save())
|
trySave(-> editor.save())
|
||||||
.then deferred.resolve
|
.then deferred.resolve
|
||||||
else
|
else
|
||||||
if filePath?
|
if filePath.length > 0
|
||||||
fullPath = if path.isAbsolute(filePath)
|
fullPath = getFullPath(filePath)
|
||||||
filePath
|
|
||||||
else
|
|
||||||
path.join(projectPath, filePath)
|
|
||||||
trySave(-> editor.saveAs(fullPath))
|
trySave(-> editor.saveAs(fullPath))
|
||||||
.then deferred.resolve
|
.then deferred.resolve
|
||||||
else
|
else
|
||||||
|
|
@ -126,8 +133,10 @@ class Ex
|
||||||
atom.workspace.saveAll()
|
atom.workspace.saveAll()
|
||||||
|
|
||||||
split: (range, args) ->
|
split: (range, args) ->
|
||||||
args = args.trimLeft()
|
args = args.trim()
|
||||||
filePaths = args.splitLeft()
|
filePaths = args.split(' ')
|
||||||
|
filePaths = undefined if filePaths.length is 1 and filePaths[0] is ''
|
||||||
|
console.log filePaths, filePaths is ['']
|
||||||
pane = atom.workspace.getActivePane()
|
pane = atom.workspace.getActivePane()
|
||||||
if filePaths? and filePaths.length > 0
|
if filePaths? and filePaths.length > 0
|
||||||
newPane = pane.splitUp()
|
newPane = pane.splitUp()
|
||||||
|
|
@ -140,8 +149,9 @@ class Ex
|
||||||
sp: (args...) => @split(args...)
|
sp: (args...) => @split(args...)
|
||||||
|
|
||||||
vsplit: (range, args) ->
|
vsplit: (range, args) ->
|
||||||
args = args.trimLeft()
|
args = args.trim()
|
||||||
filePaths = args.split(' ')
|
filePaths = args.split(' ')
|
||||||
|
filePaths = undefined if filePaths.length is 1 and filePaths[0] is ''
|
||||||
pane = atom.workspace.getActivePane()
|
pane = atom.workspace.getActivePane()
|
||||||
if filePaths? and filePaths.length > 0
|
if filePaths? and filePaths.length > 0
|
||||||
newPane = pane.splitLeft()
|
newPane = pane.splitLeft()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue