From abb5cd207f025b122522aed40dffe11e08d3d9aa Mon Sep 17 00:00:00 2001 From: Sophie Haskins Date: Thu, 29 Jun 2017 10:32:17 -0400 Subject: [PATCH 01/35] use Atom 1.19 buffer API for finding the length of a buffer --- lib/command.coffee | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/command.coffee b/lib/command.coffee index fcc1144..15e74fe 100644 --- a/lib/command.coffee +++ b/lib/command.coffee @@ -14,7 +14,11 @@ class Command addr = row else if str is '$' # Lines are 0-indexed in Atom, but 1-indexed in vim. - addr = @editor.getBuffer().lines.length - 1 + # The two ways of getting length let us support Atom 1.19's new buffer + # implementation (https://github.com/atom/atom/pull/14435) and still + # support 1.18 and below + buffer = @editor.getBuffer() + addr = (buffer.getLineCount?() ? buffer.lines.length) - 1 else if str[0] in ["+", "-"] addr = row + @parseOffset(str) else if not isNaN(str) @@ -73,7 +77,9 @@ class Command return # Step 4: Address parsing - lastLine = @editor.getBuffer().lines.length - 1 + # see comment in parseAddr about line length + buffer = @editor.getBuffer() + lastLine = (buffer.getLineCount?() ? buffer.lines.length) - 1 if cl[0] is '%' range = [0, lastLine] cl = cl[1..] From dfbbdadfbcd04c3c7a89e10b73c18862b0c7e357 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:14:39 +0200 Subject: [PATCH 02/35] :memo: update changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d767be1..47ae57c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.16.0 + +* Support for Atom 1.18 and 1.19 (#184) + ## 0.15.0 * `vim-mode-plus` support! - Add keybinding (@jmarianer) From 78a479bf9b8f9fc008d89673dfac00d9a71f273e Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:16:12 +0200 Subject: [PATCH 03/35] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 47ae57c..d708c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ ## 0.16.0 -* Support for Atom 1.18 and 1.19 (#184) +* Support for Atom 1.18 and 1.19 ([#184](https://github.com/lloeki/ex-mode/pull/184)) ## 0.15.0 * `vim-mode-plus` support! From d0e7afe164f9f9b1b2d695972f8aa94ef6b4d4b6 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:17:32 +0200 Subject: [PATCH 04/35] Prepare 0.16.0 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8dc63b8..26d692b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.15.0", + "version": "0.16.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From 3dbcf76ff79cbae59ff30054efa01d919131d414 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:18:20 +0200 Subject: [PATCH 05/35] Prepare 0.17.0 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 26d692b..1b23c20 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.16.0", + "version": "0.17.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From f2ee5516e03696aa7b3a6bc45c622b51aa13cc7a Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:20:06 +0200 Subject: [PATCH 06/35] Prepare 0.18.0 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b23c20..cda6de9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.17.0", + "version": "0.18.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From eb7a23717ada8f945c5f42b694b2e05afa2d3e94 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:20:56 +0200 Subject: [PATCH 07/35] Revert back versions, apm publish strugles.. --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cda6de9..8dc63b8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.18.0", + "version": "0.15.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From 4747bcf5e8dc212f50223799d816fee5406c96bd Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:22:18 +0200 Subject: [PATCH 08/35] :arrow_up: version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8dc63b8..26d692b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.15.0", + "version": "0.16.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From b5cb054b3976288785051b11b2a2ab6365fce32d Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 15:58:50 +0200 Subject: [PATCH 09/35] Support Promise response in trySave In Atom 1.19, TextBuffer.save returns a Promise. This commit adds support to catch this and resolve our internal callbacks when promise resolves. --- lib/ex.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index e026b96..4b13d1a 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -17,8 +17,13 @@ trySave = (func) -> deferred = defer() try - func() - deferred.resolve() + response = func() + + if response instanceof Promise + response.then -> + deferred.resolve() + else + deferred.resolve() catch error if error.message.endsWith('is a directory') atom.notifications.addWarning("Unable to save file: #{error.message}") @@ -252,7 +257,7 @@ class Ex @write(args) wq: (args) => - @write(args).then => @quit() + @write(args).then(=> @quit()) wa: => @wall() From 26ac7c50b161ec4d6a7c998f00977de9c6e3a300 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Thu, 27 Jul 2017 16:13:48 +0200 Subject: [PATCH 10/35] Support Ctrl-C to cancel ex-mode --- keymaps/ex-mode.cson | 2 ++ lib/ex-normal-mode-input-element.coffee | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/keymaps/ex-mode.cson b/keymaps/ex-mode.cson index 1c70132..6191513 100644 --- a/keymaps/ex-mode.cson +++ b/keymaps/ex-mode.cson @@ -9,5 +9,7 @@ # https://atom.io/docs/latest/advanced/keymaps 'atom-text-editor.vim-mode-plus:not(.insert-mode)': ':': 'ex-mode:open' +'atom-text-editor.ex-mode-editor': + 'ctrl-c': 'ex-mode:close' 'atom-text-editor.vim-mode:not(.insert-mode)': ':': 'ex-mode:open' diff --git a/lib/ex-normal-mode-input-element.coffee b/lib/ex-normal-mode-input-element.coffee index 73ca3da..915a5be 100644 --- a/lib/ex-normal-mode-input-element.coffee +++ b/lib/ex-normal-mode-input-element.coffee @@ -15,7 +15,8 @@ class ExCommandModeInputElement extends HTMLDivElement @editorContainer.style.height = "0px" @editorElement = document.createElement "atom-text-editor" - @editorElement.classList.add('editor') + @editorElement.classList.add('editor') # Consider this deprecated! + @editorElement.classList.add('ex-mode-editor') @editorElement.getModel().setMini(true) @editorElement.setAttribute('mini', '') @editorContainer.appendChild(@editorElement) @@ -40,6 +41,7 @@ class ExCommandModeInputElement extends HTMLDivElement atom.commands.add(@editorElement, 'core:confirm', @confirm.bind(this)) atom.commands.add(@editorElement, 'core:cancel', @cancel.bind(this)) + atom.commands.add(@editorElement, 'ex-mode:close', @cancel.bind(this)) atom.commands.add(@editorElement, 'blur', @cancel.bind(this)) backspace: -> From 9f1a767fece7b7d64c0708edc6bff9fbfa53f4e3 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Fri, 28 Jul 2017 14:28:03 +0200 Subject: [PATCH 11/35] :memo: update changeling --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d708c94..3dc73c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.17.0 (Unreleased) + +* Added support for canceling ex-mode with Ctrl-C ([#186](https://github.com/lloeki/ex-mode/pull/186)) + ## 0.16.0 * Support for Atom 1.18 and 1.19 ([#184](https://github.com/lloeki/ex-mode/pull/184)) From daddcf8d0fb6baece4be035da601ea3edaedee92 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 29 Jul 2017 17:38:07 +0200 Subject: [PATCH 12/35] add editorconfig --- .editorconfig | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..33224b4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{coffee,json}] +indent_style = space +indent_size = 2 From 91f748f85f1e4bafc05cf1925df2ad8b1ecc92d7 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 29 Jul 2017 17:40:59 +0200 Subject: [PATCH 13/35] fix indenting --- lib/ex.coffee | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 4b13d1a..2923602 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -20,10 +20,10 @@ trySave = (func) -> response = func() if response instanceof Promise - response.then -> - deferred.resolve() - else + response.then -> deferred.resolve() + else + deferred.resolve() catch error if error.message.endsWith('is a directory') atom.notifications.addWarning("Unable to save file: #{error.message}") From 3283b723942a43eac83cff084bfcbd29b29990ef Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 29 Jul 2017 17:41:38 +0200 Subject: [PATCH 14/35] :memo: update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dc73c9..43b94cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## 0.17.0 (Unreleased) +* Add support for Atom 1.19 ([#185](https://github.com/lloeki/ex-mode/pull/185)) * Added support for canceling ex-mode with Ctrl-C ([#186](https://github.com/lloeki/ex-mode/pull/186)) ## 0.16.0 From 8590f5a67877951f29fc2c1da663efdfddb0aef2 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 29 Jul 2017 17:49:40 +0200 Subject: [PATCH 15/35] :arrow_up: 1.17.0 --- CHANGELOG.md | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 43b94cc..8c0e973 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,4 @@ -## 0.17.0 (Unreleased) +## 0.17.0 * Add support for Atom 1.19 ([#185](https://github.com/lloeki/ex-mode/pull/185)) * Added support for canceling ex-mode with Ctrl-C ([#186](https://github.com/lloeki/ex-mode/pull/186)) diff --git a/package.json b/package.json index 26d692b..1b23c20 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.16.0", + "version": "0.17.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From 117d7439ad5ae59f0192cc0999334998ae0f7728 Mon Sep 17 00:00:00 2001 From: Robby Date: Sun, 6 Aug 2017 21:23:41 -0500 Subject: [PATCH 16/35] Adds save ex-mode command --- lib/ex.coffee | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/ex.coffee b/lib/ex.coffee index e026b96..6913b52 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -133,6 +133,7 @@ class Ex qall: => @quitall() + tabedit: (args) => if args.args.trim() isnt '' @edit(args) @@ -437,4 +438,11 @@ class Ex throw new CommandError("No such option: #{option}") optionProcessor() + sort: ({ range }) => + range = [[range[0], 0], [range[1] + 1, 0]] + editor = atom.workspace.getActiveTextEditor() + text = editor.getTextInBufferRange(range) + sortedText = _.sortBy(text.split(/\n/)).join('\n') + editor.buffer.setTextInRange(range, sortedText) + module.exports = Ex From 15296ff369b87400975ff308487ae05809a31ed8 Mon Sep 17 00:00:00 2001 From: Robby Date: Sun, 6 Aug 2017 21:24:22 -0500 Subject: [PATCH 17/35] Removes accidental newline --- lib/ex.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 6913b52..16f74f9 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -133,7 +133,6 @@ class Ex qall: => @quitall() - tabedit: (args) => if args.args.trim() isnt '' @edit(args) From 43127775084196b1bdbd3038e272a4abaffeefab Mon Sep 17 00:00:00 2001 From: Robby Date: Sun, 6 Aug 2017 23:22:13 -0500 Subject: [PATCH 18/35] Modifies sort function and adds a unit test --- lib/ex.coffee | 17 +++++++++++++---- spec/ex-commands-spec.coffee | 10 ++++++++++ 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 16f74f9..46ab42b 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -438,10 +438,19 @@ class Ex optionProcessor() sort: ({ range }) => - range = [[range[0], 0], [range[1] + 1, 0]] editor = atom.workspace.getActiveTextEditor() - text = editor.getTextInBufferRange(range) - sortedText = _.sortBy(text.split(/\n/)).join('\n') - editor.buffer.setTextInRange(range, sortedText) + sortingRange = [[]] + isMultiLine = range[1] - range[0] > 1 + if isMultiLine + sortingRange = [[range[0], 0], [range[1] + 1, 0]] + else + sortingRange = [[0, 0], [editor.getLastBufferRow(), 0]] + + textLines = [] + for lineIndex in [sortingRange[0][0]..sortingRange[1][0] - 1] + textLines.push(editor.lineTextForBufferRow(lineIndex)) + + sortedText = _.sortBy(textLines).join('\n') + '\n' + editor.buffer.setTextInRange(sortingRange, sortedText) module.exports = Ex diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 4e3d839..2d9facc 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -983,3 +983,13 @@ describe "the commands", -> expect(calls.length).toEqual 2 expect(calls[0].args[0].range).toEqual [0, 2] expect(calls[1].args[0].range).toEqual [3, 3] + + desctibe ':sort', -> + beforeEach -> + editor.setText('ghi\nabc\njkl\ndef\n') + editor.setCursorBufferPosition([0, 0]) + + it "sorts entire file if range is not multi-line", -> + openEx() + submitNormalModeInputText('sort') + expect(atom.getText()).toEqual('abc\ndef\nghi\njkl\n') From d76940dabc05ef7967ecdce5d69cd4b351285c0e Mon Sep 17 00:00:00 2001 From: Robby Date: Sun, 6 Aug 2017 23:40:06 -0500 Subject: [PATCH 19/35] Adds another unit test --- spec/ex-commands-spec.coffee | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 2d9facc..2eb252a 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -984,12 +984,17 @@ describe "the commands", -> expect(calls[0].args[0].range).toEqual [0, 2] expect(calls[1].args[0].range).toEqual [3, 3] - desctibe ':sort', -> + describe ':sort', -> beforeEach -> - editor.setText('ghi\nabc\njkl\ndef\n') + editor.setText('ghi\nabc\njkl\ndef\n142\nzzz\n91xfds9\n') editor.setCursorBufferPosition([0, 0]) it "sorts entire file if range is not multi-line", -> openEx() submitNormalModeInputText('sort') - expect(atom.getText()).toEqual('abc\ndef\nghi\njkl\n') + expect(editor.getText()).toEqual('142\n91xfds9\nabc\ndef\nghi\njkl\nzzz\n') + + it "sorts specific range if range is multi-line", -> + openEx() + submitNormalModeInputText('2,4sort') + expect(editor.getText()).toEqual('ghi\nabc\ndef\njkl\n142\nzzz\n91xfds9\n') From 791c62a3bad988d977a177cac7f76a1adedb0ba5 Mon Sep 17 00:00:00 2001 From: Robert Paul Date: Tue, 8 Aug 2017 14:02:29 -0500 Subject: [PATCH 20/35] Adds clarification comments --- lib/ex.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/ex.coffee b/lib/ex.coffee index 46ab42b..c84fbbf 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -440,16 +440,20 @@ class Ex sort: ({ range }) => editor = atom.workspace.getActiveTextEditor() sortingRange = [[]] + + # If no range is provided, the entire file should be sorted. isMultiLine = range[1] - range[0] > 1 if isMultiLine sortingRange = [[range[0], 0], [range[1] + 1, 0]] else sortingRange = [[0, 0], [editor.getLastBufferRow(), 0]] + # Store every bufferedRow string in an array. textLines = [] for lineIndex in [sortingRange[0][0]..sortingRange[1][0] - 1] textLines.push(editor.lineTextForBufferRow(lineIndex)) + # Sort the array and join them together with newlines for writing back to the file. sortedText = _.sortBy(textLines).join('\n') + '\n' editor.buffer.setTextInRange(sortingRange, sortedText) From 23be6cc862f269d2a0c0cd1d9cd0b6e7d150bfc2 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 8 Aug 2017 21:12:55 +0200 Subject: [PATCH 21/35] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8c0e973..bc87c40 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## (unpublished) + +* Add :sort command ([#190](https://github.com/lloeki/ex-mode/pull/190)) + ## 0.17.0 * Add support for Atom 1.19 ([#185](https://github.com/lloeki/ex-mode/pull/185)) From 2fa4584eb44d4b0c92952863e2eebdeefa91118f Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:08:28 +0900 Subject: [PATCH 22/35] 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 23/35] 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 24/35] 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 25/35] 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 26/35] 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') From 146d832e14ab0b2db75135aa5933df1b47733d4c Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 15 Aug 2017 21:33:13 +0200 Subject: [PATCH 27/35] Update CHANGELOG.md [ci skip] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bc87c40..c6c943c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## (unpublished) +* Add Gdefault support ([#191](https://github.com/lloeki/ex-mode/pull/191)) * Add :sort command ([#190](https://github.com/lloeki/ex-mode/pull/190)) ## 0.17.0 From 93d0af041fa997ed740b525cb0defd863c37986a Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 19 Aug 2017 09:43:43 +0200 Subject: [PATCH 28/35] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6c943c..41dfadf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## (unpublished) +## 0.18.0 + * Add Gdefault support ([#191](https://github.com/lloeki/ex-mode/pull/191)) * Add :sort command ([#190](https://github.com/lloeki/ex-mode/pull/190)) From 653d62ec1500934750dd8dcd4a528e978fbdee10 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 19 Aug 2017 09:44:09 +0200 Subject: [PATCH 29/35] Prepare 0.18.0 release --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1b23c20..cda6de9 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.17.0", + "version": "0.18.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" From 4f1ebf8a1a8d5e2e32d099c54656867cd42938af Mon Sep 17 00:00:00 2001 From: Bernard Laveaux Date: Tue, 17 Oct 2017 16:31:54 -0400 Subject: [PATCH 30/35] Support Ctrl-[ to close ex-mode This is merely a suggestion to also default the `ctrl-[` keymap to close ex-mode. This behaviour is very similar to vim's default behaviour: ``` CTRL-[ *c_CTRL-[* *c_* *c_Esc* When typed and 'x' not present in 'cpoptions', quit Command-line mode without executing. In macros or when 'x' present in 'cpoptions', start entered command. Note: If your key is hard to hit on your keyboard, train yourself to use CTRL-[. ``` Is very similar to the currently supported `ctrl-c` ``` CTRL-C *c_CTRL-C* quit command-line without executing ``` --- keymaps/ex-mode.cson | 1 + 1 file changed, 1 insertion(+) diff --git a/keymaps/ex-mode.cson b/keymaps/ex-mode.cson index 6191513..a071efd 100644 --- a/keymaps/ex-mode.cson +++ b/keymaps/ex-mode.cson @@ -11,5 +11,6 @@ ':': 'ex-mode:open' 'atom-text-editor.ex-mode-editor': 'ctrl-c': 'ex-mode:close' + 'ctrl-[': 'ex-mode:close' 'atom-text-editor.vim-mode:not(.insert-mode)': ':': 'ex-mode:open' From 15038d7b0cf9cea653d5ed1a04eb2cfe23106dd6 Mon Sep 17 00:00:00 2001 From: Adrian Wilkins Date: Mon, 26 Mar 2018 13:24:05 +0100 Subject: [PATCH 31/35] Only close buffers on quitall --- lib/ex-mode.coffee | 5 +++++ lib/ex.coffee | 6 +++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/ex-mode.coffee b/lib/ex-mode.coffee index c627483..d8fc766 100644 --- a/lib/ex-mode.coffee +++ b/lib/ex-mode.coffee @@ -55,3 +55,8 @@ module.exports = ExMode = description: 'When on, the ":substitute" flag \'g\' is default on' type: 'boolean' default: 'false' + onlyCloseBuffers: + title: 'Only close buffers' + description: 'When on, quitall only closes all buffers, not entire Atom instance' + type: 'boolean' + default: 'false' diff --git a/lib/ex.coffee b/lib/ex.coffee index cbc7857..a266afb 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -132,7 +132,11 @@ class Ex atom.workspace.getActivePane().destroyActiveItem() quitall: -> - atom.close() + if !atom.config.get('ex-mode.onlyCloseBuffers') + atom.close() + else + atom.workspace.getTextEditors().forEach (editor) -> + editor.destroy() q: => @quit() From a33959f82996617f10afac096120d842d04035f2 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 29 May 2018 23:09:45 +0200 Subject: [PATCH 32/35] Fix :enew not working Fixes #214 --- lib/ex.coffee | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index a266afb..58b0ebb 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -3,6 +3,7 @@ CommandError = require './command-error' fs = require 'fs-plus' VimOption = require './vim-option' _ = require 'underscore-plus' +atom defer = () -> deferred = {} @@ -210,9 +211,7 @@ class Ex e: (args) => @edit(args) enew: -> - buffer = atom.workspace.getActiveTextEditor().buffer - buffer.setPath(undefined) - buffer.load() + atom.workspace.open() write: ({ range, args, editor, saveas }) -> saveas ?= false From 23dde8c7ee9b778d75deaf33ac0fe3449b68f8b7 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 29 May 2018 23:14:45 +0200 Subject: [PATCH 33/35] :memo: update CHANGELOG [ci skip] --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41dfadf..30a0532 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## (unpublished) +* Fix `:enew` not working ([#215](https://github.com/lloeki/ex-mode/pull/215)) + ## 0.18.0 * Add Gdefault support ([#191](https://github.com/lloeki/ex-mode/pull/191)) From 744ec7351e5a27991d44db38918210d32c50d964 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 29 May 2018 23:55:46 +0200 Subject: [PATCH 34/35] Refactor :write command Update the logic to simplify it. Also fix #208 --- lib/ex.coffee | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/lib/ex.coffee b/lib/ex.coffee index 58b0ebb..b262023 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -229,29 +229,30 @@ class Ex deferred = defer() editor = atom.workspace.getActiveTextEditor() - saved = false + + # Case 1; path is provided if filePath.length isnt 0 - fullPath = getFullPath(filePath) - if editor.getPath()? and (not fullPath? or editor.getPath() == fullPath) - if saveas - throw new CommandError("Argument required") - else - # Use editor.save when no path is given or the path to the file is given - trySave(-> editor.save()).then(deferred.resolve) - saved = true - else if not fullPath? - fullPath = atom.showSaveDialogSync() + fullPath = getFullPath filePath - if not saved and fullPath? - if not force and fs.existsSync(fullPath) - throw new CommandError("File exists (add ! to override)") - if saveas or editor.getFileName() == null - editor = atom.workspace.getActiveTextEditor() - trySave(-> editor.saveAs(fullPath, editor)).then(deferred.resolve) - else - trySave(-> saveAs(fullPath, editor)).then(deferred.resolve) + # Only write when it does not exist or we have a force flag set. + if force or not fs.existsSync(fullPath) + editor.saveAs(fullPath) + return deferred.promise - deferred.promise + throw new CommandError("File exists (add ! to override)") + + # Case 2; no path provided, call editor save. + editor = atom.workspace.getActiveTextEditor() + + # Does the current buffer exist? + if editor.getPath()? and fs.existsSync(editor.getPath()) + trySave(-> editor.save()).then(deferred.promise) + else + # Cant see what the better API is but Pane.saveActiveItemAs() is the only call + # I could find that states it will ask the user. + trySave(-> atom.workspace.getActivePane().saveActiveItemAs()).then(deferred.promise) + + return deferred.promise wall: -> atom.workspace.saveAll() From 59cafd6b994467c91ed7004a40b3cd743f472474 Mon Sep 17 00:00:00 2001 From: Sarang Joshi Date: Thu, 13 Dec 2018 14:39:51 -0800 Subject: [PATCH 35/35] Add existing command information to README --- README.md | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 3f247de..ea4a068 --- a/README.md +++ b/README.md @@ -30,7 +30,34 @@ atom.packages.onDidActivatePackage (pack) -> Ex.registerAlias 'Wq', 'wq' ``` -See `lib/ex.coffee` for some examples commands. Contributions are very welcome! +## Existing commands + +This is the baseline list of commands supported in `ex-mode`. + +| Command | Operation | +| --------------------------------------- | ---------------------------------- | +| `q/quit/tabc/tabclose` | Close active tab | +| `qall/quitall` | Close all tabs | +| `tabe/tabedit/tabnew` | Open new tab | +| `e/edit/tabe/tabedit/tabnew ` | Edit given file | +| `tabn/tabnext` | Go to next tab | +| `tabp/tabprevious` | Go to previous tab | +| `tabo/tabonly` | Close other tabs | +| `w/write` | Save active tab | +| `w/write/saveas ` | Save as | +| `wall/wa` | Save all tabs | +| `sp/split` | Split window | +| `sp/split ` | Open file in split window | +| `s/substitute` | Substitute regular expression in active line | +| `vsp/vsplit` | Vertical split window | +| `vsp/vsplit ` | Open file in vertical split window | +| `delete` | Cut active line | +| `yank` | Copy active line | +| `set ` | Set options | +| `sort` | Sort all lines in file | +| `sort ` | Sort lines in line range | + +See `lib/ex.coffee` for the implementations of these commands. Contributions are very welcome! ## Status