Compare commits

...

65 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
Edvin Hultberg
8590f5a678
⬆️ 1.17.0 2017-07-29 17:49:40 +02:00
Edvin Hultberg
3283b72394
📝 update changelog 2017-07-29 17:41:38 +02:00
Edvin Hultberg
91f748f85f
fix indenting 2017-07-29 17:40:59 +02:00
Edvin Hultberg
5301f4a5d4 Merge pull request #185 from lloeki/eh-1.19
Support Promise response in trySave
2017-07-29 17:39:11 +02:00
Edvin Hultberg
daddcf8d0f
add editorconfig 2017-07-29 17:38:07 +02:00
Edvin Hultberg
9f1a767fec 📝 update changeling 2017-07-28 14:28:03 +02:00
Edvin Hultberg
afaf152432 Merge pull request #186 from lloeki/eh-ctrl-c
Support Ctrl-C to cancel ex-mode
2017-07-28 14:27:20 +02:00
Edvin Hultberg
26ac7c50b1 Support Ctrl-C to cancel ex-mode 2017-07-27 16:13:48 +02:00
Edvin Hultberg
b5cb054b39 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.
2017-07-27 15:58:50 +02:00
Edvin Hultberg
4747bcf5e8 ⬆️ version 2017-07-27 15:22:18 +02:00
Edvin Hultberg
eb7a23717a Revert back versions, apm publish strugles.. 2017-07-27 15:20:56 +02:00
Edvin Hultberg
f2ee5516e0 Prepare 0.18.0 release 2017-07-27 15:20:06 +02:00
Edvin Hultberg
3dbcf76ff7
Prepare 0.17.0 release 2017-07-27 15:18:20 +02:00
Edvin Hultberg
d0e7afe164
Prepare 0.16.0 release 2017-07-27 15:17:45 +02:00
Edvin Hultberg
78a479bf9b Update CHANGELOG.md 2017-07-27 15:16:12 +02:00
Edvin Hultberg
dfbbdadfbc
📝 update changelog 2017-07-27 15:14:39 +02:00
Edvin Hultberg
516b722f38 Merge pull request #184 from sophaskins/sophaskins-jump-to-line-1.19
use Atom 1.19 buffer API for finding the length of a buffer
2017-07-27 15:11:30 +02:00
Sophie Haskins
abb5cd207f use Atom 1.19 buffer API for finding the length of a buffer 2017-06-29 10:32:17 -04:00
jazzpi
545f13294e Prepare 0.15.0 release 2017-05-25 01:45:07 +02:00
jazzpi
9b62ba70ca Add Changelog for v0.15.0 2017-05-25 01:43:49 +02:00
Jasper v. B
def663b9cc Merge pull request #180 from jazzpi/vim-mode-plus-marks-specs
vim-mode-plus marks & specs
2017-05-25 01:38:12 +02:00
jazzpi
546aa9f95c Use vim-mode-plus in ex-input-spec as well 2017-05-25 01:33:11 +02:00
jazzpi
99dd953370 Use vim-mode-plus on Travis
Also use Linux on Travis because there are more machines available
2017-05-25 01:27:09 +02:00
jazzpi
708aa94eb0 Use vim-mode-plus in specs 2017-05-25 01:08:38 +02:00
jazzpi
02ab74465c Support vim-mode-plus marks 2017-05-25 01:08:21 +02:00
Jasper v. B
ed3417c842 Merge pull request #178 from mkiken/fix-substitute-vim-mode-plus
Support vim-mode-plus substitute command
2017-05-25 01:06:58 +02:00
Jasper v. B
daaf8b3a2d Merge pull request #173 from jmarianer/vim-mode-plus
vim-mode-plus keybinding
2017-05-25 01:05:41 +02:00
mkiken
378cf6cff4 comment refactoring. 2017-03-20 14:07:44 +09:00
mkiken
0abb61fcb8 add consumeVimModePlus. 2017-03-20 14:02:05 +09:00
mkiken
50f1beb1e9 switch searchHistory 2017-03-20 13:49:33 +09:00
mkiken
f4eb1aef7d test package.json change. 2017-03-20 12:03:35 +09:00
jazzpi
28b451f33d Prepare 0.14.0 release 2017-03-15 15:01:12 +01:00
jazzpi
cf3e250ea0 Add changelog for v0.13.1 and v0.14.0 2017-03-15 14:59:12 +01:00
Jasper v. B
26781dc9a4 Merge pull request #177 from jazzpi/fix-x-closing-atom
Fix `:x` closing Atom instead of the current pane
2017-03-15 14:52:36 +01:00
jazzpi
ccf6aa22f8 Fix :x closing Atom instead of the current pane
`x` was being matched with `xall` instead of `xit`, so add an alias.
2017-03-15 14:03:25 +01:00
Jasper v. B
e2c42a6eeb Merge pull request #172 from jmarianer/tabonly
[needs tests] Support :tabonly. Code shamelessly copied from the close-other-tabs extension.
2017-01-19 21:51:01 +01:00
Joey Marianer
ba01f8a1b1 ex-mode supports vim-mode-plus 2017-01-08 17:05:30 -08:00
Joey Marianer
cd80a163cb Support :tabonly. Code shamelessly copied from the close-other-tabs extension. 2017-01-08 14:30:44 -08:00
13 changed files with 276 additions and 43 deletions

