From 2fa4584eb44d4b0c92952863e2eebdeefa91118f Mon Sep 17 00:00:00 2001 From: mkiken Date: Sun, 13 Aug 2017 16:08:28 +0900 Subject: [PATCH 01/22] 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 02/22] 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 03/22] 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 04/22] 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 05/22] 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 06/22] 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 ddbeed1dd9113aa1ae953f165e90dfbfcca5568c Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 15 Aug 2017 21:49:01 +0200 Subject: [PATCH 07/22] add travis config from atom/ci --- .travis.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e8e09d4..ef7068a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,4 @@ -## Project specific config ### +### Project specific config ### language: generic env: @@ -12,8 +12,7 @@ env: os: - linux - -dist: trusty + - osx ### Generic setup follows ### script: @@ -35,11 +34,12 @@ git: sudo: false +dist: trusty + addons: apt: packages: - build-essential - - git - - libgnome-keyring-dev - - libsecret-1-dev - fakeroot + - git + - libsecret-1-dev From c1a464ba1399149bfa206cb780d4b55800af1c85 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 15 Aug 2017 21:51:18 +0200 Subject: [PATCH 08/22] update readme, trigger new build on travis --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3f247de..83f5566 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,5 @@ Groundwork is done. More ex commands are easy to add and will be coming as time ## License MIT + + From 11abdb95fa17ec469e0844c9d5fda9fa13bb61ad Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 15 Aug 2017 21:55:41 +0200 Subject: [PATCH 09/22] damn --- keymaps/ex-mode.cson | 1 + 1 file changed, 1 insertion(+) diff --git a/keymaps/ex-mode.cson b/keymaps/ex-mode.cson index 6191513..d857ccb 100644 --- a/keymaps/ex-mode.cson +++ b/keymaps/ex-mode.cson @@ -5,6 +5,7 @@ # Below is a basic keybinding which registers on all platforms by applying to # the root workspace element. + # For more detailed documentation see # https://atom.io/docs/latest/advanced/keymaps 'atom-text-editor.vim-mode-plus:not(.insert-mode)': From 566996a9fd7da096c832b28793ea32f73724a415 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Tue, 15 Aug 2017 22:08:06 +0200 Subject: [PATCH 10/22] use example from atom/wrap-guide --- .travis.yml | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/.travis.yml b/.travis.yml index ef7068a..a148f2e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ ### Project specific config ### -language: generic +language: objective-c env: global: - APM_TEST_PACKAGES="vim-mode-plus" - - ATOM_LINT_WITH_BUNDLED_NODE="true" + - ATOM_LINT_WITH_BUNDLED_NODE="false" matrix: - ATOM_CHANNEL=stable @@ -12,30 +12,18 @@ env: os: - linux - - osx ### Generic setup follows ### -script: - - curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh - - chmod u+x build-package.sh - - ./build-package.sh +script: 'curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh | sh' notifications: email: on_success: never on_failure: change -branches: - only: - - master - git: depth: 10 -sudo: false - -dist: trusty - addons: apt: packages: From c4f739f390d23d80a94298f84168a76b44f2f74f Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Wed, 16 Aug 2017 09:33:30 +0200 Subject: [PATCH 11/22] Lint with bundled node and fix script run In previous commit, I created a one-liner for running build-package, it did not seem to work. --- .travis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index a148f2e..3ff9b0a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,7 +4,7 @@ language: objective-c env: global: - APM_TEST_PACKAGES="vim-mode-plus" - - ATOM_LINT_WITH_BUNDLED_NODE="false" + - ATOM_LINT_WITH_BUNDLED_NODE="true" matrix: - ATOM_CHANNEL=stable @@ -14,7 +14,10 @@ os: - linux ### Generic setup follows ### -script: 'curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh | sh' +script: + - curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh + - chmod +x build-package.sh + - ./build-package.sh notifications: email: From bf2d86248accde8ff565ec6d9309575a0e9ec509 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Wed, 16 Aug 2017 19:50:48 +0200 Subject: [PATCH 12/22] use generic and Xenial as dist --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3ff9b0a..e3d146b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,5 @@ ### Project specific config ### -language: objective-c +language: generic env: global: @@ -24,6 +24,8 @@ notifications: on_success: never on_failure: change +dist: xenial + git: depth: 10 From 054eca5d79847aebd84e26bd099041464ef323ad Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Wed, 16 Aug 2017 19:55:25 +0200 Subject: [PATCH 13/22] Another attempt: Use same as vim-mode-plus --- .travis.yml | 31 ++----------------------------- 1 file changed, 2 insertions(+), 29 deletions(-) diff --git a/.travis.yml b/.travis.yml index e3d146b..d73c8e2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,38 +1,11 @@ -### Project specific config ### -language: generic - -env: - global: - - APM_TEST_PACKAGES="vim-mode-plus" - - ATOM_LINT_WITH_BUNDLED_NODE="true" - - matrix: - - ATOM_CHANNEL=stable - - ATOM_CHANNEL=beta - -os: - - linux - -### Generic setup follows ### -script: - - curl -s -O https://raw.githubusercontent.com/atom/ci/master/build-package.sh - - chmod +x build-package.sh - - ./build-package.sh +language: objective-c notifications: email: on_success: never on_failure: change -dist: xenial +script: 'curl -s https://raw.githubusercontent.com/atom/ci/master/build-package.sh | sh' git: depth: 10 - -addons: - apt: - packages: - - build-essential - - fakeroot - - git - - libsecret-1-dev From 6e58c117510f3828499a355e0b55ece863d07d90 Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 19 Aug 2017 09:36:44 +0200 Subject: [PATCH 14/22] add environment variables --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index d73c8e2..b9b8fa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,14 @@ language: objective-c +env: + global: + - APM_TEST_PACKAGES="vim-mode-plus" + - ATOM_LINT_WITH_BUNDLED_NODE="true" + + matrix: + - ATOM_CHANNEL=stable + - ATOM_CHANNEL=beta + notifications: email: on_success: never From 93d0af041fa997ed740b525cb0defd863c37986a Mon Sep 17 00:00:00 2001 From: Edvin Hultberg Date: Sat, 19 Aug 2017 09:43:43 +0200 Subject: [PATCH 15/22] 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 16/22] 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 17/22] 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 18/22] 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 19/22] 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 20/22] :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 21/22] 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 22/22] 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