From 4ec1c56077803bb047512fca1d6d9a19dddd145f Mon Sep 17 00:00:00 2001 From: Caio Cutrim Date: Thu, 26 Nov 2015 12:20:32 -0300 Subject: [PATCH 1/4] I added :wa, :qa, :waq shortcuts commands --- lib/ex.coffee | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 684b2f6..e83e7f4 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -71,10 +71,17 @@ class Ex @registerCommand: (name, func) => @singleton()[name] = func + # quit function is used on :q command quit: -> atom.workspace.getActivePane().destroyActiveItem() - + # quit function is used on :qa command shortcut + quitAll: -> + atom.workspace.getPanes()[0].destroy() + # both functions is referenced over here + # when this commands has trigered q: => @quit() + # ...and here + qa: => @quitAll() tabedit: (range, args) => if args.trim() isnt '' @@ -169,17 +176,28 @@ class Ex trySave(-> saveAs(fullPath)).then(deferred.resolve) deferred.promise + # save all files function + saveAll: -> + atom.workspace.saveAll() + # save all then quit + saveAllThenQuit: - > + atom.workspace.saveAll() + @quitAll() w: (args...) => @write(args...) wq: (args...) => @write(args...).then => @quit() + # save all files :wa command + wa: => + @saveAll() + # save all, then quit shortcut + waq: => + @saveAllThenQuit() xit: (args...) => @wq(args...) - wa: -> - atom.workspace.saveAll() split: (range, args) -> args = args.trim() @@ -199,9 +217,9 @@ class Ex substitute: (range, args) -> args = args.trimLeft() delim = args[0] - if /[a-z1-9\\"|]/i.test(delim) + if /[a-z]/i.test(delim) throw new CommandError( - "Regular expressions can't be delimited by alphanumeric characters, '\\', '\"' or '|'") + "Regular expressions can't be delimited by letters") delimRE = new RegExp("[^\\\\]#{delim}") spl = [] args_ = args[1..] From 10fbdfe969a880ec346d02e56adc8b8498ecca8d Mon Sep 17 00:00:00 2001 From: Caio Cutrim Date: Thu, 26 Nov 2015 17:16:24 -0300 Subject: [PATCH 2/4] fixed saveAllThenQuit function --- lib/ex.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index e83e7f4..34bb1db 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -180,7 +180,7 @@ class Ex saveAll: -> atom.workspace.saveAll() # save all then quit - saveAllThenQuit: - > + saveAllThenQuit: -> atom.workspace.saveAll() @quitAll() From 059719bee45d33a506ba55f0caac6a5441dfabe8 Mon Sep 17 00:00:00 2001 From: jazzpi Date: Mon, 28 Dec 2015 14:04:19 +0100 Subject: [PATCH 3/4] Fix :quitall --- lib/ex.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 1927bb0..7ee11b0 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -113,7 +113,7 @@ class Ex atom.workspace.getActivePane().destroyActiveItem() quitall: -> - atom.workspace.getPanes()[0].destroy() + atom.close() q: => @quit() @@ -234,7 +234,7 @@ class Ex @wall() wqall: => - atom.workspace.saveAll() + @wall() @quitall() wqa: => From e17a6e55338adb35cbdcf9a6a93e9ebfced3109a Mon Sep 17 00:00:00 2001 From: jazzpi Date: Sun, 3 Jan 2016 13:15:14 +0100 Subject: [PATCH 4/4] Add specs for :wall, :quitall and :wqall --- lib/ex.coffee | 2 +- spec/ex-commands-spec.coffee | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 7ee11b0..be1ba80 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -117,7 +117,7 @@ class Ex q: => @quit() - qa: => @quitall() + qall: => @quitall() tabedit: (args) => if args.args.trim() isnt '' diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 35bfd22..b1b0201 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -162,6 +162,13 @@ describe "the commands", -> expect(atom.notifications.notifications).toEqual([]) expect(fs.readFileSync(existsPath, 'utf-8')).toEqual('abc\ndef') + describe ":wall", -> + it "saves all", -> + spyOn(atom.workspace, 'saveAll') + keydown(':') + submitNormalModeInputText('wall') + expect(atom.workspace.saveAll).toHaveBeenCalled() + describe ":saveas", -> describe "when editing a new file", -> beforeEach -> @@ -288,6 +295,13 @@ describe "the commands", -> submitNormalModeInputText('quit') expect(pane.promptToSaveItem).toHaveBeenCalled() + describe ":quitall", -> + it "closes Atom", -> + spyOn(atom, 'close') + keydown(':') + submitNormalModeInputText('quitall') + expect(atom.close).toHaveBeenCalled() + describe ":tabclose", -> it "acts as an alias to :quit", -> spyOn(Ex, 'tabclose').andCallThrough() @@ -376,6 +390,15 @@ describe "the commands", -> submitNormalModeInputText('xit') expect(Ex.wq).toHaveBeenCalled() + describe ":wqall", -> + it "calls :wall, then :quitall", -> + spyOn(Ex, 'wall') + spyOn(Ex, 'quitall') + keydown(':') + submitNormalModeInputText('wqall') + expect(Ex.wall).toHaveBeenCalled() + expect(Ex.quitall).toHaveBeenCalled() + describe ":edit", -> describe "without a file name", -> it "reloads the file from the disk", ->