9
.editorconfig Normal file
View file

@ -0,0 +1,9 @@
root = true
[*]
end_of_line = lf
insert_final_newline = true
[*.{coffee,json}]
indent_style = space
indent_size = 2

View file

@ -1,13 +1,45 @@
language: objective-c ## Project specific config ###
language: generic
env: env:
- APM_TEST_PACKAGES="vim-mode" global:
- APM_TEST_PACKAGES="vim-mode-plus"
- ATOM_LINT_WITH_BUNDLED_NODE="true"
matrix:
- ATOM_CHANNEL=stable
- ATOM_CHANNEL=beta
os:
- linux
dist: trusty
### 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
notifications: notifications:
email: email:
on_success: never on_success: never
on_failure: change on_failure: change
script: 'curl -s https://raw.githubusercontent.com/atom/ci/master/build-package.sh | sh' branches:
only:
- master
git: git:
depth: 10 depth: 10
sudo: false
addons:
apt:
packages:
- build-essential
- git
- libgnome-keyring-dev
- libsecret-1-dev
- fakeroot

View file

@ -1,3 +1,36 @@
## (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))
## 0.15.0
* `vim-mode-plus` support!
- Add keybinding (@jmarianer)
- Support `:substitute` command (@mkiken)
- Support marks
- Use `vim-mode-plus` in specs
## 0.14.0
* Support `:tabonly` (@jmarianer)
* Fix `:x` closing Atom instead of the current pane
## 0.13.1
* Limit addresses to the last line
* Fix autocompleting a non existent directory (@mcnicholls)
## 0.13.0 ## 0.13.0
* Added basic support for visual marks (e.g. `:'<,'>s/foo/bar`) * Added basic support for visual marks (e.g. `:'<,'>s/foo/bar`)
* Added `smartcase` option to `:set` * Added `smartcase` option to `:set`

33
README.md Normal file → Executable file
View file

@ -4,7 +4,9 @@ ex-mode for Atom's vim-mode
## Use ## Use
Install both [vim-mode](https://github.com/atom/vim-mode) and ex-mode. Type `:` in command mode. Enter `w` or `write`. Install both [vim-mode-plus](https://github.com/t9md/atom-vim-mode-plus) (or
the deprecated `vim-mode`) and ex-mode. Type `:` in command mode. Enter `w` or
`write`.
## Extend ## Extend
@ -28,7 +30,34 @@ atom.packages.onDidActivatePackage (pack) ->
Ex.registerAlias 'Wq', 'wq' 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 ## Status

View file

@ -7,5 +7,10 @@
# For more detailed documentation see # For more detailed documentation see
# https://atom.io/docs/latest/advanced/keymaps # 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)': 'atom-text-editor.vim-mode:not(.insert-mode)':
':': 'ex-mode:open' ':': 'ex-mode:open'

View file

