diff --git a/.editorconfig b/.editorconfig deleted file mode 100644 index 33224b4..0000000 --- a/.editorconfig +++ /dev/null @@ -1,9 +0,0 @@ -root = true - -[*] -end_of_line = lf -insert_final_newline = true - -[*.{coffee,json}] -indent_style = space -indent_size = 2 diff --git a/CHANGELOG.md b/CHANGELOG.md index 30a0532..d708c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,17 +1,3 @@ -## (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)) -* 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)) -* 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)) diff --git a/README.md b/README.md old mode 100755 new mode 100644 index ea4a068..3f247de --- a/README.md +++ b/README.md @@ -30,34 +30,7 @@ atom.packages.onDidActivatePackage (pack) -> Ex.registerAlias 'Wq', 'wq' ``` -## 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! +See `lib/ex.coffee` for some examples commands. Contributions are very welcome! ## Status diff --git a/keymaps/ex-mode.cson b/keymaps/ex-mode.cson index a071efd..1c70132 100644 --- a/keymaps/ex-mode.cson +++ b/keymaps/ex-mode.cson @@ -9,8 +9,5 @@ # 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' - 'ctrl-[': 'ex-mode:close' 'atom-text-editor.vim-mode:not(.insert-mode)': ':': 'ex-mode:open' diff --git a/lib/ex-mode.coffee b/lib/ex-mode.coffee index d8fc766..5274e0a 100644 --- a/lib/ex-mode.coffee +++ b/lib/ex-mode.coffee @@ -50,13 +50,3 @@ 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' - 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-normal-mode-input-element.coffee b/lib/ex-normal-mode-input-element.coffee index 915a5be..73ca3da 100644 --- a/lib/ex-normal-mode-input-element.coffee +++ b/lib/ex-normal-mode-input-element.coffee @@ -15,8 +15,7 @@ class ExCommandModeInputElement extends HTMLDivElement @editorContainer.style.height = "0px" @editorElement = document.createElement "atom-text-editor" - @editorElement.classList.add('editor') # Consider this deprecated! - @editorElement.classList.add('ex-mode-editor') + @editorElement.classList.add('editor') @editorElement.getModel().setMini(true) @editorElement.setAttribute('mini', '') @editorContainer.appendChild(@editorElement) @@ -41,7 +40,6 @@ 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: -> diff --git a/lib/ex.coffee b/lib/ex.coffee index b262023..e026b96 100644 --- a/lib/ex.coffee +++ b/lib/ex.coffee @@ -3,7 +3,6 @@ CommandError = require './command-error' fs = require 'fs-plus' VimOption = require './vim-option' _ = require 'underscore-plus' -atom defer = () -> deferred = {} @@ -18,13 +17,8 @@ trySave = (func) -> deferred = defer() try - response = func() - - if response instanceof Promise - response.then -> - deferred.resolve() - else - deferred.resolve() + func() + deferred.resolve() catch error if error.message.endsWith('is a directory') atom.notifications.addWarning("Unable to save file: #{error.message}") @@ -133,11 +127,7 @@ class Ex atom.workspace.getActivePane().destroyActiveItem() quitall: -> - if !atom.config.get('ex-mode.onlyCloseBuffers') - atom.close() - else - atom.workspace.getTextEditors().forEach (editor) -> - editor.destroy() + atom.close() q: => @quit() @@ -211,7 +201,9 @@ class Ex e: (args) => @edit(args) enew: -> - atom.workspace.open() + buffer = atom.workspace.getActiveTextEditor().buffer + buffer.setPath(undefined) + buffer.load() write: ({ range, args, editor, saveas }) -> saveas ?= false @@ -229,30 +221,29 @@ class Ex deferred = defer() editor = atom.workspace.getActiveTextEditor() - - # Case 1; path is provided + saved = false if filePath.length isnt 0 - fullPath = getFullPath filePath + 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() - # 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 + 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) - 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 + deferred.promise wall: -> atom.workspace.saveAll() @@ -261,7 +252,7 @@ class Ex @write(args) wq: (args) => - @write(args).then(=> @quit()) + @write(args).then => @quit() wa: => @wall() @@ -365,9 +356,6 @@ 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 @@ -449,24 +437,4 @@ class Ex throw new CommandError("No such option: #{option}") optionProcessor() - 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) - module.exports = Ex diff --git a/lib/vim-option.coffee b/lib/vim-option.coffee index 223395f..ddf4688 100644 --- a/lib/vim-option.coffee +++ b/lib/vim-option.coffee @@ -56,10 +56,4 @@ class VimOption noscs: => @nosmartcase() - gdefault: => - atom.config.set("ex-mode.gdefault", true) - - nogdefault: => - atom.config.set("ex-mode.gdefault", false) - module.exports = VimOption diff --git a/package.json b/package.json index cda6de9..26d692b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "ex-mode", "main": "./lib/ex-mode", - "version": "0.18.0", + "version": "0.16.0", "description": "Ex for Atom's vim-mode", "activationCommands": { "atom-workspace": "ex-mode:open" diff --git a/spec/ex-commands-spec.coffee b/spec/ex-commands-spec.coffee index 29f211e..4e3d839 100644 --- a/spec/ex-commands-spec.coffee +++ b/spec/ex-commands-spec.coffee @@ -715,17 +715,6 @@ 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') - 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') - describe ":yank", -> beforeEach -> editor.setText('abc\ndef\nghi\njkl') @@ -955,14 +944,6 @@ 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') @@ -1002,18 +983,3 @@ 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] - - describe ':sort', -> - beforeEach -> - 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(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')