From 2fa4584eb44d4b0c92952863e2eebdeefa91118f Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:08:28 +0900 Subject: [PATCH 1/5] add gdefault option --- lib/ex-mode.coffee | 5 +++++ lib/vim-option.coffee | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/lib/ex-mode.coffee b/lib/ex-mode.coffee index 5274e0a..c627483 100644 --- a/lib/ex-mode.coffee +++ b/lib/ex-mode.coffee @@ -50,3 +50,8 @@ module.exports = ExMode = description: 'when splitting, split from right' type: 'boolean' default: 'false' + gdefault: + title: 'Gdefault' + description: 'When on, the ":substitute" flag \'g\' is default on' + type: 'boolean' + default: 'false' diff --git a/lib/vim-option.coffee b/lib/vim-option.coffee index ddf4688..223395f 100644 --- a/lib/vim-option.coffee +++ b/lib/vim-option.coffee @@ -56,4 +56,10 @@ class VimOption noscs: => @nosmartcase() + gdefault: => + atom.config.set("ex-mode.gdefault", true) + + nogdefault: => + atom.config.set("ex-mode.gdefault", false) + module.exports = VimOption From 964813a0b0d5c45bbd93f1a4295071082c3eaf0a Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:37:00 +0900 Subject: [PATCH 2/5] implement gdefault option --- lib/ex.coffee | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index a1e5ad3..cbc7857 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -18,7 +18,7 @@ trySave = (func) -> try response = func() - + if response instanceof Promise response.then -> deferred.resolve() @@ -361,6 +361,9 @@ class Ex try flagsObj = {} flags.split('').forEach((flag) -> flagsObj[flag] = true) + # gdefault option + if atom.config.get('ex-mode.gdefault') + flagsObj.g = !flagsObj.g patternRE = getSearchTerm(pattern, flagsObj) catch e if e.message.indexOf('Invalid flags supplied to RegExp constructor') is 0 From 1a515fcb056db8d6bc09d6f1cf45a040440b9bf2 Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:47:28 +0900 Subject: [PATCH 3/5] gdefault option set test --- spec/ex-commands-spec.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 2eb252a..438bbd7 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -944,6 +944,14 @@ describe "the commands", -> submitNormalModeInputText(':set nosmartcase') expect(atom.config.get('vim-mode.useSmartcaseForSearch')).toBe(false) + it "sets (no)gdefault", -> + openEx() + submitNormalModeInputText(':set gdefault') + expect(atom.config.get('ex-mode.gdefault')).toBe(true) + atom.commands.dispatch(editorElement, 'ex-mode:open') + submitNormalModeInputText(':set nogdefault') + expect(atom.config.get('ex-mode.gdefault')).toBe(false) + describe "aliases", -> it "calls the aliased function without arguments", -> ExClass.registerAlias('W', 'w') From d0059a7bb20c7e5716890cec2e76f2c92815f276 Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:57:11 +0900 Subject: [PATCH 4/5] gdefault option implementation test --- spec/ex-commands-spec.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 438bbd7..49469d0 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -715,6 +715,12 @@ describe "the commands", -> submitNormalModeInputText(':%substitute/abc/ghi/ig') expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') + it "set gdefault option", -> + openEx() + atom.config.set('ex-mode.gdefault', true) + submitNormalModeInputText(':substitute/a/x/g') + expect(editor.getText()).toEqual('xbcaABC\ndefdDEF\nabcaABC') + describe ":yank", -> beforeEach -> editor.setText('abc\ndef\nghi\njkl') From c75395174fa64232e2bc7973b795c17aaf3166e5 Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 17:18:26 +0900 Subject: [PATCH 5/5] add gdefault option implementation test --- spec/ex-commands-spec.coffee | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 49469d0..29f211e 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -718,6 +718,11 @@ describe "the commands", -> it "set gdefault option", -> openEx() atom.config.set('ex-mode.gdefault', true) + submitNormalModeInputText(':substitute/a/x') + expect(editor.getText()).toEqual('xbcxABC\ndefdDEF\nabcaABC') + + atom.commands.dispatch(editorElement, 'ex-mode:open') + atom.config.set('ex-mode.gdefault', true) submitNormalModeInputText(':substitute/a/x/g') expect(editor.getText()).toEqual('xbcaABC\ndefdDEF\nabcaABC')