@ -14,7 +14,11 @@ class Command
addr = row addr = row
else if str is '$' else if str is '$'
# Lines are 0-indexed in Atom, but 1-indexed in vim. # 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 ["+", "-"] else if str[0] in ["+", "-"]
addr = row + @parseOffset(str) addr = row + @parseOffset(str)
else if not isNaN(str) else if not isNaN(str)
@ -22,7 +26,7 @@ class Command
else if str[0] is "'" # Parse Mark... else if str[0] is "'" # Parse Mark...
unless @vimState? unless @vimState?
throw new CommandError("Couldn't get access to vim-mode.") throw new CommandError("Couldn't get access to vim-mode.")
mark = @vimState.marks[str[1]] mark = @vimState.mark.marks[str[1]]
unless mark? unless mark?
throw new CommandError("Mark #{str} not set.") throw new CommandError("Mark #{str} not set.")
addr = mark.getEndBufferPosition().row addr = mark.getEndBufferPosition().row
@ -73,7 +77,9 @@ class Command
return return
# Step 4: Address parsing # 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 '%' if cl[0] is '%'
range = [0, lastLine] range = [0, lastLine]
cl = cl[1..] cl = cl[1..]

View file

@ -36,6 +36,9 @@ module.exports = ExMode =
@vim = vim @vim = vim
@globalExState.setVim(vim) @globalExState.setVim(vim)
consumeVimModePlus: (vim) ->
this.consumeVim(vim)
config: config:
splitbelow: splitbelow:
title: 'Split below' title: 'Split below'
@ -47,3 +50,13 @@ module.exports = ExMode =
description: 'when splitting, split from right' description: 'when splitting, split from right'
type: 'boolean' type: 'boolean'
default: 'false' 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

@ -15,7 +15,8 @@ class ExCommandModeInputElement extends HTMLDivElement
@editorContainer.style.height = "0px" @editorContainer.style.height = "0px"
@editorElement = document.createElement "atom-text-editor" @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.getModel().setMini(true)
@editorElement.setAttribute('mini', '') @editorElement.setAttribute('mini', '')
@editorContainer.appendChild(@editorElement) @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:confirm', @confirm.bind(this))
atom.commands.add(@editorElement, 'core:cancel', @cancel.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)) atom.commands.add(@editorElement, 'blur', @cancel.bind(this))
backspace: -> backspace: ->

View file

