From 2cafba248ce5714bf21a0f115d80f6cf5d688e0c Mon Sep 17 00:00:00 2001 From: Dave de Fijter Date: Sun, 22 Feb 2015 16:09:40 +0100 Subject: [PATCH 1/2] added new commands for quitting, opening tabs and added argument functionality for commands --- lib/command.coffee | 5 +++-- lib/ex.coffee | 29 +++++++++++++++++++++++++---- 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/command.coffee b/lib/command.coffee index 38d5765..393b295 100644 --- a/lib/command.coffee +++ b/lib/command.coffee @@ -11,10 +11,11 @@ class Command execute: (input) -> return unless input.characters.length > 0 + [command, args...] = input.characters.split(" ") - func = (new Ex)[input.characters] + func = (new Ex)[command] if func? - func() + func(args) else throw new CommandError("#{input.characters}") diff --git a/lib/ex.coffee b/lib/ex.coffee index 9e61de4..f5e066c 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -1,9 +1,30 @@ class Ex - write: -> - if atom.workspace.getActiveTextEditor().getPath() isnt undefined - atom.workspace.getActiveEditor().save() + quit: -> + atom.workspace.getActivePane().destroyActiveItem() + q: => + @quit() + tabedit: (filenames) -> + if filenames? and filenames.length > 0 + atom.open(pathsToOpen: filenames) else - atom.workspace.getActivePane().saveActiveItemAs() + atom.open() + tabe: (filenames) => + @tabedit(filenames) + write: (close=false) => + if close + nextAction = -> + atom.notifications.addSuccess("Saved and closed") + atom.workspace.getActivePane().destroyActiveItem() + else + nextAction = -> + atom.notifications.addSuccess("Saved") + + if atom.workspace.getActiveTextEditor().getPath() isnt undefined + atom.workspace.getActivePane().saveItem(atom.workspace.getActivePane().getActiveItem(), nextAction) + else + atom.workspace.getActivePane().saveActiveItemAs(nextAction) w: => @write() + wq: => + @write(close=true) module.exports = Ex From 66e5f697f6cfe7f9b5ef4a27ed8939e56d07cbb3 Mon Sep 17 00:00:00 2001 From: Loic Nageleisen Date: Mon, 23 Feb 2015 10:44:51 +0100 Subject: [PATCH 2/2] comply with vim behavior --- lib/command.coffee | 2 +- lib/ex.coffee | 45 +++++++++++++++++++++++++-------------------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/lib/command.coffee b/lib/command.coffee index 393b295..cc85247 100644 --- a/lib/command.coffee +++ b/lib/command.coffee @@ -15,7 +15,7 @@ class Command func = (new Ex)[command] if func? - func(args) + func(args...) else throw new CommandError("#{input.characters}") diff --git a/lib/ex.coffee b/lib/ex.coffee index f5e066c..0a2daf2 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -1,30 +1,35 @@ +path = require 'path' + class Ex quit: -> atom.workspace.getActivePane().destroyActiveItem() q: => @quit() - tabedit: (filenames) -> - if filenames? and filenames.length > 0 - atom.open(pathsToOpen: filenames) + tabedit: (filePaths...) -> + pane = atom.workspace.getActivePane() + if filePaths? and filePaths.length > 0 + for file in filePaths + do -> atom.workspace.openURIInPane file, pane else - atom.open() - tabe: (filenames) => - @tabedit(filenames) - write: (close=false) => - if close - nextAction = -> - atom.notifications.addSuccess("Saved and closed") - atom.workspace.getActivePane().destroyActiveItem() - else - nextAction = -> - atom.notifications.addSuccess("Saved") - + atom.workspace.openURIInPane('', pane) + tabe: (filePaths...) => + @tabedit(filePaths...) + write: (filePath) => + projectPath = atom.project.getPath() + pane = atom.workspace.getActivePane() + editor = atom.workspace.getActiveEditor() if atom.workspace.getActiveTextEditor().getPath() isnt undefined - atom.workspace.getActivePane().saveItem(atom.workspace.getActivePane().getActiveItem(), nextAction) + if filePath? + editorPath = editor.getPath() + editor.saveAs(path.join(projectPath, filePath)) + editor.buffer.setPath(editorPath) + else + editor.save() else - atom.workspace.getActivePane().saveActiveItemAs(nextAction) - w: => @write() - wq: => - @write(close=true) + if filePath? + editor.saveAs(path.join(projectPath, filePath)) + else + pane.saveActiveItemAs() + w: (filePath) => @write(filePath) module.exports = Ex