Compare commits

..

27 commits

Author SHA1 Message Date
Edvin Hultberg
30ad82671b
Merge pull request #225 from sarangjo/master
Add existing command information to README
2019-02-25 15:52:09 +01:00
Sarang Joshi
59cafd6b99 Add existing command information to README 2018-12-13 14:39:51 -08:00
Edvin Hultberg
ef4bb8a6ac
Merge pull request #216 from lloeki/eh-refactor-write
Refactor :write command
2018-05-31 12:21:44 +02:00
Edvin Hultberg
744ec7351e Refactor :write command
Update the logic to simplify it.

Also fix #208
2018-05-29 23:55:46 +02:00
Edvin Hultberg
23dde8c7ee 📝 update CHANGELOG
[ci skip]
2018-05-29 23:14:45 +02:00
Edvin Hultberg
a887128b9f
Merge pull request #215 from lloeki/eh-fix-enew
Fix :enew not working
2018-05-29 23:13:19 +02:00
Edvin Hultberg
a33959f829 Fix :enew not working
Fixes #214
2018-05-29 23:09:50 +02:00
Edvin Hultberg
b9b3ba3e9f
Merge pull request #209 from awilkins/only-close-buffers
Only close buffers on quitall
2018-05-03 21:20:16 +02:00
Adrian Wilkins
15038d7b0c Only close buffers on quitall 2018-03-26 13:24:05 +01:00
Edvin Hultberg
2b7e6346a5 Merge pull request #201 from bl/add-ctrl-left-bracket-to-close
Support Ctrl-[ to close ex-mode
2017-10-18 18:19:52 +02:00
Bernard Laveaux
4f1ebf8a1a 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_<Esc>* *c_Esc*
<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 <Esc> 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
```
2017-10-17 16:31:54 -04:00
Edvin Hultberg
653d62ec15 Prepare 0.18.0 release 2017-08-19 09:44:09 +02:00
Edvin Hultberg
93d0af041f update changelog 2017-08-19 09:43:43 +02:00
Edvin Hultberg
146d832e14 Update CHANGELOG.md
[ci skip]
2017-08-15 21:33:13 +02:00
Edvin Hultberg
14f0c83261 Merge pull request #191 from mkiken/gdefault
Supports Vim's gdefault option.
2017-08-15 21:32:26 +02:00
mkiken
c75395174f add gdefault option implementation test 2017-08-13 17:18:26 +09:00
mkiken
d0059a7bb2 gdefault option implementation test 2017-08-13 16:57:11 +09:00
mkiken
1a515fcb05 gdefault option set test 2017-08-13 16:47:28 +09:00
mkiken
964813a0b0 implement gdefault option 2017-08-13 16:38:06 +09:00
mkiken
2fa4584eb4 add gdefault option 2017-08-13 16:08:28 +09:00
Edvin Hultberg
23be6cc862 Update CHANGELOG.md 2017-08-08 21:12:55 +02:00
Edvin Hultberg
195396b47e Merge pull request #190 from RobertPaul01/sort
Adds :sort feature
2017-08-08 21:11:25 +02:00
Robert Paul
791c62a3ba Adds clarification comments 2017-08-08 14:02:29 -05:00
Robby
d76940dabc Adds another unit test 2017-08-06 23:40:06 -05:00
Robby
4312777508 Modifies sort function and adds a unit test 2017-08-06 23:22:13 -05:00
Robby
15296ff369 Removes accidental newline 2017-08-06 21:24:22 -05:00
Robby
117d7439ad Adds save ex-mode command 2017-08-06 21:23:41 -05:00
8 changed files with 141 additions and 27 deletions

View file

@ -1,3 +1,12 @@
## (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))

29
README.md Normal file → Executable file
View file

@ -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 <file>` | 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 <file>` | Save as |
| `wall/wa` | Save all tabs |
| `sp/split` | Split window |
| `sp/split <file>` | Open file in split window |
| `s/substitute` | Substitute regular expression in active line |
| `vsp/vsplit` | Vertical split window |
| `vsp/vsplit <file>` | Open file in vertical split window |
| `delete` | Cut active line |
| `yank` | Copy active line |
| `set <options>` | Set options |
| `sort` | Sort all lines in file |
| `sort <line range>` | Sort lines in line range |
See `lib/ex.coffee` for the implementations of these commands. Contributions are very welcome!
## Status

View file

@ -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'

View file

@ -50,3 +50,13 @@ 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'

View file

@ -3,6 +3,7 @@ CommandError = require './command-error'
fs = require 'fs-plus'
VimOption = require './vim-option'
_ = require 'underscore-plus'
atom
defer = () ->
deferred = {}
@ -18,7 +19,7 @@ trySave = (func) ->
try
response = func()
if response instanceof Promise
response.then ->
deferred.resolve()
@ -132,7 +133,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()
@ -206,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
@ -226,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()
@ -361,6 +365,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
@ -442,4 +449,24 @@ 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

View file

@ -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

View file

@ -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"

View file

@ -715,6 +715,17 @@ 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')
@ -944,6 +955,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')
@ -983,3 +1002,18 @@ 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')