@ -3,6 +3,7 @@ CommandError = require './command-error'
fs = require 'fs-plus' fs = require 'fs-plus'
VimOption = require './vim-option' VimOption = require './vim-option'
_ = require 'underscore-plus' _ = require 'underscore-plus'
atom
defer = () -> defer = () ->
deferred = {} deferred = {}
@ -17,7 +18,12 @@ trySave = (func) ->
deferred = defer() deferred = defer()
try try
func() response = func()
if response instanceof Promise
response.then ->
deferred.resolve()
else
deferred.resolve() deferred.resolve()
catch error catch error
if error.message.endsWith('is a directory') if error.message.endsWith('is a directory')
@ -127,7 +133,11 @@ class Ex
atom.workspace.getActivePane().destroyActiveItem() atom.workspace.getActivePane().destroyActiveItem()
quitall: -> quitall: ->
if !atom.config.get('ex-mode.onlyCloseBuffers')
atom.close() atom.close()
else
atom.workspace.getTextEditors().forEach (editor) ->
editor.destroy()
q: => @quit() q: => @quit()
@ -163,6 +173,16 @@ class Ex
tabp: => @tabprevious() tabp: => @tabprevious()
tabonly: ->
tabBar = atom.workspace.getPanes()[0]
tabBarElement = atom.views.getView(tabBar).querySelector(".tab-bar")
tabBarElement.querySelector(".right-clicked") && tabBarElement.querySelector(".right-clicked").classList.remove("right-clicked")
tabBarElement.querySelector(".active").classList.add("right-clicked")
atom.commands.dispatch(tabBarElement, 'tabs:close-other-tabs')
tabBarElement.querySelector(".active").classList.remove("right-clicked")
tabo: => @tabonly()
edit: ({ range, args, editor }) -> edit: ({ range, args, editor }) ->
filePath = args.trim() filePath = args.trim()
if filePath[0] is '!' if filePath[0] is '!'
@ -191,9 +211,7 @@ class Ex
e: (args) => @edit(args) e: (args) => @edit(args)
enew: -> enew: ->
buffer = atom.workspace.getActiveTextEditor().buffer atom.workspace.open()
buffer.setPath(undefined)
buffer.load()
write: ({ range, args, editor, saveas }) -> write: ({ range, args, editor, saveas }) ->
saveas ?= false saveas ?= false
@ -211,29 +229,30 @@ class Ex
deferred = defer() deferred = defer()
editor = atom.workspace.getActiveTextEditor() editor = atom.workspace.getActiveTextEditor()
saved = false
# Case 1; path is provided
if filePath.length isnt 0 if filePath.length isnt 0
fullPath = getFullPath(filePath) fullPath = getFullPath filePath
if editor.getPath()? and (not fullPath? or editor.getPath() == fullPath)
if saveas # Only write when it does not exist or we have a force flag set.
throw new CommandError("Argument required") if force or not fs.existsSync(fullPath)
else editor.saveAs(fullPath)
# Use editor.save when no path is given or the path to the file is given return deferred.promise
trySave(-> editor.save()).then(deferred.resolve)
saved = true
else if not fullPath?
fullPath = atom.showSaveDialogSync()
if not saved and fullPath?
if not force and fs.existsSync(fullPath)
throw new CommandError("File exists (add ! to override)") 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)
deferred.promise # 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: -> wall: ->
atom.workspace.saveAll() atom.workspace.saveAll()
@ -242,7 +261,7 @@ class Ex
@write(args) @write(args)
wq: (args) => wq: (args) =>
@write(args).then => @quit() @write(args).then(=> @quit())
wa: => wa: =>
@wall() @wall()
@ -266,6 +285,7 @@ class Ex
xit: (args) => @wq(args) xit: (args) => @wq(args)
x: (args) => @xit(args)
split: ({ range, args }) -> split: ({ range, args }) ->
args = args.trim() args = args.trim()
@ -324,16 +344,30 @@ class Ex
[pattern, substition, flags] = parsed [pattern, substition, flags] = parsed
if pattern is '' if pattern is ''
if vimState.getSearchHistoryItem?
# vim-mode
pattern = vimState.getSearchHistoryItem() pattern = vimState.getSearchHistoryItem()
else if vimState.searchHistory?
# vim-mode-plus
pattern = vimState.searchHistory.get('prev')
if not pattern? if not pattern?
atom.beep() atom.beep()
throw new CommandError('No previous regular expression') throw new CommandError('No previous regular expression')
else else
if vimState.pushSearchHistory?
# vim-mode
vimState.pushSearchHistory(pattern) vimState.pushSearchHistory(pattern)
else if vimState.searchHistory?
# vim-mode-plus
vimState.searchHistory.save(pattern)
try try
flagsObj = {} flagsObj = {}
flags.split('').forEach((flag) -> flagsObj[flag] = true) flags.split('').forEach((flag) -> flagsObj[flag] = true)
# gdefault option
if atom.config.get('ex-mode.gdefault')
flagsObj.g = !flagsObj.g
patternRE = getSearchTerm(pattern, flagsObj) patternRE = getSearchTerm(pattern, flagsObj)
catch e catch e
if e.message.indexOf('Invalid flags supplied to RegExp constructor') is 0 if e.message.indexOf('Invalid flags supplied to RegExp constructor') is 0
@ -415,4 +449,24 @@ class Ex
throw new CommandError("No such option: #{option}") throw new CommandError("No such option: #{option}")
optionProcessor() 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 module.exports = Ex

View file

@ -56,4 +56,10 @@ class VimOption
noscs: => noscs: =>
@nosmartcase() @nosmartcase()
gdefault: =>
atom.config.set("ex-mode.gdefault", true)
nogdefault: =>
atom.config.set("ex-mode.gdefault", false)
module.exports = VimOption module.exports = VimOption

View file

@ -1,7 +1,7 @@
{ {
"name": "ex-mode", "name": "ex-mode",
"main": "./lib/ex-mode", "main": "./lib/ex-mode",
"version": "0.13.1", "version": "0.18.0",
"description": "Ex for Atom's vim-mode", "description": "Ex for Atom's vim-mode",
"activationCommands": { "activationCommands": {
"atom-workspace": "ex-mode:open" "atom-workspace": "ex-mode:open"
@ -23,6 +23,11 @@
"versions": { "versions": {
"^0.1.0": "consumeVim" "^0.1.0": "consumeVim"
} }
},
"vim-mode-plus": {
"versions": {
"^0.1.0": "consumeVimModePlus"
}
} }
}, },
"providedServices": { "providedServices": {

View file

@ -11,7 +11,7 @@ describe "the commands", ->
[editor, editorElement, vimState, exState, dir, dir2] = [] [editor, editorElement, vimState, exState, dir, dir2] = []
projectPath = (fileName) -> path.join(dir, fileName) projectPath = (fileName) -> path.join(dir, fileName)
beforeEach -> beforeEach ->
vimMode = atom.packages.loadPackage('vim-mode') vimMode = atom.packages.loadPackage('vim-mode-plus')
exMode = atom.packages.loadPackage('ex-mode') exMode = atom.packages.loadPackage('ex-mode')
waitsForPromise -> waitsForPromise ->
activationPromise = exMode.activate() activationPromise = exMode.activate()
@ -42,7 +42,6 @@ describe "the commands", ->
editor = editorElement.getModel() editor = editorElement.getModel()
vimState = vimMode.mainModule.getEditorState(editor) vimState = vimMode.mainModule.getEditorState(editor)
exState = exMode.mainModule.exStates.get(editor) exState = exMode.mainModule.exStates.get(editor)
vimState.activateNormalMode()
vimState.resetNormalMode() vimState.resetNormalMode()
editor.setText("abc\ndef\nabc\ndef") editor.setText("abc\ndef\nabc\ndef")
@ -485,6 +484,13 @@ describe "the commands", ->
submitNormalModeInputText('xit') submitNormalModeInputText('xit')
expect(Ex.wq).toHaveBeenCalled() expect(Ex.wq).toHaveBeenCalled()
describe ":x", ->
it "acts as an alias to :xit", ->
spyOn(Ex, 'xit')
openEx()
submitNormalModeInputText('x')
expect(Ex.xit).toHaveBeenCalled()
describe ":wqall", -> describe ":wqall", ->
it "calls :wall, then :quitall", -> it "calls :wall, then :quitall", ->
spyOn(Ex, 'wall') spyOn(Ex, 'wall')
@ -709,6 +715,17 @@ describe "the commands", ->
submitNormalModeInputText(':%substitute/abc/ghi/ig') submitNormalModeInputText(':%substitute/abc/ghi/ig')
expect(editor.getText()).toEqual('ghiaghi\ndefdDEF\nghiaghi') 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", -> describe ":yank", ->
beforeEach -> beforeEach ->
editor.setText('abc\ndef\nghi\njkl') editor.setText('abc\ndef\nghi\njkl')
@ -938,6 +955,14 @@ describe "the commands", ->
submitNormalModeInputText(':set nosmartcase') submitNormalModeInputText(':set nosmartcase')
expect(atom.config.get('vim-mode.useSmartcaseForSearch')).toBe(false) 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", -> describe "aliases", ->
it "calls the aliased function without arguments", -> it "calls the aliased function without arguments", ->
ExClass.registerAlias('W', 'w') ExClass.registerAlias('W', 'w')
@ -977,3 +1002,18 @@ describe "the commands", ->
expect(calls.length).toEqual 2 expect(calls.length).toEqual 2
expect(calls[0].args[0].range).toEqual [0, 2] expect(calls[0].args[0].range).toEqual [0, 2]
expect(calls[1].args[0].range).toEqual [3, 3] 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')

View file

@ -2,7 +2,7 @@ helpers = require './spec-helper'
describe "the input element", -> describe "the input element", ->
[editor, editorElement, vimState, exState] = [] [editor, editorElement, vimState, exState] = []
beforeEach -> beforeEach ->
vimMode = atom.packages.loadPackage('vim-mode') vimMode = atom.packages.loadPackage('vim-mode-plus')
exMode = atom.packages.loadPackage('ex-mode') exMode = atom.packages.loadPackage('ex-mode')
waitsForPromise -> waitsForPromise ->
activationPromise = exMode.activate() activationPromise = exMode.activate()
@ -26,7 +26,6 @@ describe "the input element", ->
atom.commands.dispatch(getCommandEditor(), "core:cancel") atom.commands.dispatch(getCommandEditor(), "core:cancel")
vimState = vimMode.mainModule.getEditorState(editor) vimState = vimMode.mainModule.getEditorState(editor)
exState = exMode.mainModule.exStates.get(editor) exState = exMode.mainModule.exStates.get(editor)
vimState.activateNormalMode()
vimState.resetNormalMode() vimState.resetNormalMode()
editor.setText("abc\ndef\nabc\ndef") editor.setText("abc\ndef\nabc\ndef")